Added new watch settings in the persistency layer, added flash read and write functions, work still in progress
This commit is contained in:
parent
185b7a7efa
commit
7e11913535
@ -1,13 +1,101 @@
|
|||||||
#include "watch_settings.h"
|
#include "watch_settings.h"
|
||||||
|
#include "wm_internal_flash.h"
|
||||||
|
#include "app_log.h"
|
||||||
|
#include "translation.h"
|
||||||
|
|
||||||
/* WatchSetting object with default values */
|
/**
|
||||||
static WatchSettings_t watchSettings =
|
* @brief WatchSetting object with default values.
|
||||||
|
*
|
||||||
|
* @note Used to restore factory settings for example or as default values when first start.
|
||||||
|
*/
|
||||||
|
static const WatchSettings_t defaultWatchSettings =
|
||||||
{
|
{
|
||||||
.timeAndDate = {.hour_format = 0, .date_format = 0, .automatic_time_and_date = 0},
|
.timeAndDate = {
|
||||||
.display = {.brightness = 255, .sleep_delay = 0,},
|
.time_and_date_hour_format = 0,
|
||||||
|
.time_and_date_date_format = 0,
|
||||||
|
.time_and_date_automatic = 0,
|
||||||
|
},
|
||||||
|
.display = {
|
||||||
|
.display_brightness = 200,
|
||||||
|
.display_delay_before_sleep = 0,
|
||||||
|
.display_orientation = LCD_ORIENTATION_DEFAULT,
|
||||||
|
.display_vibrate_on_touch_duration = 0,
|
||||||
|
.display_vibrate_on_touch_strength = 0,
|
||||||
|
.display_wrist_wakeup = true,
|
||||||
|
},
|
||||||
|
.notification = {
|
||||||
|
.notification_vibration_duration = 4,
|
||||||
|
.notification_vibration_strength = 7,
|
||||||
|
.vibrate_on_email = true,
|
||||||
|
.vibrate_on_sms = true,
|
||||||
|
},
|
||||||
|
.connectivity = {
|
||||||
|
.connectivity_ble_enabled = false,
|
||||||
|
.connectivity_wifi_enabled = false,
|
||||||
|
},
|
||||||
|
.languageAndUI = {
|
||||||
|
.language = TRANSLATION_ENGLISH,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Actual watchSettings object which can change and lives in RAM memory.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static WatchSettings_t watchSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Internal variable used to know if something has to be saved or not because some settings changed.
|
||||||
|
*
|
||||||
|
* @note This is designed to prevent excessive wear and tear on the flash.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static bool _params_changed = false;
|
||||||
|
|
||||||
|
void persistency_init(void)
|
||||||
|
{
|
||||||
|
memcpy(&watchSettings, &defaultWatchSettings, sizeof(WatchSettings_t));
|
||||||
|
}
|
||||||
|
|
||||||
WatchSettings_t *persistency_get_settings(void)
|
WatchSettings_t *persistency_get_settings(void)
|
||||||
{
|
{
|
||||||
return &watchSettings;
|
return &watchSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display_set_brightness(uint8_t brightness)
|
||||||
|
{
|
||||||
|
watchSettings.display.display_brightness = brightness;
|
||||||
|
_params_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool persistency_save_settings(void)
|
||||||
|
{
|
||||||
|
if(!_params_changed)
|
||||||
|
{
|
||||||
|
APP_LOG_INFO("Nothing to save, no params changed");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t status = TLS_FLS_STATUS_OK;
|
||||||
|
if(TLS_FLS_STATUS_OK != (status = tls_fls_write_without_erase(WATCH_SETTINGS_FLASH_STORAGE_ADDRESS, (uint8_t *) &watchSettings, sizeof watchSettings)))
|
||||||
|
{
|
||||||
|
APP_LOG_ERROR("Failed to write settings to flash : %u", status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't forget to reset the state variable here
|
||||||
|
_params_changed = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool persistency_load_settings(void)
|
||||||
|
{
|
||||||
|
uint8_t status = TLS_FLS_STATUS_OK;
|
||||||
|
if(TLS_FLS_STATUS_OK != (status = tls_fls_read(WATCH_SETTINGS_FLASH_STORAGE_ADDRESS, (uint8_t *) &watchSettings, sizeof watchSettings)))
|
||||||
|
{
|
||||||
|
APP_LOG_ERROR("Failed to read settings to flash : %u", status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -2,48 +2,206 @@
|
|||||||
#define WATCH_SETTINGS_H
|
#define WATCH_SETTINGS_H
|
||||||
|
|
||||||
#include "wm_type_def.h"
|
#include "wm_type_def.h"
|
||||||
|
#include "lcd.h"
|
||||||
|
|
||||||
/* Time and Date Settings */
|
/**
|
||||||
|
* @brief The address in flash storage where the settings are saved
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define WATCH_SETTINGS_FLASH_STORAGE_ADDRESS (0x1E0000)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Time and Date Settings
|
||||||
|
*
|
||||||
|
*/
|
||||||
typedef struct TimeAndDate
|
typedef struct TimeAndDate
|
||||||
{
|
{
|
||||||
uint32_t hour_format:1;
|
uint32_t time_and_date_hour_format:1,
|
||||||
uint32_t date_format:2;
|
time_and_date_date_format:2,
|
||||||
uint32_t automatic_time_and_date:1;
|
time_and_date_automatic:1;
|
||||||
} TimeAndDate_t;
|
} TimeAndDate_t;
|
||||||
|
|
||||||
/* Display Settings */
|
/**
|
||||||
|
* @brief Display Settings
|
||||||
|
*
|
||||||
|
*/
|
||||||
typedef struct Display
|
typedef struct Display
|
||||||
{
|
{
|
||||||
uint8_t brightness;
|
uint32_t display_brightness:8,
|
||||||
uint8_t sleep_delay;
|
display_delay_before_sleep:4,
|
||||||
uint8_t orientation:2;
|
display_orientation:2,
|
||||||
|
display_wrist_wakeup:1,
|
||||||
|
display_vibrate_on_touch_strength:3,
|
||||||
|
display_vibrate_on_touch_duration:3;
|
||||||
} Display_t;
|
} Display_t;
|
||||||
|
|
||||||
/* Connectivity Settings */
|
/**
|
||||||
|
* @brief Notification Settings
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef struct Notification
|
||||||
|
{
|
||||||
|
uint32_t vibrate_on_sms:1,
|
||||||
|
vibrate_on_email:1,
|
||||||
|
notification_vibration_strength:3,
|
||||||
|
notification_vibration_duration:3;
|
||||||
|
} Notification_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Connectivity Settings
|
||||||
|
*
|
||||||
|
*/
|
||||||
typedef struct Connectivity
|
typedef struct Connectivity
|
||||||
{
|
{
|
||||||
|
uint32_t connectivity_ble_enabled:1,
|
||||||
|
connectivity_wifi_enabled:1;
|
||||||
} Connectivity_t;
|
} Connectivity_t;
|
||||||
|
|
||||||
/* Language and UI Settings */
|
/**
|
||||||
|
* @brief Language and UI Settings
|
||||||
|
*
|
||||||
|
* @note Languages : English, French and German will be available
|
||||||
|
*
|
||||||
|
*/
|
||||||
typedef struct LanguageAndUI
|
typedef struct LanguageAndUI
|
||||||
{
|
{
|
||||||
|
uint32_t language:3;
|
||||||
} LanguageAndUI_t;
|
} LanguageAndUI_t;
|
||||||
|
|
||||||
/* Main setting structure */
|
/**
|
||||||
|
* @brief Main setting structure
|
||||||
|
*
|
||||||
|
*/
|
||||||
typedef struct WatchSettings
|
typedef struct WatchSettings
|
||||||
{
|
{
|
||||||
|
uint32_t first_time_init:1;
|
||||||
TimeAndDate_t timeAndDate;
|
TimeAndDate_t timeAndDate;
|
||||||
Display_t display;
|
Display_t display;
|
||||||
|
Notification_t notification;
|
||||||
Connectivity_t connectivity;
|
Connectivity_t connectivity;
|
||||||
LanguageAndUI_t languageAndUI;
|
LanguageAndUI_t languageAndUI;
|
||||||
} WatchSettings_t;
|
} WatchSettings_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the persistency layer. Must be called first before any other persistency API functions.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void persistency_init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return WatchSettings_t* a pointer to the WatchSettings structure
|
||||||
|
*/
|
||||||
WatchSettings_t *persistency_get_settings(void);
|
WatchSettings_t *persistency_get_settings(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param hour_24H_format
|
||||||
|
*/
|
||||||
|
void time_and_date_set_hour_format(bool hour_24H_format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param date_format
|
||||||
|
*/
|
||||||
|
void time_and_date_set_date_format(uint8_t date_format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param automatic
|
||||||
|
*/
|
||||||
|
void time_and_date_set_automatic(bool automatic);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param brightness
|
||||||
|
*/
|
||||||
|
void display_set_brightness(uint8_t brightness);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param delay
|
||||||
|
*/
|
||||||
|
void display_set_delay_before_sleep(uint8_t delay);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param orientation
|
||||||
|
*/
|
||||||
|
void display_set_orientation(LCDOrientation_e orientation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param wakeup
|
||||||
|
*/
|
||||||
|
void display_set_wrist_wakeup(bool wakeup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param level
|
||||||
|
*/
|
||||||
|
void display_set_vibrate_on_touch_strength(uint8_t level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param duration
|
||||||
|
*/
|
||||||
|
void display_set_vibrate_on_touch_duration(uint8_t duration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param level
|
||||||
|
*/
|
||||||
|
void notification_set_vibration_strength(uint8_t level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param duration
|
||||||
|
*/
|
||||||
|
void notification_set_vibration_duration(uint8_t duration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
*/
|
||||||
|
void connectivity_set_ble_enabled(bool enabled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
*/
|
||||||
|
void connectivity_set_wifi_enabled(bool enabled);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
bool persistency_save_settings(void);
|
bool persistency_save_settings(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
bool persistency_load_settings(void);
|
bool persistency_load_settings(void);
|
||||||
|
|
||||||
#endif //WATCH_SETTINGS_H
|
#endif //WATCH_SETTINGS_H
|
Loading…
Reference in New Issue
Block a user