From 521ef5659f489de6c08bc161d576cbee8d4b3bba Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:28:09 +0300 Subject: [PATCH] SubRem Configurator: add TX --- .../application.fam | 6 +- .../helpers/subrem_custom_event.h | 3 +- .../helpers/txrx/subghz_txrx.c | 2 +- .../subghz_remote_configurator/icon.png | Bin 0 -> 5000 bytes .../scenes/subrem_scene_config.h | 1 + .../scenes/subrem_scene_open_map_file.c | 2 + .../scenes/subrem_scene_remote.c | 115 ++++++++++++++++++ .../scenes/subrem_scene_start.c | 29 ++++- .../subghz_remote_app.c | 11 +- .../subghz_remote_app_i.c | 54 +++++++- .../subghz_remote_app_i.h | 7 +- 11 files changed, 213 insertions(+), 17 deletions(-) create mode 100644 applications/external/subghz_remote_configurator/icon.png create mode 100644 applications/external/subghz_remote_configurator/scenes/subrem_scene_remote.c diff --git a/applications/external/subghz_remote_configurator/application.fam b/applications/external/subghz_remote_configurator/application.fam index f43dbcbd8..a39e4af4c 100644 --- a/applications/external/subghz_remote_configurator/application.fam +++ b/applications/external/subghz_remote_configurator/application.fam @@ -9,8 +9,8 @@ App( ], stack_size=2 * 1024, order=50, - fap_description="File Editor for the SubGhz Remote app", + fap_libs=["assets",], + fap_icon="icon.png", + fap_description="SubGhz Remote, uses up to 5 .sub files", fap_category="Sub-Ghz", - fap_icon_assets="icons", - fap_icon="icons/subrem_10px.png", ) \ No newline at end of file diff --git a/applications/external/subghz_remote_configurator/helpers/subrem_custom_event.h b/applications/external/subghz_remote_configurator/helpers/subrem_custom_event.h index da3de2aae..e6b9e8ac6 100644 --- a/applications/external/subghz_remote_configurator/helpers/subrem_custom_event.h +++ b/applications/external/subghz_remote_configurator/helpers/subrem_custom_event.h @@ -10,7 +10,8 @@ typedef enum { typedef enum { // StartSubmenuIndex - SubmenuIndexSubRemEditMapFile = 0, + SubmenuIndexSubRemOpenMapFile = 0, + SubmenuIndexSubRemEditMapFile, SubmenuIndexSubRemNewMapFile, #if FURI_DEBUG SubmenuIndexSubRemRemoteView, diff --git a/applications/external/subghz_remote_configurator/helpers/txrx/subghz_txrx.c b/applications/external/subghz_remote_configurator/helpers/txrx/subghz_txrx.c index db485a2aa..8def9cf01 100644 --- a/applications/external/subghz_remote_configurator/helpers/txrx/subghz_txrx.c +++ b/applications/external/subghz_remote_configurator/helpers/txrx/subghz_txrx.c @@ -66,7 +66,7 @@ SubGhzTxRx* subghz_txrx_alloc() { subghz_devices_init(); instance->radio_device_type = SubGhzRadioDeviceTypeInternal; instance->radio_device_type = - subghz_txrx_radio_device_set(instance, SubGhzRadioDeviceTypeInternal); + subghz_txrx_radio_device_set(instance, SubGhzRadioDeviceTypeExternalCC1101); return instance; } diff --git a/applications/external/subghz_remote_configurator/icon.png b/applications/external/subghz_remote_configurator/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c6b410f4c598d6b241b851826875a568c74f4d20 GIT binary patch literal 5000 zcmeHLeQXow8NVhhfsmvNbWJE`yEq*mNzeCX`_4BziDT!(3JxJLO+Xvv_1$~UEw<0t zm)N1})-a|4OCbE6;07#-3sX@sAxkg$U?hnu$6%_P+PX_Jv(ud zLf1xG|CwUz?7R1Up5OC4zxVgNce*W&4YheW_vK(1mglK+H=%$1JZE+m`hA@F<1zI2 zyA8fptqH{ONK}=TAjGw<2*hDRkufZBKGgVD-U({Lf_l{mhyV1gGrhn5dOvmG&rb;X|2#O* z`;Gdu`y8=lFC6>o;MdlzEhu;(gUPC_z|AEGi;B+`t?Ze5z3-kKC+@xe!rsi0?9s|K zy?-daKNrL9+N8K#jUJb4ydqS`GmmU@)cv;7aPpz%>TUZsFY*}}-;x*iZ59ty6_jpT zvujoMQ}z8jJ+AG;!%Gj}Yq-_gD;(ypTplW&z40q}pQ&N1scCq0d(~q_cR%sbwf8Sv zdVdlA`l;oI1plLZ-jYiT3faL`zr6A#=Lo=7=AJsu{N?^-b1q)%coKW)>T~u}qi^rn z-7>H`clPEJwEVR7TGqA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NameUp); scene_manager_next_scene(app->scene_manager, SubRemSceneEditMenu); + } else if(start_scene_state == SubmenuIndexSubRemOpenMapFile) { + scene_manager_next_scene(app->scene_manager, SubRemSceneRemote); } } diff --git a/applications/external/subghz_remote_configurator/scenes/subrem_scene_remote.c b/applications/external/subghz_remote_configurator/scenes/subrem_scene_remote.c new file mode 100644 index 000000000..ebc582991 --- /dev/null +++ b/applications/external/subghz_remote_configurator/scenes/subrem_scene_remote.c @@ -0,0 +1,115 @@ +#include "../subghz_remote_app_i.h" +#include "../views/remote.h" + +#include + +#define TAG "SubRemScenRemote" + +void subrem_scene_remote_callback(SubRemCustomEvent event, void* context) { + furi_assert(context); + SubGhzRemoteApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, event); +} + +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; +} + +void subrem_scene_remote_on_enter(void* context) { + SubGhzRemoteApp* app = context; + + subrem_view_remote_update_data_labels(app->subrem_remote_view, app->map_preset->subs_preset); + + subrem_view_remote_set_callback(app->subrem_remote_view, subrem_scene_remote_callback, app); + + view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDRemote); +} + +bool subrem_scene_remote_on_event(void* context, SceneManagerEvent event) { + SubGhzRemoteApp* app = context; + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubRemCustomEventViewRemoteBack) { + if(!scene_manager_previous_scene(app->scene_manager)) { + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } + return true; + } else if( + event.event == SubRemCustomEventViewRemoteStartUP || + event.event == SubRemCustomEventViewRemoteStartDOWN || + event.event == SubRemCustomEventViewRemoteStartLEFT || + event.event == SubRemCustomEventViewRemoteStartRIGHT || + event.event == SubRemCustomEventViewRemoteStartOK) { + // Start sending sub + subrem_tx_stop_sub(app, true); + + uint8_t chusen_sub = subrem_scene_remote_event_to_index(event.event); + app->chusen_sub = chusen_sub; + + subrem_view_remote_set_state( + app->subrem_remote_view, SubRemViewRemoteStateLoading, chusen_sub); + + if(subrem_tx_start_sub(app, app->map_preset->subs_preset[chusen_sub])) { + if(app->map_preset->subs_preset[chusen_sub]->type == SubGhzProtocolTypeRAW) { + subghz_txrx_set_raw_file_encoder_worker_callback_end( + app->txrx, subrem_scene_remote_raw_callback_end_tx, app); + } + subrem_view_remote_set_state( + app->subrem_remote_view, SubRemViewRemoteStateSending, chusen_sub); + notification_message(app->notifications, &sequence_blink_start_magenta); + } else { + subrem_view_remote_set_state( + app->subrem_remote_view, SubRemViewRemoteStateIdle, 0); + notification_message(app->notifications, &sequence_blink_red_100); + } + return true; + } else if(event.event == SubRemCustomEventViewRemoteForcedStop) { + subrem_tx_stop_sub(app, true); + subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle, 0); + + notification_message(app->notifications, &sequence_blink_stop); + return true; + } else if(event.event == SubRemCustomEventViewRemoteStop) { + if(subrem_tx_stop_sub(app, false)) { + subrem_view_remote_set_state( + app->subrem_remote_view, SubRemViewRemoteStateIdle, 0); + + 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; + + subrem_tx_stop_sub(app, true); + + subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle, 0); + + notification_message(app->notifications, &sequence_blink_stop); +} diff --git a/applications/external/subghz_remote_configurator/scenes/subrem_scene_start.c b/applications/external/subghz_remote_configurator/scenes/subrem_scene_start.c index e5a254111..0f3399b7c 100644 --- a/applications/external/subghz_remote_configurator/scenes/subrem_scene_start.c +++ b/applications/external/subghz_remote_configurator/scenes/subrem_scene_start.c @@ -13,6 +13,20 @@ void subrem_scene_start_on_enter(void* context) { SubGhzRemoteApp* app = context; Submenu* submenu = app->submenu; + submenu_add_item( + submenu, + "Open Map File", + SubmenuIndexSubRemOpenMapFile, + subrem_scene_start_submenu_callback, + app); +#if FURI_DEBUG + submenu_add_item( + submenu, + "Remote_Debug", + SubmenuIndexSubRemRemoteView, + subrem_scene_start_submenu_callback, + app); +#endif submenu_add_item( submenu, "Edit Map File", @@ -45,7 +59,20 @@ bool subrem_scene_start_on_event(void* context, SceneManagerEvent event) { bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexSubRemEditMapFile) { + if(event.event == SubmenuIndexSubRemOpenMapFile) { + scene_manager_set_scene_state( + app->scene_manager, SubRemSceneStart, SubmenuIndexSubRemOpenMapFile); + + scene_manager_next_scene(app->scene_manager, SubRemSceneOpenMapFile); + consumed = true; + } +#if FURI_DEBUG + else if(event.event == SubmenuIndexSubRemRemoteView) { + scene_manager_next_scene(app->scene_manager, SubRemSceneRemote); + consumed = true; + } +#endif + else if(event.event == SubmenuIndexSubRemEditMapFile) { scene_manager_set_scene_state( app->scene_manager, SubRemSceneStart, SubmenuIndexSubRemEditMapFile); scene_manager_next_scene(app->scene_manager, SubRemSceneOpenMapFile); diff --git a/applications/external/subghz_remote_configurator/subghz_remote_app.c b/applications/external/subghz_remote_configurator/subghz_remote_app.c index ba71b134b..f268fea78 100644 --- a/applications/external/subghz_remote_configurator/subghz_remote_app.c +++ b/applications/external/subghz_remote_configurator/subghz_remote_app.c @@ -29,7 +29,7 @@ SubGhzRemoteApp* subghz_remote_app_alloc() { } furi_record_close(RECORD_STORAGE); - // furi_hal_power_suppress_charge_enter(); + furi_hal_power_suppress_charge_enter(); app->file_path = furi_string_alloc(); furi_string_set(app->file_path, SUBREM_APP_FOLDER); @@ -103,13 +103,8 @@ SubGhzRemoteApp* subghz_remote_app_alloc() { app->map_not_saved = false; -#ifdef SUBREM_LIGHT - scene_manager_next_scene(app->scene_manager, SubRemSceneOpenMapFile); -#else scene_manager_next_scene(app->scene_manager, SubRemSceneStart); - scene_manager_set_scene_state( - app->scene_manager, SubRemSceneStart, SubmenuIndexSubRemEditMapFile); -#endif + scene_manager_next_scene(app->scene_manager, SubRemSceneOpenMapFile); return app; } @@ -117,7 +112,7 @@ SubGhzRemoteApp* subghz_remote_app_alloc() { void subghz_remote_app_free(SubGhzRemoteApp* app) { furi_assert(app); - // furi_hal_power_suppress_charge_exit(); + furi_hal_power_suppress_charge_exit(); // Submenu view_dispatcher_remove_view(app->view_dispatcher, SubRemViewIDSubmenu); diff --git a/applications/external/subghz_remote_configurator/subghz_remote_app_i.c b/applications/external/subghz_remote_configurator/subghz_remote_app_i.c index 1eb64541f..82e762c2a 100644 --- a/applications/external/subghz_remote_configurator/subghz_remote_app_i.c +++ b/applications/external/subghz_remote_configurator/subghz_remote_app_i.c @@ -7,8 +7,8 @@ // #include // #include -// #include -// #include +#include +#include #define TAG "SubGhzRemote" @@ -204,6 +204,56 @@ void subrem_save_active_sub(void* context) { sub_preset->fff_data, furi_string_get_cstr(sub_preset->file_path)); } +bool subrem_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) { + furi_assert(app); + furi_assert(sub_preset); + bool ret = false; + + subrem_tx_stop_sub(app, true); + + if(sub_preset->type == SubGhzProtocolTypeUnknown) { + ret = false; + } else { + FURI_LOG_I(TAG, "Send %s", furi_string_get_cstr(sub_preset->label)); + + subghz_txrx_load_decoder_by_name_protocol( + app->txrx, furi_string_get_cstr(sub_preset->protocaol_name)); + + subghz_txrx_set_preset( + app->txrx, + furi_string_get_cstr(sub_preset->freq_preset.name), + sub_preset->freq_preset.frequency, + NULL, + 0); + + subghz_custom_btns_reset(); + + if(subghz_txrx_tx_start(app->txrx, sub_preset->fff_data) == SubGhzTxRxStartTxStateOk) { + ret = true; + } + } + + return ret; +} + +bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) { + furi_assert(app); + SubRemSubFilePreset* sub_preset = app->map_preset->subs_preset[app->chusen_sub]; + + if(forced || (sub_preset->type != SubGhzProtocolTypeRAW)) { + subghz_txrx_stop(app->txrx); + + if(sub_preset->type == SubGhzProtocolTypeDynamic) { + subghz_txrx_reset_dynamic_and_custom_btns(app->txrx); + } + subghz_custom_btns_reset(); + + return true; + } + + return false; +} + SubRemLoadMapState subrem_load_from_file(SubGhzRemoteApp* app) { furi_assert(app); diff --git a/applications/external/subghz_remote_configurator/subghz_remote_app_i.h b/applications/external/subghz_remote_configurator/subghz_remote_app_i.h index a84e1ba50..d200bdf96 100644 --- a/applications/external/subghz_remote_configurator/subghz_remote_app_i.h +++ b/applications/external/subghz_remote_configurator/subghz_remote_app_i.h @@ -5,7 +5,8 @@ #include "scenes/subrem_scene.h" #include "helpers/txrx/subghz_txrx.h" -#include + +#include #include "views/remote.h" #include "views/edit_menu.h" @@ -54,6 +55,10 @@ typedef struct { SubRemLoadMapState subrem_load_from_file(SubGhzRemoteApp* app); +bool subrem_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset); + +bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced); + SubRemLoadMapState subrem_map_file_load(SubGhzRemoteApp* app, const char* file_path); void subrem_map_preset_reset(SubRemMapPreset* map_preset);