Parcourir la source

Added saving sensors to SD card in the add sensors menu

Виктор Никитчук il y a 3 ans
Parent
commit
a8d727a6cf
7 fichiers modifiés avec 30 ajouts et 3 suppressions
  1. 8 0
      Sensors.c
  2. 4 0
      Sensors.h
  3. 1 1
      unitemp.c
  4. 11 1
      views/SensorEdit_view.c
  5. 1 1
      views/SensorsList_view.c
  6. 4 0
      views/Summary_view.c
  7. 1 0
      views/UnitempViews.h

+ 8 - 0
Sensors.c

@@ -325,6 +325,13 @@ bool unitemp_sensors_save(void) {
     FURI_LOG_I(APP_NAME, "Sensors have been successfully saved");
     return true;
 }
+void unitemp_sensors_reload(void) {
+    unitemp_sensors_deInit();
+    unitemp_sensors_free();
+
+    unitemp_sensors_load();
+    unitemp_sensors_init();
+}
 
 Sensor* unitemp_sensor_alloc(char* name, const SensorType* type, uint8_t* anotherValues) {
     bool status = false;
@@ -398,6 +405,7 @@ void unitemp_sensors_free(void) {
         unitemp_sensor_free(app->sensors[i]);
     }
     app->sensors_count = 0;
+    free(app->sensors);
 }
 
 bool unitemp_sensors_init(void) {

+ 4 - 0
Sensors.h

@@ -163,6 +163,10 @@ UnitempStatus unitemp_sensor_updateData(Sensor* sensor);
  */
 bool unitemp_sensors_load();
 
+/**
+ * @brief Функция перезагрузки датчиков с SD-карты
+*/
+void unitemp_sensors_reload(void);
 /**
  * @brief Сохранение настроек на SD-карту
  * 

+ 1 - 1
unitemp.c

@@ -204,7 +204,7 @@ static void unitemp_free(void) {
     //Очистка датчиков
     //Высвыбождение данных датчиков
     unitemp_sensors_free();
-    free(app->sensors);
+
     //Закрытие уведомлений
     furi_record_close(RECORD_NOTIFICATION);
     //Закрытие хранилища

+ 11 - 1
views/SensorEdit_view.c

@@ -36,7 +36,17 @@ static uint32_t _exit_callback(void* context) {
  */
 static void _enter_callback(void* context, uint32_t index) {
     UNUSED(context);
-    UNUSED(index);
+    //Смена имени
+    if(index == 0) {
+        //
+    }
+    //Сохранение
+    if(index == 3) {
+        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

@@ -67,6 +67,10 @@ void unitemp_Summary_alloc(void) {
     view_dispatcher_add_view(app->view_dispatcher, SUMMARY_VIEW, view);
 }
 
+void unitemp_Summary_switch(void) {
+    view_dispatcher_switch_to_view(app->view_dispatcher, SUMMARY_VIEW);
+}
+
 void unitemp_Summary_free(void) {
     view_free(view);
 }

+ 1 - 0
views/UnitempViews.h

@@ -16,6 +16,7 @@ typedef enum UnitempViews {
 
 /* Общий вид на датчики */
 void unitemp_Summary_alloc(void);
+void unitemp_Summary_switch(void);
 void unitemp_Summary_free(void);
 
 /* Главное меню */