diff --git a/src/W800_SDK_v1.00.10/app/persistency/watch_settings.c b/src/W800_SDK_v1.00.10/app/persistency/watch_settings.c index 070a49a..eaa5b7b 100644 --- a/src/W800_SDK_v1.00.10/app/persistency/watch_settings.c +++ b/src/W800_SDK_v1.00.10/app/persistency/watch_settings.c @@ -10,6 +10,8 @@ */ static const WatchSettings_t defaultWatchSettings = { + + .first_time_init = false, .timeAndDate = { .time_and_date_hour_format = 0, .time_and_date_date_format = 0, @@ -20,12 +22,12 @@ static const WatchSettings_t defaultWatchSettings = .display_delay_before_sleep = 0, .display_orientation = LCD_ORIENTATION_DEFAULT, .display_vibrate_on_touch_duration = 0, - .display_vibrate_on_touch_strength = 0, + .display_vibrate_on_touch_strength = 6, .display_wrist_wakeup = true, }, .notification = { - .notification_vibration_duration = 4, - .notification_vibration_strength = 7, + .notification_vibration_duration = 3, + .notification_vibration_strength = 6, .vibrate_on_email = true, .vibrate_on_sms = true, }, @@ -52,6 +54,93 @@ static WatchSettings_t watchSettings; */ static bool _params_changed = false; +void watch_settings_time_and_date_set_hour_format(bool hour_24H_format) +{ + watchSettings.timeAndDate.time_and_date_hour_format = hour_24H_format; + _params_changed = true; +} + +void watch_settings_time_and_date_set_date_format(uint8_t date_format) +{ + watchSettings.timeAndDate.time_and_date_date_format = date_format; + _params_changed = true; +} + +void watch_settings_time_and_date_set_automatic(bool automatic) +{ + watchSettings.timeAndDate.time_and_date_automatic = automatic; + _params_changed = true; +} + +void watch_settings_display_set_brightness(uint8_t brightness) +{ + watchSettings.display.display_brightness = brightness; + _params_changed = true; +} + +void watch_settings_display_set_delay_before_sleep(uint8_t delay) +{ + watchSettings.display.display_delay_before_sleep = delay; + _params_changed = true; +} + +void watch_settings_display_set_orientation(LCDOrientation_e orientation) +{ + watchSettings.display.display_orientation = orientation; + _params_changed = true; +} + +void watch_settings_display_set_wrist_wakeup(bool wakeup) +{ + watchSettings.display.display_wrist_wakeup = wakeup; + _params_changed = true; +} + +void watch_settings_display_set_vibrate_on_touch_strength(uint8_t level) +{ + watchSettings.display.display_vibrate_on_touch_strength = level; + _params_changed = true; +} + +void watch_settings_display_set_vibrate_on_touch_duration(uint8_t duration) +{ + watchSettings.display.display_vibrate_on_touch_duration = duration; + _params_changed = true; +} + +void watch_settings_notification_set_vibration_strength(uint8_t level) +{ + watchSettings.notification.notification_vibration_strength = level; + _params_changed = true; +} + +void watch_settings_notification_set_vibration_duration(uint8_t duration) +{ + watchSettings.notification.notification_vibration_duration = duration; + _params_changed = true; +} + +void watch_settings_connectivity_set_ble_enabled(bool enabled) +{ + watchSettings.connectivity.connectivity_ble_enabled = enabled; + _params_changed = true; +} + +void watch_settings_connectivity_set_wifi_enabled(bool enabled) +{ + watchSettings.connectivity.connectivity_wifi_enabled = enabled; + _params_changed = true; +} + +void watch_settings_language_and_UI_set_language(TranslationLanguage_e language) +{ + watchSettings.languageAndUI.language = language; + _params_changed = true; +} + + + + void persistency_init(void) { memcpy(&watchSettings, &defaultWatchSettings, sizeof(WatchSettings_t)); @@ -62,13 +151,7 @@ WatchSettings_t *persistency_get_settings(void) return &watchSettings; } -void display_set_brightness(uint8_t brightness) -{ - watchSettings.display.display_brightness = brightness; - _params_changed = true; -} - -bool persistency_save_settings(void) +bool persistency_save_settings_to_flash(void) { if(!_params_changed) { @@ -77,7 +160,7 @@ bool persistency_save_settings(void) } 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))) + if(TLS_FLS_STATUS_OK != (status = tls_fls_write(WATCH_SETTINGS_FLASH_STORAGE_ADDRESS, (uint8_t *) &watchSettings, sizeof watchSettings))) { APP_LOG_ERROR("Failed to write settings to flash : %u", status); return false; @@ -88,7 +171,7 @@ bool persistency_save_settings(void) return true; } -bool persistency_load_settings(void) +bool persistency_load_settings_from_flash(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))) @@ -97,5 +180,31 @@ bool persistency_load_settings(void) return false; } + // If it is the first time that we read the settings from flash, + // we load the factory ones instead and we save'em. + if(watchSettings.first_time_init) + { + persistency_factory_reset(); + return persistency_save_settings_to_flash(); + } + return true; } + +void persistency_factory_reset(void) +{ + memcpy(&watchSettings, &defaultWatchSettings, sizeof(WatchSettings_t)); + _params_changed = true; +} + +void persistency_debug(void) +{ + uint32_t *p = (uint32_t *)&watchSettings; + APP_LOG_DEBUG("%u %u %u %u %u %u", + p[0], + p[1], + p[2], + p[3], + p[4], + p[5]); +} diff --git a/src/W800_SDK_v1.00.10/app/persistency/watch_settings.h b/src/W800_SDK_v1.00.10/app/persistency/watch_settings.h index 45763c5..260b7bf 100644 --- a/src/W800_SDK_v1.00.10/app/persistency/watch_settings.h +++ b/src/W800_SDK_v1.00.10/app/persistency/watch_settings.h @@ -3,6 +3,7 @@ #include "wm_type_def.h" #include "lcd.h" +#include "translation.h" /** * @brief The address in flash storage where the settings are saved @@ -82,126 +83,147 @@ typedef struct WatchSettings LanguageAndUI_t languageAndUI; } 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); - /** * @brief * * @param hour_24H_format */ -void time_and_date_set_hour_format(bool hour_24H_format); +void watch_settings_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); +void watch_settings_time_and_date_set_date_format(uint8_t date_format); /** * @brief * * @param automatic */ -void time_and_date_set_automatic(bool automatic); +void watch_settings_time_and_date_set_automatic(bool automatic); /** * @brief * * @param brightness */ -void display_set_brightness(uint8_t brightness); +void watch_settings_display_set_brightness(uint8_t brightness); /** * @brief * * @param delay */ -void display_set_delay_before_sleep(uint8_t delay); +void watch_settings_display_set_delay_before_sleep(uint8_t delay); /** * @brief * * @param orientation */ -void display_set_orientation(LCDOrientation_e orientation); +void watch_settings_display_set_orientation(LCDOrientation_e orientation); /** * @brief * * @param wakeup */ -void display_set_wrist_wakeup(bool wakeup); +void watch_settings_display_set_wrist_wakeup(bool wakeup); /** * @brief * * @param level */ -void display_set_vibrate_on_touch_strength(uint8_t level); +void watch_settings_display_set_vibrate_on_touch_strength(uint8_t level); /** * @brief * * @param duration */ -void display_set_vibrate_on_touch_duration(uint8_t duration); +void watch_settings_display_set_vibrate_on_touch_duration(uint8_t duration); /** * @brief * * @param level */ -void notification_set_vibration_strength(uint8_t level); +void watch_settings_notification_set_vibration_strength(uint8_t level); /** * @brief * * @param duration */ -void notification_set_vibration_duration(uint8_t duration); +void watch_settings_notification_set_vibration_duration(uint8_t duration); /** * @brief * * @param enabled */ -void connectivity_set_ble_enabled(bool enabled); +void watch_settings_connectivity_set_ble_enabled(bool enabled); /** * @brief * * @param enabled */ -void connectivity_set_wifi_enabled(bool enabled); - - +void watch_settings_connectivity_set_wifi_enabled(bool enabled); /** * @brief * - * @return true - * @return false + * @param language */ -bool persistency_save_settings(void); +void watch_settings_language_and_UI_set_language(TranslationLanguage_e language); + + /** - * @brief + * @brief Initializes the persistency layer. Must be called first before any other persistency API functions. * - * @return true - * @return false */ -bool persistency_load_settings(void); +void persistency_init(void); + +/** + * @brief Returns the watchSettings structure living in RAM + * + * @return WatchSettings_t* a pointer to the WatchSettings structure + */ +WatchSettings_t *persistency_get_settings(void); + +/** + * @brief Writes the current watchSettings settings to flash + * + * @return true on success + * @return false on failure + */ +bool persistency_save_settings_to_flash(void); + +/** + * @brief Reads the stored settings in the flash to put them in the watchSettings object + * which lives in RAM. + * @note If it is the first time that the settings are read from flash, this will also write default settings to it. + * + * @return true on success + * @return false on failure + */ +bool persistency_load_settings_from_flash(void); + +/** + * @brief Reloads every settings of the watchSettings data structure with their default value. + * @note The call to this function DOES NOT save the new settings to flash. + * Call @ref persistency_save_settings_to_flash for that. + * + * @return true on success + * @return false on failure + */ +void persistency_factory_reset(void); + +void persistency_debug(void); #endif //WATCH_SETTINGS_H \ No newline at end of file