Browse Source

Temp printer

Victor 3 years ago
parent
commit
53e7a23c06
3 changed files with 43 additions and 8 deletions
  1. 1 0
      application.fam
  2. BIN
      assets/temp_C_11x14.png
  3. 42 8
      views/General_view.c

+ 1 - 0
application.fam

@@ -9,6 +9,7 @@ App(
     ],
     ],
     fap_category="GPIO",
     fap_category="GPIO",
     fap_icon="icon.png",
     fap_icon="icon.png",
+    fap_icon_assets="assets",
     stack_size=2 * 1024,
     stack_size=2 * 1024,
     order=100,
     order=100,
 )
 )

BIN
assets/temp_C_11x14.png


+ 42 - 8
views/General_view.c

@@ -1,15 +1,48 @@
 #include "UnitempViews.h"
 #include "UnitempViews.h"
-
+#include "unitemp_icons.h"
 static View* view;
 static View* view;
 
 
-// const uint8_t temp_positions
+const uint8_t temp_positions[3][2] = {{37, 24}, {37, 16}, {9, 16}};
 
 
-//     static void
-//     _draw_noSensors(Canvas* canvas) {
-//     canvas_draw_str(canvas, 0, 24, "Sensors not found");
-// }
+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_temp(Canvas* canvas, float temp, uint8_t pos) {
+    //Рисование рамки
+    canvas_draw_rframe(canvas, temp_positions[pos][0], temp_positions[pos][1], 54, 20, 3);
+    canvas_draw_rframe(canvas, temp_positions[pos][0], temp_positions[pos][1], 54, 19, 3);
+    int8_t temp_int = temp;
+    int8_t temp_dec = abs((int16_t)(temp * 10) % 10);
+
+    //Рисование иконки
+    canvas_draw_icon(
+        canvas, temp_positions[pos][0] + 3, temp_positions[pos][1] + 3, &I_temp_C_11x14);
+
+    //Целая часть температуры
+    char buff[5];
+    snprintf(buff, 5, "%d", temp_int);
+    canvas_set_font(canvas, FontBigNumbers);
+    canvas_draw_str_aligned(
+        canvas,
+        temp_positions[pos][0] + 27 + ((temp_int <= -10) ? 5 : 0),
+        temp_positions[pos][1] + 10,
+        AlignCenter,
+        AlignCenter,
+        buff);
+    //Печать дробной части температуры в диапазоне от -9 до 99 (когда два знака в числе)
+    if(temp_int > -10 && temp_int <= 99) {
+        uint8_t int_len = canvas_string_width(canvas, buff);
+        snprintf(buff, 4, ".%d", temp_dec);
+        canvas_set_font(canvas, FontPrimary);
+        canvas_draw_str_aligned(
+            canvas,
+            temp_positions[pos][0] + 27 + int_len + ((temp_int >= 0 && temp_int < 10) ? 5 : 0),
+            temp_positions[pos][1] + 10 + 3,
+            AlignRight,
+            AlignCenter,
+            buff);
+    }
 }
 }
 
 
 static void _draw_sensorsCarousel(Canvas* canvas) {
 static void _draw_sensorsCarousel(Canvas* canvas) {
@@ -27,7 +60,8 @@ static void _draw_sensorsCarousel(Canvas* canvas) {
     canvas_draw_line(canvas, 64 - line_len / 2, 12, 64 + line_len / 2, 12);
     canvas_draw_line(canvas, 64 - line_len / 2, 12, 64 + line_len / 2, 12);
 
 
     //Печать значения температуры
     //Печать значения температуры
-    _draw_temp(app->sensors[sensor_index]->temp, 0);
+    // _draw_temp(canvas, app->sensors[sensor_index]->temp, 0);
+    _draw_temp(canvas, (float)(furi_get_tick() % 30000) / 1000.0f - 15.0f, 0);
 }
 }
 
 
 static void _draw_callback(Canvas* canvas, void* _model) {
 static void _draw_callback(Canvas* canvas, void* _model) {