From 182296d8af1a61b21b72e7451c4c8ff78f0f1244 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 27 Feb 2023 01:13:21 +0300 Subject: [PATCH] Nice flor s - custom buttons --- CHANGELOG.md | 18 ++-- ReadMe.md | 2 +- .../scenes/subghz_scene_receiver_info.c | 2 + .../main/subghz/scenes/subghz_scene_rpc.c | 2 + .../subghz/scenes/subghz_scene_transmitter.c | 3 + applications/main/subghz/views/transmitter.c | 16 ++++ applications/main/unirfremix/unirfremix_app.c | 2 + firmware/targets/f7/api_symbols.csv | 4 + lib/subghz/protocols/nice_flor_s.c | 92 +++++++++++++++++++ lib/subghz/protocols/nice_flor_s.h | 8 ++ 10 files changed, 140 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 128c9465a..6cc844c23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,14 @@ ### New changes -* SubGHz: **Keeloq: Beninca - protocol support** -* SubGHz: **Hold right in received signal list to delete selected signal** -* SubGHz: **Custom buttons for Keeloq and Alutech AT4N** - now you can use arrow buttons to send signal with different button code -* SubGHz: Debug mode counter increase settings (+5, +10, default: +1) -* Infrared: Debug TX PIN output settings (ability to move tx signal out to GPIO) (implemented #364) -* Plugins: Updated -> [BH1750] Lightmeter [(by oleksiikutuzov)](https://github.com/oleksiikutuzov/flipperzero-lightmeter) -* OFW: BadUSB -> STRINGDELAY(STRING_DELAY) feature, worker signal handling refactoring -> (Fixed #365 (BadUSB won't detect connection and/or hangs)) -* OFW: Grammar fixes +* SubGHz: **Custom buttons for Nice Flor S** - now you can use arrow buttons to send signal with different button code +* OFW: Drivers: remove excessive check in bq25896 and make PVS happy +* OFW: FuriHal, Power, UnitTests: fix, rename battery charging voltage limit API -> **Breaking API change, api was changed from 14.x to 15.x** +**(this will make your manually copied plugins not work, update them in same way you installed them, or delete `apps` folder and then install firmware, if you using extra pack builds (with `e` in version) all apps in _Extra will be updated automatically)** + +* OFW: Fix incorrect type choise condition in image compressor +* OFW: Updater: handle storage errors when removing files, fix folder remove routine, prevent unused services from starting +* OFW: Unify power info, power debug, and device_info into one info command +* OFW: SD Cache: moved to diskio layer, invalidation in case of error +* OFW: Picopass: factory key support, minor code cleanup #### [🎲 Download latest extra apps pack](https://download-directory.github.io/?url=https://github.com/xMasterX/unleashed-extra-pack/tree/main/apps) diff --git a/ReadMe.md b/ReadMe.md index a78f749e0..6f99a1993 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -166,7 +166,7 @@ Games: - Sub-GHz -> Long press OK button in Sub-GHz Frequency analyzer to switch to Read menu [(by derskythe)](https://github.com/DarkFlippers/unleashed-firmware/pull/79) - Lock device with pin(or regular lock if pin not set) by holding UP button on main screen [(by an4tur0r)](https://github.com/DarkFlippers/unleashed-firmware/pull/107) * SubGHz -> **Hold right in received signal list to delete selected signal** -* SubGHz -> **Custom buttons for Keeloq and Alutech AT4N** - now you can use arrow buttons to send signal with different button code +* SubGHz -> **Custom buttons for Keeloq / Alutech AT4N / Nice Flor S** - now you can use arrow buttons to send signal with different button code * SubGHz -> Debug mode counter increase settings (+5, +10, default: +1) * SubGHz -> Debug PIN output settings for protocol development * Infrared -> Debug TX PIN output settings diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 4f4924b06..c654ad0c5 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -3,6 +3,7 @@ #include #include #include +#include void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) { furi_assert(context); @@ -236,6 +237,7 @@ void subghz_scene_receiver_info_on_exit(void* context) { keeloq_reset_kl_type(); keeloq_reset_original_btn(); alutech_reset_original_btn(); + nice_flors_reset_original_btn(); star_line_reset_mfname(); star_line_reset_kl_type(); } diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index 0ff801d79..b64f92de2 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -2,6 +2,7 @@ #include #include #include +#include typedef enum { SubGhzRpcStateIdle, @@ -113,6 +114,7 @@ void subghz_scene_rpc_on_exit(void* context) { keeloq_reset_kl_type(); keeloq_reset_original_btn(); alutech_reset_original_btn(); + nice_flors_reset_original_btn(); star_line_reset_mfname(); star_line_reset_kl_type(); } diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 53fc95981..a10e10a37 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -4,6 +4,7 @@ #include #include #include +#include void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) { furi_assert(context); @@ -93,6 +94,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { if(keeloq_get_custom_btn() != 0) { keeloq_set_btn(0); alutech_set_btn(0); + nice_flors_set_btn(0); uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); furi_hal_subghz_set_rolling_counter_mult(0); // Calling restore! @@ -135,6 +137,7 @@ void subghz_scene_transmitter_on_exit(void* context) { keeloq_reset_kl_type(); keeloq_reset_original_btn(); alutech_reset_original_btn(); + nice_flors_reset_original_btn(); star_line_reset_mfname(); star_line_reset_kl_type(); } diff --git a/applications/main/subghz/views/transmitter.c b/applications/main/subghz/views/transmitter.c index 218bf8f7e..5a64f27e2 100644 --- a/applications/main/subghz/views/transmitter.c +++ b/applications/main/subghz/views/transmitter.c @@ -6,6 +6,7 @@ #include #include +#include struct SubGhzViewTransmitter { View* view; @@ -159,6 +160,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { if(can_be_sent && event->key == InputKeyUp && event->type == InputTypePress) { keeloq_set_btn(1); alutech_set_btn(1); + nice_flors_set_btn(1); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, @@ -170,6 +172,10 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } else if(alutech_get_original_btn() != 0) { furi_string_printf(model->temp_button_id, "%01X", alutech_get_original_btn()); model->draw_temp_button = true; + } else if(nice_flors_get_original_btn() != 0) { + furi_string_printf( + model->temp_button_id, "%01X", nice_flors_get_original_btn()); + model->draw_temp_button = true; } }, true); @@ -185,6 +191,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { if(can_be_sent && event->key == InputKeyDown && event->type == InputTypePress) { keeloq_set_btn(2); alutech_set_btn(2); + nice_flors_set_btn(2); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, @@ -196,6 +203,10 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } else if(alutech_get_original_btn() != 0) { furi_string_printf(model->temp_button_id, "%01X", alutech_get_original_btn()); model->draw_temp_button = true; + } else if(nice_flors_get_original_btn() != 0) { + furi_string_printf( + model->temp_button_id, "%01X", nice_flors_get_original_btn()); + model->draw_temp_button = true; } }, true); @@ -211,6 +222,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { if(can_be_sent && event->key == InputKeyLeft && event->type == InputTypePress) { keeloq_set_btn(3); alutech_set_btn(3); + nice_flors_set_btn(3); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, @@ -222,6 +234,10 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } else if(alutech_get_original_btn() != 0) { furi_string_printf(model->temp_button_id, "%01X", alutech_get_original_btn()); model->draw_temp_button = true; + } else if(nice_flors_get_original_btn() != 0) { + furi_string_printf( + model->temp_button_id, "%01X", nice_flors_get_original_btn()); + model->draw_temp_button = true; } }, true); diff --git a/applications/main/unirfremix/unirfremix_app.c b/applications/main/unirfremix/unirfremix_app.c index 81d8ceb1a..4f8d5fa01 100644 --- a/applications/main/unirfremix/unirfremix_app.c +++ b/applications/main/unirfremix/unirfremix_app.c @@ -20,6 +20,7 @@ #include #include #include +#include #define UNIRFMAP_FOLDER "/ext/unirf" #define UNIRFMAP_EXTENSION ".txt" @@ -484,6 +485,7 @@ void unirfremix_tx_stop(UniRFRemix* app) { keeloq_reset_kl_type(); keeloq_reset_original_btn(); alutech_reset_original_btn(); + nice_flors_reset_original_btn(); star_line_reset_mfname(); star_line_reset_kl_type(); } diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 7dc6378fe..08c95fe1f 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -2063,6 +2063,10 @@ Function,-,nfca_get_crc16,uint16_t,"uint8_t*, uint16_t" Function,-,nfca_signal_alloc,NfcaSignal*, Function,-,nfca_signal_encode,void,"NfcaSignal*, uint8_t*, uint16_t, uint8_t*" Function,-,nfca_signal_free,void,NfcaSignal* +Function,-,nice_flors_get_custom_btn,uint8_t, +Function,-,nice_flors_get_original_btn,uint8_t, +Function,-,nice_flors_reset_original_btn,void, +Function,-,nice_flors_set_btn,void,uint8_t Function,+,notification_internal_message,void,"NotificationApp*, const NotificationSequence*" Function,+,notification_internal_message_block,void,"NotificationApp*, const NotificationSequence*" Function,+,notification_message,void,"NotificationApp*, const NotificationSequence*" diff --git a/lib/subghz/protocols/nice_flor_s.c b/lib/subghz/protocols/nice_flor_s.c index 5120573f0..f58c6084f 100644 --- a/lib/subghz/protocols/nice_flor_s.c +++ b/lib/subghz/protocols/nice_flor_s.c @@ -84,6 +84,25 @@ const SubGhzProtocol subghz_protocol_nice_flor_s = { .encoder = &subghz_protocol_nice_flor_s_encoder, }; +static uint8_t n_btn_temp_id; +static uint8_t n_btn_temp_id_original; + +void nice_flors_set_btn(uint8_t b) { + n_btn_temp_id = b; +} + +uint8_t nice_flors_get_original_btn() { + return n_btn_temp_id_original; +} + +uint8_t nice_flors_get_custom_btn() { + return n_btn_temp_id; +} + +void nice_flors_reset_original_btn() { + n_btn_temp_id_original = 0; +} + static void subghz_protocol_nice_flor_s_remote_controller( SubGhzBlockGeneric* instance, const char* file_name); @@ -128,6 +147,74 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( size_t index = 0; btn = instance->generic.btn; + // Save original button for later use + if(n_btn_temp_id_original == 0) { + n_btn_temp_id_original = btn; + } + + // Set custom button + if(n_btn_temp_id == 1) { + switch(n_btn_temp_id_original) { + case 0x1: + btn = 0x2; + break; + case 0x2: + btn = 0x1; + break; + case 0x4: + btn = 0x1; + break; + case 0x8: + btn = 0x1; + break; + + default: + break; + } + } + if(n_btn_temp_id == 2) { + switch(n_btn_temp_id_original) { + case 0x1: + btn = 0x4; + break; + case 0x2: + btn = 0x4; + break; + case 0x4: + btn = 0x2; + break; + case 0x8: + btn = 0x4; + break; + + default: + break; + } + } + if(n_btn_temp_id == 3) { + switch(n_btn_temp_id_original) { + case 0x1: + btn = 0x8; + break; + case 0x2: + btn = 0x8; + break; + case 0x4: + btn = 0x8; + break; + case 0x8: + btn = 0x2; + break; + + default: + break; + } + } + + if((n_btn_temp_id == 0) && (n_btn_temp_id_original != 0)) { + btn = n_btn_temp_id_original; + } + size_t size_upload = ((instance->generic.data_count_bit * 2) + ((37 + 2 + 2) * 2) * 16); if(size_upload > instance->encoder.size_upload) { FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer."); @@ -646,6 +733,11 @@ static void subghz_protocol_nice_flor_s_remote_controller( instance->serial = (decrypt >> 16) & 0xFFFFFFF; instance->btn = (decrypt >> 48) & 0xF; } + + // Save original button for later use + if(n_btn_temp_id_original == 0) { + n_btn_temp_id_original = instance->btn; + } } uint8_t subghz_protocol_decoder_nice_flor_s_get_hash_data(void* context) { diff --git a/lib/subghz/protocols/nice_flor_s.h b/lib/subghz/protocols/nice_flor_s.h index e333fc979..52f0ca745 100644 --- a/lib/subghz/protocols/nice_flor_s.h +++ b/lib/subghz/protocols/nice_flor_s.h @@ -11,6 +11,14 @@ extern const SubGhzProtocolDecoder subghz_protocol_nice_flor_s_decoder; extern const SubGhzProtocolEncoder subghz_protocol_nice_flor_s_encoder; extern const SubGhzProtocol subghz_protocol_nice_flor_s; +// Custom buttons +void nice_flors_set_btn(uint8_t b); + +uint8_t nice_flors_get_original_btn(); +uint8_t nice_flors_get_custom_btn(); + +void nice_flors_reset_original_btn(); + /** * Allocate SubGhzProtocolEncoderNiceFlorS. * @param environment Pointer to a SubGhzEnvironment instance