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)) {