SubGhz: remove direct reading subghz->txrx->rx_key_state

This commit is contained in:
gid9798 2023-05-06 17:47:49 +03:00
parent 1387d8d5d6
commit 1567225a64
9 changed files with 47 additions and 34 deletions

View File

@ -37,22 +37,22 @@ void subghz_scene_need_saving_on_enter(void* context) {
bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context; SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeBack) { if(event.type == SceneManagerEventTypeBack) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack);
scene_manager_previous_scene(subghz->scene_manager); scene_manager_previous_scene(subghz->scene_manager);
return true; return true;
} else if(event.type == SceneManagerEventTypeCustom) { } else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventSceneStay) { if(event.event == SubGhzCustomEventSceneStay) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack);
scene_manager_previous_scene(subghz->scene_manager); scene_manager_previous_scene(subghz->scene_manager);
return true; return true;
} else if(event.event == SubGhzCustomEventSceneExit) { } else if(event.event == SubGhzCustomEventSceneExit) {
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateExit) { if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateExit) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0);
scene_manager_search_and_switch_to_previous_scene( scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart); subghz->scene_manager, SubGhzSceneStart);
} else { } else {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
scene_manager_previous_scene(subghz->scene_manager); scene_manager_previous_scene(subghz->scene_manager);
} }

View File

@ -71,7 +71,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
SubGhz* subghz = context; SubGhz* subghz = context;
FuriString* file_name = furi_string_alloc(); FuriString* file_name = furi_string_alloc();
switch(subghz->txrx->rx_key_state) { switch(subghz_rx_key_state_get(subghz)) {
case SubGhzRxKeyStateBack: case SubGhzRxKeyStateBack:
subghz_read_raw_set_status( subghz_read_raw_set_status(
subghz->subghz_read_raw, subghz->subghz_read_raw,
@ -86,7 +86,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
SubGhzReadRAWStatusLoadKeyTX, SubGhzReadRAWStatusLoadKeyTX,
furi_string_get_cstr(file_name), furi_string_get_cstr(file_name),
subghz_threshold_rssi_get(subghz->threshold_rssi)); subghz_threshold_rssi_get(subghz->threshold_rssi));
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
break; break;
case SubGhzRxKeyStateRAWSave: case SubGhzRxKeyStateRAWSave:
path_extract_filename(subghz->file_path, file_name, true); path_extract_filename(subghz->file_path, file_name, true);
@ -95,7 +95,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
SubGhzReadRAWStatusSaveKey, SubGhzReadRAWStatusSaveKey,
furi_string_get_cstr(file_name), furi_string_get_cstr(file_name),
subghz_threshold_rssi_get(subghz->threshold_rssi)); subghz_threshold_rssi_get(subghz->threshold_rssi));
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
break; break;
default: default:
subghz_read_raw_set_status( subghz_read_raw_set_status(
@ -103,7 +103,7 @@ void subghz_scene_read_raw_on_enter(void* context) {
SubGhzReadRAWStatusStart, SubGhzReadRAWStatusStart,
"", "",
subghz_threshold_rssi_get(subghz->threshold_rssi)); subghz_threshold_rssi_get(subghz->threshold_rssi));
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
break; break;
} }
furi_string_free(file_name); furi_string_free(file_name);
@ -133,9 +133,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result); (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result);
subghz->state_notifications = SubGhzNotificationStateIDLE; subghz->state_notifications = SubGhzNotificationStateIDLE;
//needed save? //needed save?
if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) || if((subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) ||
(subghz->txrx->rx_key_state == SubGhzRxKeyStateBack)) { (subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateBack)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else { } else {
//Restore default setting //Restore default setting
@ -175,13 +175,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
break; break;
case SubGhzCustomEventViewReadRAWErase: case SubGhzCustomEventViewReadRAWErase:
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) {
if(subghz_scene_read_raw_update_filename(subghz)) { if(subghz_scene_read_raw_update_filename(subghz)) {
furi_string_set(subghz->file_path_tmp, subghz->file_path); furi_string_set(subghz->file_path_tmp, subghz->file_path);
subghz_delete_file(subghz); subghz_delete_file(subghz);
} }
} }
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
notification_message(subghz->notifications, &sequence_reset_rgb); notification_message(subghz->notifications, &sequence_reset_rgb);
consumed = true; consumed = true;
break; break;
@ -191,7 +191,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
if(subghz_scene_read_raw_update_filename(subghz)) { if(subghz_scene_read_raw_update_filename(subghz)) {
scene_manager_set_scene_state( scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet); subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW);
consumed = true; consumed = true;
} else { } else {
@ -214,7 +214,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz_txrx_stop(subghz); subghz_txrx_stop(subghz);
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack);
subghz_read_raw_set_status( subghz_read_raw_set_status(
subghz->subghz_read_raw, subghz->subghz_read_raw,
SubGhzReadRAWStatusIDLE, SubGhzReadRAWStatusIDLE,
@ -272,13 +272,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
} }
subghz->state_notifications = SubGhzNotificationStateIDLE; subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
consumed = true; consumed = true;
break; break;
case SubGhzCustomEventViewReadRAWREC: case SubGhzCustomEventViewReadRAWREC:
if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) { if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateIDLE) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else { } else {
if(subghz_protocol_raw_save_to_file_init( if(subghz_protocol_raw_save_to_file_init(
@ -294,7 +294,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
subghz_rx(subghz, subghz->txrx->preset->frequency); subghz_rx(subghz, subghz->txrx->preset->frequency);
subghz->state_notifications = SubGhzNotificationStateRx; subghz->state_notifications = SubGhzNotificationStateRx;
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
} else { } else {
furi_string_set(subghz->error_str, "Function requires\nan SD card."); furi_string_set(subghz->error_str, "Function requires\nan SD card.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
@ -307,7 +307,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
if(subghz_file_available(subghz) && subghz_scene_read_raw_update_filename(subghz)) { if(subghz_file_available(subghz) && subghz_scene_read_raw_update_filename(subghz)) {
scene_manager_set_scene_state( scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW); subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW);
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
} else { } else {
if(!scene_manager_search_and_switch_to_previous_scene( if(!scene_manager_search_and_switch_to_previous_scene(

View File

@ -112,7 +112,7 @@ static void subghz_scene_add_to_history_callback(
subghz_receiver_reset(receiver); subghz_receiver_reset(receiver);
furi_string_free(item_name); furi_string_free(item_name);
furi_string_free(item_time); furi_string_free(item_time);
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
} }
void subghz_scene_receiver_on_enter(void* context) { void subghz_scene_receiver_on_enter(void* context) {
@ -121,10 +121,10 @@ void subghz_scene_receiver_on_enter(void* context) {
FuriString* item_name = furi_string_alloc(); FuriString* item_name = furi_string_alloc();
FuriString* item_time = furi_string_alloc(); FuriString* item_time = furi_string_alloc();
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) { if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) {
subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0);
subghz_history_reset(subghz->txrx->history); subghz_history_reset(subghz->txrx->history);
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart);
} }
subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz_is_locked(subghz)); subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz_is_locked(subghz));
@ -142,7 +142,7 @@ void subghz_scene_receiver_on_enter(void* context) {
furi_string_get_cstr(item_name), furi_string_get_cstr(item_name),
furi_string_get_cstr(item_time), furi_string_get_cstr(item_time),
subghz_history_get_type_protocol(subghz->txrx->history, i)); subghz_history_get_type_protocol(subghz->txrx->history, i));
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey);
} }
furi_string_free(item_name); furi_string_free(item_name);
furi_string_free(item_time); furi_string_free(item_time);
@ -219,11 +219,11 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
subghz->txrx->idx_menu_chosen = 0; subghz->txrx->idx_menu_chosen = 0;
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz); subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
} else { } else {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0); subghz_preset_init(subghz, "AM650", subghz->last_settings->frequency, NULL, 0);
scene_manager_search_and_switch_to_previous_scene( scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart); subghz->scene_manager, SubGhzSceneStart);

View File

@ -27,10 +27,10 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event)
if(!subghz->in_decoder_scene) { if(!subghz->in_decoder_scene) {
if(!scene_manager_search_and_switch_to_previous_scene( if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneReceiver)) { subghz->scene_manager, SubGhzSceneReceiver)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWSave; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWSave);
if(!scene_manager_search_and_switch_to_previous_scene( if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneReadRAW)) { subghz->scene_manager, SubGhzSceneReadRAW)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
if(!scene_manager_search_and_switch_to_previous_scene( if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) { subghz->scene_manager, SubGhzSceneSaved)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);

View File

@ -5,7 +5,7 @@ void subghz_scene_saved_on_enter(void* context) {
if(subghz_load_protocol_from_file(subghz)) { if(subghz_load_protocol_from_file(subghz)) {
if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
} else { } else {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSavedMenu); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSavedMenu);

View File

@ -93,7 +93,7 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
} else if(event.event == SubmenuIndexReadRAW) { } else if(event.event == SubmenuIndexReadRAW) {
scene_manager_set_scene_state( scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW); subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW);
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
return true; return true;
} else if(event.event == SubmenuIndexRead) { } else if(event.event == SubmenuIndexRead) {

View File

@ -273,7 +273,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
subghz->txrx->txrx_state = SubGhzTxRxStateSleep; subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
subghz_hopper_set_state(subghz, SubGhzHopperStateOFF); subghz_hopper_set_state(subghz, SubGhzHopperStateOFF);
subghz->txrx->speaker_state = SubGhzSpeakerStateDisable; subghz->txrx->speaker_state = SubGhzSpeakerStateDisable;
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
subghz->txrx->debug_pin_state = false; subghz->txrx->debug_pin_state = false;
if(!alloc_for_tx_only) { if(!alloc_for_tx_only) {
subghz->txrx->history = subghz_history_alloc(); subghz->txrx->history = subghz_history_alloc();
@ -480,7 +480,7 @@ int32_t subghz_app(void* p) {
if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) { if((subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw)) {
//Load Raw TX //Load Raw TX
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
} else { } else {
//Load transmitter TX //Load transmitter TX

View File

@ -731,4 +731,14 @@ void subghz_unlock(SubGhz* subghz) {
bool subghz_is_locked(SubGhz* subghz) { bool subghz_is_locked(SubGhz* subghz) {
furi_assert(subghz); furi_assert(subghz);
return (subghz->lock == SubGhzLockOn); return (subghz->lock == SubGhzLockOn);
}
void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state) {
furi_assert(subghz);
subghz->rx_key_state = state;
}
SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz) {
furi_assert(subghz);
return subghz->rx_key_state;
} }

View File

@ -85,7 +85,6 @@ struct SubGhzTxRx {
bool ignore_auto_alarms; bool ignore_auto_alarms;
bool ignore_magellan; bool ignore_magellan;
SubGhzRxKeyState rx_key_state;
SubGhzLoadTypeFile load_type_file; SubGhzLoadTypeFile load_type_file;
bool debug_pin_state; bool debug_pin_state;
@ -137,6 +136,7 @@ struct SubGhz {
SubGhzFileEncoderWorker* decode_raw_file_worker_encoder; SubGhzFileEncoderWorker* decode_raw_file_worker_encoder;
SubGhzThresholdRssi* threshold_rssi; SubGhzThresholdRssi* threshold_rssi;
SubGhzRxKeyState rx_key_state;
void* rpc_ctx; void* rpc_ctx;
}; };
@ -192,5 +192,8 @@ bool subghz_is_locked(SubGhz* subghz);
SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz);
void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state);
SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz);
extern const NotificationSequence subghz_sequence_rx; extern const NotificationSequence subghz_sequence_rx;
extern const NotificationSequence subghz_sequence_rx_locked; extern const NotificationSequence subghz_sequence_rx_locked;