Compare commits

...

3 Commits

5 changed files with 227 additions and 54 deletions

View File

@ -43,6 +43,7 @@
* @brief i2c
*
*/
#define I2C_CLOCK_SPEED (300000) // 300 kHz seems to be the maximum achievable clock speed before the touch IC behaves funky
#define I2C_SCL WM_IO_PA_01
#define I2C_SDA WM_IO_PB_19

View File

@ -1,3 +1,4 @@
#include <stdio.h>
#include "lvgl.h"
#include "common_screen_components.h"
#include "settings_screen.h"
@ -12,9 +13,9 @@ static const char *hour_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n1
static const char *second_minute_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
static const char *date_format = "dd/mm/yyyy\ndd/mm/yy\nyyyy/mm/dd\nyy/mm/dd";
static const char *timeout_options = "Never\n5 seconds\n10 seconds\n15 seconds\n20 seconds\n25 seconds\n30 seconds\n35 seconds\n40 seconds\n45 seconds\n50 seconds\n55 seconds\n60 seconds";
static const char *timeout_options = "Off\n5 seconds\n10 seconds\n15 seconds\n20 seconds\n25 seconds\n30 seconds\n35 seconds\n40 seconds\n45 seconds\n50 seconds\n55 seconds\n60 seconds";
static const char *orientation_format = "Default\n90°\n180°\n270°";
static const char* vibration_duration = "None\n50 ms\n100 ms\n150 ms\n200 ms\n250 ms\n300 ms\n350 ms";
static const char* vibration_duration = "None\n100 ms\n150 ms\n200 ms\n250 ms\n300 ms\n350 ms\n400 ms";
static const char* vibration_force = "1\n2\n3\n4\n5\n6\n7\n8";
static const char* language_options = "Francais\nDeutsch\nEnglish";
@ -62,6 +63,11 @@ static void gesture_event_cb(lv_event_t *e)
static void cleanup_event_cb(lv_event_t *e)
{
SettingsScreen_t *settingsScreen = e->user_data;
// Here we call the save callback
if(settingsScreen->settingsScreenAPIInterface.saveSettingsCb)
settingsScreen->settingsScreenAPIInterface.saveSettingsCb();
settings_screen_destroy(settingsScreen);
LV_LOG_USER("cleanup");
}
@ -194,6 +200,10 @@ static void activation_switch_cb(lv_event_t *e)
{
if(settingsScreen->settingsScreenAPIInterface.setWiFiEnabledSettingsCb)settingsScreen->settingsScreenAPIInterface.setWiFiEnabledSettingsCb(&toggled, SETTING_MODE_SET);
}
else if(e->target == settingsScreen->wrist_tilt_switch)
{
if(settingsScreen->settingsScreenAPIInterface.setWristTiltSettingsCb)settingsScreen->settingsScreenAPIInterface.setWristTiltSettingsCb(&toggled, SETTING_MODE_SET);
}
}
static void language_dropdown_cb(lv_event_t *e)
@ -211,6 +221,13 @@ static void language_dropdown_cb(lv_event_t *e)
_settings_screen_update_labels_language(settingsScreen);
}
static void factory_reset_cb(lv_event_t *e)
{
SettingsScreen_t *settingsScreen = e->user_data;
if(settingsScreen->settingsScreenAPIInterface.factoryResetCb) settingsScreen->settingsScreenAPIInterface.factoryResetCb();
}
static void about_refresh_timer_cb(lv_timer_t *timer)
{
SettingsScreen_t *settingsScreen = timer->user_data;
@ -373,16 +390,20 @@ static void load_display_side_screen(SettingsScreen_t *settingsScreen)
lv_label_set_text_static(label, "Wakeup :");
lv_obj_align_to(label, orientation_dropdown, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
lv_obj_t *wrist_tilt_toggle = lv_switch_create(settingsScreen->side_screen);
lv_obj_align_to(wrist_tilt_toggle, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
settingsScreen->wrist_tilt_switch = lv_switch_create(settingsScreen->side_screen);
bool toggled = false;
if(settingsScreen->settingsScreenAPIInterface.setWristTiltSettingsCb)settingsScreen->settingsScreenAPIInterface.setWristTiltSettingsCb(&toggled, SETTING_MODE_GET);
if(toggled)lv_obj_add_state(settingsScreen->wrist_tilt_switch, LV_STATE_CHECKED);
lv_obj_align_to(settingsScreen->wrist_tilt_switch, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
lv_obj_add_event_cb(settingsScreen->wrist_tilt_switch, &(activation_switch_cb), LV_EVENT_VALUE_CHANGED, settingsScreen);
label = lv_label_create(settingsScreen->side_screen);
lv_label_set_text_static(label, "Wrist Tilt");
lv_obj_align_to(label, wrist_tilt_toggle, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
lv_obj_align_to(label, settingsScreen->wrist_tilt_switch, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
label = lv_label_create(settingsScreen->side_screen);
lv_label_set_text_static(label, "Vibrate On Touch :");
lv_obj_align_to(label, wrist_tilt_toggle, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
lv_obj_align_to(label, settingsScreen->wrist_tilt_switch, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
lv_obj_t *on_touch_vibration_duration_roller = lv_roller_create(settingsScreen->side_screen);
lv_obj_align_to(on_touch_vibration_duration_roller, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
@ -401,6 +422,9 @@ static void load_display_side_screen(SettingsScreen_t *settingsScreen)
lv_obj_align_to(on_touch_vibration_strength_roller, on_touch_vibration_duration_roller, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
lv_roller_set_options(on_touch_vibration_strength_roller, vibration_force, LV_ROLLER_MODE_NORMAL);
lv_roller_set_visible_row_count(on_touch_vibration_strength_roller, 2);
uint8_t strength = 0;
if(settingsScreen->settingsScreenAPIInterface.setDisplayVibrationStrengthSettingsCb)settingsScreen->settingsScreenAPIInterface.setDisplayVibrationStrengthSettingsCb(&strength, SETTING_MODE_GET);
lv_roller_set_selected(on_touch_vibration_strength_roller, strength, LV_ANIM_OFF);
lv_obj_set_width(on_touch_vibration_strength_roller, lv_obj_get_width(on_touch_vibration_duration_roller));
lv_obj_add_event_cb(on_touch_vibration_strength_roller, &(vibration_strength_roller_cb), LV_EVENT_RELEASED, settingsScreen);
@ -517,6 +541,18 @@ static void load_about_side_screen(SettingsScreen_t *settingsScreen)
lv_obj_align_to(settingsScreen->currentTime.current_time_label, rtc_time, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
_set_rtc_time_to_label(settingsScreen);
label = lv_label_create(settingsScreen->side_screen);
lv_label_set_text_static(label, "Factory Reset :");
lv_obj_align_to(label, settingsScreen->currentTime.current_time_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
lv_obj_t *factory_rst_btn = lv_btn_create(settingsScreen->side_screen);
lv_obj_align_to(factory_rst_btn, label, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
lv_obj_add_event_cb(factory_rst_btn, &(factory_reset_cb), LV_EVENT_CLICKED, settingsScreen);
label = lv_label_create(factory_rst_btn);
lv_label_set_text_static(label, "Reset");
lv_obj_center(label);
/* Create and start the refresh timer */
if(settingsScreen->about_refresh_timer)
{

View File

@ -14,12 +14,15 @@ typedef struct SettingsScreenAPIInterface
void (*setTimeSettingsCb)(uint8_t *hour, uint8_t *minute, uint8_t *second, uint8_t *day, uint8_t *month, uint8_t *year, SettingMode_e mode);
void (*setBrightnessSettingsCb)(uint8_t *brightness, SettingMode_e mode);
void (*setTimeoutSettingsCb)(uint8_t *timeout, SettingMode_e mode);
void (*setOrientationSettingsCb)(uint8_t *orientation, SettingMode_e mode);
void (*setWristTiltSettingsCb)(bool *enabled, SettingMode_e mode);
void (*setDisplayVibrationDurationSettingsCb)(uint8_t *duration, SettingMode_e mode);
void (*setDisplayVibrationStrengthSettingsCb)(uint8_t *strength, SettingMode_e mode);
void (*setOrientationSettingsCb)(uint8_t *orientation, SettingMode_e mode);
void (*setBLEEnabledSettingsCb)(bool *enabled, SettingMode_e mode);
void (*setWiFiEnabledSettingsCb)(bool *enabled, SettingMode_e mode);
void (*setLanguageSettingsCb)(uint8_t *language, SettingMode_e mode);
void (*saveSettingsCb)(void);
void (*factoryResetCb)(void);
} SettingsScreenAPIInterface_t;
typedef struct SettingsScreen
@ -43,8 +46,10 @@ typedef struct SettingsScreen
lv_obj_t *day_roller;
lv_obj_t *month_roller;
lv_obj_t *year_roller;
lv_obj_t *wrist_tilt_switch;
lv_obj_t *ble_switch;
lv_obj_t *wifi_switch;
struct
{
lv_obj_t *current_time_label;

View File

@ -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]);
}

View File

@ -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