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

Added the ability to edit the name of the sensor

Виктор Никитчук 3 лет назад
Родитель
Сommit
beb0481d76
4 измененных файлов с 39 добавлено и 2 удалено
  1. 2 0
      unitemp.c
  2. 2 2
      views/SensorEdit_view.c
  3. 29 0
      views/SensorNameEdit_view.c
  4. 6 0
      views/UnitempViews.h

+ 2 - 0
unitemp.c

@@ -183,6 +183,7 @@ static bool unitemp_alloc(void) {
     unitemp_Settings_alloc();
     unitemp_Settings_alloc();
     unitemp_SensorsList_alloc();
     unitemp_SensorsList_alloc();
     unitemp_SensorEdit_alloc();
     unitemp_SensorEdit_alloc();
+    unitemp_SensorNameEdit_alloc();
 
 
     view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
     view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
 
 
@@ -193,6 +194,7 @@ static bool unitemp_alloc(void) {
  * @brief Освыбождение памяти после работы приложения
  * @brief Освыбождение памяти после работы приложения
  */
  */
 static void unitemp_free(void) {
 static void unitemp_free(void) {
+    unitemp_SensorNameEdit_free();
     unitemp_SensorEdit_free();
     unitemp_SensorEdit_free();
     unitemp_SensorsList_free();
     unitemp_SensorsList_free();
     unitemp_Settings_free();
     unitemp_Settings_free();

+ 2 - 2
views/SensorEdit_view.c

@@ -10,7 +10,7 @@ static View* view;
 //Список
 //Список
 static VariableItemList* variable_item_list;
 static VariableItemList* variable_item_list;
 //Текущий редактируемый датчик
 //Текущий редактируемый датчик
-Sensor* editable_sensor;
+static Sensor* editable_sensor;
 
 
 //Элемент списка - имя датчика
 //Элемент списка - имя датчика
 VariableItem* sensor_name_item;
 VariableItem* sensor_name_item;
@@ -38,7 +38,7 @@ static void _enter_callback(void* context, uint32_t index) {
     UNUSED(context);
     UNUSED(context);
     //Смена имени
     //Смена имени
     if(index == 0) {
     if(index == 0) {
-        //
+        unitemp_SensorNameEdit_switch(editable_sensor);
     }
     }
     //Сохранение
     //Сохранение
     if(index == 3) {
     if(index == 3) {

+ 29 - 0
views/SensorNameEdit_view.c

@@ -0,0 +1,29 @@
+#include "UnitempViews.h"
+#include <gui/modules/text_input.h>
+
+//Окно ввода текста
+static TextInput* text_input;
+//Текущий редактируемый датчик
+static Sensor* editable_sensor;
+
+#define VIEW_ID SENSORNAMEEDIT_VIEW
+
+static void _sensor_name_changed_callback(void* context) {
+    UNUSED(context);
+    unitemp_SensorEdit_switch(editable_sensor);
+}
+
+void unitemp_SensorNameEdit_alloc(void) {
+    text_input = text_input_alloc();
+    view_dispatcher_add_view(app->view_dispatcher, VIEW_ID, text_input_get_view(text_input));
+    text_input_set_header_text(text_input, "Sensor name");
+}
+void unitemp_SensorNameEdit_switch(Sensor* sensor) {
+    editable_sensor = sensor;
+    text_input_set_result_callback(
+        text_input, _sensor_name_changed_callback, app, sensor->name, 11, true);
+    view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID);
+}
+void unitemp_SensorNameEdit_free(void) {
+    text_input_free(text_input);
+}

+ 6 - 0
views/UnitempViews.h

@@ -10,6 +10,7 @@ typedef enum UnitempViews {
     SETTINGS_VIEW,
     SETTINGS_VIEW,
     SENSORSLIST_VIEW,
     SENSORSLIST_VIEW,
     SENSOREDIT_VIEW,
     SENSOREDIT_VIEW,
+    SENSORNAMEEDIT_VIEW,
 
 
     VIEWS_COUNT
     VIEWS_COUNT
 } UnitempViews;
 } UnitempViews;
@@ -39,4 +40,9 @@ void unitemp_SensorEdit_alloc(void);
 //sensor - указатель на редактируемый датчик
 //sensor - указатель на редактируемый датчик
 void unitemp_SensorEdit_switch(Sensor* sensor);
 void unitemp_SensorEdit_switch(Sensor* sensor);
 void unitemp_SensorEdit_free(void);
 void unitemp_SensorEdit_free(void);
+
+/* Редактор имени датчика */
+void unitemp_SensorNameEdit_alloc(void);
+void unitemp_SensorNameEdit_switch(Sensor* sensor);
+void unitemp_SensorNameEdit_free(void);
 #endif
 #endif