Виктор Никитчук 3 лет назад
Родитель
Сommit
7f78119e6c
8 измененных файлов с 26 добавлено и 4 удалено
  1. 1 0
      Sensors.c
  2. 13 0
      interfaces/I2CSensor.c
  3. 2 2
      unitemp.c
  4. 1 0
      unitemp.h
  5. 2 0
      views/MainMenu_view.c
  6. 2 1
      views/SensorEdit_view.c
  7. 1 1
      views/SensorsList_view.c
  8. 4 0
      views/Summary_view.c

+ 1 - 0
Sensors.c

@@ -428,6 +428,7 @@ bool unitemp_sensors_init(void) {
         }
         FURI_LOG_D(APP_NAME, "Sensor %s successfully initialized", app->sensors[i]->name);
     }
+    app->sensors_ready = true;
     return result;
 }
 

+ 13 - 0
interfaces/I2CSensor.c

@@ -1,6 +1,8 @@
 #include "I2CSensor.h"
 #include "../sensors/SensorsDriver.h"
 
+static uint8_t sensors_count = 0;
+
 uint8_t readReg(I2CSensor* i2c_sensor, uint8_t reg) {
     //Блокировка шины
     furi_hal_i2c_acquire(i2c_sensor->i2c);
@@ -46,12 +48,23 @@ bool unitemp_I2C_sensor_alloc(Sensor* sensor, uint8_t* anotherValues) {
     } else {
         instance->currentI2CAdr = instance->minI2CAdr;
     }
+
+    //Блокировка портов GPIO
+    sensors_count++;
+    unitemp_gpio_lock(unitemp_GPIO_getFromInt(15), &I2C);
+    unitemp_gpio_lock(unitemp_GPIO_getFromInt(16), &I2C);
+
     return status;
 }
 
 bool unitemp_I2C_sensor_free(Sensor* sensor) {
     bool status = sensor->type->mem_releaser(sensor);
     free(sensor->instance);
+    if(--sensors_count == 0) {
+        unitemp_gpio_unlock(unitemp_GPIO_getFromInt(15));
+        unitemp_gpio_unlock(unitemp_GPIO_getFromInt(16));
+    }
+
     return status;
 }
 

+ 2 - 2
unitemp.c

@@ -241,10 +241,10 @@ int32_t unitemp_app() {
     //Инициализация датчиков
     unitemp_sensors_init();
 
-    view_dispatcher_switch_to_view(app->view_dispatcher, SUMMARY_VIEW);
+    unitemp_Summary_switch();
 
     while(app->processing) {
-        unitemp_sensors_updateValues();
+        if(app->sensors_ready) unitemp_sensors_updateValues();
         furi_delay_ms(100);
     }
 

+ 1 - 0
unitemp.h

@@ -49,6 +49,7 @@ typedef struct {
 typedef struct {
     //Система
     bool processing; //Флаг работы приложения. При ложном значении приложение закрывается
+    bool sensors_ready; //Флаг готовности датчиков к опросу
     //Основные настройки
     UnitempSettings settings;
     //Список указателей на датчики

+ 2 - 0
views/MainMenu_view.c

@@ -28,6 +28,8 @@ static uint32_t _exit_callback(void* context) {
 static void _enter_callback(void* context, uint32_t index) {
     UNUSED(context);
     if(index == 0) { //add new sensor
+        //TODO: сообщение о максимальном количестве датчиков
+        if(app->sensors_count >= MAX_SENSORS) return;
         unitemp_SensorsList_switch();
     }
     if(index == 1) { //Settings

+ 2 - 1
views/SensorEdit_view.c

@@ -24,7 +24,7 @@ VariableItem* sensor_name_item;
  */
 static uint32_t _exit_callback(void* context) {
     UNUSED(context);
-
+    unitemp_sensor_free(editable_sensor);
     //Возврат предыдущий вид
     return MAINMENU_VIEW;
 }
@@ -45,6 +45,7 @@ static void _enter_callback(void* context, uint32_t index) {
         app->sensors[app->sensors_count++] = editable_sensor;
         unitemp_sensors_save();
         unitemp_sensors_reload();
+
         unitemp_Summary_switch();
     }
 }

+ 1 - 1
views/SensorsList_view.c

@@ -31,7 +31,7 @@ static void _enter_callback(void* context, uint32_t index) {
     UNUSED(context);
     //Имя датчка
     char sensor_name[11];
-    snprintf(sensor_name, 11, "Sensor_%d", app->sensors_count + 1);
+    snprintf(sensor_name, 11, "Sensor%d", app->sensors_count + 1);
     const SensorType* st = unitemp_getSensorsTypes()[index];
     uint8_t anotherValues[1] = {0};
     //Выбор первого доступного порта для датчиков single wire и one wire

+ 4 - 0
views/Summary_view.c

@@ -5,6 +5,8 @@ static View* view;
 static void _draw_callback(Canvas* canvas, void* _model) {
     UNUSED(_model);
 
+    app->sensors_ready = true;
+
     //Рисование бара
     canvas_draw_box(canvas, 0, 0, 128, 14);
     canvas_set_color(canvas, ColorWhite);
@@ -52,6 +54,7 @@ static bool _input_callback(InputEvent* event, void* context) {
     }
     //Вход в главное меню по короткому нажатию "Ок"
     if(event->key == InputKeyOk && event->type == InputTypeShort) {
+        app->sensors_ready = false;
         unitemp_MainMenu_switch();
     }
 
@@ -68,6 +71,7 @@ void unitemp_Summary_alloc(void) {
 }
 
 void unitemp_Summary_switch(void) {
+    app->sensors_ready = true;
     view_dispatcher_switch_to_view(app->view_dispatcher, SUMMARY_VIEW);
 }