2021-09-01 23:22:40 +00:00
|
|
|
#include "bt_settings.h"
|
|
|
|
#include <furi.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <file_worker.h>
|
2021-09-01 23:22:40 +00:00
|
|
|
|
2021-11-12 13:04:35 +00:00
|
|
|
#define TAG "BtSettings"
|
2021-09-01 23:22:40 +00:00
|
|
|
#define BT_SETTINGS_PATH "/int/bt.settings"
|
|
|
|
|
|
|
|
bool bt_settings_load(BtSettings* bt_settings) {
|
|
|
|
furi_assert(bt_settings);
|
|
|
|
bool file_loaded = false;
|
|
|
|
BtSettings settings = {};
|
|
|
|
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_I(TAG, "Loading settings from \"%s\"", BT_SETTINGS_PATH);
|
2021-09-01 23:22:40 +00:00
|
|
|
FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
if(file_worker_open(file_worker, BT_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
|
if(file_worker_read(file_worker, &settings, sizeof(settings))) {
|
|
|
|
file_loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file_worker_free(file_worker);
|
|
|
|
|
|
|
|
if(file_loaded) {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_I(TAG, "Settings load success");
|
2021-09-01 23:22:40 +00:00
|
|
|
if(settings.version != BT_SETTINGS_VERSION) {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_E(TAG, "Settings version mismatch");
|
2021-09-01 23:22:40 +00:00
|
|
|
} else {
|
|
|
|
osKernelLock();
|
|
|
|
*bt_settings = settings;
|
|
|
|
osKernelUnlock();
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_E(TAG, "Settings load failed");
|
2021-09-01 23:22:40 +00:00
|
|
|
}
|
|
|
|
return file_loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bt_settings_save(BtSettings* bt_settings) {
|
|
|
|
furi_assert(bt_settings);
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
FileWorker* file_worker = file_worker_alloc(true);
|
|
|
|
if(file_worker_open(file_worker, BT_SETTINGS_PATH, FSAM_WRITE, FSOM_OPEN_ALWAYS)) {
|
|
|
|
if(file_worker_write(file_worker, bt_settings, sizeof(BtSettings))) {
|
2021-11-12 13:04:35 +00:00
|
|
|
FURI_LOG_I(TAG, "Settings saved to \"%s\"", BT_SETTINGS_PATH);
|
2021-09-01 23:22:40 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file_worker_free(file_worker);
|
|
|
|
return result;
|
|
|
|
}
|