Use scene state instead of other methods for BUtton Assignment Remembering

This commit is contained in:
Leeroy
2026-09-23 19:20:06 +10:00
parent 73dd992dcb
commit eefc3edffa
3 changed files with 34 additions and 38 deletions
+4 -1
View File
@@ -279,7 +279,7 @@ static void bf_finish_and_show_result(void* app, ButtonCallback result_callback)
g_host_api->notification_success(app);
}
ButtonCallback ok_cb = result_callback;
if(!ok_cb && g_active_ctx == ProtoPiratePsaBfContextReceiverInfo) {
if(!ok_cb && (g_active_ctx == ProtoPiratePsaBfContextReceiverInfo)) {
ok_cb = bf_result_ok_callback;
}
show_bf_result(app, status, ok_cb);
@@ -459,6 +459,9 @@ static bool
}
return true;
}
if(event.event == ProtoPirateCustomEventReceiverInfoBruteforceCancel) {
return true;
}
}
return false;
+11 -25
View File
@@ -8,30 +8,14 @@
#define TAG "ProtoPirateReceiverInfo"
#define STATE_EMULATE 0
#define STATE_BF 1
static void protopirate_scene_receiver_info_widget_callback(
GuiButtonType result,
InputType type,
void* context);
static bool
protopirate_receiver_info_selected_protocol_is(ProtoPirateApp* app, const char* protocol_name) {
if(!app || !app->txrx || !app->txrx->history || !protocol_name) return false;
FlipperFormat* ff =
protopirate_history_get_raw_data(app->txrx->history, app->txrx->idx_menu_chosen);
if(!ff) return false;
bool match = false;
FuriString* protocol = furi_string_alloc();
if(protocol) {
flipper_format_rewind(ff);
match = flipper_format_read_string(ff, FF_PROTOCOL, protocol) &&
furi_string_cmp_str(protocol, protocol_name) == 0;
furi_string_free(protocol);
}
return match;
}
static void protopirate_scene_receiver_info_text_input_callback(void* context) {
ProtoPirateApp* app = context;
view_dispatcher_send_custom_event(
@@ -135,6 +119,7 @@ static void protopirate_receiver_info_build_normal_widget(ProtoPirateApp* app) {
}
protopirate_psa_bf_plugin_unload_if_idle(app);
if(needs_bf) {
scene_manager_set_scene_state(app->scene_manager, ProtoPirateSceneSavedInfo, STATE_BF);
widget_add_button_element(
app->widget,
GuiButtonTypeLeft,
@@ -142,8 +127,11 @@ static void protopirate_receiver_info_build_normal_widget(ProtoPirateApp* app) {
protopirate_scene_receiver_info_widget_callback,
app);
} else
scene_manager_set_scene_state(
app->scene_manager, ProtoPirateSceneSavedInfo, STATE_EMULATE);
#ifdef ENABLE_EMULATE_FEATURE
if(app->emulate_feature_enabled && !app->emulate_disabled_for_loaded) {
if(app->emulate_feature_enabled && !app->emulate_disabled_for_loaded) {
widget_add_button_element(
app->widget,
GuiButtonTypeLeft,
@@ -183,13 +171,11 @@ static void protopirate_scene_receiver_info_widget_callback(
has_match ? ProtoPirateCustomEventReceiverInfoUpdate :
ProtoPirateCustomEventReceiverInfoSave);
} else if(result == GuiButtonTypeLeft) {
if((protopirate_receiver_info_selected_protocol_is(app, "PSA") ||
protopirate_receiver_info_selected_protocol_is(app, "Renault V1")) &&
protopirate_psa_bf_plugin_ensure_loaded(app) && app->psa_bf_plugin &&
app->psa_bf_plugin->widget_left_should_bruteforce(
app, ProtoPiratePsaBfContextReceiverInfo)) {
if(scene_manager_get_scene_state(app->scene_manager, ProtoPirateSceneSubDecode) ==
STATE_BF) {
view_dispatcher_send_custom_event(
app->view_dispatcher, ProtoPirateCustomEventReceiverInfoBruteforceStart);
}
#ifdef ENABLE_EMULATE_FEATURE
else if(app->emulate_feature_enabled && !app->emulate_disabled_for_loaded) {
+19 -12
View File
@@ -2,6 +2,9 @@
#include "../protopirate_app_i.h"
#ifdef ENABLE_SUB_DECODE_SCENE
#define STATE_EMULATE 0
#define STATE_BF 1
#ifndef PROTOPIRATE_SUB_DECODE_PLUGIN_BUILD
void protopirate_scene_sub_decode_on_enter(void* context) {
@@ -134,7 +137,6 @@ typedef struct {
uint16_t signal_count;
uint16_t selected_history_index;
bool showing_signal_info;
bool signal_info_left_is_emulate;
bool previous_preset_saved;
char previous_preset_name[SUB_DECODE_PRESET_NAME_MAX];
uint32_t previous_frequency;
@@ -371,10 +373,11 @@ static void protopirate_scene_sub_decode_widget_callback(
view_dispatcher_send_custom_event(
app->view_dispatcher, ProtoPirateCustomEventSubDecodeSave);
} else if(result == GuiButtonTypeLeft) {
SubDecodeContext* ctx = g_decode_ctx;
const uint32_t left_event = (ctx && ctx->signal_info_left_is_emulate) ?
ProtoPirateCustomEventSubDecodeEmulate :
ProtoPirateCustomEventSubDecodeBruteforceStart;
const uint32_t left_event =
(scene_manager_get_scene_state(app->scene_manager, ProtoPirateSceneSubDecode) ==
STATE_BF) ?
ProtoPirateCustomEventSubDecodeBruteforceStart :
ProtoPirateCustomEventSubDecodeEmulate;
view_dispatcher_send_custom_event(app->view_dispatcher, left_event);
}
}
@@ -475,7 +478,6 @@ static void protopirate_scene_sub_decode_reset_for_file(SubDecodeContext* ctx) {
ctx->signal_count = 0;
ctx->selected_history_index = 0;
ctx->showing_signal_info = false;
ctx->signal_info_left_is_emulate = false;
ctx->worker_startup_delay = 0;
ctx->decode_elapsed_us = 0;
}
@@ -1300,9 +1302,8 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
protopirate_scene_sub_decode_widget_callback,
app);
ctx->signal_info_left_is_emulate = false;
#ifdef ENABLE_EMULATE_FEATURE
bool left_button_used = false;
bool left_button_bf = false;
#endif
app->emulate_disabled_for_loaded = true;
@@ -1333,6 +1334,9 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
}
protopirate_psa_bf_plugin_unload_if_idle(app);
if(needs_bf) {
scene_manager_set_scene_state(
app->scene_manager, ProtoPirateSceneSubDecode, STATE_BF);
widget_add_button_element(
app->widget,
GuiButtonTypeLeft,
@@ -1340,14 +1344,15 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
protopirate_scene_sub_decode_widget_callback,
app);
#ifdef ENABLE_EMULATE_FEATURE
left_button_used = true;
left_button_bf = true;
#endif
}
}
}
#ifdef ENABLE_EMULATE_FEATURE
if(!left_button_used && app->emulate_feature_enabled &&
if(!left_button_bf && app->app->emulate_feature_enabled &&
!app->emulate_disabled_for_loaded) {
widget_add_button_element(
app->widget,
@@ -1355,11 +1360,13 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
"Emulate",
protopirate_scene_sub_decode_widget_callback,
app);
ctx->signal_info_left_is_emulate = true;
left_button_used = true;
}
#endif
scene_manager_set_scene_state(
app->scene_manager,
ProtoPirateSceneSubDecode,
left_button_bf ? STATE_BF : STATE_EMULATE);
furi_string_free(text);
}