break;
case ADDRESSSED:
- if ((address == 0) & (addr_req == 1)) {
+ if ((address == 0) && (addr_req == 1)) {
/* We received our address, store it */
address = c;
store_address = 1;
need_config = 1;
}
}
+
+
/***************************************************************************** */
int main(void)
{
humidity = bme280_compensate_humidity(&bme280_sensor, humidity) / 10;
}
- /* Display all */
- debug(1, "Sensor %d:\n\tSoil: %d\n", address, raw_humidity);
- debug(1, "\tLux: %d, IR: %d, UV: %d\n", lux, ir, uv);
- debug(1, "\tPatm: %d hPa, Temp: %d,%02d degC, Humidity: %d,%d rH\n\n",
- pressure,
- comp_temp / 10, (comp_temp > 0) ? (comp_temp % 10) : ((-comp_temp) % 10),
- humidity / 10, humidity % 10);
-
- set_led(0, 0, ((raw_humidity >> 6) & 0xFF));
-
/* Send for control */
if (1) {
char buff[20];
uint16_t* data = (uint16_t*)buff;
+ int i = 0, sum = 0;
memset(buff, 0, 20);
buff[0] = '#';
buff[1] = address | (got_tsl << 5) | (got_veml << 6) | (got_bme << 7);
data[5] = (uint16_t)htons(pressure);
data[6] = (uint16_t)htons(comp_temp);
data[7] = (uint16_t)htons(humidity);
-
+ /* Compute checksum */
+ for (i = 0; i < 19; i++) {
+ sum += buff[i];
+ }
+ buff[19] = (uint8_t)(sum & 0xFF);
serial_flush(UART0);
/* Do not place any of the following instructions before the flush end */
isb();
gpio_clear(tx_en);
+ msleep(3);
serial_write(UART0, buff, 20);
/* And wait for fush end before relaesing the line */
isb();
isb();
gpio_set(tx_en);
}
+
+ /* Display all */
+ if(0) {
+ debug(1, "Sensor %d:\n\tSoil: %d\n", address, raw_humidity);
+ debug(1, "\tLux: %d, IR: %d, UV: %d\n", lux, ir, uv);
+ debug(1, "\tPatm: %d hPa, Temp: %d,%02d degC, Humidity: %d,%d rH\n\n",
+ pressure,
+ comp_temp / 10, (comp_temp > 0) ? (comp_temp % 10) : ((-comp_temp) % 10),
+ humidity / 10, humidity % 10);
+ }
+ set_led(0, 0, ((raw_humidity >> 6) & 0xFF));
+
}
}