From 9503bde421b4639e4be3d27b886693e16e87c1fc Mon Sep 17 00:00:00 2001 From: antirez Date: Sun, 1 Jan 2023 17:43:48 +0100 Subject: [PATCH] Long press left/right for panning in raw view. --- TODO | 3 +++ app.c | 62 +++++++++++++++++++++++++++++++++++++---------------------- app.h | 1 + 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/TODO b/TODO index ba93bfc9394..0003ccd3859 100644 --- a/TODO +++ b/TODO @@ -3,9 +3,12 @@ Core improvements - Detection of non Manchester and non RZ encoded signals. Not sure if there are any signals that are not self clocked widely used in RF. Note that the current approach already detects encodings using short high + long low and long high + short low to encode 0 and 1. In addition to the current classifier, it is possible to add one that checks for a sequence of pulses that are all multiples of some base length. This should detect, for instance, even NRZ encodings where 1 and 0 are just clocked as they are. +- Views on-enter on-exit. + Features ======== +- Help screen (with press ok for next page). - Detect the line code used and try to decode the message as hex dump. - Pressing right/left you browse different modes: * Current best signal pulse classes. diff --git a/app.c b/app.c index eb465561f79..cdc5ab0da62 100644 --- a/app.c +++ b/app.c @@ -27,6 +27,7 @@ void render_signal(ProtoViewApp *app, Canvas *const canvas, RawSamplesBuffer *bu int rows = 8; uint32_t time_per_pixel = app->us_scale; + uint32_t start_idx = idx; bool level = 0; uint32_t dur = 0, sample_num = 0; for (int row = 0; row < rows ; row++) { @@ -42,7 +43,7 @@ void render_signal(ProtoViewApp *app, Canvas *const canvas, RawSamplesBuffer *bu /* Write a small triangle under the last sample detected. */ if (app->signal_bestlen != 0 && - sample_num == app->signal_bestlen+1) + sample_num+start_idx == app->signal_bestlen+1) { canvas_draw_dot(canvas,x,y+2); canvas_draw_dot(canvas,x-1,y+3); @@ -211,7 +212,7 @@ void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const cha /* Raw pulses rendering. This is our default view. */ void render_view_raw_pulses(Canvas *const canvas, ProtoViewApp *app) { /* Show signal. */ - render_signal(app, canvas, DetectedSamples, 0); + render_signal(app, canvas, DetectedSamples, app->signal_offset); /* Show signal information. */ char buf[64]; @@ -280,10 +281,8 @@ static void input_callback(InputEvent* input_event, void* ctx) { ProtoViewApp *app = ctx; - if (input_event->type == InputTypePress) { - furi_message_queue_put(app->event_queue,input_event,FuriWaitForever); - FURI_LOG_E(TAG, "INPUT CALLBACK %d", (int)input_event->key); - } + furi_message_queue_put(app->event_queue,input_event,FuriWaitForever); + FURI_LOG_E(TAG, "INPUT CALLBACK %d", (int)input_event->key); } /* Allocate the application state and initialize a number of stuff. @@ -297,7 +296,7 @@ ProtoViewApp* protoview_app_alloc() { //init setting app->setting = subghz_setting_alloc(); - subghz_setting_load(app->setting, EXT_PATH("protoview/settings.txt")); + subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user")); // GUI app->gui = furi_record_open(RECORD_GUI); @@ -311,6 +310,7 @@ ProtoViewApp* protoview_app_alloc() { // Signal found and visualization defaults app->signal_bestlen = 0; app->us_scale = 100; + app->signal_offset = 0; //init Worker & Protocol app->txrx = malloc(sizeof(ProtoViewTxRx)); @@ -382,18 +382,27 @@ static void timer_callback(void *ctx) { /* Handle input for the raw pulses view. */ void process_input_raw_pulses(ProtoViewApp *app, InputEvent input) { - if (input.key == InputKeyOk) { - /* Reset the current sample to capture the next. */ - app->signal_bestlen = 0; - raw_samples_reset(DetectedSamples); - raw_samples_reset(RawSamples); - } else if (input.key == InputKeyDown) { - /* Rescaling. The set becomes finer under 50us per pixel. */ - uint32_t scale_step = app->us_scale >= 50 ? 50 : 10; - if (app->us_scale < 500) app->us_scale += scale_step; - } else if (input.key == InputKeyUp) { - uint32_t scale_step = app->us_scale > 50 ? 50 : 10; - if (app->us_scale > 10) app->us_scale -= scale_step; + if (input.type == InputTypeRepeat) { + /* Handle panning of the signal window. Long pressing + * right will show successive samples, long pressing left + * previous samples. */ + if (input.key == InputKeyRight) app->signal_offset++; + else if (input.key == InputKeyLeft) app->signal_offset--; + } else if (input.type == InputTypeShort) { + if (input.key == InputKeyOk) { + /* Reset the current sample to capture the next. */ + app->signal_bestlen = 0; + app->signal_offset = 0; + raw_samples_reset(DetectedSamples); + raw_samples_reset(RawSamples); + } else if (input.key == InputKeyDown) { + /* Rescaling. The set becomes finer under 50us per pixel. */ + uint32_t scale_step = app->us_scale >= 50 ? 50 : 10; + if (app->us_scale < 500) app->us_scale += scale_step; + } else if (input.key == InputKeyUp) { + uint32_t scale_step = app->us_scale > 50 ? 50 : 10; + if (app->us_scale > 10) app->us_scale -= scale_step; + } } } @@ -465,18 +474,25 @@ int32_t protoview_app_entry(void* p) { while(app->running) { FuriStatus qstat = furi_message_queue_get(app->event_queue, &input, 100); if (qstat == FuriStatusOk) { - FURI_LOG_E(TAG, "Main Loop - Input: %u", input.key); + FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u", + input.type, input.key); /* Handle navigation here. Then handle view-specific inputs * in the view specific handling function. */ - if (input.key == InputKeyBack) { + if (input.type == InputTypeShort && + input.key == InputKeyBack) + { /* Exit the app. */ app->running = 0; - } else if (input.key == InputKeyRight) { + } else if (input.type == InputTypeShort && + input.key == InputKeyRight) + { /* Go to the next view. */ app->current_view++; if (app->current_view == ViewLast) app->current_view = 0; - } else if (input.key == InputKeyLeft) { + } else if (input.type == InputTypeShort && + input.key == InputKeyLeft) + { /* Go to the previous view. */ if (app->current_view == 0) app->current_view = ViewLast-1; diff --git a/app.h b/app.h index 18852a14a1f..5c8f3d1a05e 100644 --- a/app.h +++ b/app.h @@ -70,6 +70,7 @@ struct ProtoViewApp { int running; /* Once false exists the app. */ uint32_t signal_bestlen; /* Longest coherent signal observed so far. */ uint32_t us_scale; /* microseconds per pixel. */ + uint32_t signal_offset; /* Long press left/right panning in raw view. */ uint32_t frequency; /* Current frequency. */ uint8_t modulation; /* Current modulation ID, array index in the ProtoViewModulations table. */