diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 978954181..99765ee16 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -2,10 +2,8 @@ #include "../helpers/subghz_custom_event.h" #include #include -#include -#include -#include -#include + +#include void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) { furi_assert(context); @@ -238,10 +236,7 @@ void subghz_scene_receiver_info_on_exit(void* context) { keeloq_reset_mfname(); keeloq_reset_kl_type(); keeloq_reset_original_btn(); - alutech_reset_original_btn(); - nice_flors_reset_original_btn(); - somfy_telis_reset_original_btn(); - secplus2_reset_original_btn(); + subghz_custom_btns_reset(); 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 ca3d23685..9172f67c2 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -1,10 +1,8 @@ #include "../subghz_i.h" #include #include -#include -#include -#include -#include + +#include typedef enum { SubGhzRpcStateIdle, @@ -115,10 +113,7 @@ void subghz_scene_rpc_on_exit(void* context) { keeloq_reset_mfname(); keeloq_reset_kl_type(); keeloq_reset_original_btn(); - alutech_reset_original_btn(); - nice_flors_reset_original_btn(); - somfy_telis_reset_original_btn(); - secplus2_reset_original_btn(); + subghz_custom_btns_reset(); 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 e32e2b7b2..7895d8bc3 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -2,11 +2,9 @@ #include "../views/transmitter.h" #include #include -#include #include -#include -#include -#include + +#include void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) { furi_assert(context); @@ -91,12 +89,8 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { subghz_tx_stop(subghz); subghz_sleep(subghz); } - if(keeloq_get_custom_btn() != 0) { - keeloq_set_btn(0); - alutech_set_btn(0); - nice_flors_set_btn(0); - somfy_telis_set_btn(0); - secplus2_set_btn(0); + 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! @@ -138,10 +132,7 @@ void subghz_scene_transmitter_on_exit(void* context) { keeloq_reset_mfname(); keeloq_reset_kl_type(); keeloq_reset_original_btn(); - alutech_reset_original_btn(); - nice_flors_reset_original_btn(); - somfy_telis_reset_original_btn(); - secplus2_reset_original_btn(); + subghz_custom_btns_reset(); 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 7de0e6495..e8c53d1ed 100644 --- a/applications/main/subghz/views/transmitter.c +++ b/applications/main/subghz/views/transmitter.c @@ -4,11 +4,7 @@ #include #include -#include -#include -#include -#include -#include +#include struct SubGhzViewTransmitter { View* view; @@ -160,30 +156,18 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { // Temp Buttons (UP) if(can_be_sent && event->key == InputKeyUp && event->type == InputTypePress) { - keeloq_set_btn(1); - alutech_set_btn(1); - nice_flors_set_btn(1); - somfy_telis_set_btn(1); - secplus2_set_btn(1); + subghz_custom_btn_set(1); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); - if(keeloq_get_original_btn() != 0) { - furi_string_printf(model->temp_button_id, "%01X", keeloq_get_original_btn()); - model->draw_temp_button = true; - } 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; - } else if(somfy_telis_get_original_btn() != 0) { - furi_string_printf( - model->temp_button_id, "%01X", somfy_telis_get_original_btn()); - model->draw_temp_button = true; + if(subghz_custom_btn_get_original() != 0) { + if(subghz_custom_btn_get() == 1) { + furi_string_printf( + model->temp_button_id, "%01X", subghz_custom_btn_get_original()); + model->draw_temp_button = true; + } } }, true); @@ -197,30 +181,18 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } // Down if(can_be_sent && event->key == InputKeyDown && event->type == InputTypePress) { - keeloq_set_btn(2); - alutech_set_btn(2); - nice_flors_set_btn(2); - somfy_telis_set_btn(2); - secplus2_set_btn(2); + subghz_custom_btn_set(2); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); - if(keeloq_get_original_btn() != 0) { - furi_string_printf(model->temp_button_id, "%01X", keeloq_get_original_btn()); - model->draw_temp_button = true; - } 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; - } else if(somfy_telis_get_original_btn() != 0) { - furi_string_printf( - model->temp_button_id, "%01X", somfy_telis_get_original_btn()); - model->draw_temp_button = true; + if(subghz_custom_btn_get_original() != 0) { + if(subghz_custom_btn_get() == 2) { + furi_string_printf( + model->temp_button_id, "%01X", subghz_custom_btn_get_original()); + model->draw_temp_button = true; + } } }, true); @@ -234,30 +206,18 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } // Left if(can_be_sent && event->key == InputKeyLeft && event->type == InputTypePress) { - keeloq_set_btn(3); - alutech_set_btn(3); - nice_flors_set_btn(3); - somfy_telis_set_btn(3); - secplus2_set_btn(3); + subghz_custom_btn_set(3); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); - if(keeloq_get_original_btn() != 0) { - furi_string_printf(model->temp_button_id, "%01X", keeloq_get_original_btn()); - model->draw_temp_button = true; - } 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; - } else if(somfy_telis_get_original_btn() != 0) { - furi_string_printf( - model->temp_button_id, "%01X", somfy_telis_get_original_btn()); - model->draw_temp_button = true; + if(subghz_custom_btn_get_original() != 0) { + if(subghz_custom_btn_get() == 3) { + furi_string_printf( + model->temp_button_id, "%01X", subghz_custom_btn_get_original()); + model->draw_temp_button = true; + } } }, true); @@ -271,19 +231,18 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } // Right if(can_be_sent && event->key == InputKeyRight && event->type == InputTypePress) { - keeloq_set_btn(4); - alutech_set_btn(4); + subghz_custom_btn_set(4); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); - if(keeloq_get_original_btn() != 0) { - furi_string_printf(model->temp_button_id, "%01X", keeloq_get_original_btn()); - model->draw_temp_button = true; - } else if(alutech_get_original_btn() != 0) { - furi_string_printf(model->temp_button_id, "%01X", alutech_get_original_btn()); - model->draw_temp_button = true; + if(subghz_custom_btn_get_original() != 0) { + if(subghz_custom_btn_get() == 4) { + furi_string_printf( + model->temp_button_id, "%01X", subghz_custom_btn_get_original()); + model->draw_temp_button = true; + } } }, true); diff --git a/applications/main/subghz_remote/subghz_remote_app.c b/applications/main/subghz_remote/subghz_remote_app.c index e26d23cdf..991577cf5 100644 --- a/applications/main/subghz_remote/subghz_remote_app.c +++ b/applications/main/subghz_remote/subghz_remote_app.c @@ -19,10 +19,8 @@ #include #include #include -#include -#include -#include -#include + +#include #define SUBREMOTEMAP_FOLDER "/ext/subghz_remote" #define SUBREMOTEMAP_EXTENSION ".txt" @@ -489,10 +487,7 @@ void subghz_remote_tx_stop(SubGHzRemote* app) { keeloq_reset_mfname(); keeloq_reset_kl_type(); keeloq_reset_original_btn(); - alutech_reset_original_btn(); - nice_flors_reset_original_btn(); - somfy_telis_reset_original_btn(); - secplus2_reset_original_btn(); + subghz_custom_btns_reset(); 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 e62a8d694..575e9fae1 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,20.0,, +Version,+,20.1,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -503,10 +503,6 @@ Function,-,acosl,long double,long double Function,-,aligned_alloc,void*,"size_t, size_t" Function,+,aligned_free,void,void* Function,+,aligned_malloc,void*,"size_t, size_t" -Function,-,alutech_get_custom_btn,uint8_t, -Function,-,alutech_get_original_btn,uint8_t, -Function,-,alutech_reset_original_btn,void, -Function,-,alutech_set_btn,void,uint8_t Function,-,arc4random,__uint32_t, Function,-,arc4random_buf,void,"void*, size_t" Function,-,arc4random_uniform,__uint32_t,__uint32_t @@ -1780,12 +1776,9 @@ Function,-,j1f,float,float Function,-,jn,double,"int, double" Function,-,jnf,float,"int, float" Function,-,jrand48,long,unsigned short[3] -Function,-,keeloq_get_custom_btn,uint8_t, -Function,-,keeloq_get_original_btn,uint8_t, Function,-,keeloq_reset_kl_type,void, Function,-,keeloq_reset_mfname,void, Function,-,keeloq_reset_original_btn,void, -Function,-,keeloq_set_btn,void,uint8_t Function,-,l64a,char*,long Function,-,labs,long,long Function,-,lcong48,void,unsigned short[7] @@ -2093,10 +2086,6 @@ 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*" @@ -2464,10 +2453,6 @@ Function,+,scene_manager_search_and_switch_to_previous_scene_one_of,_Bool,"Scene Function,+,scene_manager_set_scene_state,void,"SceneManager*, uint32_t, uint32_t" Function,+,scene_manager_stop,void,SceneManager* Function,+,sd_api_get_fs_type_text,const char*,SDFsType -Function,-,secplus2_get_custom_btn,uint8_t, -Function,-,secplus2_get_original_btn,uint8_t, -Function,-,secplus2_reset_original_btn,void, -Function,-,secplus2_set_btn,void,uint8_t Function,-,secure_getenv,char*,const char* Function,-,seed48,unsigned short*,unsigned short[3] Function,-,select,int,"int, fd_set*, fd_set*, fd_set*, timeval*" @@ -2503,10 +2488,6 @@ Function,-,siprintf,int,"char*, const char*, ..." Function,-,siscanf,int,"const char*, const char*, ..." Function,-,sniprintf,int,"char*, size_t, const char*, ..." Function,+,snprintf,int,"char*, size_t, const char*, ..." -Function,-,somfy_telis_get_custom_btn,uint8_t, -Function,-,somfy_telis_get_original_btn,uint8_t, -Function,-,somfy_telis_reset_original_btn,void, -Function,-,somfy_telis_set_btn,void,uint8_t Function,-,sprintf,int,"char*, const char*, ..." Function,-,sqrt,double,double Function,-,sqrtf,float,float @@ -2663,6 +2644,12 @@ Function,+,subghz_block_generic_deserialize,SubGhzProtocolStatus,"SubGhzBlockGen Function,+,subghz_block_generic_deserialize_check_count_bit,SubGhzProtocolStatus,"SubGhzBlockGeneric*, FlipperFormat*, uint16_t" Function,+,subghz_block_generic_get_preset_name,void,"const char*, FuriString*" Function,+,subghz_block_generic_serialize,SubGhzProtocolStatus,"SubGhzBlockGeneric*, FlipperFormat*, SubGhzRadioPreset*" +Function,-,subghz_custom_btn_get,uint8_t, +Function,-,subghz_custom_btn_get_original,uint8_t, +Function,-,subghz_custom_btn_set,void,uint8_t +Function,-,subghz_custom_btn_set_max,void,uint8_t +Function,-,subghz_custom_btn_set_original,void,uint8_t +Function,-,subghz_custom_btns_reset,void, Function,+,subghz_environment_alloc,SubGhzEnvironment*, Function,+,subghz_environment_free,void,SubGhzEnvironment* Function,+,subghz_environment_get_alutech_at_4n_rainbow_table_file_name,const char*,SubGhzEnvironment* diff --git a/lib/subghz/blocks/custom_btn.c b/lib/subghz/blocks/custom_btn.c new file mode 100644 index 000000000..dd1436798 --- /dev/null +++ b/lib/subghz/blocks/custom_btn.c @@ -0,0 +1,34 @@ +#include "custom_btn.h" + +static uint8_t custom_btn_id; +static uint8_t custom_btn_original; +static uint8_t custom_btn_max_btns = 0; + +void subghz_custom_btn_set(uint8_t b) { + if(b > custom_btn_max_btns) { + custom_btn_id = 0; + } else { + custom_btn_id = b; + } +} + +uint8_t subghz_custom_btn_get() { + return custom_btn_id; +} + +void subghz_custom_btn_set_original(uint8_t b) { + custom_btn_original = b; +} + +uint8_t subghz_custom_btn_get_original() { + return custom_btn_original; +} + +void subghz_custom_btn_set_max(uint8_t b) { + custom_btn_max_btns = b; +} + +void subghz_custom_btns_reset() { + custom_btn_original = 0; + custom_btn_max_btns = 0; +} \ No newline at end of file diff --git a/lib/subghz/blocks/custom_btn.h b/lib/subghz/blocks/custom_btn.h new file mode 100644 index 000000000..0ea5ee654 --- /dev/null +++ b/lib/subghz/blocks/custom_btn.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include + +void subghz_custom_btn_set(uint8_t b); + +uint8_t subghz_custom_btn_get(); + +void subghz_custom_btn_set_original(uint8_t b); + +uint8_t subghz_custom_btn_get_original(); + +void subghz_custom_btn_set_max(uint8_t b); + +void subghz_custom_btns_reset(); \ No newline at end of file diff --git a/lib/subghz/protocols/alutech_at_4n.c b/lib/subghz/protocols/alutech_at_4n.c index 5c09e8bb8..04e10adf5 100644 --- a/lib/subghz/protocols/alutech_at_4n.c +++ b/lib/subghz/protocols/alutech_at_4n.c @@ -5,6 +5,8 @@ #include "../blocks/generic.h" #include "../blocks/math.h" +#include "../blocks/custom_btn.h" + #define TAG "SubGhzProtocoAlutech_at_4n" #define SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE 0xFFFFFFFF @@ -77,25 +79,6 @@ const SubGhzProtocol subghz_protocol_alutech_at_4n = { .encoder = &subghz_protocol_alutech_at_4n_encoder, }; -static uint8_t al_btn_temp_id; -static uint8_t al_btn_temp_id_original; - -void alutech_set_btn(uint8_t b) { - al_btn_temp_id = b; -} - -uint8_t alutech_get_original_btn() { - return al_btn_temp_id_original; -} - -uint8_t alutech_get_custom_btn() { - return al_btn_temp_id; -} - -void alutech_reset_original_btn() { - al_btn_temp_id_original = 0; -} - void* subghz_protocol_encoder_alutech_at_4n_alloc(SubGhzEnvironment* environment) { UNUSED(environment); SubGhzProtocolEncoderAlutech_at_4n* instance = @@ -341,13 +324,16 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( furi_assert(instance); // Save original button for later use - if(al_btn_temp_id_original == 0) { - al_btn_temp_id_original = btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(btn); } + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_num = subghz_custom_btn_get_original(); + // Set custom button - if(al_btn_temp_id == 1) { - switch(al_btn_temp_id_original) { + if(custom_btn_id == 1) { + switch(original_btn_num) { case 0x11: btn = 0x22; break; @@ -368,8 +354,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( break; } } - if(al_btn_temp_id == 2) { - switch(al_btn_temp_id_original) { + if(custom_btn_id == 2) { + switch(original_btn_num) { case 0x11: btn = 0x44; break; @@ -390,8 +376,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( break; } } - if(al_btn_temp_id == 3) { - switch(al_btn_temp_id_original) { + if(custom_btn_id == 3) { + switch(original_btn_num) { case 0x11: btn = 0x33; break; @@ -412,8 +398,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( break; } } - if(al_btn_temp_id == 4) { - switch(al_btn_temp_id_original) { + if(custom_btn_id == 4) { + switch(original_btn_num) { case 0x11: btn = 0xFF; break; @@ -435,8 +421,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( } } - if((al_btn_temp_id == 0) && (al_btn_temp_id_original != 0)) { - btn = al_btn_temp_id_original; + if((custom_btn_id == 0) && (original_btn_num != 0)) { + btn = original_btn_num; } //gen new key if(subghz_protocol_alutech_at_4n_gen_data(instance, btn)) { @@ -735,9 +721,10 @@ static void subghz_protocol_alutech_at_4n_remote_controller( } // Save original button for later use - if(al_btn_temp_id_original == 0) { - al_btn_temp_id_original = instance->btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(instance->btn); } + subghz_custom_btn_set_max(4); } uint8_t subghz_protocol_decoder_alutech_at_4n_get_hash_data(void* context) { diff --git a/lib/subghz/protocols/alutech_at_4n.h b/lib/subghz/protocols/alutech_at_4n.h index 89adbb5c6..b7b5b9ede 100644 --- a/lib/subghz/protocols/alutech_at_4n.h +++ b/lib/subghz/protocols/alutech_at_4n.h @@ -10,14 +10,6 @@ extern const SubGhzProtocolDecoder subghz_protocol_alutech_at_4n_decoder; extern const SubGhzProtocolEncoder subghz_protocol_alutech_at_4n_encoder; extern const SubGhzProtocol subghz_protocol_alutech_at_4n; -// Custom buttons -void alutech_set_btn(uint8_t b); - -uint8_t alutech_get_original_btn(); -uint8_t alutech_get_custom_btn(); - -void alutech_reset_original_btn(); - /** * Allocate SubGhzProtocolEncoderAlutech_at_4n. * @param environment Pointer to a SubGhzEnvironment instance diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 759a524fe..6698f54fe 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -10,6 +10,8 @@ #include "../blocks/generic.h" #include "../blocks/math.h" +#include "../blocks/custom_btn.h" + #define TAG "SubGhzProtocolKeeloq" static const SubGhzBlockConst subghz_protocol_keeloq_const = { @@ -86,25 +88,12 @@ const SubGhzProtocol subghz_protocol_keeloq = { static const char* mfname; static uint8_t kl_type; -static uint8_t btn_temp_id; -static uint8_t btn_temp_id_original; static uint8_t klq_prog_mode; static uint16_t temp_counter; -void keeloq_set_btn(uint8_t b) { - btn_temp_id = b; -} - -uint8_t keeloq_get_original_btn() { - return btn_temp_id_original; -} - -uint8_t keeloq_get_custom_btn() { - return btn_temp_id; -} - void keeloq_reset_original_btn() { - btn_temp_id_original = 0; + subghz_custom_btn_set_original(0); + subghz_custom_btn_set_max(0); temp_counter = 0; klq_prog_mode = 0; } @@ -384,8 +373,8 @@ static bool furi_assert(instance); // Save original button - if(btn_temp_id_original == 0) { - btn_temp_id_original = btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(btn); } if(instance->manufacture_name == 0x0) { @@ -402,9 +391,12 @@ static bool klq_last_custom_btn = 0xF; } + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_num = subghz_custom_btn_get_original(); + // Set custom button - if(btn_temp_id == 1) { - switch(btn_temp_id_original) { + if(custom_btn_id == 1) { + switch(original_btn_num) { case 0x1: btn = 0x2; break; @@ -429,8 +421,8 @@ static bool break; } } - if(btn_temp_id == 2) { - switch(btn_temp_id_original) { + if(custom_btn_id == 2) { + switch(original_btn_num) { case 0x1: btn = 0x4; break; @@ -455,8 +447,8 @@ static bool break; } } - if(btn_temp_id == 3) { - switch(btn_temp_id_original) { + if(custom_btn_id == 3) { + switch(original_btn_num) { case 0x1: btn = 0x8; break; @@ -481,8 +473,8 @@ static bool break; } } - if(btn_temp_id == 4) { - switch(btn_temp_id_original) { + if(custom_btn_id == 4) { + switch(original_btn_num) { case 0x1: btn = klq_last_custom_btn; break; @@ -508,8 +500,8 @@ static bool } } - if((btn_temp_id == 0) && (btn_temp_id_original != 0)) { - btn = btn_temp_id_original; + if((custom_btn_id == 0) && (original_btn_num != 0)) { + btn = original_btn_num; } // Generate new key @@ -1213,9 +1205,10 @@ static void subghz_protocol_keeloq_check_remote_controller( instance->btn = key_fix >> 28; // Save original button for later use - if(btn_temp_id_original == 0) { - btn_temp_id_original = instance->btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(instance->btn); } + subghz_custom_btn_set_max(4); } uint8_t subghz_protocol_decoder_keeloq_get_hash_data(void* context) { diff --git a/lib/subghz/protocols/keeloq.h b/lib/subghz/protocols/keeloq.h index f0715648c..9862e0e92 100644 --- a/lib/subghz/protocols/keeloq.h +++ b/lib/subghz/protocols/keeloq.h @@ -2,6 +2,8 @@ #include "base.h" +#include "../blocks/custom_btn.h" + #define SUBGHZ_PROTOCOL_KEELOQ_NAME "KeeLoq" typedef struct SubGhzProtocolDecoderKeeloq SubGhzProtocolDecoderKeeloq; @@ -15,11 +17,6 @@ void keeloq_reset_mfname(); void keeloq_reset_kl_type(); -void keeloq_set_btn(uint8_t b); - -uint8_t keeloq_get_original_btn(); -uint8_t keeloq_get_custom_btn(); - void keeloq_reset_original_btn(); /** diff --git a/lib/subghz/protocols/nice_flor_s.c b/lib/subghz/protocols/nice_flor_s.c index dbdb4c8b5..5d8e7f587 100644 --- a/lib/subghz/protocols/nice_flor_s.c +++ b/lib/subghz/protocols/nice_flor_s.c @@ -6,6 +6,8 @@ #include "../blocks/generic.h" #include "../blocks/math.h" +#include "../blocks/custom_btn.h" + /* * https://phreakerclub.com/1615 * https://phreakerclub.com/forum/showthread.php?t=2360 @@ -84,25 +86,6 @@ 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); @@ -148,13 +131,16 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( btn = instance->generic.btn; // Save original button for later use - if(n_btn_temp_id_original == 0) { - n_btn_temp_id_original = btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(btn); } + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_num = subghz_custom_btn_get_original(); + // Set custom button - if(n_btn_temp_id == 1) { - switch(n_btn_temp_id_original) { + if(custom_btn_id == 1) { + switch(original_btn_num) { case 0x1: btn = 0x2; break; @@ -172,8 +158,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( break; } } - if(n_btn_temp_id == 2) { - switch(n_btn_temp_id_original) { + if(custom_btn_id == 2) { + switch(original_btn_num) { case 0x1: btn = 0x4; break; @@ -191,8 +177,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( break; } } - if(n_btn_temp_id == 3) { - switch(n_btn_temp_id_original) { + if(custom_btn_id == 3) { + switch(original_btn_num) { case 0x1: btn = 0x8; break; @@ -211,8 +197,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( } } - if((n_btn_temp_id == 0) && (n_btn_temp_id_original != 0)) { - btn = n_btn_temp_id_original; + if((custom_btn_id == 0) && (original_btn_num != 0)) { + btn = original_btn_num; } size_t size_upload = ((instance->generic.data_count_bit * 2) + ((37 + 2 + 2) * 2) * 16); @@ -756,9 +742,10 @@ static void subghz_protocol_nice_flor_s_remote_controller( } // Save original button for later use - if(n_btn_temp_id_original == 0) { - n_btn_temp_id_original = instance->btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(instance->btn); } + subghz_custom_btn_set_max(3); } 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 679b31812..5f8b30644 100644 --- a/lib/subghz/protocols/nice_flor_s.h +++ b/lib/subghz/protocols/nice_flor_s.h @@ -11,14 +11,6 @@ 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 diff --git a/lib/subghz/protocols/secplus_v2.c b/lib/subghz/protocols/secplus_v2.c index a0bc2b9f4..5d0ecb0dd 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -7,6 +7,8 @@ #include "../blocks/generic.h" #include "../blocks/math.h" +#include "../blocks/custom_btn.h" + /* * Help * https://github.com/argilo/secplus @@ -83,25 +85,6 @@ const SubGhzProtocol subghz_protocol_secplus_v2 = { .encoder = &subghz_protocol_secplus_v2_encoder, }; -static uint8_t sc_btn_temp_id; -static uint8_t sc_btn_temp_id_original; - -void secplus2_set_btn(uint8_t b) { - sc_btn_temp_id = b; -} - -uint8_t secplus2_get_original_btn() { - return sc_btn_temp_id_original; -} - -uint8_t secplus2_get_custom_btn() { - return sc_btn_temp_id; -} - -void secplus2_reset_original_btn() { - sc_btn_temp_id_original = 0; -} - void* subghz_protocol_encoder_secplus_v2_alloc(SubGhzEnvironment* environment) { UNUSED(environment); SubGhzProtocolEncoderSecPlus_v2* instance = malloc(sizeof(SubGhzProtocolEncoderSecPlus_v2)); @@ -359,9 +342,10 @@ static void } // Save original button for later use - if(sc_btn_temp_id_original == 0) { - sc_btn_temp_id_original = instance->btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(instance->btn); } + subghz_custom_btn_set_max(3); } /** @@ -398,13 +382,16 @@ static uint64_t subghz_protocol_secplus_v2_encode_half(uint8_t roll_array[], uin static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* instance) { // Save original button for later use - if(sc_btn_temp_id_original == 0) { - sc_btn_temp_id_original = instance->generic.btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(instance->generic.btn); } + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_num = subghz_custom_btn_get_original(); + // Set custom button - if(sc_btn_temp_id == 1) { - switch(sc_btn_temp_id_original) { + if(custom_btn_id == 1) { + switch(original_btn_num) { case 0x68: instance->generic.btn = 0x80; break; @@ -422,8 +409,8 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i break; } } - if(sc_btn_temp_id == 2) { - switch(sc_btn_temp_id_original) { + if(custom_btn_id == 2) { + switch(original_btn_num) { case 0x68: instance->generic.btn = 0x81; break; @@ -441,8 +428,8 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i break; } } - if(sc_btn_temp_id == 3) { - switch(sc_btn_temp_id_original) { + if(custom_btn_id == 3) { + switch(original_btn_num) { case 0x68: instance->generic.btn = 0xE2; break; @@ -460,8 +447,8 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i break; } } - if((sc_btn_temp_id == 0) && (sc_btn_temp_id_original != 0)) { - instance->generic.btn = sc_btn_temp_id_original; + if((custom_btn_id == 0) && (original_btn_num != 0)) { + instance->generic.btn = original_btn_num; } uint32_t fixed_1[1] = {instance->generic.btn << 12 | instance->generic.serial >> 20}; uint32_t fixed_2[1] = {instance->generic.serial & 0xFFFFF}; diff --git a/lib/subghz/protocols/secplus_v2.h b/lib/subghz/protocols/secplus_v2.h index 155d943b2..0eea732af 100644 --- a/lib/subghz/protocols/secplus_v2.h +++ b/lib/subghz/protocols/secplus_v2.h @@ -10,14 +10,6 @@ extern const SubGhzProtocolDecoder subghz_protocol_secplus_v2_decoder; extern const SubGhzProtocolEncoder subghz_protocol_secplus_v2_encoder; extern const SubGhzProtocol subghz_protocol_secplus_v2; -// Custom buttons -void secplus2_set_btn(uint8_t b); - -uint8_t secplus2_get_original_btn(); -uint8_t secplus2_get_custom_btn(); - -void secplus2_reset_original_btn(); - /** * Allocate SubGhzProtocolEncoderSecPlus_v2. * @param environment Pointer to a SubGhzEnvironment instance diff --git a/lib/subghz/protocols/somfy_telis.c b/lib/subghz/protocols/somfy_telis.c index 0294a1922..047efb688 100644 --- a/lib/subghz/protocols/somfy_telis.c +++ b/lib/subghz/protocols/somfy_telis.c @@ -7,6 +7,8 @@ #include "../blocks/generic.h" #include "../blocks/math.h" +#include "../blocks/custom_btn.h" + #define TAG "SubGhzProtocolSomfyTelis" static const SubGhzBlockConst subghz_protocol_somfy_telis_const = { @@ -73,25 +75,6 @@ const SubGhzProtocol subghz_protocol_somfy_telis = { .encoder = &subghz_protocol_somfy_telis_encoder, }; -static uint8_t st_btn_temp_id; -static uint8_t st_btn_temp_id_original; - -void somfy_telis_set_btn(uint8_t b) { - st_btn_temp_id = b; -} - -uint8_t somfy_telis_get_original_btn() { - return st_btn_temp_id_original; -} - -uint8_t somfy_telis_get_custom_btn() { - return st_btn_temp_id; -} - -void somfy_telis_reset_original_btn() { - st_btn_temp_id_original = 0; -} - void* subghz_protocol_encoder_somfy_telis_alloc(SubGhzEnvironment* environment) { UNUSED(environment); SubGhzProtocolEncoderSomfyTelis* instance = malloc(sizeof(SubGhzProtocolEncoderSomfyTelis)); @@ -128,13 +111,16 @@ static bool subghz_protocol_somfy_telis_gen_data( } // Save original button for later use - if(st_btn_temp_id_original == 0) { - st_btn_temp_id_original = btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(btn); } + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_num = subghz_custom_btn_get_original(); + // Set custom button - if(st_btn_temp_id == 1) { - switch(st_btn_temp_id_original) { + if(custom_btn_id == 1) { + switch(original_btn_num) { case 0x1: btn = 0x2; break; @@ -152,8 +138,8 @@ static bool subghz_protocol_somfy_telis_gen_data( break; } } - if(st_btn_temp_id == 2) { - switch(st_btn_temp_id_original) { + if(custom_btn_id == 2) { + switch(original_btn_num) { case 0x1: btn = 0x4; break; @@ -171,8 +157,8 @@ static bool subghz_protocol_somfy_telis_gen_data( break; } } - if(st_btn_temp_id == 3) { - switch(st_btn_temp_id_original) { + if(custom_btn_id == 3) { + switch(original_btn_num) { case 0x1: btn = 0x8; break; @@ -191,8 +177,8 @@ static bool subghz_protocol_somfy_telis_gen_data( } } - if((st_btn_temp_id == 0) && (st_btn_temp_id_original != 0)) { - btn = st_btn_temp_id_original; + if((custom_btn_id == 0) && (original_btn_num != 0)) { + btn = original_btn_num; } if(instance->generic.cnt < 0xFFFF) { @@ -684,9 +670,10 @@ static void subghz_protocol_somfy_telis_check_remote_controller(SubGhzBlockGener instance->serial = data & 0xFFFFFF; // address // Save original button for later use - if(st_btn_temp_id_original == 0) { - st_btn_temp_id_original = instance->btn; + if(subghz_custom_btn_get_original() == 0) { + subghz_custom_btn_set_original(instance->btn); } + subghz_custom_btn_set_max(3); } /** diff --git a/lib/subghz/protocols/somfy_telis.h b/lib/subghz/protocols/somfy_telis.h index 36f6c70b5..cb5cf8e96 100644 --- a/lib/subghz/protocols/somfy_telis.h +++ b/lib/subghz/protocols/somfy_telis.h @@ -11,14 +11,6 @@ extern const SubGhzProtocolDecoder subghz_protocol_somfy_telis_decoder; extern const SubGhzProtocolEncoder subghz_protocol_somfy_telis_encoder; extern const SubGhzProtocol subghz_protocol_somfy_telis; -// Custom buttons -void somfy_telis_set_btn(uint8_t b); - -uint8_t somfy_telis_get_original_btn(); -uint8_t somfy_telis_get_custom_btn(); - -void somfy_telis_reset_original_btn(); - /** * Allocate SubGhzProtocolEncoderSomfyTelis. * @param environment Pointer to a SubGhzEnvironment instance