From e28d45aeee32aa361c2caa89cd56d1338e84328f Mon Sep 17 00:00:00 2001 From: Leeroy <135471162+LeeroysHub@users.noreply.github.com> Date: Tue, 29 Sep 2026 08:28:15 +1000 Subject: [PATCH] UI BUG: Not drawing History once a key is received. * This code also refactors the frequency, preset, and history_stat strings, makes them char* instead of FuriString* --- helpers/protopirate_txrx.c | 15 +++--- helpers/protopirate_txrx.h | 5 +- protopirate_history.c | 13 ----- protopirate_history.h | 1 - .../plugins/protopirate_tool_scene_plugin.h | 4 ++ scenes/protopirate_scene_receiver.c | 17 +++--- scenes/protopirate_scene_sub_decode.c | 38 ++++++++++--- views/protopirate_receiver.c | 54 ++++++++++--------- views/protopirate_receiver.h | 3 ++ 9 files changed, 89 insertions(+), 61 deletions(-) diff --git a/helpers/protopirate_txrx.c b/helpers/protopirate_txrx.c index ffeda9d..96ae7ab 100644 --- a/helpers/protopirate_txrx.c +++ b/helpers/protopirate_txrx.c @@ -58,13 +58,13 @@ void protopirate_get_frequency_modulation_str( size_t modulation_size) { furi_check(app); - if(frequency && frequency_size > 0) { + if(frequency) { unsigned long mhz = (unsigned long)((app->txrx->preset->frequency / 1000000UL) % 1000UL); unsigned long khz = (unsigned long)((app->txrx->preset->frequency / 10000UL) % 100UL); snprintf(frequency, frequency_size, "%03lu.%02lu", mhz, khz); } - if(modulation && modulation_size > 0) { + if(modulation) { snprintf( modulation, modulation_size, "%.2s", furi_string_get_cstr(app->txrx->preset->name)); } @@ -73,19 +73,20 @@ void protopirate_get_frequency_modulation_str( void protopirate_get_frequency_modulation( ProtoPirateApp* app, FuriString* frequency, - FuriString* modulation) { + size_t frequency_size, + FuriString* modulation, + size_t modulation_size) { furi_check(app); char frequency_buf[16] = {0}; char modulation_buf[8] = {0}; - protopirate_get_frequency_modulation_str( - app, frequency_buf, sizeof(frequency_buf), modulation_buf, sizeof(modulation_buf)); + protopirate_get_frequency_modulation_str(app, frequency_buf, 16, modulation_buf, 8); if(frequency != NULL) { - furi_string_set_str(frequency, frequency_buf); + memcpy(frequency, frequency_buf, frequency_size); } if(modulation != NULL) { - furi_string_set_str(modulation, modulation_buf); + memcpy(modulation, modulation_buf, modulation_size); } } diff --git a/helpers/protopirate_txrx.h b/helpers/protopirate_txrx.h index f947b71..9ac99aa 100644 --- a/helpers/protopirate_txrx.h +++ b/helpers/protopirate_txrx.h @@ -20,7 +20,10 @@ void protopirate_preset_init( void protopirate_get_frequency_modulation( ProtoPirateApp* app, FuriString* frequency, - FuriString* modulation); + size_t frequency_size, + FuriString* modulation, + size_t modulation_size); + void protopirate_get_frequency_modulation_str( ProtoPirateApp* app, char* frequency, diff --git a/protopirate_history.c b/protopirate_history.c index 6229d36..0032847 100644 --- a/protopirate_history.c +++ b/protopirate_history.c @@ -204,10 +204,6 @@ void protopirate_history_format_status_text( furi_check(instance); furi_check(output); - if(output_size == 0) { - return; - } - uint16_t n = protopirate_history_get_item(instance); if(n >= PROTOPIRATE_HISTORY_MAX) { snprintf(output, output_size, "FULL"); @@ -216,15 +212,6 @@ void protopirate_history_format_status_text( } } -void protopirate_history_get_status_text(ProtoPirateHistory* instance, FuriString* output) { - furi_check(instance); - furi_check(output); - - char status_text[16]; - protopirate_history_format_status_text(instance, status_text, sizeof(status_text)); - furi_string_set_str(output, status_text); -} - bool protopirate_history_get_capture_path( ProtoPirateHistory* instance, uint16_t idx, diff --git a/protopirate_history.h b/protopirate_history.h index c218d17..e6d3b22 100644 --- a/protopirate_history.h +++ b/protopirate_history.h @@ -19,7 +19,6 @@ void protopirate_history_format_status_text( ProtoPirateHistory* instance, char* output, size_t output_size); -void protopirate_history_get_status_text(ProtoPirateHistory* instance, FuriString* output); bool protopirate_history_get_capture_path( ProtoPirateHistory* instance, diff --git a/scenes/plugins/protopirate_tool_scene_plugin.h b/scenes/plugins/protopirate_tool_scene_plugin.h index 5b49bb1..27a0364 100644 --- a/scenes/plugins/protopirate_tool_scene_plugin.h +++ b/scenes/plugins/protopirate_tool_scene_plugin.h @@ -57,9 +57,13 @@ typedef struct { void (*receiver_add_data_statusbar)( ProtoPirateReceiver* receiver, const char* frequency_str, + size_t frequency_size, const char* preset_str, + size_t preset_size, const char* history_stat_str, + size_t history_stat_size, bool external_radio); + uint16_t (*receiver_get_idx_menu)(ProtoPirateReceiver* receiver); void (*receiver_set_idx_menu)(ProtoPirateReceiver* receiver, uint16_t idx); void (*receiver_set_callback)( diff --git a/scenes/protopirate_scene_receiver.c b/scenes/protopirate_scene_receiver.c index ff545b2..24f86be 100644 --- a/scenes/protopirate_scene_receiver.c +++ b/scenes/protopirate_scene_receiver.c @@ -24,8 +24,7 @@ static void protopirate_scene_receiver_update_statusbar(void* context) { char modulation_str[8] = {0}; char history_stat_str[16] = {0}; - protopirate_get_frequency_modulation_str( - app, frequency_str, sizeof(frequency_str), modulation_str, sizeof(modulation_str)); + protopirate_get_frequency_modulation_str(app, frequency_str, 16, modulation_str, 8); bool is_external = false; if(app->radio_initialized && app->txrx->radio_device) { @@ -33,14 +32,20 @@ static void protopirate_scene_receiver_update_statusbar(void* context) { } if(app->txrx->history) { - protopirate_history_format_status_text( - app->txrx->history, history_stat_str, sizeof(history_stat_str)); + protopirate_history_format_status_text(app->txrx->history, history_stat_str, 20); } else { - snprintf(history_stat_str, sizeof(history_stat_str), "0/%u", PROTOPIRATE_HISTORY_MAX); + snprintf(history_stat_str, 16, "0/%u", PROTOPIRATE_HISTORY_MAX); } protopirate_view_receiver_add_data_statusbar( - app->protopirate_receiver, frequency_str, modulation_str, history_stat_str, is_external); + app->protopirate_receiver, + frequency_str, + 16, + modulation_str, + 8, + history_stat_str, + 16, + is_external); } static void protopirate_scene_receiver_callback( diff --git a/scenes/protopirate_scene_sub_decode.c b/scenes/protopirate_scene_sub_decode.c index 5cf938d..b15df69 100644 --- a/scenes/protopirate_scene_sub_decode.c +++ b/scenes/protopirate_scene_sub_decode.c @@ -70,10 +70,26 @@ static const ProtoPirateToolSceneHostApi* g_tool_scene_host_api = NULL; app, frequency, frequency_size, modulation, modulation_size) #define radio_device_loader_is_external(radio_device) \ g_tool_scene_host_api->radio_device_is_external(radio_device) + #define protopirate_view_receiver_add_data_statusbar( \ - receiver, frequency, modulation, history, external) \ + receiver, \ + frequency, \ + frequency_size, \ + modulation, \ + modulation_size, \ + history, \ + history_size, \ + external) \ g_tool_scene_host_api->receiver_add_data_statusbar( \ - receiver, frequency, modulation, history, external) + receiver, \ + frequency, \ + frequency_size, \ + modulation, \ + modulation_size, \ + history, \ + history_size, \ + external) + #define protopirate_view_receiver_get_idx_menu(receiver) \ g_tool_scene_host_api->receiver_get_idx_menu(receiver) #define protopirate_view_receiver_set_idx_menu(receiver, idx) \ @@ -227,12 +243,11 @@ static void protopirate_scene_sub_decode_update_receiver_statusbar( char modulation_str[8] = {0}; char history_stat_str[16] = {0}; - protopirate_get_frequency_modulation_str( - app, frequency_str, sizeof(frequency_str), modulation_str, sizeof(modulation_str)); + protopirate_get_frequency_modulation_str(app, frequency_str, 16, modulation_str, 8); if(ctx && ctx->frequency > 0U) { snprintf( frequency_str, - sizeof(frequency_str), + 20, "%03lu.%02lu", (unsigned long)((ctx->frequency / 1000000UL) % 1000UL), (unsigned long)((ctx->frequency / 10000UL) % 100UL)); @@ -240,13 +255,20 @@ static void protopirate_scene_sub_decode_update_receiver_statusbar( const uint16_t signal_count = (ctx && ctx->history) ? protopirate_history_get_item(ctx->history) : 0U; - snprintf( - history_stat_str, sizeof(history_stat_str), "%u/%u", signal_count, PROTOPIRATE_HISTORY_MAX); + snprintf(history_stat_str, 16, "%u/%u", signal_count, PROTOPIRATE_HISTORY_MAX); bool is_external = app->txrx->radio_device ? radio_device_loader_is_external(app->txrx->radio_device) : false; + protopirate_view_receiver_add_data_statusbar( - app->protopirate_receiver, frequency_str, modulation_str, history_stat_str, is_external); + app->protopirate_receiver, + frequency_str, + 16, + modulation_str, + 8, + history_stat_str, + 16, + is_external); } static void protopirate_scene_sub_decode_update_receiver_progress( diff --git a/views/protopirate_receiver.c b/views/protopirate_receiver.c index 2dcc99c..cd7e5ff 100644 --- a/views/protopirate_receiver.c +++ b/views/protopirate_receiver.c @@ -27,9 +27,9 @@ typedef struct { uint8_t history_item; float rssi; bool auto_save; - FuriString* frequency_str; - FuriString* preset_str; - FuriString* history_stat_str; + char* frequency_str; + char* preset_str; + char* history_stat_str; FuriString* draw_scratch; bool external_radio; ProtoPirateLock lock; @@ -191,24 +191,26 @@ static void protopirate_view_receiver_update_offset(ProtoPirateReceiver* receive void protopirate_view_receiver_add_data_statusbar( ProtoPirateReceiver* receiver, const char* frequency_str, + size_t freqency_size, const char* preset_str, + size_t preset_size, const char* history_stat_str, + size_t history_stat_size, bool external_radio) { furi_check(receiver); with_view_model( receiver->view, ProtoPirateReceiverModel * model, { - furi_string_set_str(model->frequency_str, frequency_str); - furi_string_set_str(model->preset_str, preset_str); - furi_string_set_str(model->history_stat_str, history_stat_str); + memcpy(model->frequency_str, frequency_str, freqency_size); + memcpy(model->preset_str, preset_str, preset_size); + memcpy(model->history_stat_str, history_stat_str, history_stat_size); model->external_radio = external_radio; }, true); } static void protopirate_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) { - canvas_set_color(canvas, ColorBlack); canvas_draw_box(canvas, 0, 0 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT); canvas_set_color(canvas, ColorWhite); @@ -280,6 +282,9 @@ void protopirate_view_receiver_draw(Canvas* canvas, ProtoPirateReceiverModel* mo canvas, 4, 9 + (i * FRAME_HEIGHT), furi_string_get_cstr(model->draw_scratch)); } + //Last item may be selected, it wont reset. + canvas_set_color(canvas, ColorBlack); + //Draw scrollbar if needed if(scrollbar) { // Calculate maximum scroll position @@ -360,8 +365,7 @@ void protopirate_view_receiver_draw(Canvas* canvas, ProtoPirateReceiverModel* mo canvas_set_font(canvas, FontSecondary); if(model->sub_decode_mode) { - canvas_draw_str_aligned( - canvas, 127, 0, AlignRight, AlignTop, furi_string_get_cstr(model->preset_str)); + canvas_draw_str_aligned(canvas, 127, 0, AlignRight, AlignTop, model->preset_str); } else { if(model->external_radio) { canvas_draw_str_aligned(canvas, 127, 0, AlignRight, AlignTop, "Ext"); @@ -381,12 +385,12 @@ void protopirate_view_receiver_draw(Canvas* canvas, ProtoPirateReceiverModel* mo //Draw the unlock instructions last, so they appear on top... if(model->lock_count) { if(model->sub_decode_mode) { - canvas_draw_str(canvas, 44, 63, furi_string_get_cstr(model->frequency_str)); - canvas_draw_str(canvas, 96, 63, furi_string_get_cstr(model->history_stat_str)); + canvas_draw_str(canvas, 44, 63, model->frequency_str); + canvas_draw_str(canvas, 96, 63, model->history_stat_str); } else { - canvas_draw_str(canvas, 44, 63, furi_string_get_cstr(model->frequency_str)); - canvas_draw_str(canvas, 79, 63, furi_string_get_cstr(model->preset_str)); - canvas_draw_str(canvas, 96, 63, furi_string_get_cstr(model->history_stat_str)); + canvas_draw_str(canvas, 44, 63, model->frequency_str); + canvas_draw_str(canvas, 79, 63, model->preset_str); + canvas_draw_str(canvas, 96, 63, model->history_stat_str); } canvas_set_font(canvas, FontSecondary); elements_bold_rounded_frame(canvas, 14, 8, 99, 48); @@ -402,12 +406,12 @@ void protopirate_view_receiver_draw(Canvas* canvas, ProtoPirateReceiverModel* mo canvas_draw_str(canvas, 74, 62, "Locked"); } else { if(model->sub_decode_mode) { - canvas_draw_str(canvas, 44, 63, furi_string_get_cstr(model->frequency_str)); - canvas_draw_str(canvas, 96, 63, furi_string_get_cstr(model->history_stat_str)); + canvas_draw_str(canvas, 44, 63, model->frequency_str); + canvas_draw_str(canvas, 96, 63, model->history_stat_str); } else { - canvas_draw_str(canvas, 44, 63, furi_string_get_cstr(model->frequency_str)); - canvas_draw_str(canvas, 79, 63, furi_string_get_cstr(model->preset_str)); - canvas_draw_str(canvas, 96, 63, furi_string_get_cstr(model->history_stat_str)); + canvas_draw_str(canvas, 44, 63, model->frequency_str); + canvas_draw_str(canvas, 79, 63, model->preset_str); + canvas_draw_str(canvas, 96, 63, model->history_stat_str); } } } @@ -583,9 +587,9 @@ ProtoPirateReceiver* protopirate_view_receiver_alloc(bool auto_save) { ProtoPirateReceiverModel * model, { model->history = NULL; - model->frequency_str = furi_string_alloc(); - model->preset_str = furi_string_alloc(); - model->history_stat_str = furi_string_alloc(); + model->frequency_str = malloc(16); + model->preset_str = malloc(8); + model->history_stat_str = malloc(16); model->draw_scratch = furi_string_alloc(); furi_check(model->draw_scratch); model->list_offset = 0; @@ -612,9 +616,9 @@ void protopirate_view_receiver_free(ProtoPirateReceiver* receiver) { receiver->view, ProtoPirateReceiverModel * model, { - furi_string_free(model->frequency_str); - furi_string_free(model->preset_str); - furi_string_free(model->history_stat_str); + free(model->frequency_str); + free(model->preset_str); + free(model->history_stat_str); furi_string_free(model->draw_scratch); }, false); diff --git a/views/protopirate_receiver.h b/views/protopirate_receiver.h index 679391d..f7b8d2e 100644 --- a/views/protopirate_receiver.h +++ b/views/protopirate_receiver.h @@ -21,8 +21,11 @@ View* protopirate_view_receiver_get_view(ProtoPirateReceiver* receiver); void protopirate_view_receiver_add_data_statusbar( ProtoPirateReceiver* receiver, const char* frequency_str, + size_t freqency_size, const char* preset_str, + size_t preset_size, const char* history_stat_str, + size_t history_stat_size, bool external_radio); uint16_t protopirate_view_receiver_get_idx_menu(ProtoPirateReceiver* receiver);