do not save detect raw on/off settings

This commit is contained in:
MX
2022-10-02 06:38:34 +03:00
parent cea14ae9c5
commit 85eb740559
6 changed files with 37 additions and 40 deletions

View File

@@ -341,5 +341,5 @@ void subghz_scene_read_raw_on_exit(void* context) {
notification_message(subghz->notifications, &sequence_reset_rgb);
//filter restoration
subghz_last_settings_set_detect_raw_values(subghz);
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
}

View File

@@ -29,6 +29,11 @@ const char* const detect_raw_text[DETECT_RAW_COUNT] = {
"ON",
};
const SubGhzProtocolFlag detect_raw_value[DETECT_RAW_COUNT] = {
SubGhzProtocolFlag_Decodable,
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW,
};
#define RSSI_THRESHOLD_COUNT 7
const char* const rssi_threshold_text[RSSI_THRESHOLD_COUNT] = {
"-72db",
@@ -100,6 +105,20 @@ uint8_t subghz_scene_receiver_config_hopper_value_index(
}
}
uint8_t subghz_scene_receiver_config_detect_raw_value_index(
const SubGhzProtocolFlag value,
const SubGhzProtocolFlag values[],
uint8_t values_count) {
uint8_t index = 0;
for(uint8_t i = 0; i < values_count; i++) {
if(value == values[i]) {
index = i;
break;
}
}
return index;
}
uint8_t subghz_scene_receiver_config_rssi_threshold_value_index(
const int value,
const int values[],
@@ -167,9 +186,12 @@ static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) {
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, detect_raw_text[index]);
subghz->last_settings->detect_raw = index;
subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]);
subghz_last_settings_set_detect_raw_values(subghz);
subghz_protocol_decoder_raw_set_auto_mode(
subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME),
(index == 1));
}
static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) {
@@ -282,7 +304,10 @@ void subghz_scene_receiver_config_on_enter(void* context) {
DETECT_RAW_COUNT,
subghz_scene_receiver_config_set_detect_raw,
subghz);
value_index = subghz->last_settings->detect_raw;
value_index = subghz_scene_receiver_config_detect_raw_value_index(
subghz_receiver_get_filter(subghz->txrx->receiver),
detect_raw_value,
DETECT_RAW_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, detect_raw_text[value_index]);

View File

@@ -21,7 +21,11 @@ void subghz_scene_start_on_enter(void* context) {
if(subghz->state_notifications == SubGhzNotificationStateStarting) {
subghz->state_notifications = SubGhzNotificationStateIDLE;
}
subghz_last_settings_set_detect_raw_values(subghz);
subghz_protocol_decoder_raw_set_auto_mode(
subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME),
false);
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
submenu_add_item(
subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz);

View File

@@ -183,10 +183,9 @@ SubGhz* subghz_alloc() {
#if FURI_DEBUG
FURI_LOG_D(
TAG,
"last frequency: %d, preset: %d, detect_raw: %d",
"last frequency: %d, preset: %d",
subghz->last_settings->frequency,
subghz->last_settings->preset,
subghz->last_settings->detect_raw);
subghz->last_settings->preset);
#endif
subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency);
@@ -216,7 +215,7 @@ SubGhz* subghz_alloc() {
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s"));
subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment);
subghz_last_settings_set_detect_raw_values(subghz);
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
subghz_worker_set_overrun_callback(
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);

View File

@@ -1,6 +1,5 @@
#include "subghz_last_settings.h"
#include "subghz_i.h"
#include <lib/subghz/protocols/raw.h>
#define TAG "SubGhzLastSettings"
@@ -11,11 +10,9 @@
// "AM270", "AM650", "FM238", "FM476",
#define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1
#define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000
#define SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW 0
#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency"
#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset"
#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw"
SubGhzLastSettings* subghz_last_settings_alloc(void) {
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
@@ -38,7 +35,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
uint32_t temp_frequency = 0;
int32_t temp_preset = 0;
uint32_t temp_read_raw = 0;
if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH &&
flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) {
@@ -46,8 +42,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1);
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1);
flipper_format_read_uint32(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, (uint32_t*)&temp_read_raw, 1);
} else {
FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH);
}
@@ -56,10 +50,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
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->detect_raw = SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW;
} else {
instance->frequency = temp_frequency;
instance->detect_raw = temp_read_raw;
if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) {
FURI_LOG_W(TAG, "Last used preset no found");
@@ -105,10 +97,6 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) {
break;
}
if(!flipper_format_insert_or_update_uint32(
file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, &instance->detect_raw, 1)) {
break;
}
saved = true;
} while(0);
@@ -122,15 +110,3 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
return saved;
}
void subghz_last_settings_set_detect_raw_values(void* context) {
furi_assert(context);
SubGhz* instance = (SubGhz*)context;
bool is_detect_raw = instance->last_settings->detect_raw > 0;
subghz_receiver_set_filter(
instance->txrx->receiver, is_detect_raw ? DETECT_RAW_TRUE : DETECT_RAW_FALSE);
subghz_protocol_decoder_raw_set_auto_mode(
subghz_receiver_search_decoder_base_by_name(
instance->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME),
is_detect_raw);
}

View File

@@ -4,14 +4,9 @@
#include <stdint.h>
#include <stdbool.h>
#include <storage/storage.h>
#include <lib/subghz/protocols/base.h>
#define DETECT_RAW_FALSE SubGhzProtocolFlag_Decodable
#define DETECT_RAW_TRUE SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW
typedef struct {
uint32_t frequency;
uint32_t detect_raw;
int32_t preset;
} SubGhzLastSettings;
@@ -22,5 +17,3 @@ 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_set_detect_raw_values(void* context);