2021-09-02 02:22:40 +03:00
|
|
|
#include "bt_settings.h"
|
2024-08-04 12:54:02 +03:00
|
|
|
#include "bt_settings_filename.h"
|
2022-04-21 18:36:53 +03:00
|
|
|
|
2021-09-02 02:22:40 +03:00
|
|
|
#include <furi.h>
|
2022-07-26 15:21:51 +03:00
|
|
|
#include <storage/storage.h>
|
2024-08-04 12:54:02 +03:00
|
|
|
#include <toolbox/saved_struct.h>
|
|
|
|
|
|
|
|
#define TAG "BtSettings"
|
2021-09-02 02:22:40 +03:00
|
|
|
|
2024-07-15 07:38:49 +03:00
|
|
|
#define BT_SETTINGS_PATH INT_PATH(BT_SETTINGS_FILE_NAME)
|
2022-04-21 18:36:53 +03:00
|
|
|
#define BT_SETTINGS_VERSION (0)
|
2024-07-15 07:38:49 +03:00
|
|
|
#define BT_SETTINGS_MAGIC (0x19)
|
2021-09-02 02:22:40 +03:00
|
|
|
|
2024-08-04 12:54:02 +03:00
|
|
|
void bt_settings_load(BtSettings* bt_settings) {
|
2021-09-02 02:22:40 +03:00
|
|
|
furi_assert(bt_settings);
|
|
|
|
|
2024-08-04 12:54:02 +03:00
|
|
|
const bool success = saved_struct_load(
|
2022-04-21 18:36:53 +03:00
|
|
|
BT_SETTINGS_PATH, bt_settings, sizeof(BtSettings), BT_SETTINGS_MAGIC, BT_SETTINGS_VERSION);
|
2024-08-04 12:54:02 +03:00
|
|
|
|
|
|
|
if(!success) {
|
|
|
|
FURI_LOG_W(TAG, "Failed to load settings, using defaults");
|
|
|
|
memset(bt_settings, 0, sizeof(BtSettings));
|
|
|
|
bt_settings_save(bt_settings);
|
|
|
|
}
|
2021-09-02 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
2024-08-04 12:54:02 +03:00
|
|
|
void bt_settings_save(const BtSettings* bt_settings) {
|
2021-09-02 02:22:40 +03:00
|
|
|
furi_assert(bt_settings);
|
|
|
|
|
2024-08-04 12:54:02 +03:00
|
|
|
const bool success = saved_struct_save(
|
2022-04-21 18:36:53 +03:00
|
|
|
BT_SETTINGS_PATH, bt_settings, sizeof(BtSettings), BT_SETTINGS_MAGIC, BT_SETTINGS_VERSION);
|
2024-08-04 12:54:02 +03:00
|
|
|
|
|
|
|
if(!success) {
|
|
|
|
FURI_LOG_E(TAG, "Failed to save settings");
|
|
|
|
}
|
2021-09-02 02:22:40 +03:00
|
|
|
}
|