forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,207 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#include "quac_settings.h" | ||
|
||
#include <flipper_format/flipper_format.h> | ||
|
||
// Quac Settings File Info | ||
// TODO: Fix this path to use existing #defs for /ext, etc | ||
#define QUAC_SETTINGS_FILENAME "/ext/apps_data/quac/.quac.conf" | ||
#define QUAC_SETTINGS_FILE_TYPE "Quac Settings File" | ||
#define QUAC_SETTINGS_FILE_VERSION 1 | ||
|
||
// Quac Settings Defaults | ||
#define QUAC_SETTINGS_DEFAULT_RFID_DURATION 2500 | ||
#define QUAC_SETTINGS_DEFAULT_LAYOUT QUAC_APP_LANDSCAPE // QUAC_APP_PORTRAIT | ||
#define QUAC_SETTINGS_DEFAULT_SHOW_ICONS true | ||
#define QUAC_SETTINGS_DEFAULT_SHOW_HEADERS true | ||
|
||
void quac_set_default_settings(App* app) { | ||
app->settings.rfid_duration = QUAC_SETTINGS_DEFAULT_RFID_DURATION; | ||
app->settings.layout = QUAC_SETTINGS_DEFAULT_LAYOUT; | ||
app->settings.show_icons = QUAC_SETTINGS_DEFAULT_SHOW_ICONS; | ||
app->settings.show_headers = QUAC_SETTINGS_DEFAULT_SHOW_HEADERS; | ||
} | ||
|
||
void quac_load_settings(App* app) { | ||
FlipperFormat* fff_settings = flipper_format_file_alloc(app->storage); | ||
FuriString* temp_str; | ||
temp_str = furi_string_alloc(); | ||
uint32_t temp_data32 = 0; | ||
|
||
FURI_LOG_I(TAG, "SETTINGS: Reading settings file"); | ||
bool successful = false; | ||
do { | ||
if(!flipper_format_file_open_existing(fff_settings, QUAC_SETTINGS_FILENAME)) { | ||
FURI_LOG_I(TAG, "SETTINGS: File not found, loading defaults"); | ||
break; | ||
} | ||
|
||
if(!flipper_format_read_header(fff_settings, temp_str, &temp_data32)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Missing or incorrect header"); | ||
break; | ||
} | ||
|
||
if((!strcmp(furi_string_get_cstr(temp_str), QUAC_SETTINGS_FILE_TYPE)) && | ||
(temp_data32 == QUAC_SETTINGS_FILE_VERSION)) { | ||
} else { | ||
FURI_LOG_E(TAG, "SETTINGS: Type or version mismatch"); | ||
break; | ||
} | ||
|
||
// Now read actual values we care about | ||
if(!flipper_format_read_string(fff_settings, "Layout", temp_str)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Missing Layout"); | ||
break; | ||
} | ||
if(!strcmp(furi_string_get_cstr(temp_str), "Landscape")) { | ||
app->settings.layout = QUAC_APP_LANDSCAPE; | ||
} else if(!strcmp(furi_string_get_cstr(temp_str), "Portrait")) { | ||
app->settings.layout = QUAC_APP_PORTRAIT; | ||
} else { | ||
FURI_LOG_E(TAG, "SETTINGS: Invalid Layout"); | ||
break; | ||
} | ||
|
||
if(!flipper_format_read_uint32(fff_settings, "Show Icons", &temp_data32, 1)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Missing 'Show Icons'"); | ||
break; | ||
} | ||
app->settings.show_icons = (temp_data32 == 0) ? false : true; | ||
|
||
if(!flipper_format_read_uint32(fff_settings, "Show Headers", &temp_data32, 1)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Missing 'Show Headers'"); | ||
break; | ||
} | ||
app->settings.show_headers = (temp_data32 == 0) ? false : true; | ||
|
||
if(!flipper_format_read_uint32(fff_settings, "RFID Duration", &temp_data32, 1)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Missing 'RFID Duration'"); | ||
break; | ||
} | ||
app->settings.rfid_duration = temp_data32; | ||
|
||
successful = true; | ||
} while(false); | ||
|
||
if(!successful) { | ||
quac_set_default_settings(app); | ||
} | ||
|
||
furi_string_free(temp_str); | ||
flipper_format_free(fff_settings); | ||
} | ||
|
||
void quac_save_settings(App* app) { | ||
FlipperFormat* fff_settings = flipper_format_file_alloc(app->storage); | ||
uint32_t temp_data32; | ||
|
||
bool successful = false; | ||
do { | ||
if(!flipper_format_file_open_always(fff_settings, QUAC_SETTINGS_FILENAME)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Unable to open file for save!!"); | ||
break; | ||
} | ||
|
||
if(!flipper_format_write_header_cstr( | ||
fff_settings, QUAC_SETTINGS_FILE_TYPE, QUAC_SETTINGS_FILE_VERSION)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Failed writing file type and version"); | ||
break; | ||
} | ||
// layout, icons, headers, duration | ||
if(!flipper_format_write_string_cstr( | ||
fff_settings, | ||
"Layout", | ||
app->settings.layout == QUAC_APP_LANDSCAPE ? "Landscape" : "Portrait")) { | ||
FURI_LOG_E(TAG, "SETTINGS: Failed to write Layout"); | ||
break; | ||
} | ||
|
||
temp_data32 = app->settings.show_icons ? 1 : 0; | ||
if(!flipper_format_write_uint32(fff_settings, "Show Icons", &temp_data32, 1)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'Show Icons'"); | ||
break; | ||
} | ||
temp_data32 = app->settings.show_headers ? 1 : 0; | ||
if(!flipper_format_write_uint32(fff_settings, "Show Headers", &temp_data32, 1)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'Show Headers'"); | ||
break; | ||
} | ||
if(!flipper_format_write_uint32( | ||
fff_settings, "RFID Duration", &app->settings.rfid_duration, 1)) { | ||
FURI_LOG_E(TAG, "SETTINGS: Failed to write 'RFID Duration'"); | ||
break; | ||
} | ||
successful = true; | ||
} while(false); | ||
|
||
if(!successful) { | ||
FURI_LOG_E(TAG, "SETTINGS: Failed to save settings!!"); | ||
} | ||
|
||
flipper_format_file_close(fff_settings); | ||
flipper_format_free(fff_settings); | ||
} |
Oops, something went wrong.