diff options
author | Skorpionm <85568270+Skorpionm@users.noreply.github.com> | 2021-11-24 16:59:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 16:59:45 +0300 |
commit | a13f87fedb3f31a4a450e5da52750a5e45c5e30d (patch) | |
tree | 4b75681fdd0656bba1331ff0f05a9c9d78b70a12 /applications/subghz/scenes | |
parent | 01f08f99b1d307d0e8406309ae5da2122031b3f0 (diff) |
[FL-2047] SubGhz: New GUI ReadRAW view (#832)
* SubGhz: GUI RAW Read view
* SubGhz: GUI Read RAW refactoring
* SubGhz: fix bug wrong frequency of the allowed transmission
* GUI Read RAW refactoring
* SubGhz: fix set the default frequency
* SubGhz: fix save filename when returning from another menu
* SubGhz: fix Send and Back button behavior
Co-authored-by: あく <alleteam@gmail.com>
Diffstat (limited to 'applications/subghz/scenes')
7 files changed, 140 insertions, 107 deletions
diff --git a/applications/subghz/scenes/subghz_scene_config.h b/applications/subghz/scenes/subghz_scene_config.h index 6d89cb74..d0be3c00 100644 --- a/applications/subghz/scenes/subghz_scene_config.h +++ b/applications/subghz/scenes/subghz_scene_config.h @@ -18,5 +18,4 @@ ADD_SCENE(subghz, test_packet, TestPacket) ADD_SCENE(subghz, set_type, SetType) ADD_SCENE(subghz, frequency_analyzer, FrequencyAnalyzer) ADD_SCENE(subghz, read_raw, ReadRAW) -ADD_SCENE(subghz, read_raw_menu, ReadRAWMenu) ADD_SCENE(subghz, need_saving, NeedSaving)
\ No newline at end of file diff --git a/applications/subghz/scenes/subghz_scene_need_saving.c b/applications/subghz/scenes/subghz_scene_need_saving.c index c7f83ce0..b46b2450 100644 --- a/applications/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/subghz/scenes/subghz_scene_need_saving.c @@ -6,11 +6,9 @@ void subghz_scene_need_saving_callback(GuiButtonType result, InputType type, voi SubGhz* subghz = context; if((result == GuiButtonTypeRight) && (type == InputTypeShort)) { - view_dispatcher_send_custom_event( - subghz->view_dispatcher, SubghzCustomEventSceneNeedSavingYes); + view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneStay); } else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) { - view_dispatcher_send_custom_event( - subghz->view_dispatcher, SubghzCustomEventSceneNeedSavingNo); + view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneExit); } } @@ -18,30 +16,36 @@ void subghz_scene_need_saving_on_enter(void* context) { SubGhz* subghz = context; widget_add_string_multiline_element( + subghz->widget, 64, 13, AlignCenter, AlignCenter, FontPrimary, "Exit to Gub-Ghz menu?"); + widget_add_string_multiline_element( subghz->widget, 64, - 25, + 32, AlignCenter, AlignCenter, FontSecondary, - "There is an unsaved data.\nDo you want to save it?"); + "All unsaved will be\nlost."); widget_add_button_element( - subghz->widget, GuiButtonTypeRight, "Save", subghz_scene_need_saving_callback, subghz); + subghz->widget, GuiButtonTypeRight, "Stay", subghz_scene_need_saving_callback, subghz); widget_add_button_element( - subghz->widget, GuiButtonTypeLeft, "Delete", subghz_scene_need_saving_callback, subghz); + subghz->widget, GuiButtonTypeLeft, "Exit", subghz_scene_need_saving_callback, subghz); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget); } bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubghzCustomEventSceneNeedSavingYes) { - subghz->txrx->rx_key_state = SubGhzRxKeyStateNeedSave; + if(event.type == SceneManagerEventTypeBack) { + subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + scene_manager_previous_scene(subghz->scene_manager); + return true; + } else if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubghzCustomEventSceneStay) { + subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; scene_manager_previous_scene(subghz->scene_manager); return true; - } else if(event.event == SubghzCustomEventSceneNeedSavingNo) { + } else if(event.event == SubghzCustomEventSceneExit) { if(subghz->txrx->rx_key_state == SubGhzRxKeyStateExit) { subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; scene_manager_search_and_switch_to_previous_scene( diff --git a/applications/subghz/scenes/subghz_scene_read_raw.c b/applications/subghz/scenes/subghz_scene_read_raw.c index 7bf5576e..0bdd394c 100644 --- a/applications/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/subghz/scenes/subghz_scene_read_raw.c @@ -2,6 +2,9 @@ #include "../views/subghz_read_raw.h" #include <lib/subghz/protocols/subghz_protocol_raw.h> #include <lib/subghz/subghz_parser.h> +#include <lib/toolbox/path.h> + +#define RAW_FILE_NAME "Raw_temp" static void subghz_scene_read_raw_update_statusbar(void* context) { furi_assert(context); @@ -27,13 +30,20 @@ void subghz_scene_read_raw_callback(SubghzCustomEvent event, void* context) { view_dispatcher_send_custom_event(subghz->view_dispatcher, event); } +void subghz_scene_read_raw_callback_end_tx(void* context) { + furi_assert(context); + SubGhz* subghz = context; + view_dispatcher_send_custom_event( + subghz->view_dispatcher, SubghzCustomEventViewReadRAWSendStop); +} + void subghz_scene_read_raw_on_enter(void* context) { SubGhz* subghz = context; - if(subghz->txrx->rx_key_state == SubGhzRxKeyStateNeedSave) { - view_dispatcher_send_custom_event( - subghz->view_dispatcher, SubghzCustomEventViewReadRAWMore); + if(subghz->txrx->rx_key_state == SubGhzRxKeyStateBack) { + subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusIDLE); } else { + subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusStart); subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; } @@ -46,6 +56,11 @@ void subghz_scene_read_raw_on_enter(void* context) { subghz_worker_set_pair_callback( subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_raw_parse); + subghz_protocol_raw_file_encoder_worker_set_callback_end( + (SubGhzProtocolRAW*)subghz->txrx->protocol_result, + subghz_scene_read_raw_callback_end_tx, + subghz); + view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewReadRAW); } @@ -54,20 +69,29 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case SubghzCustomEventViewReadRAWBack: + //Stop TX + if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { + subghz_tx_stop(subghz); + subghz_sleep(subghz); + } + //Stop RX if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { subghz_rx_end(subghz); subghz_sleep(subghz); }; - subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92]; - subghz->txrx->preset = FuriHalSubGhzPresetOok650Async; + //Stop save file subghz_protocol_raw_save_to_file_stop( (SubGhzProtocolRAW*)subghz->txrx->protocol_result); subghz->state_notifications = SubGhzNotificationStateIDLE; - - if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { + //needed save? + if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) || + (subghz->txrx->rx_key_state == SubGhzRxKeyStateBack)) { subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { + //Restore default setting + subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92]; + subghz->txrx->preset = FuriHalSubGhzPresetOok650Async; scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } @@ -80,6 +104,63 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig); return true; break; + case SubghzCustomEventViewReadRAWErase: + subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; + return true; + break; + case SubghzCustomEventViewReadRAWSendStart: + //set the path to read the file + if(strcmp( + subghz_protocol_raw_get_last_file_name( + (SubGhzProtocolRAW*)subghz->txrx->protocol_result), + "")) { + string_t temp_str; + string_init_printf( + temp_str, + "%s", + subghz_protocol_raw_get_last_file_name( + (SubGhzProtocolRAW*)subghz->txrx->protocol_result)); + path_extract_filename_no_ext(string_get_cstr(temp_str), temp_str); + strlcpy( + subghz->file_name, + string_get_cstr(temp_str), + strlen(string_get_cstr(temp_str)) + 1); + string_printf( + temp_str, + "%s/%s%s", + SUBGHZ_APP_PATH_FOLDER, + subghz->file_name, + SUBGHZ_APP_EXTENSION); + + subghz_protocol_raw_set_last_file_name( + (SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str)); + string_clear(temp_str); + //start send + subghz->state_notifications = SubGhzNotificationStateIDLE; + if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { + subghz_rx_end(subghz); + } + if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || + (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { + if(!subghz_tx_start(subghz)) { + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); + } else { + subghz->state_notifications = SubGhzNotificationStateTX; + subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; + } + } + } + return true; + break; + case SubghzCustomEventViewReadRAWSendStop: + subghz->state_notifications = SubGhzNotificationStateIDLE; + if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { + subghz_tx_stop(subghz); + subghz_sleep(subghz); + } + subghz_read_raw_stop_send(subghz->subghz_read_raw); + return true; + break; case SubghzCustomEventViewReadRAWIDLE: if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { subghz_rx_end(subghz); @@ -101,7 +182,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz_get_preset_name(subghz, subghz->error_str); if(subghz_protocol_raw_save_to_file_init( (SubGhzProtocolRAW*)subghz->txrx->protocol_result, - "Raw_temp", + RAW_FILE_NAME, subghz->txrx->frequency, string_get_cstr(subghz->error_str))) { if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || @@ -118,21 +199,25 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { return true; break; - case SubghzCustomEventViewReadRAWMore: + case SubghzCustomEventViewReadRAWSave: if(strcmp( subghz_protocol_raw_get_last_file_name( (SubGhzProtocolRAW*)subghz->txrx->protocol_result), "")) { + string_t temp_str; + string_init_printf( + temp_str, + "%s", + subghz_protocol_raw_get_last_file_name( + (SubGhzProtocolRAW*)subghz->txrx->protocol_result)); + path_extract_filename_no_ext(string_get_cstr(temp_str), temp_str); strlcpy( subghz->file_name, - subghz_protocol_raw_get_last_file_name( - (SubGhzProtocolRAW*)subghz->txrx->protocol_result), - strlen(subghz_protocol_raw_get_last_file_name( - (SubGhzProtocolRAW*)subghz->txrx->protocol_result)) + - 1); + string_get_cstr(temp_str), + strlen(string_get_cstr(temp_str)) + 1); + //set the path to read the file - string_t temp_str; - string_init_printf( + string_printf( temp_str, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, @@ -142,7 +227,10 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { (SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str)); string_clear(temp_str); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAWMenu); + scene_manager_set_scene_state( + subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerSet); + subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); } return true; break; @@ -160,6 +248,10 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { (SubGhzProtocolRAW*)subghz->txrx->protocol_result)); subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, furi_hal_subghz_get_rssi()); break; + case SubGhzNotificationStateTX: + notification_message(subghz->notifications, &sequence_blink_green_10); + subghz_read_raw_update_sin(subghz->subghz_read_raw); + break; default: break; } diff --git a/applications/subghz/scenes/subghz_scene_read_raw_menu.c b/applications/subghz/scenes/subghz_scene_read_raw_menu.c deleted file mode 100644 index 2c6deefc..00000000 --- a/applications/subghz/scenes/subghz_scene_read_raw_menu.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "../subghz_i.h" - -enum SubmenuIndex { - SubmenuIndexEmulate, - SubmenuIndexEdit, - SubmenuIndexDelete, -}; - -void subghz_scene_read_raw_menu_submenu_callback(void* context, uint32_t index) { - SubGhz* subghz = context; - view_dispatcher_send_custom_event(subghz->view_dispatcher, index); -} - -void subghz_scene_read_raw_menu_on_enter(void* context) { - SubGhz* subghz = context; - submenu_add_item( - subghz->submenu, - "Emulate", - SubmenuIndexEmulate, - subghz_scene_read_raw_menu_submenu_callback, - subghz); - - submenu_add_item( - subghz->submenu, - "Save", - SubmenuIndexEdit, - subghz_scene_read_raw_menu_submenu_callback, - subghz); - - submenu_add_item( - subghz->submenu, - "Delete", - SubmenuIndexDelete, - subghz_scene_read_raw_menu_submenu_callback, - subghz); - - submenu_set_selected_item( - subghz->submenu, - scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSavedMenu)); - - view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu); -} - -bool subghz_scene_read_raw_menu_on_event(void* context, SceneManagerEvent event) { - SubGhz* subghz = context; - - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexEmulate) { - scene_manager_set_scene_state( - subghz->scene_manager, SubGhzSceneReadRAWMenu, SubmenuIndexEmulate); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter); - return true; - } else if(event.event == SubmenuIndexDelete) { - scene_manager_set_scene_state( - subghz->scene_manager, SubGhzSceneReadRAWMenu, SubmenuIndexDelete); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDelete); - return true; - } else if(event.event == SubmenuIndexEdit) { - scene_manager_set_scene_state( - subghz->scene_manager, SubGhzSceneReadRAWMenu, SubghzCustomEventManagerSet); - scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); - return true; - } - } - return false; -} - -void subghz_scene_read_raw_menu_on_exit(void* context) { - SubGhz* subghz = context; - submenu_clean(subghz->submenu); - subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; -} diff --git a/applications/subghz/scenes/subghz_scene_save_name.c b/applications/subghz/scenes/subghz_scene_save_name.c index d448119c..b86f9655 100644 --- a/applications/subghz/scenes/subghz_scene_save_name.c +++ b/applications/subghz/scenes/subghz_scene_save_name.c @@ -2,6 +2,7 @@ #include <lib/toolbox/random_name.h> #include "file-worker.h" #include "../helpers/subghz_custom_event.h" +#include <lib/subghz/protocols/subghz_protocol_raw.h> void subghz_scene_save_name_text_input_callback(void* context) { SubGhz* subghz = context; @@ -20,7 +21,7 @@ void subghz_scene_save_name_on_enter(void* context) { dev_name_empty = true; } else { memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name) + 1); - if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAWMenu) == + if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) == SubghzCustomEventManagerSet) { subghz_get_next_name_file(subghz); } @@ -49,6 +50,11 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { subghz_save_protocol_to_file(subghz, subghz->file_name); } + if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) == + SubghzCustomEventManagerSet) { + subghz_protocol_raw_set_last_file_name( + (SubGhzProtocolRAW*)subghz->txrx->protocol_result, subghz->file_name); + } subghz_file_name_clear(subghz); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess); return true; @@ -68,5 +74,5 @@ void subghz_scene_save_name_on_exit(void* context) { // Clear view text_input_clean(subghz->text_input); scene_manager_set_scene_state( - subghz->scene_manager, SubGhzSceneReadRAWMenu, SubghzCustomEventManagerNoSet); + subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerNoSet); } diff --git a/applications/subghz/scenes/subghz_scene_save_success.c b/applications/subghz/scenes/subghz_scene_save_success.c index 31e7d3ee..7509abd8 100644 --- a/applications/subghz/scenes/subghz_scene_save_success.c +++ b/applications/subghz/scenes/subghz_scene_save_success.c @@ -26,8 +26,11 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) if(event.event == SubghzCustomEventSceneSaveSuccess) { if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneReceiver)) { - scene_manager_search_and_switch_to_previous_scene( - subghz->scene_manager, SubGhzSceneStart); + if(!scene_manager_search_and_switch_to_previous_scene( + subghz->scene_manager, SubGhzSceneReadRAW)) { + scene_manager_search_and_switch_to_previous_scene( + subghz->scene_manager, SubGhzSceneStart); + } } return true; } diff --git a/applications/subghz/scenes/subghz_scene_start.c b/applications/subghz/scenes/subghz_scene_start.c index 3b5b5cd1..ecdfde12 100644 --- a/applications/subghz/scenes/subghz_scene_start.c +++ b/applications/subghz/scenes/subghz_scene_start.c @@ -23,7 +23,7 @@ void subghz_scene_start_on_enter(void* context) { subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); submenu_add_item( subghz->submenu, - "Read Raw", + "Read RAW", SubmenuIndexReadRAW, subghz_scene_start_submenu_callback, subghz); @@ -57,6 +57,7 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) { if(event.event == SubmenuIndexReadRAW) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW); + subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); return true; } else if(event.event == SubmenuIndexRead) { |