Skip to content

Commit a13925e

Browse files
committed
Added Autosave feature
Co-authored-by: WillyJL <me@willyjl.dev>
1 parent 221efbc commit a13925e

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

applications/main/subghz/scenes/subghz_scene_receiver.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../subghz_i.h"
22
#include <dolphin/dolphin.h>
33
#include <lib/subghz/protocols/bin_raw.h>
4+
#include <toolbox/name_generator.h>
45

56
#define TAG "SubGhzSceneReceiver"
67

@@ -142,6 +143,32 @@ static void subghz_scene_add_to_history_callback(
142143
furi_string_get_cstr(item_time),
143144
subghz_history_get_type_protocol(history, idx));
144145

146+
if(decoder_base->protocol->flag & SubGhzProtocolFlag_Save &&
147+
subghz->last_settings->autosave) {
148+
// File name
149+
char file[SUBGHZ_MAX_LEN_NAME] = {0};
150+
const char* prefix = subghz->last_settings->protocol_file_names ?
151+
decoder_base->protocol->name :
152+
SUBGHZ_APP_FILENAME_PREFIX;
153+
DateTime time = subghz_history_get_datetime(history, idx);
154+
name_generator_make_detailed_datetime(file, sizeof(file), prefix, &time);
155+
// Directory to save
156+
FuriString* path = furi_string_alloc_set(SUBGHZ_APP_FOLDER "/autosave");
157+
char* dir = strdup(furi_string_get_cstr(path));
158+
// Find non-existent path
159+
const char* ext = SUBGHZ_APP_FILENAME_EXTENSION;
160+
Storage* storage = furi_record_open(RECORD_STORAGE);
161+
storage_get_next_filename(storage, dir, file, ext, path, sizeof(file));
162+
strlcpy(file, furi_string_get_cstr(path), sizeof(file));
163+
furi_string_printf(path, "%s/%s%s", dir, file, ext);
164+
furi_record_close(RECORD_STORAGE);
165+
free(dir);
166+
// Save
167+
subghz_save_protocol_to_file(
168+
subghz, subghz_history_get_raw_data(history, idx), furi_string_get_cstr(path));
169+
furi_string_free(path);
170+
}
171+
145172
subghz_scene_receiver_update_statusbar(subghz);
146173
if(subghz_history_get_text_space_left(subghz->history, NULL)) {
147174
notification_message(subghz->notifications, &sequence_error);

applications/main/subghz/scenes/subghz_scene_receiver_config.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum SubGhzSettingIndex {
88
SubGhzSettingIndexHopping,
99
SubGhzSettingIndexModulation,
1010
SubGhzSettingIndexBinRAW,
11+
SubGhzSettingIndexAutosave,
1112
SubGhzSettingIndexIgnoreReversRB2,
1213
SubGhzSettingIndexIgnoreAlarms,
1314
SubGhzSettingIndexIgnoreSensors,
@@ -340,6 +341,15 @@ static void subghz_scene_receiver_config_set_delete_old_signals(VariableItem* it
340341
subghz->last_settings->delete_old_signals = index == 1;
341342
}
342343

344+
static void subghz_scene_receiver_config_set_autosave(VariableItem* item) {
345+
SubGhz* subghz = variable_item_get_context(item);
346+
uint8_t index = variable_item_get_current_value_index(item);
347+
348+
variable_item_set_current_value_text(item, combobox_text[index]);
349+
350+
subghz->last_settings->autosave = index == 1;
351+
}
352+
343353
static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
344354
furi_assert(context);
345355
SubGhz* subghz = context;
@@ -371,6 +381,8 @@ static void subghz_scene_receiver_config_var_list_enter_callback(void* context,
371381
subghz->last_settings->filter = subghz->filter;
372382
subghz->last_settings->delete_old_signals = false;
373383
subghz->last_settings->tx_power = subghz->tx_power = 0;
384+
subghz->last_settings->autosave = false;
385+
374386
subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[default_index]);
375387

376388
subghz_txrx_hopper_set_state(subghz->txrx, hopping_value[default_index]);
@@ -452,6 +464,17 @@ void subghz_scene_receiver_config_on_enter(void* context) {
452464
value_index = value_index_uint32(subghz->filter, bin_raw_value, COMBO_BOX_COUNT);
453465
variable_item_set_current_value_index(item, value_index);
454466
variable_item_set_current_value_text(item, combobox_text[value_index]);
467+
468+
item = variable_item_list_add(
469+
subghz->variable_item_list,
470+
"Autosave",
471+
COMBO_BOX_COUNT,
472+
subghz_scene_receiver_config_set_autosave,
473+
subghz);
474+
475+
value_index = subghz->last_settings->autosave;
476+
variable_item_set_current_value_index(item, value_index);
477+
variable_item_set_current_value_text(item, combobox_text[value_index]);
455478
}
456479

457480
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=

applications/main/subghz/subghz_last_settings.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD "HoppingThreshold"
2121
#define SUBGHZ_LAST_SETTING_FIELD_LED_AND_POWER_AMP "LedAndPowerAmp"
2222
#define SUBGHZ_LAST_SETTING_FIELD_TX_POWER "TXPower"
23+
#define SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE "Autosave"
2324

2425
SubGhzLastSettings* subghz_last_settings_alloc(void) {
2526
SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings));
@@ -46,6 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
4647
instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN;
4748
instance->hopping_threshold = -90.0f;
4849
instance->leds_and_amp = true;
50+
instance->autosave = false;
4951

5052
Storage* storage = furi_record_open(RECORD_STORAGE);
5153
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
@@ -140,6 +142,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count
140142
1)) {
141143
flipper_format_rewind(fff_data_file);
142144
}
145+
if(!flipper_format_read_bool(
146+
fff_data_file,
147+
SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE,
148+
&instance->autosave,
149+
1)) {
150+
flipper_format_rewind(fff_data_file);
151+
}
143152

144153
} while(0);
145154
} else {
@@ -244,7 +253,10 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) {
244253
file, SUBGHZ_LAST_SETTING_FIELD_LED_AND_POWER_AMP, &instance->leds_and_amp, 1)) {
245254
break;
246255
}
247-
256+
if(!flipper_format_write_bool(
257+
file, SUBGHZ_LAST_SETTING_FIELD_AUTOSAVE, &instance->autosave, 1)) {
258+
break;
259+
}
248260
saved = true;
249261
} while(0);
250262

applications/main/subghz/subghz_last_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef struct {
2727
float hopping_threshold;
2828
bool leds_and_amp;
2929
uint8_t tx_power;
30+
bool autosave;
3031
} SubGhzLastSettings;
3132

3233
SubGhzLastSettings* subghz_last_settings_alloc(void);

0 commit comments

Comments
 (0)