Skip to content

Commit

Permalink
Improve binraw/repeater state logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Dec 14, 2023
1 parent fdc826a commit 36c46fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
19 changes: 8 additions & 11 deletions applications/main/subghz/scenes/subghz_scene_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,16 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz->repeater = subghz->last_settings->repeater_state;

//Did the user set BinRAW or me?
if(subghz->last_settings->repeater_state != SubGhzRepeaterStateOff) {
//Save the state, we are on.
subghz->repeater = subghz->last_settings->repeater_state;

if(subghz->repeater != SubGhzRepeaterStateOff) {
//User had BinRAW on if the last settings had BinRAW on, if not, repeater is on, and BinRAW goes on, but State CHanged is false!
subghz->bin_raw_menu_changed =
(subghz->last_settings->filter !=
(SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW));
subghz->filter = SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW;
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
subghz->repeater_bin_raw_was_off =
(subghz->last_settings->filter & SubGhzProtocolFlag_BinRAW) == 0;
if((subghz->filter & SubGhzProtocolFlag_BinRAW) == 0) {
subghz->filter = SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW;
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
}
} else {
subghz->repeater = SubGhzRepeaterStateOff;
subghz->bin_raw_menu_changed = false;
subghz->repeater_bin_raw_was_off = false;
}

subghz_txrx_rx_start(subghz->txrx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) {
subghz->last_settings->filter = subghz->filter;

//If the user changed BinRAW menu, dont reset it with the repeater.
subghz->bin_raw_menu_changed = false;
subghz->repeater_bin_raw_was_off = false;
}

static void subghz_scene_receiver_config_set_repeater(VariableItem* item) {
Expand All @@ -300,18 +300,17 @@ static void subghz_scene_receiver_config_set_repeater(VariableItem* item) {
variable_item_set_current_value_index(
bin_raw_menu, 1 /*Index of ON in BIN_Raw menu!*/);
subghz_scene_receiver_config_set_bin_raw(bin_raw_menu);
subghz->bin_raw_menu_changed = true;
subghz->repeater_bin_raw_was_off = true;
}

//Lock the BinRAW menu, Flipper doesnt understand everything so BinRAW makes every key send.
variable_item_set_locked(bin_raw_menu, true, NULL);
} else {
//Put BinRAW back how it was, if we changed it.
if(subghz->bin_raw_menu_changed) {
if(subghz->repeater_bin_raw_was_off) {
variable_item_set_current_value_index(
bin_raw_menu, 0 /*Index of OFF in BIN_Raw menu!*/);
subghz_scene_receiver_config_set_bin_raw(bin_raw_menu);
subghz->bin_raw_menu_changed = false;
}

//Lock the BinRAW menu, Flipper doesnt understand everything so BinRAW makes very key send.
Expand Down Expand Up @@ -681,7 +680,7 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even
void subghz_scene_receiver_config_on_exit(void* context) {
SubGhz* subghz = context;

if(subghz->bin_raw_menu_changed) {
if(subghz->repeater_bin_raw_was_off) {
subghz->last_settings->filter = bin_raw_value[0 /*BinRAW Off*/];
}

Expand Down
2 changes: 1 addition & 1 deletion applications/main/subghz/subghz_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct SubGhz {
SubGhzHistory* history;
SubGhzGPS* gps;
SubGhzRepeaterState repeater;
bool bin_raw_menu_changed;
bool repeater_bin_raw_was_off;

uint16_t idx_menu_chosen;
SubGhzLoadTypeFile load_type_file;
Expand Down

0 comments on commit 36c46fd

Please sign in to comment.