From cdf8daff867049d16986b1109eb814cbd9ba631a Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Mon, 15 May 2023 22:11:18 +0300 Subject: [PATCH] add tx 2 --- .../helpers/subrem_custom_event.h | 1 + .../scenes/subrem_scene_remote.c | 67 +++++++++++++++- .../subghz_remote_new/subghz_remote_app.c | 2 + .../subghz_remote_new/subghz_remote_app_i.c | 21 ++++- .../subghz_remote_new/subghz_remote_app_i.h | 13 +++- .../subghz_remote_new/views/transmitter.c | 78 +++++++++++++------ .../subghz_remote_new/views/transmitter.h | 4 +- 7 files changed, 153 insertions(+), 33 deletions(-) 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..0c999d5e5 100644 --- a/applications/external/subghz_remote_new/helpers/subrem_custom_event.h +++ b/applications/external/subghz_remote_new/helpers/subrem_custom_event.h @@ -17,6 +17,7 @@ typedef enum { SubRemCustomEventViewRemoteStartRIGHT, SubRemCustomEventViewRemoteStartOK, SubRemCustomEventViewRemoteStop, + SubRemCustomEventViewRemoteForceStop, // SubRemCustomEventSceneDeleteSuccess = 100, // SubRemCustomEventSceneDelete, 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..f7da910ab 100644 --- a/applications/external/subghz_remote_new/scenes/subrem_scene_remote.c +++ b/applications/external/subghz_remote_new/scenes/subrem_scene_remote.c @@ -1,6 +1,8 @@ #include "../subghz_remote_app_i.h" #include "../views/transmitter.h" +#include + // TODO: // #include // #include @@ -13,6 +15,12 @@ void subrem_scene_remote_callback(SubRemCustomEvent event, void* 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, SubRemCustomEventViewRemoteForceStop); +} + bool subrem_scene_remote_update_data_show(void* context) { SubGhzRemoteApp* app = context; //UNUSED(app); @@ -113,12 +121,65 @@ bool subrem_scene_remote_on_event(void* context, SceneManagerEvent event) { app->scene_manager, SubRemSceneStart); return true; } else if(event.event == SubRemCustomEventViewRemoteStartUP) { - if(subghz_tx_start_sub(app, app->subs_preset[0])) { + if(subghz_tx_start_sub( + app, app->subs_preset[0], subrem_scene_remote_raw_callback_end_tx)) { + app->chusen_sub = 0; + subrem_view_remote_set_state(app->subrem_remote_view, 1); notification_message(app->notifications, &sequence_blink_start_magenta); } - } else if(event.event == SubRemCustomEventViewRemoteStop) { - subghz_tx_stop_sub(app, app->subs_preset[0]); + return true; + } else if(event.event == SubRemCustomEventViewRemoteStartDOWN) { + if(subghz_tx_start_sub( + app, app->subs_preset[1], subrem_scene_remote_raw_callback_end_tx)) { + app->chusen_sub = 1; + subrem_view_remote_set_state(app->subrem_remote_view, 2); + notification_message(app->notifications, &sequence_blink_start_magenta); + } + return true; + } else if(event.event == SubRemCustomEventViewRemoteStartLEFT) { + if(subghz_tx_start_sub( + app, app->subs_preset[2], subrem_scene_remote_raw_callback_end_tx)) { + app->chusen_sub = 2; + subrem_view_remote_set_state(app->subrem_remote_view, 3); + notification_message(app->notifications, &sequence_blink_start_magenta); + } + return true; + } else if(event.event == SubRemCustomEventViewRemoteStartRIGHT) { + if(subghz_tx_start_sub( + app, app->subs_preset[3], subrem_scene_remote_raw_callback_end_tx)) { + app->chusen_sub = 3; + subrem_view_remote_set_state(app->subrem_remote_view, 4); + notification_message(app->notifications, &sequence_blink_start_magenta); + } + return true; + } else if(event.event == SubRemCustomEventViewRemoteStartOK) { + if(subghz_tx_start_sub( + app, app->subs_preset[4], subrem_scene_remote_raw_callback_end_tx)) { + app->chusen_sub = 4; + subrem_view_remote_set_state(app->subrem_remote_view, 5); + notification_message(app->notifications, &sequence_blink_start_magenta); + } + return true; + } else if(event.event == SubRemCustomEventViewRemoteForceStop) { + if(app->tx_running) { + subghz_tx_stop_sub(app); + subrem_view_remote_set_state(app->subrem_remote_view, 0); + } notification_message(app->notifications, &sequence_blink_stop); + return true; + } else if(event.event == SubRemCustomEventViewRemoteStop) { + // if(app->tx_running && + // (app->subs_preset[app->chusen_sub]->type == SubRemSubKeyTypeRawKey)) { + // subghz_tx_stop_sub(app); + // subrem_view_remote_set_state(app->subrem_remote_view, 0); + // } + // notification_message(app->notifications, &sequence_blink_stop); + if(app->tx_running) { + subghz_tx_stop_sub(app); + subrem_view_remote_set_state(app->subrem_remote_view, 0); + } + notification_message(app->notifications, &sequence_blink_stop); + return true; } // notification_message(app->notification, &sequence_blink_stop); diff --git a/applications/external/subghz_remote_new/subghz_remote_app.c b/applications/external/subghz_remote_new/subghz_remote_app.c index 1bfa3a1b3..17a559da8 100644 --- a/applications/external/subghz_remote_new/subghz_remote_app.c +++ b/applications/external/subghz_remote_new/subghz_remote_app.c @@ -137,6 +137,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; 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..ef22a9e6d 100644 --- a/applications/external/subghz_remote_new/subghz_remote_app_i.c +++ b/applications/external/subghz_remote_new/subghz_remote_app_i.c @@ -115,7 +115,10 @@ 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; @@ -152,19 +155,26 @@ bool subghz_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) break; } + if(sub_preset->type == SubRemSubKeyTypeRawKey) { + 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); + app->tx_running = ret; // TODO: - // ret = false; // TODO: return ret; } -void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) { +void subghz_tx_stop_sub(SubGhzRemoteApp* app) { furi_assert(app); - furi_assert(sub_preset); //Stop TX furi_hal_subghz_stop_async_tx(); @@ -173,7 +183,10 @@ void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) { subghz_transmitter_free(app->transmitter); furi_hal_subghz_idle(); + // SubRemSubFilePreset* sub_preset = app->subs_preset[app->chusen_sub]; + // TODO: need saving logic + app->tx_running = false; } static bool subrem_sub_presets_check(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) { 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..13f3d63c5 100644 --- a/applications/external/subghz_remote_new/subghz_remote_app_i.h +++ b/applications/external/subghz_remote_new/subghz_remote_app_i.h @@ -18,6 +18,8 @@ #include #include +#include + #include #include #include @@ -75,6 +77,10 @@ typedef struct { SubGhzReceiver* receiver; SubGhzTransmitter* transmitter; + bool tx_running; + + uint8_t chusen_sub; + // AvrIspProgrammerView* subghz_remote_programmer_view; // AvrIspReaderView* subghz_remote_reader_view; // AvrIspWriterView* subghz_remote_writer_view; @@ -85,5 +91,8 @@ typedef struct { 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); +void subghz_tx_stop_sub(SubGhzRemoteApp* app); \ No newline at end of file diff --git a/applications/external/subghz_remote_new/views/transmitter.c b/applications/external/subghz_remote_new/views/transmitter.c index 6f43a1406..a814880f9 100644 --- a/applications/external/subghz_remote_new/views/transmitter.c +++ b/applications/external/subghz_remote_new/views/transmitter.c @@ -85,6 +85,15 @@ void subrem_view_remote_add_data_to_show( true); } +void subrem_view_remote_set_state(SubRemViewRemote* subrem_view_remote, uint8_t state) { + furi_assert(subrem_view_remote); + with_view_model( + subrem_view_remote->view, + SubRemViewRemoteModel * model, + { model->pressed_btn = state; }, + true); +} + void subrem_view_remote_draw(Canvas* canvas, SubRemViewRemoteModel* model) { canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); @@ -139,10 +148,10 @@ void subrem_view_remote_draw(Canvas* canvas, SubRemViewRemoteModel* model) { 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); + canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation270); break; case 4: - canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation270); + canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation90); break; case 5: canvas_draw_icon(canvas, 116, 18, &I_Pin_star_7x7); @@ -177,28 +186,51 @@ 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; - } + return false; // TODO: check + } 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( + SubRemCustomEventViewRemoteForceStop, 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) { + 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; + } + return true; } diff --git a/applications/external/subghz_remote_new/views/transmitter.h b/applications/external/subghz_remote_new/views/transmitter.h index a324d09ec..64985ff12 100644 --- a/applications/external/subghz_remote_new/views/transmitter.h +++ b/applications/external/subghz_remote_new/views/transmitter.h @@ -24,4 +24,6 @@ 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_state(SubRemViewRemote* subrem_view_remote, uint8_t state); \ No newline at end of file