Browse Source

Added sensors list view

Виктор Никитчук 3 years ago
parent
commit
650b7beba2
8 changed files with 110 additions and 3 deletions
  1. 7 0
      Sensors.c
  2. 12 0
      Sensors.h
  3. 2 2
      interfaces/SingleWireSensor.c
  4. 2 0
      unitemp.c
  5. 1 0
      views/MainMenu_view.c
  6. 79 0
      views/SensorsList_view.c
  7. 1 1
      views/Settings_view.c
  8. 6 0
      views/UnitempViews.h

+ 7 - 0
Sensors.c

@@ -62,6 +62,13 @@ const SensorType* unitemp_getTypeFromInt(int type) {
     return sensorTypes[type];
 }
 
+uint8_t unitemp_getSensorsTypesCount(void) {
+    return SENSOR_TYPES_COUNT;
+}
+const SensorType** unitemp_getSensorsTypes(void) {
+    return sensorTypes;
+}
+
 int unitemp_getIntFromType(const SensorType* type) {
     for(int i = 0; i < SENSOR_TYPES_COUNT; i++) {
         if(!strcmp(type->typename, sensorTypes[i]->typename)) {

+ 12 - 0
Sensors.h

@@ -96,6 +96,18 @@ extern const Interface ONE_WIRE; //Однопроводной протокол D
 extern const Interface I2C; //I2C_2 (PC0, PC1)
 //extern const Interface SPI;
 
+/**
+* @brief Получить количество доступных типов датчиков
+* @return Количество доступных типов датчиков
+*/
+uint8_t unitemp_getSensorsTypesCount(void);
+
+/**
+* @brief Получить списк доступных типов датчиков
+* @return Указатель на список датчиков
+*/
+const SensorType** unitemp_getSensorsTypes(void);
+
 /**
  * @brief Конвертация номера порта на корпусе FZ в GPIO 
  * 

+ 2 - 2
interfaces/SingleWireSensor.c

@@ -17,7 +17,7 @@ const SensorType DHT11 = {
     .deinitializer = unitemp_singleWire_deinit,
     .updater = unitemp_singleWire_update};
 const SensorType DHT12_SW = {
-    .typename = "DHT12 (1 Wire)",
+    .typename = "DHT12 (single wire)",
     .interface = &SINGLE_WIRE,
     .pollingInterval = 2000,
     .allocator = unitemp_singleWire_alloc,
@@ -45,7 +45,7 @@ const SensorType DHT22 = {
     .deinitializer = unitemp_singleWire_deinit,
     .updater = unitemp_singleWire_update};
 const SensorType AM2320_SW = {
-    .typename = "AM2320 (1 Wire)",
+    .typename = "AM2320 (single wire)",
     .interface = &SINGLE_WIRE,
     .pollingInterval = 2000,
     .allocator = unitemp_singleWire_alloc,

+ 2 - 0
unitemp.c

@@ -190,6 +190,7 @@ static bool unitemp_alloc(void) {
     unitemp_Summary_alloc();
     unitemp_MainMenu_alloc();
     unitemp_Settings_alloc();
+    unitemp_SensorsList_alloc();
 
     view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
 
@@ -203,6 +204,7 @@ static void unitemp_free(void) {
     //Автоматическое управление подсветкой
     notification_message(app->notifications, &sequence_display_backlight_enforce_auto);
 
+    unitemp_SensorsList_free();
     unitemp_Settings_free();
     unitemp_MainMenu_free();
     unitemp_Summary_free();

+ 1 - 0
views/MainMenu_view.c

@@ -28,6 +28,7 @@ static uint32_t _exit_callback(void* context) {
 static void _enter_callback(void* context, uint32_t index) {
     UNUSED(context);
     if(index == 0) { //add new sensor
+        unitemp_SensorsList_switch();
     }
     if(index == 1) { //Settings
         unitemp_Settings_switch();

+ 79 - 0
views/SensorsList_view.c

@@ -0,0 +1,79 @@
+#include "UnitempViews.h"
+#include <gui/modules/variable_item_list.h>
+
+//Текущий вид
+static View* view;
+//Список
+static VariableItemList* variable_item_list;
+
+#define VIEW_ID SENSORSLIST_VIEW
+
+/**
+ * @brief Функция обработки нажатия кнопки "Назад"
+ *
+ * @param context Указатель на данные приложения
+ * @return ID вида в который нужно переключиться
+ */
+static uint32_t _exit_callback(void* context) {
+    UNUSED(context);
+
+    //Возврат предыдущий вид
+    return MAINMENU_VIEW;
+}
+/**
+ * @brief Функция обработки нажатия средней кнопки
+ *
+ * @param context Указатель на данные приложения
+ * @param index На каком элементе списка была нажата кнопка
+ */
+static void _enter_callback(void* context, uint32_t index) {
+    UNUSED(context);
+    UNUSED(index);
+}
+
+/**
+ * @brief Создание меню редактирования настроек
+ */
+void unitemp_SensorsList_alloc(void) {
+    variable_item_list = variable_item_list_alloc();
+    //Сброс всех элементов меню
+    variable_item_list_reset(variable_item_list);
+
+    //Добавление в список доступных датчиков
+    for(uint8_t i = 0; i < unitemp_getSensorsTypesCount(); i++) {
+        variable_item_list_add(
+            variable_item_list, unitemp_getSensorsTypes()[i]->typename, 1, NULL, app);
+    }
+
+    //Добавление колбека на нажатие средней кнопки
+    variable_item_list_set_enter_callback(variable_item_list, _enter_callback, app);
+
+    //Создание вида из списка
+    view = variable_item_list_get_view(variable_item_list);
+    //Добавление колбека на нажатие кнопки "Назад"
+    view_set_previous_callback(view, _exit_callback);
+    //Добавление вида в диспетчер
+    view_dispatcher_add_view(app->view_dispatcher, VIEW_ID, view);
+}
+
+void unitemp_SensorsList_switch(void) {
+    //Обнуление последнего выбранного пункта
+    variable_item_list_set_selected_item(variable_item_list, 0);
+
+    // variable_item_set_current_value_index(
+    //     infinity_backlight_item, (uint8_t)app->SensorsList.infinityBacklight);
+    // variable_item_set_current_value_text(
+    //     infinity_backlight_item,
+    //     states[variable_item_get_current_value_index(infinity_backlight_item)]);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID);
+}
+
+void unitemp_SensorsList_free(void) {
+    //Очистка списка элементов
+    variable_item_list_free(variable_item_list);
+    //Очистка вида
+    view_free(view);
+    //Удаление вида после обработки
+    view_dispatcher_remove_view(app->view_dispatcher, VIEW_ID);
+}

+ 1 - 1
views/Settings_view.c

@@ -43,7 +43,7 @@ static void _enter_callback(void* context, uint32_t index) {
     UNUSED(index);
 }
 
-void _setting_change_callback(VariableItem* item) {
+static void _setting_change_callback(VariableItem* item) {
     if(item == infinity_backlight_item) {
         variable_item_set_current_value_text(
             infinity_backlight_item,

+ 6 - 0
views/UnitempViews.h

@@ -8,6 +8,7 @@ typedef enum UnitempViews {
     SUMMARY_VIEW,
     MAINMENU_VIEW,
     SETTINGS_VIEW,
+    SENSORSLIST_VIEW,
 
     VIEWS_COUNT
 } UnitempViews;
@@ -25,4 +26,9 @@ void unitemp_MainMenu_free(void);
 void unitemp_Settings_alloc(void);
 void unitemp_Settings_switch(void);
 void unitemp_Settings_free(void);
+
+/* Список датчиков */
+void unitemp_SensorsList_alloc(void);
+void unitemp_SensorsList_switch(void);
+void unitemp_SensorsList_free(void);
 #endif