antirez 3 лет назад
Родитель
Сommit
24071c10f0
5 измененных файлов с 59 добавлено и 9 удалено
  1. 4 0
      app.c
  2. 7 4
      app.h
  3. 7 4
      protocols/oregon2.c
  4. 41 0
      view_info.c
  5. 0 1
      view_settings.c

+ 4 - 0
app.c

@@ -26,6 +26,7 @@ static void render_callback(Canvas *const canvas, void *ctx) {
     /* Call who is in charge right now. */
     switch(app->current_view) {
     case ViewRawPulses: render_view_raw_pulses(canvas,app); break;
+    case ViewInfo: render_view_info(canvas,app); break;
     case ViewFrequencySettings:
     case ViewModulationSettings:
         render_view_settings(canvas,app); break;
@@ -189,6 +190,9 @@ int32_t protoview_app_entry(void* p) {
                 case ViewRawPulses:
                     process_input_raw_pulses(app,input);
                     break;
+                case ViewInfo:
+                    process_input_info(app,input);
+                    break;
                 case ViewFrequencySettings:
                 case ViewModulationSettings:
                     process_input_settings(app,input);

+ 7 - 4
app.h

@@ -40,6 +40,7 @@ typedef enum {
 /* Currently active view. */
 typedef enum {
     ViewRawPulses,
+    ViewInfo,
     ViewFrequencySettings,
     ViewModulationSettings,
     ViewLast, /* Just a sentinel to wrap around. */
@@ -67,15 +68,15 @@ typedef struct ProtoViewTxRx ProtoViewTxRx;
 /* This stucture is filled by the decoder for specific protocols with the
  * informations about the message. ProtoView will display such information
  * in the message info view. */
-#define PROTOVIEW_MSG_STR_LEN 16
+#define PROTOVIEW_MSG_STR_LEN 32
 typedef struct ProtoViewMsgInfo {
     char name[PROTOVIEW_MSG_STR_LEN]; /* Protocol name and version. */
     char raw[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific raw representation.*/
     /* The following is what the decoder wants to show to user. Each decoder
      * can use the number of fileds it needs. */
-    char info1[16];     /* Protocol specific decoded string, line 1. */
-    char info2[16];     /* Protocol specific decoded string, line 2. */
-    char info3[16];     /* Protocol specific decoded string, line 3. */
+    char info1[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 1. */
+    char info2[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 2. */
+    char info3[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 3. */
     uint64_t len;       /* Bits consumed from the stream. */
 } ProtoViewMsgInfo;
 
@@ -144,6 +145,8 @@ void render_view_raw_pulses(Canvas *const canvas, ProtoViewApp *app);
 void process_input_raw_pulses(ProtoViewApp *app, InputEvent input);
 void render_view_settings(Canvas *const canvas, ProtoViewApp *app);
 void process_input_settings(ProtoViewApp *app, InputEvent input);
+void render_view_info(Canvas *const canvas, ProtoViewApp *app);
+void process_input_info(ProtoViewApp *app, InputEvent input);
 
 /* ui.c */
 void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);

+ 7 - 4
protocols/oregon2.c

@@ -54,6 +54,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     uint32_t decoded =
         convert_from_line_code(buffer,sizeof(buffer),bits,numbytes,off,"1001","0110");
     FURI_LOG_E(TAG, "Oregon2 decoded bits: %lu", decoded);
+
     if (decoded < 11*4) return false; /* Minimum len to extract some data. */
 
     char temp[3] = {0}, deviceid[2] = {0}, hum[2] = {0};
@@ -80,12 +81,14 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     }
 
     snprintf(info->name,sizeof(info->name),"%s","Oregon v2.1");
-    snprintf(info->raw,sizeof(info->raw),"%08llX", *((uint64_t*)buffer));
-    snprintf(info->info1,sizeof(info->info2),"ID %02X%02X",
+    /* The following line crashes the Flipper because of broken
+     * snprintf() implementation. */
+    if (0) snprintf(info->raw,sizeof(info->raw),"%08llX", *((uint64_t*)buffer));
+    snprintf(info->info1,sizeof(info->info1),"Sensor ID %02X%02X",
         deviceid[0], deviceid[1]);
-    snprintf(info->info2,sizeof(info->info1),"Temp %d%d.%d",
+    snprintf(info->info2,sizeof(info->info2),"Temperature %d%d.%d",
         temp[0],temp[1],temp[2]);
-    snprintf(info->info3,sizeof(info->info1),"Humidity %d%d",
+    snprintf(info->info3,sizeof(info->info3),"Humidity %d%d",
         hum[0],hum[1]);
     return true;
 }

+ 41 - 0
view_info.c

@@ -0,0 +1,41 @@
+/* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
+ * See the LICENSE file for information about the license. */
+
+#include "app.h"
+
+/* Renders the view with the detected message information. */
+void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
+    if (app->signal_decoded == false) {
+        canvas_set_font(canvas, FontSecondary);
+        canvas_draw_str(canvas, 30,36,"No signal decoded");
+        return;
+    }
+
+    /* Protocol name as title. */
+    canvas_set_font(canvas, FontPrimary);
+    uint8_t y = 8, lineheight = 10;
+    canvas_draw_str(canvas, 0, y, app->signal_info.name);
+    y += lineheight;
+
+    /* Info fields. */
+    char buf[128];
+    canvas_set_font(canvas, FontSecondary);
+    if (app->signal_info.raw[0]) {
+        snprintf(buf,sizeof(buf),"Raw: %s", app->signal_info.raw);
+        canvas_draw_str(canvas, 0, y, buf);
+        y += lineheight;
+    }
+    canvas_draw_str(canvas, 0, y, app->signal_info.info1);
+    y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->signal_info.info2);
+    y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->signal_info.info3);
+    y += lineheight;
+}
+
+/* Handle input for the settings view. */
+void process_input_info(ProtoViewApp *app, InputEvent input) {
+    UNUSED(app);
+    UNUSED(input);
+    return;
+}

+ 0 - 1
view_settings.c

@@ -7,7 +7,6 @@
  * this are logically two different views, and only one of the settings
  * will be highlighted. */
 void render_view_settings(Canvas *const canvas, ProtoViewApp *app) {
-    UNUSED(app);
     canvas_set_font(canvas, FontPrimary);
     if (app->current_view == ViewFrequencySettings)
         canvas_draw_str_with_border(canvas,1,10,"Frequency",ColorWhite,ColorBlack);