From 3df6c819478820de4e795a83f111d3ee746dff92 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:51:25 +0100 Subject: [PATCH] Sub-GHz: Choose RSSI threshold for Hopping mode --- CHANGELOG.md | 1 + .../main/subghz/helpers/subghz_txrx.c | 4 +- .../main/subghz/helpers/subghz_txrx.h | 3 +- .../subghz/scenes/subghz_scene_receiver.c | 2 +- .../scenes/subghz_scene_receiver_config.c | 59 +++++++++++++++---- .../scenes/subghz_scene_receiver_info.c | 2 +- .../main/subghz/subghz_last_settings.c | 16 +++++ .../main/subghz/subghz_last_settings.h | 1 + 8 files changed, 71 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c133aee7..bfa1b2659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Added: - Sub-GHz: - New Legrand doorbell protocol (by @user890104) + - Choose RSSI threshold for Hopping mode (by @Willy-JL) - UL: Novoferm remotes full support (by @xMasterX) - UL: Add manually Hormann EcoStar, also Sommer FM238 option when default won't work (by @xMasterX) - OFW: Princeton protocol add custom guard time (by @Skorpionm & @xMasterX) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 56e7b5415..4bdf7b2ea 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -377,7 +377,7 @@ void subghz_txrx_stop(SubGhzTxRx* instance) { } } -void subghz_txrx_hopper_update(SubGhzTxRx* instance) { +void subghz_txrx_hopper_update(SubGhzTxRx* instance, float stay_threshold) { furi_assert(instance); switch(instance->hopper_state) { @@ -400,7 +400,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) { float rssi = subghz_devices_get_rssi(instance->radio_device); // Stay if RSSI is high enough - if(rssi > -90.0f) { + if(rssi > stay_threshold) { instance->hopper_timeout = 10; instance->hopper_state = SubGhzHopperStateRSSITimeOut; return; diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index ec87e270c..8687607c9 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -141,8 +141,9 @@ void subghz_txrx_sleep(SubGhzTxRx* instance); * Update frequency CC1101 in automatic mode (hopper) * * @param instance Pointer to a SubGhzTxRx + * @param stay_threshold RSSI theshold over which to stay before hopping */ -void subghz_txrx_hopper_update(SubGhzTxRx* instance); +void subghz_txrx_hopper_update(SubGhzTxRx* instance, float stay_threshold); /** * Get state hopper diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 32ad1d2c9..23dd987e0 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -478,7 +478,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { } else if(event.type == SceneManagerEventTypeTick) { if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateTX) { if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { - subghz_txrx_hopper_update(subghz->txrx); + subghz_txrx_hopper_update(subghz->txrx, subghz->last_settings->hopping_threshold); subghz_scene_receiver_update_statusbar(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 7986cbe66..870f1f817 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -77,6 +77,37 @@ const char* const combobox_text[COMBO_BOX_COUNT] = { "ON", }; +#define HOPPING_MODE_COUNT 12 +const char* const hopping_mode_text[HOPPING_MODE_COUNT] = { + "OFF", + "-90.0", + "-85.0", + "-80.0", + "-75.0", + "-70.0", + "-65.0", + "-60.0", + "-55.0", + "-50.0", + "-45.0", + "-40.0", + +}; +const float hopping_mode_value[HOPPING_MODE_COUNT] = { + NAN, + -90.0f, + -85.0f, + -80.0f, + -75.0f, + -70.0f, + -65.0f, + -60.0f, + -55.0f, + -50.0f, + -45.0f, + -40.0f, +}; + #define REPEATER_COUNT 4 const char* const repeater_text[REPEATER_COUNT] = { "OFF", @@ -143,17 +174,19 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* return index; } -SubGhzHopperState subghz_scene_receiver_config_hopper_value_index(void* context) { +uint8_t subghz_scene_receiver_config_hopper_value_index(void* context) { furi_assert(context); SubGhz* subghz = context; if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { - return SubGhzHopperStateOFF; + return 0; } else { variable_item_set_current_value_text( variable_item_list_get(subghz->variable_item_list, SubGhzSettingIndexFrequency), " -----"); - return SubGhzHopperStateRunning; + return value_index_float( + subghz->last_settings->hopping_threshold, hopping_mode_value, HOPPING_MODE_COUNT); + ; } } @@ -213,16 +246,16 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { subghz->last_settings->preset_index = index; } -static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { +static void subghz_scene_receiver_config_set_hopping(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); - SubGhzHopperState index = variable_item_get_current_value_index(item); + uint8_t index = variable_item_get_current_value_index(item); SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); VariableItem* frequency_item = variable_item_list_get(subghz->variable_item_list, SubGhzSettingIndexFrequency); - variable_item_set_current_value_text(item, combobox_text[(uint8_t)index]); + variable_item_set_current_value_text(item, hopping_mode_text[index]); - if(index == SubGhzHopperStateOFF) { + if(index == 0) { char text_buf[10] = {0}; uint32_t frequency = subghz_setting_get_default_frequency(setting); SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); @@ -251,8 +284,10 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) variable_item_set_current_value_index( frequency_item, subghz_setting_get_frequency_default_index(setting)); } - subghz->last_settings->enable_hopping = index != SubGhzHopperStateOFF; - subghz_txrx_hopper_set_state(subghz->txrx, index); + subghz->last_settings->enable_hopping = index != 0; + subghz->last_settings->hopping_threshold = hopping_mode_value[index]; + subghz_txrx_hopper_set_state( + subghz->txrx, index != 0 ? SubGhzHopperStateRunning : SubGhzHopperStateOFF); } static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { @@ -497,13 +532,13 @@ void subghz_scene_receiver_config_on_enter(void* context) { item = variable_item_list_add( subghz->variable_item_list, "Hopping", - COMBO_BOX_COUNT, - subghz_scene_receiver_config_set_hopping_running, + HOPPING_MODE_COUNT, + subghz_scene_receiver_config_set_hopping, subghz); value_index = subghz_scene_receiver_config_hopper_value_index(subghz); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, combobox_text[value_index]); + variable_item_set_current_value_text(item, hopping_mode_text[value_index]); } if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 5e1008d85..2f242d075 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -197,7 +197,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) } } else if(event.type == SceneManagerEventTypeTick) { if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { - subghz_txrx_hopper_update(subghz->txrx); + subghz_txrx_hopper_update(subghz->txrx, subghz->last_settings->hopping_threshold); } switch(subghz->state_notifications) { case SubGhzNotificationStateTx: diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 673c27e8e..2ea191490 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -23,6 +23,7 @@ #define SUBGHZ_LAST_SETTING_FIELD_REPEATER "Repeater" #define SUBGHZ_LAST_SETTING_FIELD_ENABLE_SOUND "Sound" #define SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE "Autosave" +#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD "HoppingThreshold" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -46,6 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count // See bin_raw_value in scenes/subghz_scene_receiver_config.c instance->filter = SubGhzProtocolFlag_Decodable; instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN; + instance->hopping_threshold = -90.0f; Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); @@ -153,6 +155,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE, &instance->autosave, 1)) { flipper_format_rewind(fff_data_file); } + if(!flipper_format_read_float( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD, + &instance->hopping_threshold, + 1)) { + flipper_format_rewind(fff_data_file); + } } while(0); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); @@ -265,6 +274,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE, &instance->autosave, 1)) { break; } + if(!flipper_format_write_float( + file, + SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD, + &instance->hopping_threshold, + 1)) { + break; + } saved = true; } while(0); diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 91dfbef3a..430cb11ae 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -30,6 +30,7 @@ typedef struct { uint32_t repeater_state; bool enable_sound; bool autosave; + float hopping_threshold; } SubGhzLastSettings; SubGhzLastSettings* subghz_last_settings_alloc(void);