Просмотр исходного кода

Added AHT10 sensor. Fixed incorrect I2C address editing

Victor 3 лет назад
Родитель
Сommit
8b8932cf14
5 измененных файлов с 28 добавлено и 11 удалено
  1. 3 2
      Sensors.c
  2. 13 3
      sensors/DHT20.c
  3. 1 0
      sensors/DHT20.h
  4. 2 1
      views/General_view.c
  5. 9 5
      views/SensorEdit_view.c

+ 3 - 2
Sensors.c

@@ -77,12 +77,13 @@ static const SensorType* sensorTypes[] = {
     &DHT20,
     &DHT21,
     &DHT22,
+    &Dallas,
     &AM2320_SW,
     &AM2320_I2C,
+    &AHT10,
     &LM75,
     &BMP280,
-    &BME280,
-    &Dallas};
+    &BME280};
 
 const SensorType* unitemp_sensors_getTypeFromInt(uint8_t index) {
     if(index > SENSOR_TYPES_COUNT) return NULL;

+ 13 - 3
sensors/DHT20.c

@@ -23,7 +23,17 @@ const SensorType DHT20 = {
     .altname = "DHT20/AM2108/AHT20",
     .interface = &I2C,
     .datatype = UT_TEMPERATURE | UT_HUMIDITY,
-    .pollingInterval = 2000,
+    .pollingInterval = 1000,
+    .allocator = unitemp_DHT20_I2C_alloc,
+    .mem_releaser = unitemp_DHT20_I2C_free,
+    .initializer = unitemp_DHT20_init,
+    .deinitializer = unitemp_DHT20_I2C_deinit,
+    .updater = unitemp_DHT20_I2C_update};
+const SensorType AHT10 = {
+    .typename = "AHT10",
+    .interface = &I2C,
+    .datatype = UT_TEMPERATURE | UT_HUMIDITY,
+    .pollingInterval = 1000,
     .allocator = unitemp_DHT20_I2C_alloc,
     .mem_releaser = unitemp_DHT20_I2C_free,
     .initializer = unitemp_DHT20_init,
@@ -73,7 +83,7 @@ bool unitemp_DHT20_I2C_alloc(Sensor* sensor, char* args) {
 
     //Адреса на шине I2C (7 бит)
     i2c_sensor->minI2CAdr = 0x38 << 1;
-    i2c_sensor->maxI2CAdr = 0x38 << 1;
+    i2c_sensor->maxI2CAdr = (sensor->type == &DHT20) ? (0x38 << 1) : (0x39 << 1);
     return true;
 }
 
@@ -89,7 +99,7 @@ bool unitemp_DHT20_init(Sensor* sensor) {
     uint8_t data[3] = {0xA8, 0x00, 0x00};
     if(!unitemp_i2c_writeArray(i2c_sensor, 3, data)) return false;
     furi_delay_ms(10);
-    data[0] = 0xBE;
+    data[0] = (sensor->type == &DHT20) ? 0xBE : 0xE1;
     data[1] = 0x08;
     if(!unitemp_i2c_writeArray(i2c_sensor, 3, data)) return false;
     furi_delay_ms(10);

+ 1 - 0
sensors/DHT20.h

@@ -21,6 +21,7 @@
 #include "../unitemp.h"
 #include "../Sensors.h"
 extern const SensorType DHT20;
+extern const SensorType AHT10;
 /**
  * @brief Выделение памяти и установка начальных значений датчика DHT20
  *

+ 2 - 1
views/General_view.c

@@ -362,7 +362,8 @@ static void _draw_carousel_info(Canvas* canvas) {
             BUFF_SIZE,
             "0x%02X",
             ((I2CSensor*)unitemp_sensor_getActive(generalview_sensor_index)->instance)
-                ->currentI2CAdr);
+                    ->currentI2CAdr >>
+                1);
         canvas_draw_str(canvas, 57, 35, app->buff);
         canvas_draw_str(canvas, 54, 46, "15 (C0)");
         canvas_draw_str(canvas, 54, 58, "16 (C1)");

+ 9 - 5
views/SensorEdit_view.c

@@ -214,9 +214,9 @@ static void _gpio_change_callback(VariableItem* item) {
 static void _i2caddr_change_callback(VariableItem* item) {
     uint8_t index = variable_item_get_current_value_index(item);
     ((I2CSensor*)editable_sensor->instance)->currentI2CAdr =
-        ((I2CSensor*)editable_sensor->instance)->minI2CAdr + index;
+        ((I2CSensor*)editable_sensor->instance)->minI2CAdr + index * 2;
     char buff[5];
-    snprintf(buff, 5, "0x%2X", ((I2CSensor*)editable_sensor->instance)->currentI2CAdr);
+    snprintf(buff, 5, "0x%2X", ((I2CSensor*)editable_sensor->instance)->currentI2CAdr >> 1);
     variable_item_set_current_value_text(item, buff);
 }
 /**
@@ -335,11 +335,15 @@ void unitemp_SensorEdit_switch(Sensor* sensor) {
         VariableItem* item = variable_item_list_add(
             variable_item_list,
             "I2C address",
-            ((I2CSensor*)sensor->instance)->maxI2CAdr - ((I2CSensor*)sensor->instance)->minI2CAdr +
-                1,
+            (((I2CSensor*)sensor->instance)->maxI2CAdr >> 1) -
+                (((I2CSensor*)sensor->instance)->minI2CAdr >> 1) + 1,
             _i2caddr_change_callback,
             app);
-        snprintf(app->buff, 5, "0x%2X", ((I2CSensor*)sensor->instance)->currentI2CAdr);
+        snprintf(app->buff, 5, "0x%2X", ((I2CSensor*)sensor->instance)->currentI2CAdr >> 1);
+        variable_item_set_current_value_index(
+            item,
+            (((I2CSensor*)sensor->instance)->currentI2CAdr >> 1) -
+                (((I2CSensor*)sensor->instance)->minI2CAdr >> 1));
         variable_item_set_current_value_text(item, app->buff);
     }