mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-04 19:47:36 +03:00
finalization of saving last settings
- Check loading of critical values in subghz_last_settings_log - Change comparison of float type to safe - Refactor
This commit is contained in:
parent
8c44dfb6af
commit
5bbee02704
@ -345,7 +345,21 @@ void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance);
|
||||
|
||||
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw
|
||||
|
||||
/**
|
||||
* @brief Set current preset AM650 without additional params
|
||||
*
|
||||
* @param instance - instance Pointer to a SubGhzTxRx
|
||||
* @param frequency - frequency of preset, if pass 0 then taking default frequency 433.92MHz
|
||||
*/
|
||||
void subghz_txrx_set_default_preset(SubGhzTxRx* instance, uint32_t frequency);
|
||||
|
||||
/**
|
||||
* @brief Set current preset by index
|
||||
*
|
||||
* @param instance - instance Pointer to a SubGhzTxRx
|
||||
* @param frequency - frequency of new preset
|
||||
* @param index - index of preset taken from SubGhzSetting
|
||||
* @return const char* - name of preset
|
||||
*/
|
||||
const char*
|
||||
subghz_txrx_set_preset_internal(SubGhzTxRx* instance, uint32_t frequency, uint8_t index);
|
||||
|
@ -61,7 +61,7 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e
|
||||
if(frequency > 0) {
|
||||
subghz->last_settings->frequency = frequency;
|
||||
#ifdef FURI_DEBUG
|
||||
subghz_last_settings_log(subghz->last_settings, subghz->ignore_filter);
|
||||
subghz_last_settings_log(subghz->last_settings);
|
||||
#endif
|
||||
subghz_last_settings_save(subghz->last_settings);
|
||||
}
|
||||
|
@ -146,9 +146,6 @@ void subghz_scene_receiver_on_enter(void* context) {
|
||||
FuriString* item_time = furi_string_alloc();
|
||||
|
||||
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) {
|
||||
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(
|
||||
@ -156,6 +153,10 @@ void subghz_scene_receiver_on_enter(void* context) {
|
||||
subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown :
|
||||
SubGhzSpeakerStateEnable);
|
||||
|
||||
subghz->filter = subghz->last_settings->filter;
|
||||
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
|
||||
subghz->ignore_filter = subghz->last_settings->ignore_filter;
|
||||
|
||||
subghz_history_reset(history);
|
||||
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart);
|
||||
subghz->idx_menu_chosen = 0;
|
||||
|
@ -447,7 +447,7 @@ void subghz_scene_receiver_config_on_exit(void* 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);
|
||||
subghz_last_settings_log(subghz->last_settings);
|
||||
#endif
|
||||
subghz_last_settings_save(subghz->last_settings);
|
||||
scene_manager_set_scene_state(
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <furi/core/log.h>
|
||||
#include <subghz/types.h>
|
||||
#include <lib/toolbox/path.h>
|
||||
#include <float_tools.h>
|
||||
#include "subghz_i.h"
|
||||
|
||||
#define TAG "SubGhzApp"
|
||||
@ -198,7 +199,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
||||
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);
|
||||
subghz_last_settings_log(subghz->last_settings);
|
||||
#endif
|
||||
if(!alloc_for_tx_only) {
|
||||
subghz_txrx_set_preset_internal(
|
||||
@ -210,6 +211,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
||||
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
|
||||
|
||||
subghz->secure_data = malloc(sizeof(SecureData));
|
||||
|
||||
if(!alloc_for_tx_only) {
|
||||
subghz->ignore_filter = subghz->last_settings->ignore_filter;
|
||||
subghz->filter = subghz->last_settings->filter;
|
||||
@ -221,7 +223,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
||||
subghz_txrx_set_need_save_callback(subghz->txrx, subghz_save_to_file, subghz);
|
||||
|
||||
if(!alloc_for_tx_only) {
|
||||
if(subghz->last_settings->rssi != 0) {
|
||||
if(!float_is_equal(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;
|
||||
@ -230,10 +232,6 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
|
||||
//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;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ void subghz_dialog_message_freq_error(SubGhz* subghz, bool only_rx) {
|
||||
DialogsApp* dialogs = subghz->dialogs;
|
||||
DialogMessage* message = dialog_message_alloc();
|
||||
const char* header_text = "Frequency not supported";
|
||||
const char* message_text = "Frequency\nis outside of\nsuported range.";
|
||||
const char* message_text = "Frequency\nis outside of\nsupported range.";
|
||||
|
||||
if(only_rx) {
|
||||
header_text = "Transmission is blocked";
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#define SUBGHZ_MAX_LEN_NAME 64
|
||||
#define SUBGHZ_EXT_PRESET_NAME true
|
||||
#define SUBGHZ_RAW_THRESHOLD_MIN (-90.0f)
|
||||
|
||||
typedef struct {
|
||||
uint8_t fix[4];
|
||||
|
@ -55,12 +55,17 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
||||
uint32_t temp_sound = 0;
|
||||
float temp_rssi = 0;
|
||||
uint32_t temp_preset = 0;
|
||||
|
||||
bool preset_was_read = false;
|
||||
bool rssi_was_read = false;
|
||||
bool filter_was_read = false;
|
||||
bool ignore_filter_was_read = false;
|
||||
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_uint32(
|
||||
preset_was_read = 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);
|
||||
@ -99,16 +104,16 @@ 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(
|
||||
rssi_was_read = 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(
|
||||
ignore_filter_was_read = flipper_format_read_uint32(
|
||||
fff_data_file,
|
||||
SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER,
|
||||
(uint32_t*)&temp_ignore_filter,
|
||||
1);
|
||||
flipper_format_read_uint32(
|
||||
filter_was_read = flipper_format_read_uint32(
|
||||
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FILTER, (uint32_t*)&temp_filter, 1);
|
||||
|
||||
} else {
|
||||
@ -143,7 +148,10 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
|
||||
temp_frequency_analyzer_trigger :
|
||||
SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER;
|
||||
|
||||
if(temp_preset > (uint32_t)preset_count - 1) {
|
||||
if(!preset_was_read) {
|
||||
FURI_LOG_W(TAG, "Preset was not read. Set default");
|
||||
instance->preset_index = SUBGHZ_LAST_SETTING_DEFAULT_PRESET;
|
||||
} else 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",
|
||||
@ -162,17 +170,13 @@ 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->rssi = rssi_was_read ? temp_rssi : SUBGHZ_RAW_THRESHOLD_MIN;
|
||||
instance->enable_hopping = temp_enable_hopping;
|
||||
instance->ignore_filter = temp_ignore_filter;
|
||||
instance->filter = temp_filter;
|
||||
instance->ignore_filter = ignore_filter_was_read ? temp_ignore_filter : 0x00;
|
||||
instance->filter = filter_was_read ? temp_filter : SubGhzProtocolFlag_Decodable;
|
||||
instance->sound = temp_sound;
|
||||
// Set globally in furi hal
|
||||
furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp);
|
||||
|
||||
/*/} else {
|
||||
instance->preset = temp_preset;
|
||||
}*/
|
||||
}
|
||||
|
||||
flipper_format_file_close(fff_data_file);
|
||||
@ -295,9 +299,8 @@ 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) {
|
||||
void subghz_last_settings_log(SubGhzLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
UNUSED(ignore_filter);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
|
@ -34,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, SubGhzProtocolFlag ignore_filter);
|
||||
void subghz_last_settings_log(SubGhzLastSettings* instance);
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include "../helpers/subghz_types.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
#define SUBGHZ_RAW_THRESHOLD_MIN -90.0f
|
||||
|
||||
typedef struct SubGhzReadRAW SubGhzReadRAW;
|
||||
|
||||
typedef void (*SubGhzReadRAWCallback)(SubGhzCustomEvent event, void* context);
|
||||
|
Loading…
Reference in New Issue
Block a user