Did more code cleaning, integrated notification logic, a few things still needed to be fully functional
This commit is contained in:
parent
4107a5461f
commit
111ebd65c5
@ -16,6 +16,7 @@
|
|||||||
#include "notification_screen.h"
|
#include "notification_screen.h"
|
||||||
#include "watch_peripherals.h"
|
#include "watch_peripherals.h"
|
||||||
#include "watch_settings.h"
|
#include "watch_settings.h"
|
||||||
|
#include "watch_power_management.h"
|
||||||
#include "firmware_version.h"
|
#include "firmware_version.h"
|
||||||
#include "MAX3010X.h"
|
#include "MAX3010X.h"
|
||||||
|
|
||||||
@ -29,7 +30,6 @@ static void date_time_cb(struct tm * const dateTime)
|
|||||||
tls_get_rtc(dateTime);
|
tls_get_rtc(dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _is_in_ble_sleep_mode = false;
|
|
||||||
bool _is_ble_device_subscribed = false;
|
bool _is_ble_device_subscribed = false;
|
||||||
static void _perform_deferred_display_wake_up_set_timestamp(void);
|
static void _perform_deferred_display_wake_up_set_timestamp(void);
|
||||||
static void _perform_deferred_display_wake_up(uint8_t deferred_time_in_ms);
|
static void _perform_deferred_display_wake_up(uint8_t deferred_time_in_ms);
|
||||||
@ -152,7 +152,7 @@ static void setTimeFormatCb(bool *hour_24H_format, SettingMode_e mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setDisplayVibrationDuration(uint8_t *duration, SettingMode_e mode)
|
static void setDisplayVibrationDurationCb(uint8_t *duration, SettingMode_e mode)
|
||||||
{
|
{
|
||||||
if(SETTING_MODE_GET == mode)
|
if(SETTING_MODE_GET == mode)
|
||||||
{
|
{
|
||||||
@ -164,7 +164,7 @@ static void setDisplayVibrationDuration(uint8_t *duration, SettingMode_e mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setDisplayVibrationStrength(uint8_t *strength, SettingMode_e mode)
|
static void setDisplayVibrationStrengthCb(uint8_t *strength, SettingMode_e mode)
|
||||||
{
|
{
|
||||||
if(SETTING_MODE_GET == mode)
|
if(SETTING_MODE_GET == mode)
|
||||||
{
|
{
|
||||||
@ -176,6 +176,78 @@ static void setDisplayVibrationStrength(uint8_t *strength, SettingMode_e mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setNotificationEnabledCb(bool *enabled, SettingMode_e mode)
|
||||||
|
{
|
||||||
|
if(SETTING_MODE_GET == mode)
|
||||||
|
{
|
||||||
|
*enabled = persistency_get_settings()->notification.notification_enabled;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
watch_settings_notification_set_notification_enabled(*enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setNotificationVibrationDurationCb(uint8_t *duration, SettingMode_e mode)
|
||||||
|
{
|
||||||
|
if(SETTING_MODE_GET == mode)
|
||||||
|
{
|
||||||
|
*duration = persistency_get_settings()->notification.notification_vibration_duration;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
watch_settings_notification_set_notification_vibration_duration(*duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setNotificationVibrationStrengthCb(uint8_t *strength, SettingMode_e mode)
|
||||||
|
{
|
||||||
|
if(SETTING_MODE_GET == mode)
|
||||||
|
{
|
||||||
|
*strength = persistency_get_settings()->notification.notification_vibration_strength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
watch_settings_notification_set_notification_vibration_strength(*strength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setCallEnabledCb(bool *enabled, SettingMode_e mode)
|
||||||
|
{
|
||||||
|
if(SETTING_MODE_GET == mode)
|
||||||
|
{
|
||||||
|
*enabled = persistency_get_settings()->notification.call_enabled;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
watch_settings_notification_set_call_enabled(*enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setCallVibrationDurationCb(uint8_t *duration, SettingMode_e mode)
|
||||||
|
{
|
||||||
|
if(SETTING_MODE_GET == mode)
|
||||||
|
{
|
||||||
|
*duration = persistency_get_settings()->notification.call_vibration_duration;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
watch_settings_notification_set_call_vibration_duration(*duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setCallVibrationStrengthCb(uint8_t *strength, SettingMode_e mode)
|
||||||
|
{
|
||||||
|
if(SETTING_MODE_GET == mode)
|
||||||
|
{
|
||||||
|
*strength = persistency_get_settings()->notification.call_vibration_strength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
watch_settings_notification_set_call_vibration_strength(*strength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void setTimeoutCb(uint8_t *timeout, SettingMode_e mode)
|
static void setTimeoutCb(uint8_t *timeout, SettingMode_e mode)
|
||||||
{
|
{
|
||||||
if(SETTING_MODE_GET == mode)
|
if(SETTING_MODE_GET == mode)
|
||||||
@ -342,8 +414,14 @@ SettingsScreenAPIInterface_t settingsScreenAPIInterface =
|
|||||||
.setTimeFormatSettingsCb = &(setTimeFormatCb),
|
.setTimeFormatSettingsCb = &(setTimeFormatCb),
|
||||||
.setBrightnessSettingsCb = &(setGetBrightnessCb),
|
.setBrightnessSettingsCb = &(setGetBrightnessCb),
|
||||||
.setTimeoutSettingsCb = &(setTimeoutCb),
|
.setTimeoutSettingsCb = &(setTimeoutCb),
|
||||||
.setDisplayVibrationDurationSettingsCb = &(setDisplayVibrationDuration),
|
.setDisplayVibrationDurationSettingsCb = &(setDisplayVibrationDurationCb),
|
||||||
.setDisplayVibrationStrengthSettingsCb = &(setDisplayVibrationStrength),
|
.setDisplayVibrationStrengthSettingsCb = &(setDisplayVibrationStrengthCb),
|
||||||
|
.setNotificationEnabledSettingsCb = &(setNotificationEnabledCb),
|
||||||
|
.setNotificationVibrationDurationSettingsCb = &(setNotificationVibrationDurationCb),
|
||||||
|
.setNotificationVibrationStrengthSettingsCb = &(setNotificationVibrationStrengthCb),
|
||||||
|
.setCallEnabledSettingsCb = &(setCallEnabledCb),
|
||||||
|
.setCallVibrationDurationSettingsCb = &(setCallVibrationDurationCb),
|
||||||
|
.setCallVibrationStrengthSettingsCb = &(setCallVibrationStrengthCb),
|
||||||
.setOrientationSettingsCb = &(setOrientationCb),
|
.setOrientationSettingsCb = &(setOrientationCb),
|
||||||
.setWristTiltSettingsCb = &(setWristTiltCb),
|
.setWristTiltSettingsCb = &(setWristTiltCb),
|
||||||
.setBLEEnabledSettingsCb = &(setBLEEnabledCb),
|
.setBLEEnabledSettingsCb = &(setBLEEnabledCb),
|
||||||
@ -400,19 +478,22 @@ static void parser_event_cb(gadget_bridge_event_data_t *gadget_bridge_event_data
|
|||||||
break;
|
break;
|
||||||
case GADGET_BRIDGE_EVENT_TYPE_NOTIFY:
|
case GADGET_BRIDGE_EVENT_TYPE_NOTIFY:
|
||||||
{
|
{
|
||||||
// Let's retrieve the time from the watch :
|
if(persistency_get_settings()->notification.notification_enabled)
|
||||||
struct tm date_time;
|
{
|
||||||
tls_get_rtc(&date_time);
|
// Let's retrieve the time from the watch :
|
||||||
|
struct tm date_time;
|
||||||
|
tls_get_rtc(&date_time);
|
||||||
|
|
||||||
notification_screen_notify(¬ificationScreen, gadget_bridge_event_data->notification.handle,
|
notification_screen_notify(¬ificationScreen, gadget_bridge_event_data->notification.handle,
|
||||||
mktime(&date_time),
|
mktime(&date_time),
|
||||||
gadget_bridge_event_data->notification.notification_type,
|
gadget_bridge_event_data->notification.notification_type,
|
||||||
gadget_bridge_event_data->notification.title,
|
gadget_bridge_event_data->notification.title,
|
||||||
gadget_bridge_event_data->notification.body);
|
gadget_bridge_event_data->notification.body);
|
||||||
|
|
||||||
//As we don't want the title and the body strings to be freed after the callback returns, let's set them to NULL
|
//As we don't want the title and the body strings to be freed after the callback returns, let's set them to NULL
|
||||||
gadget_bridge_event_data->notification.title = NULL;
|
gadget_bridge_event_data->notification.title = NULL;
|
||||||
gadget_bridge_event_data->notification.body = NULL;
|
gadget_bridge_event_data->notification.body = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -554,6 +635,30 @@ static void sendMusicPlaybackBLECommandCb(MusicPlaybackCtrlAction_e musicPlaybac
|
|||||||
gadget_bridge_send_music_control(musicPlaybackCtrlAction);
|
gadget_bridge_send_music_control(musicPlaybackCtrlAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void notification_on_state_change_cb(NotificationState_e notificationState)
|
||||||
|
{
|
||||||
|
switch (notificationState)
|
||||||
|
{
|
||||||
|
case NOTIFICATION_STATE_DISPLAYED:
|
||||||
|
// Let's give a user feedback by vibrating the watch if it is configured to do so
|
||||||
|
if(persistency_get_settings()->notification.notification_vibration_duration)
|
||||||
|
{
|
||||||
|
uint16_t vibration_strength = (persistency_get_settings()->notification.notification_vibration_strength + 1)*32;
|
||||||
|
uint32_t vibration_duration_ms = 0;
|
||||||
|
|
||||||
|
if(persistency_get_settings()->notification.notification_vibration_duration)
|
||||||
|
vibration_duration_ms = persistency_get_settings()->notification.notification_vibration_duration*50 + 50;
|
||||||
|
|
||||||
|
uint16_t vibration_pattern[VIBRATION_PATTERN_SLOTS] = {vibration_duration_ms, vibration_duration_ms, vibration_duration_ms};
|
||||||
|
watch_peripherals_vibrate_with_pattern(vibration_strength > 255 ? 255 : vibration_strength, vibration_pattern);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NOTIFICATION_STATE_CLEARED:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern LCDConfig_t LCDConfig;
|
extern LCDConfig_t LCDConfig;
|
||||||
|
|
||||||
void gfx_task(void *param)
|
void gfx_task(void *param)
|
||||||
@ -598,7 +703,7 @@ void gfx_task(void *param)
|
|||||||
struct tm curr_time = {
|
struct tm curr_time = {
|
||||||
.tm_mday = 1,
|
.tm_mday = 1,
|
||||||
.tm_mon = 1,
|
.tm_mon = 1,
|
||||||
.tm_year = 22, // Starting from 2000
|
.tm_year = 122, // Starting from 1900
|
||||||
};
|
};
|
||||||
tls_set_rtc(&curr_time);
|
tls_set_rtc(&curr_time);
|
||||||
}
|
}
|
||||||
@ -627,6 +732,7 @@ void gfx_task(void *param)
|
|||||||
music_player_screen_register_music_player_time_ref_ms_cb(&musicPlayerScreen, &(elapsed_ms));
|
music_player_screen_register_music_player_time_ref_ms_cb(&musicPlayerScreen, &(elapsed_ms));
|
||||||
|
|
||||||
notification_screen_init(¬ificationScreen);
|
notification_screen_init(¬ificationScreen);
|
||||||
|
notification_screen_register_on_state_change_cb(¬ificationScreen, &(notification_on_state_change_cb));
|
||||||
|
|
||||||
settings_screen_init(&settingsScreen);
|
settings_screen_init(&settingsScreen);
|
||||||
settings_screen_register_on_state_change_cb(&settingsScreen, &(settings_screen_on_state_change_cb));
|
settings_screen_register_on_state_change_cb(&settingsScreen, &(settings_screen_on_state_change_cb));
|
||||||
@ -660,30 +766,16 @@ void gfx_task(void *param)
|
|||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Actions to perform when the watch is active only */
|
/* Actions to perform when the watch is active only, not in BLE sleep */
|
||||||
if(!_is_in_ble_sleep_mode)
|
if(!watch_power_management_check_current_power_state_is(WATCH_POWER_STATE_BLE_SLEEP))
|
||||||
{
|
{
|
||||||
lv_timer_handler();
|
lv_timer_handler();
|
||||||
|
|
||||||
/* Throttle CPU freq down when inactive to save power or to increase responsiveness */
|
/* Throttle CPU freq down when inactive to save power or to increase responsiveness */
|
||||||
tls_sys_clk clk;
|
|
||||||
tls_sys_clk_get(&clk);
|
|
||||||
if(lv_disp_get_inactive_time(NULL) > 5000)
|
if(lv_disp_get_inactive_time(NULL) > 5000)
|
||||||
{
|
watch_power_management_change_power_state(WATCH_POWER_STATE_IDLE);
|
||||||
if(clk.cpuclk != 40)
|
|
||||||
{
|
|
||||||
tls_sys_clk_set(CPU_CLK_40M);
|
|
||||||
APP_LOG_DEBUG("CPU 40MHz");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
watch_power_management_change_power_state(WATCH_POWER_STATE_FULL_SPEED);
|
||||||
if(clk.cpuclk != 160)
|
|
||||||
{
|
|
||||||
tls_sys_clk_set(CPU_CLK_160M);
|
|
||||||
APP_LOG_DEBUG("CPU 160MHz");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Will wake the display up after some ms to avoid seeing the second hand jumping */
|
/* Will wake the display up after some ms to avoid seeing the second hand jumping */
|
||||||
_perform_deferred_display_wake_up(30);
|
_perform_deferred_display_wake_up(30);
|
||||||
@ -706,11 +798,7 @@ void gfx_task(void *param)
|
|||||||
/* We need to keep the BLE stack running so we can't juste put the MCU in sleep mode :-( */
|
/* We need to keep the BLE stack running so we can't juste put the MCU in sleep mode :-( */
|
||||||
if(is_ble_modem_on())
|
if(is_ble_modem_on())
|
||||||
{
|
{
|
||||||
APP_LOG_DEBUG("Entering BLE sleep mode");
|
watch_power_management_change_power_state(WATCH_POWER_STATE_BLE_SLEEP);
|
||||||
/* We can stop the lvgl timer */
|
|
||||||
APP_LOG_TRACE("Stopping LVGL tick timer");
|
|
||||||
lv_port_tick_stop();
|
|
||||||
_is_in_ble_sleep_mode = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -724,9 +812,10 @@ void gfx_task(void *param)
|
|||||||
|
|
||||||
/* Let's sleep for real */
|
/* Let's sleep for real */
|
||||||
tls_pmu_sleep_start();
|
tls_pmu_sleep_start();
|
||||||
|
us_delay(100);
|
||||||
if(watch_peripherals_wakeup_source_is_user())
|
if(watch_peripherals_wakeup_source_is_user())
|
||||||
{
|
{
|
||||||
|
APP_LOG_INFO("User IO wakeup !");
|
||||||
/* Just to clear it off */
|
/* Just to clear it off */
|
||||||
tls_pmu_timer0_stop();
|
tls_pmu_timer0_stop();
|
||||||
watch_peripherals_wakeup_source_is_timer();
|
watch_peripherals_wakeup_source_is_timer();
|
||||||
@ -734,7 +823,7 @@ void gfx_task(void *param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the periodic background tasks */
|
/* Perform the periodic background tasks */
|
||||||
ms_delay(1);APP_LOG_INFO("Periodic timer wakeup !");
|
APP_LOG_INFO("Periodic timer wakeup !");
|
||||||
|
|
||||||
} while (watch_peripherals_wakeup_source_is_timer());
|
} while (watch_peripherals_wakeup_source_is_timer());
|
||||||
|
|
||||||
@ -796,17 +885,30 @@ void gfx_task(void *param)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wrist_tilt = false ,touch_screen_touch = false;
|
bool wrist_tilt = false ,touch_screen_touch = false, notification_received = false;
|
||||||
if((wrist_tilt = watch_peripherals_accelerometer_wrist_wakeup_interrupt()) || ((touch_screen_touch = lv_port_indev_touched()) && _is_in_ble_sleep_mode))
|
if(
|
||||||
|
(wrist_tilt = watch_peripherals_accelerometer_wrist_wakeup_interrupt()) ||
|
||||||
|
(notification_received = notification_screen_new_notification_available(¬ificationScreen)) ||
|
||||||
|
((touch_screen_touch = lv_port_indev_touched()) && watch_power_management_check_current_power_state_is(WATCH_POWER_STATE_BLE_SLEEP))
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if(wrist_tilt)
|
|
||||||
APP_LOG_DEBUG("Wrist tilt");
|
|
||||||
if(touch_screen_touch)
|
if(touch_screen_touch)
|
||||||
APP_LOG_DEBUG("Touch screen touch");
|
APP_LOG_DEBUG("Touch screen touch");
|
||||||
|
if(wrist_tilt)
|
||||||
if(_is_in_ble_sleep_mode)
|
|
||||||
{
|
{
|
||||||
_is_in_ble_sleep_mode = false;
|
lv_disp_trig_activity(NULL);
|
||||||
|
APP_LOG_DEBUG("Wrist tilt");
|
||||||
|
}
|
||||||
|
if(notification_received)
|
||||||
|
{
|
||||||
|
lv_disp_trig_activity(NULL);
|
||||||
|
APP_LOG_DEBUG("Notification received");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(watch_power_management_check_current_power_state_is(WATCH_POWER_STATE_BLE_SLEEP))
|
||||||
|
{
|
||||||
|
watch_power_management_change_power_state(WATCH_POWER_STATE_IDLE);
|
||||||
lv_port_tick_start();
|
lv_port_tick_start();
|
||||||
|
|
||||||
watch_face_force_sync(&watchFace);
|
watch_face_force_sync(&watchFace);
|
||||||
|
Loading…
Reference in New Issue
Block a user