SubGhz Autosave option (#331)

This commit is contained in:
Willy-JL
2024-01-27 21:09:01 +00:00
parent 9db00f3743
commit 0cc8e190ef
4 changed files with 65 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
#include "../subghz_i.h"
#include <dolphin/dolphin.h>
#include <lib/subghz/protocols/bin_raw.h>
#include <toolbox/name_generator.h>
#define TAG "SubGhzSceneReceiver"
@@ -196,6 +197,34 @@ static void subghz_scene_add_to_history_callback(
subghz_history_get_type_protocol(history, idx),
subghz_history_get_repeats(history, idx));
if(decoder_base->protocol->flag & SubGhzProtocolFlag_Save &&
subghz->last_settings->autosave) {
// File name
char file[SUBGHZ_MAX_LEN_NAME] = {0};
const char* suf = subghz->last_settings->protocol_file_names ?
decoder_base->protocol->name :
SUBGHZ_APP_FILENAME_PREFIX;
FuriHalRtcDateTime time = subghz_history_get_datetime(history, idx);
name_generator_make_detailed_datetime(file, sizeof(file), suf, &time, true);
// Dir name
FuriString* path = furi_string_alloc_set(SUBGHZ_APP_FOLDER "/Autosave");
char* dir = strdup(furi_string_get_cstr(path));
// Find non-existent path
const char* ext = SUBGHZ_APP_FILENAME_EXTENSION;
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_get_next_filename(storage, dir, file, ext, path, sizeof(file));
strlcpy(file, furi_string_get_cstr(path), sizeof(file));
furi_string_printf(path, "%s/%s%s", dir, file, ext);
furi_record_close(RECORD_STORAGE);
free(dir);
// Save
subghz_save_protocol_to_file(
subghz,
subghz_history_get_raw_data(history, idx),
furi_string_get_cstr(path));
furi_string_free(path);
}
subghz_scene_receiver_update_statusbar(subghz);
if(!subghz->last_settings->delete_old_signals &&
subghz_history_full(subghz->history)) {

View File

@@ -13,6 +13,7 @@ enum SubGhzSettingIndex {
SubGhzSettingIndexRepeater,
SubGhzSettingIndexRemoveDuplicates,
SubGhzSettingIndexDeleteOldSignals,
SubGhzSettingIndexAutosave,
SubGhzSettingIndexIgnoreStarline,
SubGhzSettingIndexIgnoreCars,
SubGhzSettingIndexIgnoreMagellan,
@@ -355,6 +356,15 @@ static void subghz_scene_receiver_config_set_delete_old_signals(VariableItem* it
subghz->last_settings->delete_old_signals = index == 1;
}
static void subghz_scene_receiver_config_set_autosave(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, combobox_text[index]);
subghz->last_settings->autosave = index == 1;
}
static inline bool subghz_scene_receiver_config_ignore_filter_get_index(
SubGhzProtocolFilter filter,
SubGhzProtocolFilter flag) {
@@ -427,6 +437,7 @@ static void subghz_scene_receiver_config_var_list_enter_callback(void* context,
subghz->last_settings->repeater_state = SubGhzRepeaterStateOff;
subghz->repeater = SubGhzRepeaterStateOff;
subghz->last_settings->delete_old_signals = false;
subghz->last_settings->autosave = false;
subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[default_index]);
subghz->last_settings->enable_sound = false;
@@ -546,6 +557,17 @@ void subghz_scene_receiver_config_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, combobox_text[value_index]);
item = variable_item_list_add(
subghz->variable_item_list,
"Autosave",
COMBO_BOX_COUNT,
subghz_scene_receiver_config_set_autosave,
subghz);
value_index = subghz->last_settings->autosave;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, combobox_text[value_index]);
item = variable_item_list_add(
subghz->variable_item_list,
"Ignore Starline",

View File

@@ -24,6 +24,7 @@
#define SUBGHZ_LAST_SETTING_FIELD_REPEATER "Repeater"
#define SUBGHZ_LAST_SETTING_FIELD_ENABLE_SOUND "Sound"
#define SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD "DelOldSignals"
#define SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE "Autosave"
SubGhzLastSettings* subghz_last_settings_alloc(void) {
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
@@ -53,6 +54,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
uint32_t temp_repeater_state;
bool temp_remove_duplicates = false;
bool temp_delete_old_sig = false;
bool temp_autosave = false;
uint32_t temp_ignore_filter = 0;
uint32_t temp_filter = 0;
float temp_rssi = 0;
@@ -133,6 +135,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_ENABLE_SOUND, (bool*)&temp_enable_sound, 1);
flipper_format_read_bool(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD, (bool*)&temp_delete_old_sig, 1);
flipper_format_read_bool(
fff_data_file, SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE, (bool*)&temp_autosave, 1);
} else {
FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH);
@@ -154,6 +158,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->remove_duplicates = false;
instance->repeater_state = 0;
instance->enable_sound = 0;
instance->autosave = false;
instance->ignore_filter = 0x00;
// See bin_raw_value in applications/main/subghz/scenes/subghz_scene_receiver_config.c
instance->filter = SubGhzProtocolFlag_Decodable;
@@ -190,6 +195,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
instance->delete_old_signals = temp_delete_old_sig;
instance->autosave = temp_autosave;
// External power amp CC1101
instance->external_module_power_amp = temp_external_module_power_amp;
@@ -332,6 +339,10 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
file, SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD, &instance->delete_old_signals, 1)) {
break;
}
if(!flipper_format_insert_or_update_bool(
file, SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE, &instance->autosave, 1)) {
break;
}
saved = true;
} while(0);
@@ -365,7 +376,7 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) {
TAG,
"Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s,\n"
"GPSBaudrate: %ld, Hopping: %s,\nPreset: %ld, RSSI: %.2f, "
"BinRAW: %s, Repeater: %lu, Duplicates: %s, Starline: %s, Cars: %s, Magellan: %s, NiceFloR-S: %s, Weather: %s, TPMS: %s, Sound: %s",
"BinRAW: %s, Repeater: %lu, Duplicates: %s, Autosave: %s, Starline: %s, Cars: %s, Magellan: %s, NiceFloR-S: %s, Weather: %s, TPMS: %s, Sound: %s",
instance->frequency / 1000000 % 1000,
instance->frequency / 10000 % 100,
instance->frequency_analyzer_feedback_level,
@@ -381,6 +392,7 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) {
subghz_last_settings_log_filter_get_index(instance->filter, SubGhzProtocolFlag_BinRAW),
instance->repeater_state,
bool_to_char(instance->remove_duplicates),
bool_to_char(instance->autosave),
subghz_last_settings_log_filter_get_index(
instance->ignore_filter, SubGhzProtocolFilter_StarLine),
subghz_last_settings_log_filter_get_index(

View File

@@ -35,6 +35,7 @@ typedef struct {
uint32_t filter;
float rssi;
bool delete_old_signals;
bool autosave;
} SubGhzLastSettings;
SubGhzLastSettings* subghz_last_settings_alloc(void);