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

The development of a beautiful GUI has begun

Victor 3 лет назад
Родитель
Сommit
d23425433b
6 измененных файлов с 126 добавлено и 89 удалено
  1. 3 3
      unitemp.c
  2. 117 0
      views/General_view.c
  3. 1 1
      views/MainMenu_view.c
  4. 1 1
      views/SensorEdit_view.c
  5. 0 80
      views/Summary_view.c
  6. 4 4
      views/UnitempViews.h

+ 3 - 3
unitemp.c

@@ -186,7 +186,7 @@ static bool unitemp_alloc(void) {
 
 
     app->sensors = NULL;
     app->sensors = NULL;
 
 
-    unitemp_Summary_alloc();
+    unitemp_General_alloc();
     unitemp_MainMenu_alloc();
     unitemp_MainMenu_alloc();
     unitemp_Settings_alloc();
     unitemp_Settings_alloc();
     unitemp_SensorsList_alloc();
     unitemp_SensorsList_alloc();
@@ -207,7 +207,7 @@ static void unitemp_free(void) {
     unitemp_SensorsList_free();
     unitemp_SensorsList_free();
     unitemp_Settings_free();
     unitemp_Settings_free();
     unitemp_MainMenu_free();
     unitemp_MainMenu_free();
-    unitemp_Summary_free();
+    unitemp_General_free();
 
 
     view_dispatcher_free(app->view_dispatcher);
     view_dispatcher_free(app->view_dispatcher);
     furi_record_close(RECORD_GUI);
     furi_record_close(RECORD_GUI);
@@ -252,7 +252,7 @@ int32_t unitemp_app() {
     //Инициализация датчиков
     //Инициализация датчиков
     unitemp_sensors_init();
     unitemp_sensors_init();
 
 
-    unitemp_Summary_switch();
+    unitemp_General_switch();
 
 
     while(app->processing) {
     while(app->processing) {
         if(app->sensors_ready) unitemp_sensors_updateValues();
         if(app->sensors_ready) unitemp_sensors_updateValues();

+ 117 - 0
views/General_view.c

@@ -0,0 +1,117 @@
+#include "UnitempViews.h"
+
+static View* view;
+
+// const uint8_t temp_positions
+
+//     static void
+//     _draw_noSensors(Canvas* canvas) {
+//     canvas_draw_str(canvas, 0, 24, "Sensors not found");
+// }
+
+static void _draw_temp(float temp, uint8_t pos) {
+}
+
+static void _draw_sensorsCarousel(Canvas* canvas) {
+    static uint8_t sensor_index = 0;
+    //Рисование рамки
+    canvas_draw_rframe(canvas, 3, 0, 122, 63, 7);
+    canvas_draw_rframe(canvas, 3, 0, 122, 64, 7);
+
+    //Печать имени
+    canvas_set_font(canvas, FontPrimary);
+    canvas_draw_str_aligned(
+        canvas, 64, 7, AlignCenter, AlignCenter, app->sensors[sensor_index]->name);
+    //Подчёркивание
+    uint8_t line_len = canvas_string_width(canvas, app->sensors[sensor_index]->name) + 2;
+    canvas_draw_line(canvas, 64 - line_len / 2, 12, 64 + line_len / 2, 12);
+
+    //Печать значения температуры
+    _draw_temp(app->sensors[sensor_index]->temp, 0);
+}
+
+static void _draw_callback(Canvas* canvas, void* _model) {
+    UNUSED(_model);
+
+    app->sensors_ready = true;
+
+    uint8_t sensors_count = unitemp_sensors_getCount();
+
+    if(sensors_count == 0) {
+        _draw_noSensors(canvas);
+    }
+    if(sensors_count > 0) {
+        _draw_sensorsCarousel(canvas);
+    }
+
+    // //Рисование бара
+    // canvas_draw_box(canvas, 0, 0, 128, 14);
+    // canvas_set_color(canvas, ColorWhite);
+    // canvas_set_font(canvas, FontPrimary);
+    // canvas_draw_str_aligned(canvas, 64, 7, AlignCenter, AlignCenter, "Unitemp");
+
+    // canvas_set_color(canvas, ColorBlack);
+    // if(unitemp_sensors_getCount() > 0) {
+    //     for(uint8_t i = 0; i < unitemp_sensors_getCount(); i++) {
+    //         canvas_set_font(canvas, FontPrimary);
+    //         canvas_draw_str(canvas, 0, 24 + 10 * i, app->sensors[i]->name);
+
+    //         canvas_set_font(canvas, FontSecondary);
+    //         if(app->sensors[i]->status != UT_OK && app->sensors[i]->status != UT_EARLYPOOL &&
+    //            app->sensors[i]->status != UT_POLLING) {
+    //             if(app->sensors[i]->status == UT_BADCRC) {
+    //                 canvas_draw_str(canvas, 96, 24 + 10 * i, "bad CRC");
+    //             } else {
+    //                 canvas_draw_str(canvas, 96, 24 + 10 * i, "timeout");
+    //             }
+    //         } else {
+    //             char buff[20];
+    //             snprintf(
+    //                 buff,
+    //                 sizeof(buff),
+    //                 "%2.1f*%c/%d%%",
+    //                 (double)app->sensors[i]->temp,
+    //                 app->settings.unit == CELSIUS ? 'C' : 'F',
+    //                 (int8_t)app->sensors[i]->hum);
+    //             canvas_draw_str(canvas, 64, 24 + 10 * i, buff);
+    //         }
+    //     }
+    // } else {
+    //     canvas_set_font(canvas, FontSecondary);
+    //     if(unitemp_sensors_getCount() == 0) canvas_draw_str(canvas, 0, 24, "Sensors not found");
+    // }
+}
+
+static bool _input_callback(InputEvent* event, void* context) {
+    Unitemp* app = context;
+
+    //Выход по короткому нажатию "назад"
+    if(event->key == InputKeyBack && event->type == InputTypeShort) {
+        app->processing = false;
+    }
+    //Вход в главное меню по короткому нажатию "Ок"
+    if(event->key == InputKeyOk && event->type == InputTypeShort) {
+        app->sensors_ready = false;
+        unitemp_MainMenu_switch();
+    }
+
+    return true;
+}
+
+void unitemp_General_alloc(void) {
+    view = view_alloc();
+    view_set_context(view, app);
+    view_set_draw_callback(view, _draw_callback);
+    view_set_input_callback(view, _input_callback);
+
+    view_dispatcher_add_view(app->view_dispatcher, GENERAL_VIEW, view);
+}
+
+void unitemp_General_switch(void) {
+    app->sensors_ready = true;
+    view_dispatcher_switch_to_view(app->view_dispatcher, GENERAL_VIEW);
+}
+
+void unitemp_General_free(void) {
+    view_free(view);
+}

+ 1 - 1
views/MainMenu_view.c

@@ -17,7 +17,7 @@ static VariableItemList* variable_item_list;
 static uint32_t _exit_callback(void* context) {
 static uint32_t _exit_callback(void* context) {
     UNUSED(context);
     UNUSED(context);
     //Возврат в общий вид
     //Возврат в общий вид
-    return SUMMARY_VIEW;
+    return GENERAL_VIEW;
 }
 }
 /**
 /**
  * @brief Функция обработки нажатия средней кнопки
  * @brief Функция обработки нажатия средней кнопки

+ 1 - 1
views/SensorEdit_view.c

@@ -149,7 +149,7 @@ static void _enter_callback(void* context, uint32_t index) {
         unitemp_sensors_save();
         unitemp_sensors_save();
         unitemp_sensors_reload();
         unitemp_sensors_reload();
 
 
-        unitemp_Summary_switch();
+        unitemp_General_switch();
     }
     }
     //Адрес устройства на шине one wire
     //Адрес устройства на шине one wire
     if(index == 3 && editable_sensor->type->interface == &ONE_WIRE) {
     if(index == 3 && editable_sensor->type->interface == &ONE_WIRE) {

+ 0 - 80
views/Summary_view.c

@@ -1,80 +0,0 @@
-#include "UnitempViews.h"
-
-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);
-    canvas_set_font(canvas, FontPrimary);
-    canvas_draw_str_aligned(canvas, 64, 7, AlignCenter, AlignCenter, "Unitemp");
-
-    canvas_set_color(canvas, ColorBlack);
-    if(unitemp_sensors_getCount() > 0) {
-        for(uint8_t i = 0; i < unitemp_sensors_getCount(); i++) {
-            canvas_set_font(canvas, FontPrimary);
-            canvas_draw_str(canvas, 0, 24 + 10 * i, app->sensors[i]->name);
-
-            canvas_set_font(canvas, FontSecondary);
-            if(app->sensors[i]->status != UT_OK && app->sensors[i]->status != UT_EARLYPOOL &&
-               app->sensors[i]->status != UT_POLLING) {
-                if(app->sensors[i]->status == UT_BADCRC) {
-                    canvas_draw_str(canvas, 96, 24 + 10 * i, "bad CRC");
-                } else {
-                    canvas_draw_str(canvas, 96, 24 + 10 * i, "timeout");
-                }
-            } else {
-                char buff[20];
-                snprintf(
-                    buff,
-                    sizeof(buff),
-                    "%2.1f*%c/%d%%",
-                    (double)app->sensors[i]->temp,
-                    app->settings.unit == CELSIUS ? 'C' : 'F',
-                    (int8_t)app->sensors[i]->hum);
-                canvas_draw_str(canvas, 64, 24 + 10 * i, buff);
-            }
-        }
-    } else {
-        canvas_set_font(canvas, FontSecondary);
-        if(unitemp_sensors_getCount() == 0) canvas_draw_str(canvas, 0, 24, "Sensors not found");
-    }
-}
-
-static bool _input_callback(InputEvent* event, void* context) {
-    Unitemp* app = context;
-
-    //Выход по короткому нажатию "назад"
-    if(event->key == InputKeyBack && event->type == InputTypeShort) {
-        app->processing = false;
-    }
-    //Вход в главное меню по короткому нажатию "Ок"
-    if(event->key == InputKeyOk && event->type == InputTypeShort) {
-        app->sensors_ready = false;
-        unitemp_MainMenu_switch();
-    }
-
-    return true;
-}
-
-void unitemp_Summary_alloc(void) {
-    view = view_alloc();
-    view_set_context(view, app);
-    view_set_draw_callback(view, _draw_callback);
-    view_set_input_callback(view, _input_callback);
-
-    view_dispatcher_add_view(app->view_dispatcher, SUMMARY_VIEW, view);
-}
-
-void unitemp_Summary_switch(void) {
-    app->sensors_ready = true;
-    view_dispatcher_switch_to_view(app->view_dispatcher, SUMMARY_VIEW);
-}
-
-void unitemp_Summary_free(void) {
-    view_free(view);
-}

+ 4 - 4
views/UnitempViews.h

@@ -5,7 +5,7 @@
 
 
 //Виды менюшек
 //Виды менюшек
 typedef enum UnitempViews {
 typedef enum UnitempViews {
-    SUMMARY_VIEW,
+    GENERAL_VIEW,
     MAINMENU_VIEW,
     MAINMENU_VIEW,
     SETTINGS_VIEW,
     SETTINGS_VIEW,
     SENSORSLIST_VIEW,
     SENSORSLIST_VIEW,
@@ -16,9 +16,9 @@ typedef enum UnitempViews {
 } UnitempViews;
 } UnitempViews;
 
 
 /* Общий вид на датчики */
 /* Общий вид на датчики */
-void unitemp_Summary_alloc(void);
-void unitemp_Summary_switch(void);
-void unitemp_Summary_free(void);
+void unitemp_General_alloc(void);
+void unitemp_General_switch(void);
+void unitemp_General_free(void);
 
 
 /* Главное меню */
 /* Главное меню */
 void unitemp_MainMenu_alloc(void);
 void unitemp_MainMenu_alloc(void);