From 24e4c6522122a0429f876df1a8514b4ed832984e Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Wed, 17 May 2023 17:52:46 +0300 Subject: [PATCH] some improvement and cleanup --- .../helpers/subrem_custom_event.h | 66 +------ .../subghz_remote_new/helpers/subrem_types.h | 45 ++--- .../scenes/subrem_scene_openmapfile.c | 7 +- .../scenes/subrem_scene_remote.c | 171 ++++++++-------- .../scenes/subrem_scene_start.c | 54 ++--- .../subghz_remote_new/subghz_remote_app.c | 48 +---- .../subghz_remote_new/subghz_remote_app_i.c | 185 +++++++++++------- .../subghz_remote_new/subghz_remote_app_i.h | 36 ++-- .../views/{transmitter.c => remote.c} | 157 +++++++++------ .../views/{transmitter.h => remote.h} | 13 +- 10 files changed, 376 insertions(+), 406 deletions(-) rename applications/external/subghz_remote_new/views/{transmitter.c => remote.c} (67%) rename applications/external/subghz_remote_new/views/{transmitter.h => remote.h} (66%) diff --git a/applications/external/subghz_remote_new/helpers/subrem_custom_event.h b/applications/external/subghz_remote_new/helpers/subrem_custom_event.h index 0e0ab94ef..90d60f026 100644 --- a/applications/external/subghz_remote_new/helpers/subrem_custom_event.h +++ b/applications/external/subghz_remote_new/helpers/subrem_custom_event.h @@ -6,69 +6,17 @@ typedef enum { // SubRemCustomEventManagerSetRAW, //SubmenuIndex - SubmenuIndexOpenMapFile, - SubmenuIndexOpenView, // TODO: temp debug + SubmenuIndexSubRemOpenMapFile, + SubmenuIndexSubRemRemoteView, // TODO: temp debug + SubmenuIndexSubRemAbout, //SubRemCustomEvent - SubRemCustomEventViewRemoteBack = 100, - SubRemCustomEventViewRemoteStartUP, + SubRemCustomEventViewRemoteStartUP = 100, SubRemCustomEventViewRemoteStartDOWN, SubRemCustomEventViewRemoteStartLEFT, SubRemCustomEventViewRemoteStartRIGHT, SubRemCustomEventViewRemoteStartOK, + SubRemCustomEventViewRemoteBack, SubRemCustomEventViewRemoteStop, - - // SubRemCustomEventSceneDeleteSuccess = 100, - // SubRemCustomEventSceneDelete, - // SubRemCustomEventSceneDeleteRAW, - // SubRemCustomEventSceneDeleteRAWBack, - - // SubRemCustomEventSceneReceiverInfoTxStart, - // SubRemCustomEventSceneReceiverInfoTxStop, - // SubRemCustomEventSceneReceiverInfoSave, - // SubRemCustomEventSceneSaveName, - // SubRemCustomEventSceneSaveSuccess, - // SubRemCustomEventSceneShowErrorBack, - // SubRemCustomEventSceneShowErrorOk, - // SubRemCustomEventSceneShowErrorSub, - // SubRemCustomEventSceneShowOnlyRX, - // SubRemCustomEventSceneAnalyzerLock, - // SubRemCustomEventSceneAnalyzerUnlock, - // SubRemCustomEventSceneSettingLock, - - // SubRemCustomEventSceneExit, - // SubRemCustomEventSceneStay, - - // SubRemCustomEventSceneRpcLoad, - // SubRemCustomEventSceneRpcButtonPress, - // SubRemCustomEventSceneRpcButtonRelease, - // SubRemCustomEventSceneRpcSessionClose, - - // SubRemCustomEventViewReceiverOK, - // SubRemCustomEventViewReceiverConfig, - // SubRemCustomEventViewReceiverBack, - // SubRemCustomEventViewReceiverOffDisplay, - // SubRemCustomEventViewReceiverUnlock, - // SubRemCustomEventViewReceiverDeleteItem, - - // SubRemCustomEventViewReadRAWBack, - // SubRemCustomEventViewReadRAWIDLE, - // SubRemCustomEventViewReadRAWREC, - // SubRemCustomEventViewReadRAWConfig, - // SubRemCustomEventViewReadRAWErase, - // SubRemCustomEventViewReadRAWSendStart, - // SubRemCustomEventViewReadRAWSendStop, - // SubRemCustomEventViewReadRAWSave, - // SubRemCustomEventViewReadRAWTXRXStop, - // SubRemCustomEventViewReadRAWMore, - - // SubRemCustomEventViewTransmitterBack, - // SubRemCustomEventViewTransmitterSendStart, - // SubRemCustomEventViewTransmitterSendStop, - // SubRemCustomEventViewTransmitterError, - - // SubRemCustomEventViewFreqAnalOkShort, - // SubRemCustomEventViewFreqAnalOkLong, - - // SubRemCustomEventByteInputDone, -} SubRemCustomEvent; + SubRemCustomEventViewRemoteForcedStop, +} SubRemCustomEvent; \ No newline at end of file diff --git a/applications/external/subghz_remote_new/helpers/subrem_types.h b/applications/external/subghz_remote_new/helpers/subrem_types.h index 56687977f..0bf31e6a4 100644 --- a/applications/external/subghz_remote_new/helpers/subrem_types.h +++ b/applications/external/subghz_remote_new/helpers/subrem_types.h @@ -2,50 +2,39 @@ #include #include -/* -#define AVR_ISP_VERSION_APP "0.1" -#define AVR_ISP_DEVELOPED "SkorP" -#define AVR_ISP_GITHUB "https://github.com/flipperdevices/flipperzero-firmware" -#define AVR_ISP_APP_FILE_VERSION 1 -#define AVR_ISP_APP_FILE_TYPE "Flipper Dump AVR" -#define AVR_ISP_APP_EXTENSION ".avr" -*/ - -// TODO: rename Filepath -//#define SUBREMOTEMAP_FOLDER "/ext/subghz_remote" -#define SUBGHZ_REMOTE_APP_EXTENSION ".txt" -#define SUBGHZ_REMOTE_APP_PATH_PREFIX "/ext/subghz_remote" +// #define SUBREM_APP_APP_FILE_VERSION 1 +// #define SUBREM_APP_APP_FILE_TYPE "Flipper SubRem Map file" +#define SUBREM_APP_EXTENSION ".txt" + +typedef enum { + SubRemSubKeyNameUp = (0U), + SubRemSubKeyNameDown, + SubRemSubKeyNameLeft, + SubRemSubKeyNameRight, + SubRemSubKeyNameOk, + SubRemSubKeyNameMaxCount, +} SubRemSubKeyName; typedef enum { - //SubRemViewVariableItemList, SubRemViewSubmenu, - //SubRemViewProgrammer, - //SubRemViewReader, - //SubRemViewWriter, SubRemViewWidget, SubRemViewPopup, SubRemViewTextInput, SubRemViewIDRemote, - //SubRemViewChipDetect, } SubRemViewID; typedef enum { // Loadin State SubRemSubKeyTypeNoData = 0, - SubRemSubKeyTypeHaveFileName, + // SubRemSubKeyTypeHaveFileName, // Key Type SubRemSubKeyTypeStaticKey = 100, SubRemSubKeyTypeDynamicKey, SubRemSubKeyTypeRawKey, -} SubRemSubKeyType; +} SubRemSubKeyType; // TODO: depricated -/* -typedef enum { - SubRemErrorNoError, - SubRemErrorReading, - SubRemErrorWriting, - SubRemErrorVerification, - SubRemErrorWritingFuse, -} SubRemError;*/ \ No newline at end of file +// typedef enum { +// +// } SubRemLoadMapState; \ No newline at end of file diff --git a/applications/external/subghz_remote_new/scenes/subrem_scene_openmapfile.c b/applications/external/subghz_remote_new/scenes/subrem_scene_openmapfile.c index 67ccca1c3..504bfee2e 100644 --- a/applications/external/subghz_remote_new/scenes/subrem_scene_openmapfile.c +++ b/applications/external/subghz_remote_new/scenes/subrem_scene_openmapfile.c @@ -4,14 +4,9 @@ void subrem_scene_openmapfile_on_enter(void* context) { SubGhzRemoteApp* app = context; if(subrem_load_from_file(app)) { - // if(subghz_get_load_type_file(subghz) == SubGhzLoadTypeFileRaw) { - // subghz_rx_key_state_set(subghz, SubGhzRxKeyStateRAWLoad); - // scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW); - // } else { - // scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSavedMenu); - // } scene_manager_next_scene(app->scene_manager, SubRemSceneRemote); } else { + // TODO: Map Preset Reset scene_manager_search_and_switch_to_previous_scene(app->scene_manager, SubRemSceneStart); } } diff --git a/applications/external/subghz_remote_new/scenes/subrem_scene_remote.c b/applications/external/subghz_remote_new/scenes/subrem_scene_remote.c index 58e253d1c..a04399cd3 100644 --- a/applications/external/subghz_remote_new/scenes/subrem_scene_remote.c +++ b/applications/external/subghz_remote_new/scenes/subrem_scene_remote.c @@ -1,5 +1,9 @@ #include "../subghz_remote_app_i.h" -#include "../views/transmitter.h" +#include "../views/remote.h" + +#include + +#define TAG "SubRemScenRemote" // TODO: // #include @@ -13,61 +17,48 @@ void subrem_scene_remote_callback(SubRemCustomEvent event, void* context) { view_dispatcher_send_custom_event(app->view_dispatcher, event); } -bool subrem_scene_remote_update_data_show(void* context) { +void subrem_scene_remote_raw_callback_end_tx(void* context) { + furi_assert(context); + SubGhzRemoteApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, SubRemCustomEventViewRemoteForcedStop); +} + +static uint8_t subrem_scene_remote_event_to_index(SubRemCustomEvent event_id) { + uint8_t ret = 0; + + if(event_id == SubRemCustomEventViewRemoteStartUP) { + ret = SubRemSubKeyNameUp; + } else if(event_id == SubRemCustomEventViewRemoteStartDOWN) { + ret = SubRemSubKeyNameDown; + } else if(event_id == SubRemCustomEventViewRemoteStartLEFT) { + ret = SubRemSubKeyNameLeft; + } else if(event_id == SubRemCustomEventViewRemoteStartRIGHT) { + ret = SubRemSubKeyNameRight; + } else if(event_id == SubRemCustomEventViewRemoteStartOK) { + ret = SubRemSubKeyNameOk; + } + + return ret; +} + +static bool subrem_scene_remote_update_data_show(void* context) { SubGhzRemoteApp* app = context; - //UNUSED(app); bool ret = false; subrem_view_remote_add_data_to_show( - //app->subrem_remote_view, "N/A", "N/A", "N/A", "N/A", "N/A"); app->subrem_remote_view, - // "UP", - // "DOWN", - // "LEFT", - // "RIGHT", - // "OK"); - furi_string_get_cstr(app->subs_preset[0]->label), furi_string_get_cstr(app->subs_preset[1]->label), furi_string_get_cstr(app->subs_preset[2]->label), furi_string_get_cstr(app->subs_preset[3]->label), furi_string_get_cstr(app->subs_preset[4]->label)); - // SubGhzProtocolDecoderBase* decoder = subghz_txrx_get_decoder(app->txrx); - - // if(decoder) { - // FuriString* key_str = furi_string_alloc(); - // FuriString* frequency_str = furi_string_alloc(); - // FuriString* modulation_str = furi_string_alloc(); - - // if(subghz_protocol_decoder_base_deserialize( - // decoder, subghz_txrx_get_fff_data(app->txrx)) == SubGhzProtocolStatusOk) { - // subghz_protocol_decoder_base_get_string(decoder, key_str); - - // subghz_txrx_get_frequency_and_modulation( - // app->txrx, frequency_str, modulation_str, false); - // subghz_view_transmitter_add_data_to_show( - // app->subghz_transmitter, - // furi_string_get_cstr(key_str), - // furi_string_get_cstr(frequency_str), - // furi_string_get_cstr(modulation_str), - // subghz_txrx_protocol_is_transmittable(app->txrx, false)); - // ret = true; - // } - // furi_string_free(frequency_str); - // furi_string_free(modulation_str); - // furi_string_free(key_str); - // } return ret; } void subrem_scene_remote_on_enter(void* context) { SubGhzRemoteApp* app = context; - // TODO: reset custom btns - // keeloq_reset_original_btn(); - // subghz_custom_btns_reset(); - // TODO: init view data if(!subrem_scene_remote_update_data_show(app)) { @@ -84,63 +75,71 @@ void subrem_scene_remote_on_enter(void* context) { bool subrem_scene_remote_on_event(void* context, SceneManagerEvent event) { SubGhzRemoteApp* app = context; if(event.type == SceneManagerEventTypeCustom) { - // if(event.event == SubGhzCustomEventViewTransmitterSendStart) { - // app->state_notifications = SubGhzNotificationStateIDLE; - - // if(subghz_tx_start(app, subghz_txrx_get_fff_data(app->txrx))) { - // app->state_notifications = SubGhzNotificationStateTx; - // subrem_scene_remote_update_data_show(app); - // DOLPHIN_DEED(DolphinDeedSubGhzSend); - // } - // return true; - // } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) { - // app->state_notifications = SubGhzNotificationStateIDLE; - // subghz_txrx_stop(app->txrx); - // if(subghz_custom_btn_get() != 0) { - // subghz_custom_btn_set(0); - // uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); - // furi_hal_subghz_set_rolling_counter_mult(0); - // // Calling restore! - // subghz_tx_start(app, subghz_txrx_get_fff_data(app->txrx)); - // subghz_txrx_stop(app->txrx); - // furi_hal_subghz_set_rolling_counter_mult(tmp_counter); - // } - // return true; - // } else if(event.event == SubRemCustomEventViewRemoteBack) { - // app->state_notifications = SubGhzNotificationStateIDLE; //TODO: notification - scene_manager_search_and_switch_to_previous_scene( - app->scene_manager, SubRemSceneStart); - return true; - } else if(event.event == SubRemCustomEventViewRemoteStartUP) { - if(subghz_tx_start_sub(app, app->subs_preset[0])) { - notification_message(app->notifications, &sequence_blink_start_magenta); + if(!scene_manager_search_and_switch_to_previous_scene( + app->scene_manager, SubRemSceneOpenMapFile)) { + if(!scene_manager_search_and_switch_to_previous_scene( + app->scene_manager, SubRemSceneStart)) { + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } } - } else if(event.event == SubRemCustomEventViewRemoteStop) { - subghz_tx_stop_sub(app, app->subs_preset[0]); - notification_message(app->notifications, &sequence_blink_stop); - } - // notification_message(app->notification, &sequence_blink_stop); + return true; + } else if( + event.event == SubRemCustomEventViewRemoteStartUP || + event.event == SubRemCustomEventViewRemoteStartDOWN || + event.event == SubRemCustomEventViewRemoteStartLEFT || + event.event == SubRemCustomEventViewRemoteStartRIGHT || + event.event == SubRemCustomEventViewRemoteStartOK) { + // Start sending sub + subghz_tx_stop_sub(app, true); + app->chusen_sub = subrem_scene_remote_event_to_index(event.event); + subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateLoading); + if(subghz_tx_start_sub( + app, + app->subs_preset[app->chusen_sub], + subrem_scene_remote_raw_callback_end_tx)) { + subrem_view_remote_set_presed_btn(app->subrem_remote_view, app->chusen_sub); + subrem_view_remote_set_state( + app->subrem_remote_view, SubRemViewRemoteStateSending); + notification_message(app->notifications, &sequence_blink_start_magenta); + } else { + subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle); + } + return true; + } else if(event.event == SubRemCustomEventViewRemoteForcedStop) { + subghz_tx_stop_sub(app, true); + subrem_view_remote_set_presed_btn(app->subrem_remote_view, 0); + subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle); - // else if(event.event == SubGhzCustomEventViewTransmitterError) { - // furi_string_set(app->error_str, "Protocol not\nfound!"); - // scene_manager_next_scene(app->scene_manager, SubGhzSceneShowErrorSub); - // } - } else if(event.type == SceneManagerEventTypeTick) { - // if(app->state_notifications == SubGhzNotificationStateTx) { - // notification_message(app->notifications, &sequence_blink_magenta_10); - // } - // return true; + notification_message(app->notifications, &sequence_blink_stop); + return true; + } else if(event.event == SubRemCustomEventViewRemoteStop) { + if(subghz_tx_stop_sub(app, false)) { + subrem_view_remote_set_presed_btn(app->subrem_remote_view, 0); + subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle); + + notification_message(app->notifications, &sequence_blink_stop); + } + return true; + } } + // } else if(event.type == SceneManagerEventTypeTick) { + // } return false; } void subrem_scene_remote_on_exit(void* context) { SubGhzRemoteApp* app = context; - UNUSED(app); - // TODO: notifications and reset KL - //app->state_notifications = SubGhzNotificationStateIDLE; + subghz_tx_stop_sub(app, true); + + subrem_view_remote_set_presed_btn(app->subrem_remote_view, 0); + subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle); + + notification_message(app->notifications, &sequence_blink_stop); + + // TODO: notifications and reset KL // keeloq_reset_mfname(); // keeloq_reset_kl_type(); diff --git a/applications/external/subghz_remote_new/scenes/subrem_scene_start.c b/applications/external/subghz_remote_new/scenes/subrem_scene_start.c index 0ad9837e9..75328ab8a 100644 --- a/applications/external/subghz_remote_new/scenes/subrem_scene_start.c +++ b/applications/external/subghz_remote_new/scenes/subrem_scene_start.c @@ -16,23 +16,17 @@ void subrem_scene_start_on_enter(void* context) { submenu_add_item( submenu, "Open Map File", - SubmenuIndexOpenMapFile, + SubmenuIndexSubRemOpenMapFile, subrem_scene_start_submenu_callback, app); +#if FURI_DEBUG submenu_add_item( - submenu, "Remote", SubmenuIndexOpenView, subrem_scene_start_submenu_callback, app); - // submenu_add_item( - // submenu, - // "ISP Programmer", - // SubmenuIndexSubGhzRemoteProgrammer, - // subrem_scene_start_submenu_callback, - // app); - // submenu_add_item( - // submenu, - // "Wiring", - // SubmenuIndexAvrIsWiring, - // subrem_scene_start_submenu_callback, - // app); + submenu, + "Remote_Debug", + SubmenuIndexSubRemRemoteView, + subrem_scene_start_submenu_callback, + app); +#endif // submenu_add_item( // submenu, // "About", @@ -53,33 +47,21 @@ bool subrem_scene_start_on_event(void* context, SceneManagerEvent event) { bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexOpenMapFile) { + if(event.event == SubmenuIndexSubRemOpenMapFile) { + //scene_manager_set_scene_state(app->scene_manager, SubRemSceneStart, event.event); scene_manager_next_scene(app->scene_manager, SubRemSceneOpenMapFile); consumed = true; - } else if(event.event == SubmenuIndexOpenView) { + } + // } else if(event.event == SubmenuIndexSubRemAbout) { + // scene_manager_next_scene(app->scene_manager, SubRemSceneAbout); + // consumed = true; + // } +#if FURI_DEBUG + else if(event.event == SubmenuIndexSubRemRemoteView) { scene_manager_next_scene(app->scene_manager, SubRemSceneRemote); consumed = true; } - // } else if(event.event == SubmenuIndexSubGhzRemoteProgrammer) { - // scene_manager_set_scene_state( - // app->scene_manager, SubRemSceneChipDetect, SubGhzRemoteViewProgrammer); - // scene_manager_next_scene(app->scene_manager, SubRemSceneChipDetect); - // consumed = true; - // } else if(event.event == SubmenuIndexSubGhzRemoteReader) { - // scene_manager_set_scene_state( - // app->scene_manager, SubRemSceneChipDetect, SubGhzRemoteViewReader); - // scene_manager_next_scene(app->scene_manager, SubRemSceneChipDetect); - // consumed = true; - // } else if(event.event == SubmenuIndexSubGhzRemoteWriter) { - // scene_manager_set_scene_state( - // app->scene_manager, SubRemSceneChipDetect, SubGhzRemoteViewWriter); - // scene_manager_next_scene(app->scene_manager, SubRemSceneChipDetect); - // consumed = true; - // } else if(event.event == SubmenuIndexAvrIsWiring) { - // scene_manager_next_scene(app->scene_manager, SubRemSceneWiring); - // consumed = true; - // } - scene_manager_set_scene_state(app->scene_manager, SubRemSceneStart, event.event); +#endif } return consumed; diff --git a/applications/external/subghz_remote_new/subghz_remote_app.c b/applications/external/subghz_remote_new/subghz_remote_app.c index 1bfa3a1b3..ad6fe13fb 100644 --- a/applications/external/subghz_remote_new/subghz_remote_app.c +++ b/applications/external/subghz_remote_new/subghz_remote_app.c @@ -93,29 +93,8 @@ SubGhzRemoteApp* subghz_remote_app_alloc() { app->view_dispatcher, SubRemViewIDRemote, subrem_view_remote_get_view(app->subrem_remote_view)); - /* - // Reader view - app->subghz_remote_reader_view = subghz_remote_reader_view_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - SubRemViewReader, - subghz_remote_reader_view_get_view(app->subghz_remote_reader_view)); - // Writer view - app->subghz_remote_writer_view = subghz_remote_writer_view_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - SubRemViewWriter, - subghz_remote_writer_view_get_view(app->subghz_remote_writer_view)); - - // Chip detect view - app->subghz_remote_chip_detect_view = subghz_remote_chip_detect_view_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - SubRemViewChipDetect, - subghz_remote_chip_detect_view_get_view(app->subghz_remote_chip_detect_view)); -*/ - for(uint8_t i = 0; i < SUBREM_MAX_SUB_KEY_COUNT; i++) { + for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) { app->subs_preset[i] = subrem_sub_file_preset_alloc(); } @@ -137,6 +116,8 @@ SubGhzRemoteApp* subghz_remote_app_alloc() { app->receiver = subghz_receiver_alloc_init(app->environment); + app->tx_running = false; + scene_manager_next_scene(app->scene_manager, SubRemSceneStart); return app; @@ -179,26 +160,10 @@ void subghz_remote_app_free(SubGhzRemoteApp* app) { subghz_environment_free(app->environment); subghz_setting_free(app->setting); - for(uint8_t i = 0; i < SUBREM_MAX_SUB_KEY_COUNT; i++) { + for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) { subrem_sub_file_preset_free(app->subs_preset[i]); } - // // Reader view - // view_dispatcher_remove_view(app->view_dispatcher, SubRemViewReader); - // subghz_remote_reader_view_free(app->subghz_remote_reader_view); - - // // Writer view - // view_dispatcher_remove_view(app->view_dispatcher, SubRemViewWriter); - // subghz_remote_writer_view_free(app->subghz_remote_writer_view); - - // // Chip detect view - // view_dispatcher_remove_view(app->view_dispatcher, SubRemViewChipDetect); - // subghz_remote_chip_detect_view_free(app->subghz_remote_chip_detect_view); - - // // View dispatcher - // view_dispatcher_free(app->view_dispatcher); - // scene_manager_free(app->scene_manager); - // Notifications furi_record_close(RECORD_NOTIFICATION); app->notifications = NULL; @@ -209,11 +174,6 @@ void subghz_remote_app_free(SubGhzRemoteApp* app) { // Path strings furi_string_free(app->file_path); - // Disable 5v power - // if(furi_hal_power_is_otg_enabled()) { - // furi_hal_power_disable_otg(); - // } - free(app); } diff --git a/applications/external/subghz_remote_new/subghz_remote_app_i.c b/applications/external/subghz_remote_new/subghz_remote_app_i.c index 7ebad702f..dac0d15b7 100644 --- a/applications/external/subghz_remote_new/subghz_remote_app_i.c +++ b/applications/external/subghz_remote_new/subghz_remote_app_i.c @@ -7,15 +7,16 @@ #define TAG "SubGhzRemote" -static const char* map_file_labels[SUBREM_MAX_SUB_KEY_COUNT][2] = { - {"UP", "ULABEL"}, - {"DOWN", "DLABEL"}, - {"LEFT", "LLABEL"}, - {"RIGHT", "RLABEL"}, - {"OK", "OKLABEL"}, +static const char* map_file_labels[SubRemSubKeyNameMaxCount][2] = { + [SubRemSubKeyNameUp] = {"UP", "ULABEL"}, + [SubRemSubKeyNameDown] = {"DOWN", "DLABEL"}, + [SubRemSubKeyNameLeft] = {"LEFT", "LLABEL"}, + [SubRemSubKeyNameRight] = {"RIGHT", "RLABEL"}, + [SubRemSubKeyNameOk] = {"OK", "OKLABEL"}, }; -bool subrem_set_preset_data(SubGhzSetting* setting, FreqPreset* freq_preset, const char* preset) { +static bool + subrem_set_preset_data(SubGhzSetting* setting, FreqPreset* freq_preset, const char* preset) { const char* preset_name = ""; if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { preset_name = "AM270"; @@ -45,7 +46,7 @@ SubRemSubFilePreset* subrem_sub_file_preset_alloc() { sub_preset->protocaol_name = furi_string_alloc(); sub_preset->label = furi_string_alloc_set_str("N/A"); - sub_preset->type = SubRemSubKeyTypeNoData; + sub_preset->type = SubGhzProtocolTypeUnknown; return sub_preset; } @@ -61,7 +62,7 @@ void subrem_sub_file_preset_free(SubRemSubFilePreset* sub_preset) { free(sub_preset); } -void subrem_subs_file_preset_reset(SubRemSubFilePreset* sub_preset) { +static void subrem_sub_file_preset_reset(SubRemSubFilePreset* sub_preset) { furi_assert(sub_preset); furi_string_set_str(sub_preset->label, "N/A"); @@ -71,43 +72,45 @@ void subrem_subs_file_preset_reset(SubRemSubFilePreset* sub_preset) { Stream* fff_data_stream = flipper_format_get_raw_stream(sub_preset->fff_data); stream_clean(fff_data_stream); - sub_preset->type = SubRemSubKeyTypeNoData; + sub_preset->type = SubGhzProtocolTypeUnknown; } -void subrem_sub_file_presets_reset(SubGhzRemoteApp* app) { +void subrem_map_preset_reset(SubGhzRemoteApp* app) { furi_assert(app); - for(uint8_t i = 0; i < SUBREM_MAX_SUB_KEY_COUNT; i++) { - subrem_subs_file_preset_reset(app->subs_preset[i]); + for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) { + subrem_sub_file_preset_reset(app->subs_preset[i]); } } -static bool subrem_sub_file_presets_load(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) { +static bool subrem_map_preset_load(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) { furi_assert(app); bool ret = false; - - for(uint8_t i = 0; i < SUBREM_MAX_SUB_KEY_COUNT; i++) { + SubRemSubFilePreset* sub_preset; + for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) { + sub_preset = app->subs_preset[i]; if(!flipper_format_read_string( - fff_data_file, map_file_labels[i][0], app->subs_preset[i]->file_path)) { + fff_data_file, map_file_labels[i][0], sub_preset->file_path)) { +#if FURO_LOG FURI_LOG_W(TAG, "No file patch for %s", map_file_labels[i][0]); - app->subs_preset[i]->type = SubRemSubKeyTypeNoData; - //continue; +#endif + sub_preset->type = SubGhzProtocolTypeUnknown; } else if(!flipper_format_rewind(fff_data_file)) { // Rewind error - //continue; } else if(!flipper_format_read_string( - fff_data_file, map_file_labels[i][1], app->subs_preset[i]->label)) { + fff_data_file, map_file_labels[i][1], sub_preset->label)) { +#if FURO_LOG FURI_LOG_W(TAG, "No Label for %s", map_file_labels[i][0]); - furi_string_set_str(app->subs_preset[i]->label, "N/A"); +#endif + furi_string_set_str(sub_preset->label, + "N/A"); // TODO: Standart name or part of name } else { FURI_LOG_I( TAG, - // "Loaded %s key \r\nLabel %s file %s", - "Loaded %s key: %s %s", + "%-5s: %s %s", map_file_labels[i][0], - furi_string_get_cstr(app->subs_preset[i]->label), - furi_string_get_cstr(app->subs_preset[i]->file_path)); - app->subs_preset[i]->type = SubRemSubKeyTypeHaveFileName; // TODO: + furi_string_get_cstr(sub_preset->label), + furi_string_get_cstr(sub_preset->file_path)); ret = true; } flipper_format_rewind(fff_data_file); @@ -115,11 +118,20 @@ static bool subrem_sub_file_presets_load(SubGhzRemoteApp* app, FlipperFormat* ff return ret; } -bool subghz_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) { +bool subghz_tx_start_sub( + SubGhzRemoteApp* app, + SubRemSubFilePreset* sub_preset, + SubGhzProtocolEncoderRAWCallbackEnd callback) { furi_assert(app); furi_assert(sub_preset); bool ret = false; + subghz_tx_stop_sub(app, true); + + if(sub_preset->type == SubGhzProtocolTypeUnknown) { + return false; + } + FURI_LOG_I(TAG, "Send %s", furi_string_get_cstr(sub_preset->label)); do { @@ -152,19 +164,27 @@ bool subghz_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) break; } + if(sub_preset->type == SubGhzProtocolTypeRAW) { + subghz_protocol_raw_file_encoder_worker_set_callback_end( + (SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance( + app->transmitter), + callback, + app); + } + furi_hal_subghz_start_async_tx(subghz_transmitter_yield, app->transmitter); ret = true; } } while(false); - // ret = false; // TODO: + app->tx_running = ret; // TODO: + return ret; } -void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) { +static void subghz_tx_stop(SubGhzRemoteApp* app) { furi_assert(app); - furi_assert(sub_preset); //Stop TX furi_hal_subghz_stop_async_tx(); @@ -172,29 +192,46 @@ void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) { subghz_transmitter_stop(app->transmitter); subghz_transmitter_free(app->transmitter); furi_hal_subghz_idle(); +} + +bool subghz_tx_stop_sub(SubGhzRemoteApp* app, bool forced) { + furi_assert(app); + + if(forced || (app->subs_preset[app->chusen_sub]->type != SubGhzProtocolTypeRAW)) { + // SubRemSubKeyTypeRawKey)) { + if(app->tx_running) { + subghz_tx_stop(app); + app->tx_running = false; + return true; + } + } + + return false; + + // SubRemSubFilePreset* sub_preset = app->subs_preset[app->chusen_sub]; // TODO: need saving logic } -static bool subrem_sub_presets_check(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) { +static bool subrem_map_preset_check(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) { furi_assert(app); FuriString* temp_str = furi_string_alloc(); uint32_t temp_data32; bool ret = false; + bool sub_preset_loaded = false; SubRemSubFilePreset* sub_preset; - for(uint8_t i = 0; i < SUBREM_MAX_SUB_KEY_COUNT; i++) { + for(uint8_t i = 0; i < SubRemSubKeyNameMaxCount; i++) { sub_preset = app->subs_preset[i]; - if(sub_preset->type == SubRemSubKeyTypeNoData) { + sub_preset_loaded = false; + if(furi_string_empty(sub_preset->file_path)) { + // FURI_LOG_I(TAG, "Empty file path"); continue; } do { if(!flipper_format_file_open_existing( fff_data_file, furi_string_get_cstr(sub_preset->file_path))) { - FURI_LOG_E( - TAG, - "Error open file %s", - furi_string_get_cstr(sub_preset->file_path)); // TODO: warning + FURI_LOG_W(TAG, "Error open file %s", furi_string_get_cstr(sub_preset->file_path)); break; } @@ -213,9 +250,9 @@ static bool subrem_sub_presets_check(SubGhzRemoteApp* app, FlipperFormat* fff_da //Load frequency if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) { - FURI_LOG_W(TAG, "Cannot read frequency. Defaulting to 433.92 MHz"); - sub_preset->freq_preset.frequency = subghz_setting_get_default_frequency( - app->setting); // TODO: Get default from settings + FURI_LOG_W(TAG, "Cannot read frequency. Set default frequency"); + sub_preset->freq_preset.frequency = + subghz_setting_get_default_frequency(app->setting); } else if(!furi_hal_subghz_is_tx_allowed(temp_data32)) { FURI_LOG_E(TAG, "This frequency can only be used for RX"); break; @@ -246,7 +283,6 @@ static bool subrem_sub_presets_check(SubGhzRemoteApp* app, FlipperFormat* fff_da //if RAW subghz_protocol_raw_gen_fff_data( fff_data, furi_string_get_cstr(sub_preset->file_path)); - sub_preset->type = SubRemSubKeyTypeRawKey; } else { stream_copy_full( flipper_format_get_raw_stream(fff_data_file), @@ -262,70 +298,82 @@ static bool subrem_sub_presets_check(SubGhzRemoteApp* app, FlipperFormat* fff_da if(!protocol) { FURI_LOG_E(TAG, "Protocol not found"); break; - } else if(protocol->flag & SubGhzProtocolFlag_Send) { // FIXME: - - if(protocol->type == SubGhzProtocolTypeStatic) { - sub_preset->type = SubRemSubKeyTypeStaticKey; - } else if(protocol->type == SubGhzProtocolTypeDynamic) { - sub_preset->type = SubRemSubKeyTypeDynamicKey; - } else if(protocol->type == SubGhzProtocolTypeRAW) { - sub_preset->type = SubRemSubKeyTypeRawKey; - // } else if(protocol->type == SubGhzProtocolTypeBinRAW) { // TODO: BINRAW + } else if(protocol->flag & SubGhzProtocolFlag_Send) { + if((protocol->type == SubGhzProtocolTypeStatic) || + (protocol->type == SubGhzProtocolTypeDynamic) || + // (protocol->type == SubGhzProtocolTypeBinRAW) || // TODO: BINRAW + (protocol->type == SubGhzProtocolTypeRAW)) { + sub_preset->type = protocol->type; } else { FURI_LOG_E(TAG, "Unsuported Protocol"); break; } furi_string_set(sub_preset->protocaol_name, temp_str); - } // TODO: check dynamic and protocol found - - ret |= true; - - if(ret) { - FURI_LOG_I(TAG, "Protocol Loaded"); + } else { + FURI_LOG_E(TAG, "Protocol does not support transmission"); } + + sub_preset_loaded = true; + ret |= true; +#if FURI_DEBUG + FURI_LOG_I(TAG, "%-16s - protocol Loaded", furi_string_get_cstr(sub_preset->label)); +#endif } while(false); + // TODO: + // Load file state logic + // Label depending on the state + + if(!sub_preset_loaded) { + furi_string_set_str(sub_preset->label, "N/A"); + } + flipper_format_file_close(fff_data_file); } furi_string_free(temp_str); - //ret = false; // TODO: return ret; } bool subrem_map_file_load(SubGhzRemoteApp* app, const char* file_path) { furi_assert(app); furi_assert(file_path); - // TODO: drop furi log - FURI_LOG_I(TAG, "Load Map File Start"); // drop +#if FURI_DEBUG + FURI_LOG_I(TAG, "Load Map File Start"); +#endif Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); bool ret = false; - FURI_LOG_I(TAG, "Open Map File.."); // drop - - subrem_sub_file_presets_reset(app); +#if FURI_DEBUG + FURI_LOG_I(TAG, "Open Map File.."); +#endif + subrem_map_preset_reset(app); if(!flipper_format_file_open_existing(fff_data_file, file_path)) { FURI_LOG_E(TAG, "Could not open MAP file %s", file_path); } else { - if(!subrem_sub_file_presets_load(app, fff_data_file)) { - // TODO: error popup or return error type - FURI_LOG_E(TAG, "Could no Sub file path in MAP file"); + if(!subrem_map_preset_load(app, fff_data_file)) { + FURI_LOG_E(TAG, "Could no Sub file path in MAP file"); + // ret = // error for popup } else if( (flipper_format_file_close(fff_data_file)) && - (subrem_sub_presets_check(app, fff_data_file))) { + (subrem_map_preset_check(app, fff_data_file))) { FURI_LOG_I(TAG, "Load Map File Seccesful"); ret = true; } } + // TODO: Pop for error or return error type + if(!ret) { + FURI_LOG_E(TAG, "Broken Map File"); + } + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); - //ret = false; // TODO: return ret; } @@ -344,7 +392,6 @@ bool subrem_load_from_file(SubGhzRemoteApp* app) { if(res) { res = subrem_map_file_load(app, furi_string_get_cstr(app->file_path)); - // FIXME res = subghz_key_load(app, furi_string_get_cstr(app->file_path), true); } furi_string_free(file_path); diff --git a/applications/external/subghz_remote_new/subghz_remote_app_i.h b/applications/external/subghz_remote_new/subghz_remote_app_i.h index d954eca02..8941f1401 100644 --- a/applications/external/subghz_remote_new/subghz_remote_app_i.h +++ b/applications/external/subghz_remote_new/subghz_remote_app_i.h @@ -1,12 +1,12 @@ #pragma once #include "helpers/subrem_types.h" +#include // TODO: -#include "views/transmitter.h" +#include "views/remote.h" #include "scenes/subrem_scene.h" -#include // TODO: #include #include #include @@ -18,21 +18,16 @@ #include #include +#include + #include #include #include #include // FIXME: -// #include "views/subghz_remote_view_programmer.h" -// #include "views/subghz_remote_view_reader.h" -// #include "views/subghz_remote_view_writer.h" -// #include "views/subghz_remote_view_chip_detect.h" - -#define SUBREM_APP_EXTENSION ".txt" -#define SUBREM_APP_FOLDER "/ext/subghz_remote" +#define SUBREM_APP_FOLDER ANY_PATH("subghz_remote") #define SUBGHZ_REMOTE_MAX_LEN_NAME 64 -#define SUBREM_MAX_SUB_KEY_COUNT (5U) typedef struct { uint32_t frequency; @@ -46,7 +41,7 @@ typedef struct { FuriString* file_path; FuriString* protocaol_name; FuriString* label; - SubRemSubKeyType type; + SubGhzProtocolType type; } SubRemSubFilePreset; SubRemSubFilePreset* subrem_sub_file_preset_alloc(); @@ -68,22 +63,25 @@ typedef struct { SubRemViewRemote* subrem_remote_view; - SubRemSubFilePreset* subs_preset[SUBREM_MAX_SUB_KEY_COUNT]; + SubRemSubFilePreset* subs_preset[SubRemSubKeyNameMaxCount]; SubGhzSetting* setting; SubGhzEnvironment* environment; SubGhzReceiver* receiver; SubGhzTransmitter* transmitter; - // AvrIspProgrammerView* subghz_remote_programmer_view; - // AvrIspReaderView* subghz_remote_reader_view; - // AvrIspWriterView* subghz_remote_writer_view; - // AvrIspChipDetectView* subghz_remote_chip_detect_view; + bool tx_running; - // AvrIspError error; + uint8_t chusen_sub; + + // TODO: LoadFileError } SubGhzRemoteApp; bool subrem_load_from_file(SubGhzRemoteApp* app); -bool subghz_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset); -void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset); \ No newline at end of file +bool subghz_tx_start_sub( + SubGhzRemoteApp* app, + SubRemSubFilePreset* sub_preset, + SubGhzProtocolEncoderRAWCallbackEnd callback); + +bool subghz_tx_stop_sub(SubGhzRemoteApp* app, bool forced); \ No newline at end of file diff --git a/applications/external/subghz_remote_new/views/transmitter.c b/applications/external/subghz_remote_new/views/remote.c similarity index 67% rename from applications/external/subghz_remote_new/views/transmitter.c rename to applications/external/subghz_remote_new/views/remote.c index 6f43a1406..c631c76cc 100644 --- a/applications/external/subghz_remote_new/views/transmitter.c +++ b/applications/external/subghz_remote_new/views/remote.c @@ -1,27 +1,18 @@ -#include "transmitter.h" +#include "remote.h" #include "../subghz_remote_app_i.h" #include #include #define SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH 16 + struct SubRemViewRemote { View* view; SubRemViewRemoteCallback callback; void* context; }; -// FIXME: drop -// static char* char_to_str(char* str, int i) { -// char* converted = malloc(sizeof(char) * i + 1); -// memcpy(converted, str, i); - -// converted[i] = '\0'; - -// return converted; -// } // TODO: model - typedef struct { // FuriString* up_label; // FuriString* down_label; @@ -35,6 +26,8 @@ typedef struct { char* right_label; char* ok_label; + SubRemViewRemoteState state; + uint8_t pressed_btn; // bool show_button; // FuriString* temp_button_id; @@ -70,12 +63,6 @@ void subrem_view_remote_add_data_to_show( strncpy(model->right_label, right_label, SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH); strncpy(model->ok_label, ok_label, SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH); - // model->up_label = char_to_str((char*)up_label, 16); - // model->down_label = char_to_str((char*)down_label, 16); - // model->left_label = char_to_str((char*)left_label, 16); - // model->right_label = char_to_str((char*)right_label, 16); - // model->ok_label = char_to_str((char*)ok_label, 16); - // furi_string_set(model->up_label, up_label); // furi_string_set(model->down_label, down_label); // furi_string_set(model->left_label, left_label); @@ -85,6 +72,23 @@ void subrem_view_remote_add_data_to_show( true); } +void subrem_view_remote_set_presed_btn(SubRemViewRemote* subrem_view_remote, uint8_t presed_btn) { + furi_assert(subrem_view_remote); + with_view_model( + subrem_view_remote->view, + SubRemViewRemoteModel * model, + { model->pressed_btn = presed_btn; }, + true); +} + +void subrem_view_remote_set_state( + SubRemViewRemote* subrem_view_remote, + SubRemViewRemoteState state) { + furi_assert(subrem_view_remote); + with_view_model( + subrem_view_remote->view, SubRemViewRemoteModel * model, { model->state = state; }, true); +} + void subrem_view_remote_draw(Canvas* canvas, SubRemViewRemoteModel* model) { canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); @@ -126,29 +130,44 @@ void subrem_view_remote_draw(Canvas* canvas, SubRemViewRemoteModel* model) { canvas_draw_str_aligned(canvas, 11, 62, AlignLeft, AlignBottom, "Hold=Exit."); //Status text and indicator - // canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, app->send_status); + + //canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, model->state); canvas_draw_icon(canvas, 113, 15, &I_Pin_cell_13x13); - switch(model->pressed_btn) { - case 0: - break; - case 1: - canvas_draw_icon(canvas, 116, 17, &I_Pin_arrow_up_7x9); - break; - case 2: - canvas_draw_icon_ex(canvas, 116, 17, &I_Pin_arrow_up_7x9, IconRotation180); - break; - case 3: - canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation90); - break; - case 4: - canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation270); - break; - case 5: - canvas_draw_icon(canvas, 116, 18, &I_Pin_star_7x7); - break; - } + if(model->state == SubRemViewRemoteStateIdle) { + canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, "Idle"); + } else { + switch(model->state) { + case SubRemViewRemoteStateSending: + canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, "Send"); + break; + case SubRemViewRemoteStateLoading: + canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, "Load"); + break; + default: + canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, "Idle"); + break; + } + + switch(model->pressed_btn) { + case SubRemSubKeyNameUp: + canvas_draw_icon(canvas, 116, 17, &I_Pin_arrow_up_7x9); + break; + case SubRemSubKeyNameDown: + canvas_draw_icon_ex(canvas, 116, 17, &I_Pin_arrow_up_7x9, IconRotation180); + break; + case SubRemSubKeyNameLeft: + canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation270); + break; + case SubRemSubKeyNameRight: + canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation90); + break; + case SubRemSubKeyNameOk: + canvas_draw_icon(canvas, 116, 18, &I_Pin_star_7x7); + break; + } + } //Repeat indicator //canvas_draw_str_aligned(canvas, 125, 40, AlignRight, AlignBottom, "Repeat:"); //canvas_draw_icon(canvas, 115, 39, &I_SubGHzRemote_Repeat_12x14); @@ -160,6 +179,7 @@ bool subrem_view_remote_input(InputEvent* event, void* context) { SubRemViewRemote* subrem_view_remote = context; if(event->key == InputKeyBack && event->type == InputTypeLong) { + // TODO: remove reset Debug with_view_model( subrem_view_remote->view, SubRemViewRemoteModel * model, @@ -177,28 +197,47 @@ bool subrem_view_remote_input(InputEvent* event, void* context) { // furi_string_reset(model->ok_label); }, false); - return false; - } else if(event->key == InputKeyUp) { - if(event->type == InputTypePress) { - with_view_model( - subrem_view_remote->view, - SubRemViewRemoteModel * model, - { model->pressed_btn = 1; }, - true); - subrem_view_remote->callback( - SubRemCustomEventViewRemoteStartUP, subrem_view_remote->context); - return true; - } else if(event->type == InputTypeRelease) { - with_view_model( - subrem_view_remote->view, - SubRemViewRemoteModel * model, - { model->pressed_btn = 0; }, - true); - subrem_view_remote->callback( - SubRemCustomEventViewRemoteStop, subrem_view_remote->context); - return true; - } + subrem_view_remote->callback(SubRemCustomEventViewRemoteBack, subrem_view_remote->context); + return true; + } else if(event->key == InputKeyBack && event->type == InputTypeShort) { + with_view_model( + subrem_view_remote->view, + SubRemViewRemoteModel * model, + { model->pressed_btn = 0; }, + true); + subrem_view_remote->callback( + SubRemCustomEventViewRemoteForcedStop, subrem_view_remote->context); + return true; + } else if(event->key == InputKeyBack) { + return true; } + // BACK button processing end + + if(event->key == InputKeyUp && event->type == InputTypePress) { + subrem_view_remote->callback( + SubRemCustomEventViewRemoteStartUP, subrem_view_remote->context); + return true; + } else if(event->key == InputKeyDown && event->type == InputTypePress) { + subrem_view_remote->callback( + SubRemCustomEventViewRemoteStartDOWN, subrem_view_remote->context); + return true; + } else if(event->key == InputKeyLeft && event->type == InputTypePress) { + subrem_view_remote->callback( + SubRemCustomEventViewRemoteStartLEFT, subrem_view_remote->context); + return true; + } else if(event->key == InputKeyRight && event->type == InputTypePress) { + subrem_view_remote->callback( + SubRemCustomEventViewRemoteStartRIGHT, subrem_view_remote->context); + return true; + } else if(event->key == InputKeyOk && event->type == InputTypePress) { + subrem_view_remote->callback( + SubRemCustomEventViewRemoteStartOK, subrem_view_remote->context); + return true; + } else if(event->type == InputTypeRelease) { + subrem_view_remote->callback(SubRemCustomEventViewRemoteStop, subrem_view_remote->context); + return true; + } + return true; } @@ -227,6 +266,8 @@ SubRemViewRemote* subrem_view_remote_alloc() { subrem_view_remote->view, SubRemViewRemoteModel * model, { + model->state = SubRemViewRemoteStateIdle; + model->up_label = malloc(sizeof(char) * SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH + 1); model->down_label = malloc(sizeof(char) * SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH + 1); model->left_label = malloc(sizeof(char) * SUBREM_VIEW_REMOTE_MAX_LABEL_LENGTH + 1); diff --git a/applications/external/subghz_remote_new/views/transmitter.h b/applications/external/subghz_remote_new/views/remote.h similarity index 66% rename from applications/external/subghz_remote_new/views/transmitter.h rename to applications/external/subghz_remote_new/views/remote.h index a324d09ec..76121cf8a 100644 --- a/applications/external/subghz_remote_new/views/transmitter.h +++ b/applications/external/subghz_remote_new/views/remote.h @@ -3,6 +3,12 @@ #include #include "../helpers/subrem_custom_event.h" +typedef enum { + SubRemViewRemoteStateIdle, + SubRemViewRemoteStateLoading, + SubRemViewRemoteStateSending, +} SubRemViewRemoteState; + typedef struct SubRemViewRemote SubRemViewRemote; typedef void (*SubRemViewRemoteCallback)(SubRemCustomEvent event, void* context); @@ -24,4 +30,9 @@ void subrem_view_remote_add_data_to_show( const char* down_label, const char* left_label, const char* right_label, - const char* ok_label); \ No newline at end of file + const char* ok_label); + +void subrem_view_remote_set_presed_btn(SubRemViewRemote* subrem_view_remote, uint8_t presed_btn); +void subrem_view_remote_set_state( + SubRemViewRemote* subrem_view_remote, + SubRemViewRemoteState state); \ No newline at end of file