Przeglądaj źródła

Added values print selector in sensors carousel

Victor 3 lat temu
rodzic
commit
62484c426f
7 zmienionych plików z 44 dodań i 5 usunięć
  1. 15 0
      Sensors.h
  2. 1 0
      interfaces/OneWireSensor.c
  3. 6 1
      interfaces/SingleWireSensor.c
  4. 1 0
      sensors/BMP280.c
  5. 1 0
      sensors/LM75.c
  6. 1 0
      unitemp.c
  7. 19 4
      views/General_view.c

+ 15 - 0
Sensors.h

@@ -3,7 +3,20 @@
 #include <furi.h>
 #include <input/input.h>
 
+//Маски бит для определения типов возвращаемых значений
+#define UT_TEMPERATURE 0b00000001
+#define UT_HUMIDITY 0b00000010
+#define UT_PRESSURE 0b00000100
+
 //Статусы опроса датчика
+typedef enum {
+    UT_DATA_TYPE_TEMP = UT_TEMPERATURE,
+    UT_DATA_TYPE_TEMP_HUM = UT_TEMPERATURE | UT_HUMIDITY,
+    UT_DATA_TYPE_TEMP_PRESS = UT_TEMPERATURE | UT_PRESSURE,
+    UT_DATA_TYPE_TEMP_HUM_PRESS = UT_TEMPERATURE | UT_HUMIDITY | UT_PRESSURE,
+} SensorDataType;
+
+//Типы возвращаемых данных
 typedef enum {
     UT_OK, //Всё хорошо, опрос успешен
     UT_TIMEOUT, //Датчик не отозвался
@@ -59,6 +72,8 @@ typedef struct Interface {
 typedef struct {
     //Имя типа датчика
     const char* typename;
+    //Тип возвращаемых данных
+    SensorDataType datatype;
     //Интерфейс подключения
     const Interface* interface;
     //Интервал опроса датчика

+ 1 - 0
interfaces/OneWireSensor.c

@@ -8,6 +8,7 @@
 const SensorType DS18x2x = {
     .typename = "DS18x2x",
     .interface = &ONE_WIRE,
+    .datatype = UT_DATA_TYPE_TEMP,
     .pollingInterval = 250,
     .allocator = unitemp_onewire_sensor_alloc,
     .mem_releaser = unitemp_onewire_sensor_free,

+ 6 - 1
interfaces/SingleWireSensor.c

@@ -7,6 +7,7 @@
 const SensorType DHT11 = {
     .typename = "DHT11",
     .interface = &SINGLE_WIRE,
+    .datatype = UT_DATA_TYPE_TEMP_HUM,
     .pollingInterval = 2000,
     .allocator = unitemp_singlewire_alloc,
     .mem_releaser = unitemp_singlewire_free,
@@ -16,6 +17,7 @@ const SensorType DHT11 = {
 const SensorType DHT12_SW = {
     .typename = "DHT12",
     .interface = &SINGLE_WIRE,
+    .datatype = UT_DATA_TYPE_TEMP_HUM,
     .pollingInterval = 2000,
     .allocator = unitemp_singlewire_alloc,
     .mem_releaser = unitemp_singlewire_free,
@@ -25,7 +27,8 @@ const SensorType DHT12_SW = {
 const SensorType DHT21 = {
     .typename = "DHT21",
     .interface = &SINGLE_WIRE,
-    .pollingInterval = 2000,
+    .datatype = UT_DATA_TYPE_TEMP_HUM,
+    .pollingInterval = 1000,
     .allocator = unitemp_singlewire_alloc,
     .mem_releaser = unitemp_singlewire_free,
     .initializer = unitemp_singlewire_init,
@@ -34,6 +37,7 @@ const SensorType DHT21 = {
 const SensorType DHT22 = {
     .typename = "DHT22",
     .interface = &SINGLE_WIRE,
+    .datatype = UT_DATA_TYPE_TEMP_HUM,
     .pollingInterval = 2000,
     .allocator = unitemp_singlewire_alloc,
     .mem_releaser = unitemp_singlewire_free,
@@ -43,6 +47,7 @@ const SensorType DHT22 = {
 const SensorType AM2320_SW = {
     .typename = "AM2320",
     .interface = &SINGLE_WIRE,
+    .datatype = UT_DATA_TYPE_TEMP_HUM,
     .pollingInterval = 2000,
     .allocator = unitemp_singlewire_alloc,
     .mem_releaser = unitemp_singlewire_free,

+ 1 - 0
sensors/BMP280.c

@@ -3,6 +3,7 @@
 const SensorType BMP280 = {
     .typename = "BMP280",
     .interface = &I2C,
+    .datatype = UT_DATA_TYPE_TEMP_PRESS,
     .pollingInterval = 500,
     .allocator = unitemp_BMP280_alloc,
     .mem_releaser = unitemp_BMP280_free,

+ 1 - 0
sensors/LM75.c

@@ -17,6 +17,7 @@
 const SensorType LM75 = {
     .typename = "LM75",
     .interface = &I2C,
+    .datatype = UT_DATA_TYPE_TEMP,
     .pollingInterval = 500,
     .allocator = unitemp_LM75_alloc,
     .mem_releaser = unitemp_LM75_free,

+ 1 - 0
unitemp.c

@@ -8,6 +8,7 @@
 
 //TODO: Реализовать ограничение на добавление датчиков если интерфейс недоступен
 //TODO: Не выкидывать датчик в ошибку при первом же неудачном опросе
+//TODO: Исправить зависание BMP280
 
 /* Переменные */
 //Данные приложения

+ 19 - 4
views/General_view.c

@@ -157,10 +157,25 @@ static void _draw_sensorsCarousel(Canvas* canvas) {
         canvas_draw_icon(canvas, 64 - line_len / 2 - 8, 3, &I_arrow_left_5x9);
     }
 
-    //Печать значения температуры
-    _draw_temp(canvas, app->sensors[sensor_index]->temp, 1);
-    //_draw_hum(canvas, app->sensors[sensor_index]->hum, 1);
-    _draw_press(canvas, app->sensors[sensor_index]->pressure);
+    //Селектор значений для отображения
+    switch(app->sensors[sensor_index]->type->datatype) {
+    case UT_DATA_TYPE_TEMP:
+        _draw_temp(canvas, app->sensors[sensor_index]->temp, 0);
+        break;
+    case UT_DATA_TYPE_TEMP_HUM:
+        _draw_temp(canvas, app->sensors[sensor_index]->temp, 1);
+        _draw_hum(canvas, app->sensors[sensor_index]->hum, 0);
+        break;
+    case UT_DATA_TYPE_TEMP_PRESS:
+        _draw_temp(canvas, app->sensors[sensor_index]->temp, 1);
+        _draw_press(canvas, app->sensors[sensor_index]->pressure);
+        break;
+    case UT_DATA_TYPE_TEMP_HUM_PRESS:
+        _draw_temp(canvas, app->sensors[sensor_index]->temp, 2);
+        _draw_hum(canvas, app->sensors[sensor_index]->hum, 1);
+        _draw_press(canvas, app->sensors[sensor_index]->pressure);
+        break;
+    }
 }
 
 static void _draw_callback(Canvas* canvas, void* _model) {