From 500ca0758afb3a776ec053570634ef796514c7ab Mon Sep 17 00:00:00 2001 From: DerSkythe Date: Fri, 4 Aug 2023 18:52:16 +0400 Subject: [PATCH 1/2] Save hopping in last settings - Save hopping state - Add easy logging to SubGhzLastSettings - Add to CLI alias 'l' for log command - Fix misspelled names --- .../main/subghz/helpers/subghz_txrx.c | 18 ++++---- .../main/subghz/helpers/subghz_txrx.h | 6 +-- .../subghz/scenes/subghz_scene_decode_raw.c | 9 ++-- .../subghz/scenes/subghz_scene_receiver.c | 23 +++++++--- .../scenes/subghz_scene_receiver_config.c | 38 +++++++++------- .../subghz/scenes/subghz_scene_save_success.c | 2 +- applications/main/subghz/subghz.c | 14 +----- applications/main/subghz/subghz_i.c | 4 +- .../main/subghz/subghz_last_settings.c | 44 ++++++++++++++++--- .../main/subghz/subghz_last_settings.h | 3 ++ applications/main/subghz/views/receiver.c | 12 ++++- applications/main/subghz/views/receiver.h | 3 +- .../subghz/views/subghz_frequency_analyzer.c | 6 +-- applications/services/cli/cli_commands.c | 1 + 14 files changed, 118 insertions(+), 65 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index d878c0e04..57dea99f5 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -3,10 +3,9 @@ #include #include #include - #include -#define TAG "SubGhz" +#define TAG "SubGhzTxRx" static void subghz_txrx_radio_device_power_on(SubGhzTxRx* instance) { UNUSED(instance); @@ -383,10 +382,11 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) { default: break; } - float rssi = -127.0f; + // Init value isn't using + // float rssi = -127.0f; if(instance->hopper_state != SubGhzHopperStateRSSITimeOut) { // See RSSI Calculation timings in CC1101 17.3 RSSI - rssi = subghz_devices_get_rssi(instance->radio_device); + float rssi = subghz_devices_get_rssi(instance->radio_device); // Stay if RSSI is high enough if(rssi > -90.0f) { @@ -407,7 +407,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) { if(instance->txrx_state == SubGhzTxRxStateRx) { subghz_txrx_rx_end(instance); - }; + } if(instance->txrx_state == SubGhzTxRxStateIDLE) { subghz_receiver_reset(instance->receiver); instance->preset->frequency = @@ -554,7 +554,7 @@ void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag fi subghz_receiver_set_filter(instance->receiver, filter); } -void subghz_txrx_set_rx_calback( +void subghz_txrx_set_rx_callback( SubGhzTxRx* instance, SubGhzReceiverCallback callback, void* context) { @@ -629,12 +629,12 @@ const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) { return subghz_devices_get_name(instance->radio_device); } -bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) { +bool subghz_txrx_radio_device_is_frequency_valid(SubGhzTxRx* instance, uint32_t frequency) { furi_assert(instance); return subghz_devices_is_frequency_valid(instance->radio_device, frequency); } -bool subghz_txrx_radio_device_is_tx_alowed(SubGhzTxRx* instance, uint32_t frequency) { +bool subghz_txrx_radio_device_is_tx_allowed(SubGhzTxRx* instance, uint32_t frequency) { furi_assert(instance); furi_assert(instance->txrx_state != SubGhzTxRxStateSleep); @@ -667,4 +667,4 @@ void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance) { SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) { furi_assert(instance); return instance->receiver; -} \ No newline at end of file +} diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index 76c7c8ead..c31915d30 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -274,7 +274,7 @@ void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag fi * @param callback Callback for receive data * @param context Context for callback */ -void subghz_txrx_set_rx_calback( +void subghz_txrx_set_rx_callback( SubGhzTxRx* instance, SubGhzReceiverCallback callback, void* context); @@ -334,9 +334,9 @@ const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance); * @param instance Pointer to a SubGhzTxRx * @return bool True if the frequency is valid */ -bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency); +bool subghz_txrx_radio_device_is_frequency_valid(SubGhzTxRx* instance, uint32_t frequency); -bool subghz_txrx_radio_device_is_tx_alowed(SubGhzTxRx* instance, uint32_t frequency); +bool subghz_txrx_radio_device_is_tx_allowed(SubGhzTxRx* instance, uint32_t frequency); void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state); bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance); diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 988a61c8b..1b076ae27 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -21,13 +21,14 @@ static void subghz_scene_receiver_update_statusbar(void* context) { subghz->subghz_receiver, furi_string_get_cstr(frequency_str), furi_string_get_cstr(modulation_str), - furi_string_get_cstr(history_stat_str)); + furi_string_get_cstr(history_stat_str), + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); furi_string_free(frequency_str); furi_string_free(modulation_str); } else { subghz_view_receiver_add_data_statusbar( - subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", ""); + subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false); } furi_string_free(history_stat_str); } @@ -154,7 +155,7 @@ void subghz_scene_decode_raw_on_enter(void* context) { subghz_view_receiver_set_callback( subghz->subghz_receiver, subghz_scene_decode_raw_callback, subghz); - subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); + subghz_txrx_set_rx_callback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_Decodable); @@ -202,7 +203,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) { subghz->scene_manager, SubGhzSceneDecodeRAW, SubGhzDecodeRawStateStart); subghz->idx_menu_chosen = 0; - subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz); + subghz_txrx_set_rx_callback(subghz->txrx, NULL, subghz); if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) { subghz_file_encoder_worker_stop(subghz->decode_raw_file_worker_encoder); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index ac09ebcea..dd7b4cf02 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -70,13 +70,14 @@ static void subghz_scene_receiver_update_statusbar(void* context) { subghz->subghz_receiver, furi_string_get_cstr(frequency_str), furi_string_get_cstr(modulation_str), - furi_string_get_cstr(history_stat_str)); + furi_string_get_cstr(history_stat_str), + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); furi_string_free(frequency_str); furi_string_free(modulation_str); } else { subghz_view_receiver_add_data_statusbar( - subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", ""); + subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false); subghz->state_notifications = SubGhzNotificationStateIDLE; } furi_string_free(history_stat_str); @@ -151,7 +152,7 @@ void subghz_scene_receiver_on_enter(void* context) { subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz_is_locked(subghz)); subghz_view_receiver_set_mode(subghz->subghz_receiver, SubGhzViewReceiverModeLive); - //Load history to receiver + // Load history to receiver subghz_view_receiver_exit(subghz->subghz_receiver); for(uint8_t i = 0; i < subghz_history_get_item(history); i++) { furi_string_reset(item_name); @@ -167,14 +168,24 @@ void subghz_scene_receiver_on_enter(void* context) { } furi_string_free(item_name); furi_string_free(item_time); - subghz_scene_receiver_update_statusbar(subghz); + subghz_view_receiver_set_callback( subghz->subghz_receiver, subghz_scene_receiver_callback, subghz); - subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); + subghz_txrx_set_rx_callback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); if(!subghz_history_get_text_space_left(subghz->history, NULL)) { subghz->state_notifications = SubGhzNotificationStateRx; } + + // Check if hopping was enabled +#ifdef FURI_DEBUG + subghz_last_settings_log(subghz->last_settings); +#endif + if(subghz->last_settings->enable_hopping) { + subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateRunning); + } + + subghz_scene_receiver_update_statusbar(subghz); subghz_txrx_rx_start(subghz->txrx); subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->idx_menu_chosen); @@ -198,7 +209,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); - subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz); + subghz_txrx_set_rx_callback(subghz->txrx, NULL, subghz); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 62ee53871..8a8c21653 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -1,6 +1,8 @@ #include "../subghz_i.h" #include +#define TAG "SubGhzSceneReceiverConfig" + enum SubGhzSettingIndex { SubGhzSettingIndexFrequency, SubGhzSettingIndexHopping, @@ -14,6 +16,10 @@ enum SubGhzSettingIndex { SubGhzSettingIndexRAWThresholdRSSI, }; +static inline const char* bool_to_char(bool value) { + return value ? "ON" : "OFF"; +} + #define RAW_THRESHOLD_RSSI_COUNT 11 const char* const raw_threshold_rssi_text[RAW_THRESHOLD_RSSI_COUNT] = { "-----", @@ -111,23 +117,18 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* return index; } -uint8_t subghz_scene_receiver_config_hopper_value_index( - const uint32_t value, - const uint32_t values[], - uint8_t values_count, - void* context) { +SubGhzHopperState subghz_scene_receiver_config_hopper_value_index(void* context) { furi_assert(context); - UNUSED(values_count); SubGhz* subghz = context; - if(value == values[0]) { - return 0; + if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { + return SubGhzHopperStateOFF; } else { variable_item_set_current_value_text( (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig), " -----"); - return 1; + return SubGhzHopperStateRunning; } } @@ -184,13 +185,14 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); + SubGhzHopperState index = variable_item_get_current_value_index(item); SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); VariableItem* frequency_item = (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig); - variable_item_set_current_value_text(item, hopping_text[index]); - if(hopping_value[index] == SubGhzHopperStateOFF) { + variable_item_set_current_value_text(item, hopping_text[(uint8_t)index]); + + if(index == SubGhzHopperStateOFF) { char text_buf[10] = {0}; uint32_t frequency = subghz_setting_get_default_frequency(setting); SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); @@ -203,6 +205,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) (frequency % 1000000) / 10000); variable_item_set_current_value_text(frequency_item, text_buf); + // Maybe better add one more function with only with the frequency argument? subghz_txrx_set_preset( subghz->txrx, furi_string_get_cstr(preset.name), @@ -216,8 +219,11 @@ 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_txrx_hopper_set_state(subghz->txrx, hopping_value[index]); + subghz->last_settings->enable_hopping = index != SubGhzHopperStateOFF; +#ifdef FURI_DEBUG + subghz_last_settings_log(subghz->last_settings); +#endif + subghz_txrx_hopper_set_state(subghz->txrx, index); } static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { @@ -333,8 +339,8 @@ void subghz_scene_receiver_config_on_enter(void* context) { HOPPING_COUNT, subghz_scene_receiver_config_set_hopping_running, subghz); - value_index = subghz_scene_receiver_config_hopper_value_index( - subghz_txrx_hopper_get_state(subghz->txrx), hopping_value, HOPPING_COUNT, 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, hopping_text[value_index]); } diff --git a/applications/main/subghz/scenes/subghz_scene_save_success.c b/applications/main/subghz/scenes/subghz_scene_save_success.c index 6a5346492..276e5ecc0 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_success.c +++ b/applications/main/subghz/scenes/subghz_scene_save_success.c @@ -42,7 +42,7 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) subghz->scene_manager, SubGhzSceneDecodeRAW, SubGhzDecodeRawStateStart); subghz->idx_menu_chosen = 0; - subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz); + subghz_txrx_set_rx_callback(subghz->txrx, NULL, subghz); if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) { subghz_file_encoder_worker_stop(subghz->decode_raw_file_worker_encoder); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 2af334db6..302976a28 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -197,26 +197,14 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->last_settings = subghz_last_settings_alloc(); subghz_last_settings_load(subghz->last_settings, 0); if(!alloc_for_tx_only) { -#if FURI_DEBUG - FURI_LOG_D( - TAG, - "last frequency: %ld, preset: %ld", - subghz->last_settings->frequency, - subghz->last_settings->preset); -#endif subghz_setting_set_default_frequency(setting, subghz->last_settings->frequency); - } - if(!alloc_for_tx_only) { subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz->history = subghz_history_alloc(); } subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - if(!alloc_for_tx_only) { - subghz->history = subghz_history_alloc(); - } - subghz->secure_data = malloc(sizeof(SecureData)); subghz->filter = SubGhzProtocolFlag_Decodable; diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index f91f128cf..dbfe3d426 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -115,13 +115,13 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { break; } - if(!subghz_txrx_radio_device_is_frequecy_valid(subghz->txrx, temp_data32)) { + if(!subghz_txrx_radio_device_is_frequency_valid(subghz->txrx, temp_data32)) { FURI_LOG_E(TAG, "Frequency not supported on chosen radio module"); load_key_state = SubGhzLoadKeyStateUnsuportedFreq; break; } - if(!subghz_txrx_radio_device_is_tx_alowed(subghz->txrx, temp_data32)) { + if(!subghz_txrx_radio_device_is_tx_allowed(subghz->txrx, temp_data32)) { FURI_LOG_E(TAG, "This frequency can only be used for RX on chosen radio module"); load_key_state = SubGhzLoadKeyStateOnlyRx; break; diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 465312b19..84a3b18de 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -21,6 +21,11 @@ #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower" #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" +#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE "Hopping" + +static inline const char* bool_to_char(bool value) { + return value ? "ON" : "OFF"; +} SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -35,9 +40,6 @@ void subghz_last_settings_free(SubGhzLastSettings* instance) { void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count) { UNUSED(preset_count); furi_assert(instance); -#ifdef FURI_DEBUG - FURI_LOG_I(TAG, "subghz_last_settings_load"); -#endif Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); @@ -49,6 +51,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool temp_external_module_power_5v_disable = false; bool temp_external_module_power_amp = false; bool temp_timestamp_file_names = false; + bool temp_enable_hopping = false; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; bool frequency_analyzer_trigger_was_read = false; @@ -90,7 +93,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, (bool*)&temp_external_module_power_amp, 1); - + flipper_format_read_bool( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE, + (bool*)&temp_enable_hopping, + 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } @@ -105,6 +112,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_enabled = false; instance->timestamp_file_names = false; instance->external_module_power_amp = false; + instance->enable_hopping = false; } else { instance->frequency = temp_frequency; @@ -130,6 +138,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count // External power amp CC1101 instance->external_module_power_amp = temp_external_module_power_amp; + instance->enable_hopping = temp_enable_hopping; + // Set globally in furi hal furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp); @@ -137,6 +147,9 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->preset = temp_preset; }*/ } +#ifdef FURI_DEBUG + subghz_last_settings_log(instance); +#endif flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); @@ -146,7 +159,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool subghz_last_settings_save(SubGhzLastSettings* instance) { furi_assert(instance); #ifdef FURI_DEBUG - FURI_LOG_I(TAG, "last_settings_save"); + subghz_last_settings_log(instance); #endif bool saved = false; @@ -217,6 +230,10 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { 1)) { break; } + if(!flipper_format_insert_or_update_bool( + file, SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE, &instance->enable_hopping, 1)) { + break; + } saved = true; } while(0); @@ -230,3 +247,20 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { return saved; } + +void subghz_last_settings_log(SubGhzLastSettings* instance) { + furi_assert(instance); + + FURI_LOG_I( + TAG, + "Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s, Hopping: %s", + instance->frequency / 1000000 % 1000, + instance->frequency / 10000 % 100, + instance->frequency_analyzer_feedback_level, + (double)instance->frequency_analyzer_trigger, + bool_to_char(instance->external_module_enabled), + bool_to_char(instance->external_module_power_5v_disable), + bool_to_char(instance->timestamp_file_names), + bool_to_char(instance->external_module_power_amp), + bool_to_char(instance->enable_hopping)); +} diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index c351cb6a5..d24d876d8 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -16,6 +16,7 @@ typedef struct { bool external_module_power_amp; // saved so as not to change the version bool timestamp_file_names; + bool enable_hopping; } SubGhzLastSettings; SubGhzLastSettings* subghz_last_settings_alloc(void); @@ -25,3 +26,5 @@ void subghz_last_settings_free(SubGhzLastSettings* instance); void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count); bool subghz_last_settings_save(SubGhzLastSettings* instance); + +void subghz_last_settings_log(SubGhzLastSettings* instance); diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 9d514b8ca..5e4d068c3 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -62,6 +62,7 @@ typedef struct { FuriString* preset_str; FuriString* history_stat_str; FuriString* progress_str; + bool hopping_enabled; SubGhzReceiverHistory* history; uint16_t idx; uint16_t list_offset; @@ -200,7 +201,8 @@ void subghz_view_receiver_add_data_statusbar( SubGhzViewReceiver* subghz_receiver, const char* frequency_str, const char* preset_str, - const char* history_stat_str) { + const char* history_stat_str, + bool hopping_enabled) { furi_assert(subghz_receiver); with_view_model( subghz_receiver->view, @@ -209,6 +211,7 @@ void subghz_view_receiver_add_data_statusbar( furi_string_set(model->frequency_str, frequency_str); furi_string_set(model->preset_str, preset_str); furi_string_set(model->history_stat_str, history_stat_str); + model->hopping_enabled = hopping_enabled; }, true); } @@ -311,7 +314,6 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) { canvas_set_color(canvas, ColorBlack); if(model->history_item == 0) { - // TODO if(model->mode == SubGhzViewReceiverModeLive) { canvas_draw_icon( canvas, @@ -323,6 +325,12 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) { canvas_draw_str(canvas, 63, 46, "Scanning..."); //canvas_draw_line(canvas, 46, 51, 125, 51); canvas_set_font(canvas, FontSecondary); + + if(model->hopping_enabled) { + const uint8_t vertical_offset = 7; + const uint8_t horizontal_offset = 3; + canvas_draw_icon(canvas, horizontal_offset, vertical_offset, &I_Dynamic_9x7); + } } else { canvas_draw_icon( canvas, diff --git a/applications/main/subghz/views/receiver.h b/applications/main/subghz/views/receiver.h index 57718cfc4..264d8a983 100644 --- a/applications/main/subghz/views/receiver.h +++ b/applications/main/subghz/views/receiver.h @@ -31,7 +31,8 @@ void subghz_view_receiver_add_data_statusbar( SubGhzViewReceiver* subghz_receiver, const char* frequency_str, const char* preset_str, - const char* history_stat_str); + const char* history_stat_str, + bool hopping_enabled); void subghz_view_receiver_set_radio_device_type( SubGhzViewReceiver* subghz_receiver, diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index 7800c9081..9f39bb0d6 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -315,7 +315,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { uint32_t frequency_candidate = model->history_frequency[model->selected_index]; if(frequency_candidate == 0 || // !furi_hal_subghz_is_frequency_valid(frequency_candidate) || - !subghz_txrx_radio_device_is_frequecy_valid( + !subghz_txrx_radio_device_is_frequency_valid( instance->txrx, frequency_candidate) || prev_freq_to_save == frequency_candidate) { frequency_candidate = 0; @@ -339,7 +339,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { uint32_t frequency_candidate = subghz_frequency_find_correct(model->frequency); if(frequency_candidate == 0 || // !furi_hal_subghz_is_frequency_valid(frequency_candidate) || - !subghz_txrx_radio_device_is_frequecy_valid( + !subghz_txrx_radio_device_is_frequency_valid( instance->txrx, frequency_candidate) || prev_freq_to_save == frequency_candidate) { frequency_candidate = 0; @@ -356,7 +356,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { uint32_t frequency_candidate = subghz_frequency_find_correct(model->frequency); if(frequency_candidate == 0 || // !furi_hal_subghz_is_frequency_valid(frequency_candidate) || - !subghz_txrx_radio_device_is_frequecy_valid( + !subghz_txrx_radio_device_is_frequency_valid( instance->txrx, frequency_candidate) || prev_freq_to_save == frequency_candidate) { frequency_candidate = 0; diff --git a/applications/services/cli/cli_commands.c b/applications/services/cli/cli_commands.c index 58dfb9300..2c40fdc16 100644 --- a/applications/services/cli/cli_commands.c +++ b/applications/services/cli/cli_commands.c @@ -473,6 +473,7 @@ void cli_commands_init(Cli* cli) { cli_add_command(cli, "uptime", CliCommandFlagDefault, cli_command_uptime, NULL); cli_add_command(cli, "date", CliCommandFlagParallelSafe, cli_command_date, NULL); cli_add_command(cli, "log", CliCommandFlagParallelSafe, cli_command_log, NULL); + cli_add_command(cli, "l", CliCommandFlagParallelSafe, cli_command_log, NULL); cli_add_command(cli, "sysctl", CliCommandFlagDefault, cli_command_sysctl, NULL); cli_add_command(cli, "ps", CliCommandFlagParallelSafe, cli_command_ps, NULL); cli_add_command(cli, "free", CliCommandFlagParallelSafe, cli_command_free, NULL); From 8c44dfb6af4d52e554d1adca902c2377ec19f488 Mon Sep 17 00:00:00 2001 From: DerSkythe Date: Tue, 8 Aug 2023 08:58:20 +0400 Subject: [PATCH 2/2] Save preset, RSSIm ignore values in last settings - Save preset - Save RSSI - Save Ignore Starline, Cars, Magellan - Fix types of COUNT_OF result - Move subghz_set_default_preset to SubGhzTxRx - In subghz_txrx_radio_device_is_tx_allowed check for SubGhzTxRxStateSleep is not working --- .../main/subghz/helpers/subghz_txrx.c | 33 ++++- .../main/subghz/helpers/subghz_txrx.h | 7 +- .../subghz/scenes/subghz_scene_decode_raw.c | 12 +- .../subghz/scenes/subghz_scene_delete_raw.c | 1 + .../scenes/subghz_scene_frequency_analyzer.c | 3 + .../subghz/scenes/subghz_scene_read_raw.c | 18 ++- .../subghz/scenes/subghz_scene_receiver.c | 28 ++-- .../scenes/subghz_scene_receiver_config.c | 113 ++++++++-------- .../scenes/subghz_scene_receiver_info.c | 2 + .../main/subghz/scenes/subghz_scene_saved.c | 2 + .../subghz/scenes/subghz_scene_transmitter.c | 2 + applications/main/subghz/subghz.c | 35 +++-- applications/main/subghz/subghz_i.c | 17 --- applications/main/subghz/subghz_i.h | 2 +- .../main/subghz/subghz_last_settings.c | 124 +++++++++++++----- .../main/subghz/subghz_last_settings.h | 11 +- applications/main/subghz/views/receiver.c | 36 +++-- .../subghz/views/subghz_frequency_analyzer.h | 2 +- 18 files changed, 294 insertions(+), 154 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 57dea99f5..4b7852947 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -29,8 +29,7 @@ SubGhzTxRx* subghz_txrx_alloc() { instance->preset = malloc(sizeof(SubGhzRadioPreset)); instance->preset->name = furi_string_alloc(); - subghz_txrx_set_preset( - instance, "AM650", subghz_setting_get_default_frequency(instance->setting), NULL, 0); + subghz_txrx_set_default_preset(instance, 0); instance->txrx_state = SubGhzTxRxStateSleep; @@ -636,7 +635,7 @@ bool subghz_txrx_radio_device_is_frequency_valid(SubGhzTxRx* instance, uint32_t bool subghz_txrx_radio_device_is_tx_allowed(SubGhzTxRx* instance, uint32_t frequency) { furi_assert(instance); - furi_assert(instance->txrx_state != SubGhzTxRxStateSleep); + //furi_assert(instance->txrx_state != SubGhzTxRxStateSleep); subghz_devices_idle(instance->radio_device); subghz_devices_set_frequency(instance->radio_device, frequency); @@ -668,3 +667,31 @@ SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) { furi_assert(instance); return instance->receiver; } + +void subghz_txrx_set_default_preset(SubGhzTxRx* instance, uint32_t frequency) { + furi_assert(instance); + + const char* default_modulation = "AM650"; + if(frequency == 0) { + frequency = subghz_setting_get_default_frequency(subghz_txrx_get_setting(instance)); + } + subghz_txrx_set_preset(instance, default_modulation, frequency, NULL, 0); +} + +const char* + subghz_txrx_set_preset_internal(SubGhzTxRx* instance, uint32_t frequency, uint8_t index) { + furi_assert(instance); + + SubGhzSetting* setting = subghz_txrx_get_setting(instance); + const char* preset_name = subghz_setting_get_preset_name(setting, index); + subghz_setting_set_default_frequency(setting, frequency); + + subghz_txrx_set_preset( + instance, + preset_name, + frequency, + subghz_setting_get_preset_data(setting, index), + subghz_setting_get_preset_data_size(setting, index)); + + return preset_name; +} diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index c31915d30..73be12cf6 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -329,7 +329,7 @@ float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance); */ const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance); -/* Get get intelligence whether frequency the selected radio device to use +/* Get intelligence whether frequency the selected radio device to use * * @param instance Pointer to a SubGhzTxRx * @return bool True if the frequency is valid @@ -344,3 +344,8 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance); void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance); SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw + +void subghz_txrx_set_default_preset(SubGhzTxRx* instance, uint32_t frequency); + +const char* + subghz_txrx_set_preset_internal(SubGhzTxRx* instance, uint32_t frequency, uint8_t index); diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 1b076ae27..6cb231935 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -1,8 +1,4 @@ #include "../subghz_i.h" -#include "../views/receiver.h" -#include - -#include #define TAG "SubGhzDecodeRaw" #define SAMPLES_TO_READ_PER_TICK 400 @@ -28,7 +24,11 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_free(modulation_str); } else { subghz_view_receiver_add_data_statusbar( - subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false); + subghz->subghz_receiver, + furi_string_get_cstr(history_stat_str), + "", + "", + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); } furi_string_free(history_stat_str); } @@ -171,7 +171,7 @@ void subghz_scene_decode_raw_on_enter(void* context) { } else { //Load history to receiver subghz_view_receiver_exit(subghz->subghz_receiver); - for(uint8_t i = 0; i < subghz_history_get_item(subghz->history); i++) { + for(uint16_t i = 0; i < subghz_history_get_item(subghz->history); i++) { furi_string_reset(item_name); furi_string_reset(item_time); subghz_history_get_text_item_menu(subghz->history, item_name, i); diff --git a/applications/main/subghz/scenes/subghz_scene_delete_raw.c b/applications/main/subghz/scenes/subghz_scene_delete_raw.c index ada0f4c5c..0b3cfd6ee 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_delete_raw.c @@ -1,3 +1,4 @@ +#include "../subghz.h" #include "../subghz_i.h" #include "../helpers/subghz_custom_event.h" diff --git a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c index b1071d836..afee251ca 100644 --- a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c +++ b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c @@ -60,6 +60,9 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer); if(frequency > 0) { subghz->last_settings->frequency = frequency; +#ifdef FURI_DEBUG + subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter); +#endif subghz_last_settings_save(subghz->last_settings); } diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 9dfb695e7..83b7dc854 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -104,8 +104,17 @@ void subghz_scene_read_raw_on_enter(void* context) { if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateBack) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + if(furi_string_empty(file_name)) { + subghz_txrx_set_preset_internal( + subghz->txrx, + subghz->last_settings->frequency, + subghz->last_settings->preset_index); + subghz_txrx_speaker_set_state( + subghz->txrx, + subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown : + SubGhzSpeakerStateEnable); + } } - furi_string_free(file_name); subghz_scene_read_raw_update_statusbar(subghz); //set callback view raw @@ -115,6 +124,8 @@ void subghz_scene_read_raw_on_enter(void* context) { //set filter RAW feed subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_RAW); + furi_string_free(file_name); + view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReadRAW); } @@ -139,10 +150,9 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { } else { //Restore default setting if(subghz->raw_send_only) { - subghz_set_default_preset(subghz); + subghz_txrx_set_default_preset(subghz->txrx, 0); } else { - subghz_txrx_set_preset( - subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency); } if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneSaved)) { diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index dd7b4cf02..3f172bb45 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -1,5 +1,4 @@ #include "../subghz_i.h" -#include "../views/receiver.h" #include #include @@ -77,7 +76,11 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_free(modulation_str); } else { subghz_view_receiver_add_data_statusbar( - subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "", false); + subghz->subghz_receiver, + furi_string_get_cstr(history_stat_str), + "", + "", + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); subghz->state_notifications = SubGhzNotificationStateIDLE; } furi_string_free(history_stat_str); @@ -143,7 +146,16 @@ void subghz_scene_receiver_on_enter(void* context) { FuriString* item_time = furi_string_alloc(); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) { - subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz->filter = subghz->last_settings->filter; + subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); + subghz->ignore_filter = subghz->last_settings->ignore_filter; + subghz_txrx_set_preset_internal( + subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index); + subghz_txrx_speaker_set_state( + subghz->txrx, + subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown : + SubGhzSpeakerStateEnable); + subghz_history_reset(history); subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); subghz->idx_menu_chosen = 0; @@ -154,7 +166,7 @@ void subghz_scene_receiver_on_enter(void* context) { // Load history to receiver subghz_view_receiver_exit(subghz->subghz_receiver); - for(uint8_t i = 0; i < subghz_history_get_item(history); i++) { + for(uint16_t i = 0; i < subghz_history_get_item(history); i++) { furi_string_reset(item_name); furi_string_reset(item_time); subghz_history_get_text_item_menu(history, item_name, i); @@ -178,11 +190,10 @@ void subghz_scene_receiver_on_enter(void* context) { } // Check if hopping was enabled -#ifdef FURI_DEBUG - subghz_last_settings_log(subghz->last_settings); -#endif if(subghz->last_settings->enable_hopping) { subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateRunning); + } else { + subghz_txrx_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF); } subghz_scene_receiver_update_statusbar(subghz); @@ -216,8 +227,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - subghz_txrx_set_preset( - subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); + subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency); scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 8a8c21653..3477523f3 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -16,10 +16,6 @@ enum SubGhzSettingIndex { SubGhzSettingIndexRAWThresholdRSSI, }; -static inline const char* bool_to_char(bool value) { - return value ? "ON" : "OFF"; -} - #define RAW_THRESHOLD_RSSI_COUNT 11 const char* const raw_threshold_rssi_text[RAW_THRESHOLD_RSSI_COUNT] = { "-----", @@ -49,47 +45,51 @@ const float raw_threshold_rssi_value[RAW_THRESHOLD_RSSI_COUNT] = { -40.0f, }; -#define HOPPING_COUNT 2 -const char* const hopping_text[HOPPING_COUNT] = { - "OFF", - "ON", -}; -const uint32_t hopping_value[HOPPING_COUNT] = { +#define COMBO_BOX_COUNT 2 + +const uint32_t hopping_value[COMBO_BOX_COUNT] = { SubGhzHopperStateOFF, SubGhzHopperStateRunning, }; -#define SPEAKER_COUNT 2 -const char* const speaker_text[SPEAKER_COUNT] = { - "OFF", - "ON", -}; -const uint32_t speaker_value[SPEAKER_COUNT] = { +const uint32_t speaker_value[COMBO_BOX_COUNT] = { SubGhzSpeakerStateShutdown, SubGhzSpeakerStateEnable, }; -#define BIN_RAW_COUNT 2 -const char* const bin_raw_text[BIN_RAW_COUNT] = { - "OFF", - "ON", -}; -const uint32_t bin_raw_value[BIN_RAW_COUNT] = { + +const uint32_t bin_raw_value[COMBO_BOX_COUNT] = { SubGhzProtocolFlag_Decodable, SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW, }; -#define PROTOCOL_IGNORE_COUNT 2 -const char* const protocol_ignore_text[PROTOCOL_IGNORE_COUNT] = { + +const char* const combobox_text[COMBO_BOX_COUNT] = { "OFF", "ON", }; +static void + subghz_scene_receiver_config_set_ignore_filter(VariableItem* item, SubGhzProtocolFlag filter) { + SubGhz* subghz = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, combobox_text[index]); + + if(index == 0) { + CLEAR_BIT(subghz->ignore_filter, filter); + } else { + SET_BIT(subghz->ignore_filter, filter); + } + + subghz->last_settings->ignore_filter = subghz->ignore_filter; +} + uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) { furi_assert(context); SubGhz* subghz = context; SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); uint8_t index = 0; - for(uint8_t i = 0; i < subghz_setting_get_frequency_count(setting); i++) { + for(size_t i = 0; i < subghz_setting_get_frequency_count(setting); i++) { if(value == subghz_setting_get_frequency(setting, i)) { index = i; break; @@ -106,7 +106,7 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* uint8_t index = 0; SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); - for(uint8_t i = 0; i < subghz_setting_get_preset_count(setting); i++) { + for(size_t i = 0; i < subghz_setting_get_preset_count(setting); i++) { if(!strcmp(subghz_setting_get_preset_name(setting, i), preset_name)) { index = i; break; @@ -181,6 +181,7 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { preset.frequency, subghz_setting_get_preset_data(setting, index), subghz_setting_get_preset_data_size(setting, index)); + subghz->last_settings->preset_index = index; } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -190,7 +191,7 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) VariableItem* frequency_item = (VariableItem*)scene_manager_get_scene_state( subghz->scene_manager, SubGhzSceneReceiverConfig); - variable_item_set_current_value_text(item, hopping_text[(uint8_t)index]); + variable_item_set_current_value_text(item, combobox_text[(uint8_t)index]); if(index == SubGhzHopperStateOFF) { char text_buf[10] = {0}; @@ -220,9 +221,6 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) frequency_item, subghz_setting_get_frequency_default_index(setting)); } subghz->last_settings->enable_hopping = index != SubGhzHopperStateOFF; -#ifdef FURI_DEBUG - subghz_last_settings_log(subghz->last_settings); -#endif subghz_txrx_hopper_set_state(subghz->txrx, index); } @@ -230,17 +228,21 @@ static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, speaker_text[index]); + variable_item_set_current_value_text(item, combobox_text[index]); subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[index]); + + subghz->last_settings->sound = index; } static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, bin_raw_text[index]); + variable_item_set_current_value_text(item, combobox_text[index]); subghz->filter = bin_raw_value[index]; subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); + + subghz->last_settings->filter = subghz->filter; } static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* item) { @@ -249,21 +251,10 @@ static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* it variable_item_set_current_value_text(item, raw_threshold_rssi_text[index]); subghz_threshold_rssi_set(subghz->threshold_rssi, raw_threshold_rssi_value[index]); + + subghz->last_settings->rssi = raw_threshold_rssi_value[index]; } -static inline void - subghz_scene_receiver_config_set_ignore_filter(VariableItem* item, SubGhzProtocolFlag filter) { - SubGhz* subghz = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); - - variable_item_set_current_value_text(item, protocol_ignore_text[index]); - - if(index == 0) { - CLEAR_BIT(subghz->ignore_filter, filter); - } else { - SET_BIT(subghz->ignore_filter, filter); - } -} static inline bool subghz_scene_receiver_config_ignore_filter_get_index( SubGhzProtocolFlag filter, SubGhzProtocolFlag flag) { @@ -336,13 +327,13 @@ void subghz_scene_receiver_config_on_enter(void* context) { item = variable_item_list_add( subghz->variable_item_list, "Hopping:", - HOPPING_COUNT, + COMBO_BOX_COUNT, subghz_scene_receiver_config_set_hopping_running, 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, hopping_text[value_index]); + variable_item_set_current_value_text(item, combobox_text[value_index]); } if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != @@ -350,12 +341,13 @@ void subghz_scene_receiver_config_on_enter(void* context) { item = variable_item_list_add( subghz->variable_item_list, "Bin RAW:", - BIN_RAW_COUNT, + COMBO_BOX_COUNT, subghz_scene_receiver_config_set_bin_raw, subghz); - value_index = value_index_uint32(subghz->filter, bin_raw_value, BIN_RAW_COUNT); + + value_index = value_index_uint32(subghz->filter, bin_raw_value, COMBO_BOX_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, bin_raw_text[value_index]); + variable_item_set_current_value_text(item, combobox_text[value_index]); } if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != @@ -363,51 +355,51 @@ void subghz_scene_receiver_config_on_enter(void* context) { item = variable_item_list_add( subghz->variable_item_list, "Ignore Starline:", - PROTOCOL_IGNORE_COUNT, + COMBO_BOX_COUNT, subghz_scene_receiver_config_set_starline, subghz); value_index = subghz_scene_receiver_config_ignore_filter_get_index( subghz->ignore_filter, SubGhzProtocolFlag_StarLine); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, protocol_ignore_text[value_index]); + variable_item_set_current_value_text(item, combobox_text[value_index]); item = variable_item_list_add( subghz->variable_item_list, "Ignore Cars:", - PROTOCOL_IGNORE_COUNT, + COMBO_BOX_COUNT, subghz_scene_receiver_config_set_auto_alarms, subghz); value_index = subghz_scene_receiver_config_ignore_filter_get_index( subghz->ignore_filter, SubGhzProtocolFlag_AutoAlarms); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, protocol_ignore_text[value_index]); + variable_item_set_current_value_text(item, combobox_text[value_index]); item = variable_item_list_add( subghz->variable_item_list, "Ignore Magellan:", - PROTOCOL_IGNORE_COUNT, + COMBO_BOX_COUNT, subghz_scene_receiver_config_set_magellan, subghz); value_index = subghz_scene_receiver_config_ignore_filter_get_index( subghz->ignore_filter, SubGhzProtocolFlag_Magelan); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, protocol_ignore_text[value_index]); + variable_item_set_current_value_text(item, combobox_text[value_index]); } // Enable speaker, will send all incoming noises and signals to speaker so you can listen how your remote sounds like :) item = variable_item_list_add( subghz->variable_item_list, "Sound:", - SPEAKER_COUNT, + COMBO_BOX_COUNT, subghz_scene_receiver_config_set_speaker, subghz); value_index = value_index_uint32( - subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, SPEAKER_COUNT); + subghz_txrx_speaker_get_state(subghz->txrx), speaker_value, COMBO_BOX_COUNT); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, speaker_text[value_index]); + variable_item_set_current_value_text(item, combobox_text[value_index]); if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerSet) { @@ -454,6 +446,9 @@ void subghz_scene_receiver_config_on_exit(void* context) { SubGhz* subghz = context; variable_item_list_set_selected_item(subghz->variable_item_list, 0); variable_item_list_reset(subghz->variable_item_list); +#ifdef FURI_DEBUG + subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter); +#endif subghz_last_settings_save(subghz->last_settings); scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index fc1c1a8e9..4ca6c0f35 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -3,6 +3,8 @@ #include +#define TAG "SubGhzSceneReceiverInfo" + void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) { furi_assert(context); SubGhz* subghz = context; diff --git a/applications/main/subghz/scenes/subghz_scene_saved.c b/applications/main/subghz/scenes/subghz_scene_saved.c index 8b198e339..af4c35835 100644 --- a/applications/main/subghz/scenes/subghz_scene_saved.c +++ b/applications/main/subghz/scenes/subghz_scene_saved.c @@ -1,5 +1,7 @@ #include "../subghz_i.h" +#define TAG "SubGhzSceneSaved" + void subghz_scene_saved_on_enter(void* context) { SubGhz* subghz = context; diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 9a38cecd7..1a67aa560 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -4,6 +4,8 @@ #include +#define TAG "SubGhzSceneTransmitter" + void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) { furi_assert(context); SubGhz* subghz = context; diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 302976a28..46daef0af 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -1,9 +1,9 @@ /* Abandon hope, all ye who enter here. */ +#include #include #include #include "subghz_i.h" -#include #define TAG "SubGhzApp" @@ -73,7 +73,7 @@ static void subghz_load_custom_presets(SubGhzSetting* setting) { FlipperFormat* fff_temp = flipper_format_string_alloc(); - for(uint8_t i = 0; i < COUNT_OF(presets); i++) { + for(size_t i = 0; i < COUNT_OF(presets); i++) { flipper_format_insert_or_update_string_cstr(fff_temp, "Custom_preset_data", presets[i][1]); flipper_format_rewind(fff_temp); @@ -195,26 +195,45 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { // Load last used values for Read, Read RAW, etc. or default subghz->last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(subghz->last_settings, 0); + size_t preset_count = subghz_setting_get_preset_count(setting); + subghz_last_settings_load(subghz->last_settings, preset_count); +#ifdef FURI_DEBUG + subghz_last_settings_log(subghz->last_settings, subghz->last_settings->ignore_filter); +#endif if(!alloc_for_tx_only) { - subghz_setting_set_default_frequency(setting, subghz->last_settings->frequency); + subghz_txrx_set_preset_internal( + subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index); - subghz_txrx_set_preset(subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); subghz->history = subghz_history_alloc(); } subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); subghz->secure_data = malloc(sizeof(SecureData)); - - subghz->filter = SubGhzProtocolFlag_Decodable; - subghz->ignore_filter = 0x0; + if(!alloc_for_tx_only) { + subghz->ignore_filter = subghz->last_settings->ignore_filter; + subghz->filter = subghz->last_settings->filter; + } else { + subghz->filter = SubGhzProtocolFlag_Decodable; + subghz->ignore_filter = 0x0; + } subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); subghz_txrx_set_need_save_callback(subghz->txrx, subghz_save_to_file, subghz); + if(!alloc_for_tx_only) { + if(subghz->last_settings->rssi != 0) { + subghz_threshold_rssi_set(subghz->threshold_rssi, subghz->last_settings->rssi); + } else { + subghz->last_settings->rssi = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; + } + } //Init Error_str subghz->error_str = furi_string_alloc(); +#ifdef FURI_DEBUG + subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter); +#endif + return subghz; } diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index dbfe3d426..89ba3a461 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -4,30 +4,13 @@ #include "subghz/types.h" #include #include -#include -#include -#include #include #include #include -#include "views/receiver.h" - #include -#include -#include #define TAG "SubGhz" -void subghz_set_default_preset(SubGhz* subghz) { - furi_assert(subghz); - subghz_txrx_set_preset( - subghz->txrx, - "AM650", - subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)), - NULL, - 0); -} - void subghz_blink_start(SubGhz* subghz) { furi_assert(subghz); notification_message(subghz->notifications, &sequence_blink_stop); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 8d01c845d..3aeed112d 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -98,7 +98,6 @@ struct SubGhz { void* rpc_ctx; }; -void subghz_set_default_preset(SubGhz* subghz); void subghz_blink_start(SubGhz* subghz); void subghz_blink_stop(SubGhz* subghz); @@ -106,6 +105,7 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format); void subghz_dialog_message_freq_error(SubGhz* subghz, bool only_rx); bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog); +// Not used bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len); bool subghz_save_protocol_to_file( SubGhz* subghz, diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 84a3b18de..06ff8e73c 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -11,10 +11,9 @@ #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 #define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 #define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL 2 -#define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER -93.0f #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" -//#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" +#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" // AKA Modulation #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_FEEDBACK_LEVEL "FeedbackLevel" #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External" @@ -22,10 +21,10 @@ #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" #define SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE "Hopping" - -static inline const char* bool_to_char(bool value) { - return value ? "ON" : "OFF"; -} +#define SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER "IgnoreFilter" +#define SUBGHZ_LAST_SETTING_FIELD_FILTER "Filter" +#define SUBGHZ_LAST_SETTING_FIELD_SOUND "Sound" +#define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -38,7 +37,6 @@ void subghz_last_settings_free(SubGhzLastSettings* instance) { } void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count) { - UNUSED(preset_count); furi_assert(instance); Storage* storage = furi_record_open(RECORD_STORAGE); @@ -52,15 +50,18 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool temp_external_module_power_amp = false; bool temp_timestamp_file_names = false; bool temp_enable_hopping = false; - //int32_t temp_preset = 0; + uint32_t temp_ignore_filter = 0; + uint32_t temp_filter = 0; + uint32_t temp_sound = 0; + float temp_rssi = 0; + uint32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; bool frequency_analyzer_trigger_was_read = false; if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { - /* - flipper_format_read_int32( - fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1);*/ + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (uint32_t*)&temp_preset, 1); flipper_format_read_uint32( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1); frequency_analyzer_feedback_level_was_read = flipper_format_read_uint32( @@ -98,14 +99,27 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE, (bool*)&temp_enable_hopping, 1); + flipper_format_read_float( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, (float*)&temp_rssi, 1); + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_SOUND, (uint32_t*)&temp_sound, 1); + flipper_format_read_uint32( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER, + (uint32_t*)&temp_ignore_filter, + 1); + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FILTER, (uint32_t*)&temp_filter, 1); + } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } if(temp_frequency == 0 || !furi_hal_subghz_is_tx_allowed(temp_frequency)) { FURI_LOG_W(TAG, "Last used frequency not found or can't be used!"); + instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY; - instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; + instance->preset_index = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; instance->frequency_analyzer_feedback_level = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL; instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; @@ -113,7 +127,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->timestamp_file_names = false; instance->external_module_power_amp = false; instance->enable_hopping = false; - + instance->ignore_filter = 0x00; + // See bin_raw_value in applications/main/subghz/scenes/subghz_scene_receiver_config.c + instance->filter = SubGhzProtocolFlag_Decodable; + instance->sound = 0; + instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN; } else { instance->frequency = temp_frequency; instance->frequency_analyzer_feedback_level = @@ -125,10 +143,16 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count temp_frequency_analyzer_trigger : SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; - /*if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) { - FURI_LOG_W(TAG, "Last used preset no found");*/ - instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; - + if(temp_preset > (uint32_t)preset_count - 1) { + FURI_LOG_W( + TAG, + "Last used preset out of range. Preset to set: %ld, Max index: %ld. Set default", + temp_preset, + (uint32_t)preset_count - 1); + instance->preset_index = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; + } else { + instance->preset_index = temp_preset; + } instance->external_module_enabled = temp_external_module_enabled; instance->external_module_power_5v_disable = temp_external_module_power_5v_disable; @@ -138,8 +162,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count // External power amp CC1101 instance->external_module_power_amp = temp_external_module_power_amp; + instance->rssi = temp_rssi; instance->enable_hopping = temp_enable_hopping; - + instance->ignore_filter = temp_ignore_filter; + instance->filter = temp_filter; + instance->sound = temp_sound; // Set globally in furi hal furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp); @@ -147,9 +174,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->preset = temp_preset; }*/ } -#ifdef FURI_DEBUG - subghz_last_settings_log(instance); -#endif flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); @@ -158,9 +182,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool subghz_last_settings_save(SubGhzLastSettings* instance) { furi_assert(instance); -#ifdef FURI_DEBUG - subghz_last_settings_log(instance); -#endif bool saved = false; Storage* storage = furi_record_open(RECORD_STORAGE); @@ -178,12 +199,10 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { if(!flipper_format_write_header_cstr( file, SUBGHZ_LAST_SETTING_FILE_TYPE, SUBGHZ_LAST_SETTING_FILE_VERSION)) break; - - /* - if(!flipper_format_insert_or_update_int32( - file, SUBGHZ_LAST_SETTING_FIELD_PRESET, &instance->preset, 1)) { + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_PRESET, &instance->preset_index, 1)) { break; - }*/ + } if(!flipper_format_insert_or_update_uint32( file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) { break; @@ -234,6 +253,22 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE, &instance->enable_hopping, 1)) { break; } + if(!flipper_format_insert_or_update_float( + file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, &instance->rssi, 1)) { + break; + } + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_SOUND, &instance->sound, 1)) { + break; + } + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER, &instance->ignore_filter, 1)) { + break; + } + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_FILTER, &instance->filter, 1)) { + break; + } saved = true; } while(0); @@ -248,12 +283,27 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { return saved; } -void subghz_last_settings_log(SubGhzLastSettings* instance) { +const char* LOG_ON = "ON"; +const char* LOG_OFF = "OFF"; + +static inline const char* + subghz_last_settings_log_filter_get_index(uint32_t filter, uint32_t flag) { + return READ_BIT(filter, flag) > 0 ? LOG_ON : LOG_OFF; +} + +static inline const char* bool_to_char(bool value) { + return value ? LOG_ON : LOG_OFF; +} + +void subghz_last_settings_log(SubGhzLastSettings* instance, SubGhzProtocolFlag ignore_filter) { furi_assert(instance); + UNUSED(ignore_filter); FURI_LOG_I( TAG, - "Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s, Hopping: %s", + "Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s,\n" + "Hopping: %s,\nPreset: %ld, RSSI: %.2f, " + "Starline: %s, Cars: %s, Magellan: %s, BinRAW: %s, Sound: %ld", instance->frequency / 1000000 % 1000, instance->frequency / 10000 % 100, instance->frequency_analyzer_feedback_level, @@ -262,5 +312,15 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) { bool_to_char(instance->external_module_power_5v_disable), bool_to_char(instance->timestamp_file_names), bool_to_char(instance->external_module_power_amp), - bool_to_char(instance->enable_hopping)); + bool_to_char(instance->enable_hopping), + instance->preset_index, + (double)instance->rssi, + subghz_last_settings_log_filter_get_index( + instance->ignore_filter, SubGhzProtocolFlag_StarLine), + subghz_last_settings_log_filter_get_index( + instance->ignore_filter, SubGhzProtocolFlag_AutoAlarms), + subghz_last_settings_log_filter_get_index( + instance->ignore_filter, SubGhzProtocolFlag_Magelan), + subghz_last_settings_log_filter_get_index(instance->filter, SubGhzProtocolFlag_BinRAW), + instance->sound); } diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index d24d876d8..8021bb003 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -4,10 +4,13 @@ #include #include #include +#include + +#define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER (-93.0f) typedef struct { uint32_t frequency; - int32_t preset; + uint32_t preset_index; // AKA Modulation uint32_t frequency_analyzer_feedback_level; float frequency_analyzer_trigger; // TODO not using but saved so as not to change the version @@ -17,6 +20,10 @@ typedef struct { // saved so as not to change the version bool timestamp_file_names; bool enable_hopping; + uint32_t ignore_filter; + uint32_t filter; + uint32_t sound; + float rssi; } SubGhzLastSettings; SubGhzLastSettings* subghz_last_settings_alloc(void); @@ -27,4 +34,4 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool subghz_last_settings_save(SubGhzLastSettings* instance); -void subghz_last_settings_log(SubGhzLastSettings* instance); +void subghz_last_settings_log(SubGhzLastSettings* instance, SubGhzProtocolFlag ignore_filter); diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 5e4d068c3..8bff2244f 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -12,7 +12,7 @@ #define MENU_ITEMS 4u #define UNLOCK_CNT 3 -#define SUBGHZ_RAW_THRESHOLD_MIN -90.0f +// #define SUBGHZ_RAW_THRESHOLD_MIN (-90.0f) #define FLIP_TIMEOUT (500) @@ -322,15 +322,19 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) { (model->device_type == SubGhzRadioDeviceTypeInternal) ? &I_Scanning_123x52 : &I_Fishing_123x52); canvas_set_font(canvas, FontPrimary); - canvas_draw_str(canvas, 63, 46, "Scanning..."); + if(model->hopping_enabled) { + canvas_draw_str(canvas, 59, 46, "Hopper scan..."); + } else { + canvas_draw_str(canvas, 59, 46, "Fixed scan..."); + } //canvas_draw_line(canvas, 46, 51, 125, 51); canvas_set_font(canvas, FontSecondary); - if(model->hopping_enabled) { - const uint8_t vertical_offset = 7; - const uint8_t horizontal_offset = 3; - canvas_draw_icon(canvas, horizontal_offset, vertical_offset, &I_Dynamic_9x7); - } + // if(model->hopping_enabled) { + // const uint8_t vertical_offset = 0; + // const uint8_t horizontal_offset = 3; + // canvas_draw_icon(canvas, horizontal_offset, vertical_offset, &I_Dynamic_9x7); + // } } else { canvas_draw_icon( canvas, @@ -466,8 +470,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { return true; } + bool consumed = false; if(event->key == InputKeyBack && event->type == InputTypeShort) { subghz_receiver->callback(SubGhzCustomEventViewReceiverBack, subghz_receiver->context); + consumed = true; } else if( event->key == InputKeyUp && (event->type == InputTypeShort || event->type == InputTypeRepeat)) { @@ -479,6 +485,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { subghz_view_receiver_show_time_moment(context); }, true); + consumed = true; } else if( event->key == InputKeyDown && (event->type == InputTypeShort || event->type == InputTypeRepeat)) { @@ -492,8 +499,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { } }, true); + consumed = true; } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { subghz_receiver->callback(SubGhzCustomEventViewReceiverConfig, subghz_receiver->context); + consumed = true; } else if(event->key == InputKeyRight && event->type == InputTypeLong) { with_view_model( subghz_receiver->view, @@ -506,6 +515,7 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { } }, false); + consumed = true; } else if(event->key == InputKeyOk && event->type == InputTypeShort) { with_view_model( subghz_receiver->view, @@ -517,11 +527,13 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { } }, false); + consumed = true; } - subghz_view_receiver_update_offset(subghz_receiver); - - return true; + if(consumed) { + subghz_view_receiver_update_offset(subghz_receiver); + } + return consumed; } void subghz_view_receiver_enter(void* context) { @@ -551,6 +563,7 @@ void subghz_view_receiver_exit(void* context) { model->list_offset = 0; model->history_item = 0; model->nodraw = false; + model->hopping_enabled = false; }, false); furi_timer_stop(subghz_receiver->timer); @@ -587,6 +600,7 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() { model->bar_show = SubGhzViewReceiverBarShowDefault; model->nodraw = false; model->history = malloc(sizeof(SubGhzReceiverHistory)); + model->hopping_enabled = false; SubGhzReceiverMenuItemArray_init(model->history->data); }, true); @@ -630,7 +644,7 @@ View* subghz_view_receiver_get_view(SubGhzViewReceiver* subghz_receiver) { uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver) { furi_assert(subghz_receiver); - uint16_t idx = 0; + uint16_t idx; with_view_model( subghz_receiver->view, SubGhzViewReceiverModel * model, { idx = model->idx; }, false); return idx; diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.h b/applications/main/subghz/views/subghz_frequency_analyzer.h index f8c643222..d304cc795 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.h +++ b/applications/main/subghz/views/subghz_frequency_analyzer.h @@ -32,4 +32,4 @@ SubGHzFrequencyAnalyzerFeedbackLevel subghz_frequency_analyzer_feedback_level( SubGHzFrequencyAnalyzerFeedbackLevel level, bool update); -float subghz_frequency_analyzer_get_trigger_level(SubGhzFrequencyAnalyzer* instance); \ No newline at end of file +float subghz_frequency_analyzer_get_trigger_level(SubGhzFrequencyAnalyzer* instance);