mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-08 23:08:10 -07:00
Xfw app frequency editor actually save to file
This commit is contained in:
@@ -72,7 +72,7 @@ void xtreme_app_scene_protocols_frequencies_on_enter(void* context) {
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||
}
|
||||
|
||||
void remove_frequency(FrequencyList_t list, uint8_t index) {
|
||||
void remove_frequency(XtremeApp* app, FrequencyList_t list, uint8_t index) {
|
||||
if(!FrequencyList_size(list)) return;
|
||||
uint32_t value = *FrequencyList_get(list, index);
|
||||
FrequencyList_it_t it;
|
||||
@@ -84,6 +84,7 @@ void remove_frequency(FrequencyList_t list, uint8_t index) {
|
||||
FrequencyList_next(it);
|
||||
}
|
||||
}
|
||||
app->save_subghz_frequencies = true;
|
||||
}
|
||||
|
||||
bool xtreme_app_scene_protocols_frequencies_on_event(void* context, SceneManagerEvent event) {
|
||||
@@ -93,17 +94,16 @@ bool xtreme_app_scene_protocols_frequencies_on_event(void* context, SceneManager
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(app->scene_manager, XtremeAppSceneProtocolsFrequencies, event.event);
|
||||
consumed = true;
|
||||
bool redraw = false;
|
||||
bool redraw = true;
|
||||
switch(event.event) {
|
||||
case VarItemListIndexDeleteStatic:
|
||||
remove_frequency(app->subghz_static_frequencies, app->subghz_static_index);
|
||||
redraw = true;
|
||||
remove_frequency(app, app->subghz_static_frequencies, app->subghz_static_index);
|
||||
break;
|
||||
case VarItemListIndexDeleteHopper:
|
||||
remove_frequency(app->subghz_hopper_frequencies, app->subghz_hopper_index);
|
||||
redraw = true;
|
||||
remove_frequency(app, app->subghz_hopper_frequencies, app->subghz_hopper_index);
|
||||
break;
|
||||
default:
|
||||
redraw = false;
|
||||
break;
|
||||
}
|
||||
if(redraw) {
|
||||
|
||||
@@ -23,6 +23,34 @@ static bool xtreme_app_back_event_callback(void* context) {
|
||||
}
|
||||
|
||||
if(app->save_subghz_frequencies) {
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
do {
|
||||
FrequencyList_it_t it;
|
||||
if(!flipper_format_file_open_always(file, EXT_PATH("subghz/assets/setting_user"))) break;
|
||||
|
||||
if(!flipper_format_write_header_cstr(file, SUBGHZ_SETTING_FILE_TYPE, SUBGHZ_SETTING_FILE_VERSION)) break;
|
||||
|
||||
while(flipper_format_delete_key(file, "Add_standard_frequencies"));
|
||||
flipper_format_write_bool(file, "Add_standard_frequencies", &app->subghz_use_defaults, 1);
|
||||
|
||||
if(!flipper_format_rewind(file)) break;
|
||||
while(flipper_format_delete_key(file, "Default_frequency"));
|
||||
flipper_format_write_uint32(file, "Default_frequency", &app->subghz_default_frequency, 1);
|
||||
|
||||
if(!flipper_format_rewind(file)) break;
|
||||
while(flipper_format_delete_key(file, "Frequency"));
|
||||
FrequencyList_it(it, app->subghz_static_frequencies);
|
||||
for(uint i = 0; i < FrequencyList_size(app->subghz_static_frequencies); i++) {
|
||||
flipper_format_write_uint32(file, "Frequency", FrequencyList_get(app->subghz_static_frequencies, i), 1);
|
||||
}
|
||||
|
||||
if(!flipper_format_rewind(file)) break;
|
||||
while(flipper_format_delete_key(file, "Hopper_frequency"));
|
||||
for(uint i = 0; i < FrequencyList_size(app->subghz_hopper_frequencies); i++) {
|
||||
flipper_format_write_uint32(file, "Hopper_frequency", FrequencyList_get(app->subghz_hopper_frequencies, i), 1);
|
||||
}
|
||||
} while(false);
|
||||
flipper_format_free(file);
|
||||
}
|
||||
|
||||
if(app->save_level) {
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
#define TAG "SubGhzSetting"
|
||||
|
||||
#define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File"
|
||||
#define SUBGHZ_SETTING_FILE_VERSION 1
|
||||
|
||||
#define FREQUENCY_FLAG_DEFAULT (1 << 31)
|
||||
#define FREQUENCY_MASK (0xFFFFFFFF ^ FREQUENCY_FLAG_DEFAULT)
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File"
|
||||
#define SUBGHZ_SETTING_FILE_VERSION 1
|
||||
|
||||
#define SUBGHZ_SETTING_DEFAULT_PRESET_COUNT 4
|
||||
|
||||
LIST_DEF(FrequencyList, uint32_t)
|
||||
|
||||
Reference in New Issue
Block a user