Update exanh v04 sensors support master
authorNathael Pajani <nathael.pajani@ed3l.fr>
Wed, 18 Aug 2021 08:21:55 +0000 (10:21 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Wed, 18 Aug 2021 08:21:55 +0000 (10:21 +0200)
apps/exanh/v04/main.c

index 2cd6205..e7b3a34 100644 (file)
@@ -255,7 +255,7 @@ void serial_req(uint8_t c)
                        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;
@@ -319,6 +319,8 @@ void button_request(uint32_t gpio)
                need_config = 1;
        }
 }
+
+
 /***************************************************************************** */
 int main(void)
 {
@@ -485,20 +487,11 @@ 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);
@@ -509,11 +502,16 @@ int main(void)
                                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();
@@ -521,6 +519,18 @@ int main(void)
                                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));
+
                }
        }