Did more code cleaning, integrated notification logic, a few things still needed to be fully functional

This commit is contained in:
Th3maz1ng 2023-10-22 09:00:33 +02:00
parent 4107a5461f
commit 111ebd65c5

View File

@ -16,6 +16,7 @@
#include "notification_screen.h"
#include "watch_peripherals.h"
#include "watch_settings.h"
#include "watch_power_management.h"
#include "firmware_version.h"
#include "MAX3010X.h"
@ -29,7 +30,6 @@ static void date_time_cb(struct tm * const dateTime)
tls_get_rtc(dateTime);
}
bool _is_in_ble_sleep_mode = false;
bool _is_ble_device_subscribed = false;
static void _perform_deferred_display_wake_up_set_timestamp(void);
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)
{
@ -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)
{
@ -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)
{
if(SETTING_MODE_GET == mode)
@ -342,8 +414,14 @@ SettingsScreenAPIInterface_t settingsScreenAPIInterface =
.setTimeFormatSettingsCb = &(setTimeFormatCb),
.setBrightnessSettingsCb = &(setGetBrightnessCb),
.setTimeoutSettingsCb = &(setTimeoutCb),
.setDisplayVibrationDurationSettingsCb = &(setDisplayVibrationDuration),
.setDisplayVibrationStrengthSettingsCb = &(setDisplayVibrationStrength),
.setDisplayVibrationDurationSettingsCb = &(setDisplayVibrationDurationCb),
.setDisplayVibrationStrengthSettingsCb = &(setDisplayVibrationStrengthCb),
.setNotificationEnabledSettingsCb = &(setNotificationEnabledCb),
.setNotificationVibrationDurationSettingsCb = &(setNotificationVibrationDurationCb),
.setNotificationVibrationStrengthSettingsCb = &(setNotificationVibrationStrengthCb),
.setCallEnabledSettingsCb = &(setCallEnabledCb),
.setCallVibrationDurationSettingsCb = &(setCallVibrationDurationCb),
.setCallVibrationStrengthSettingsCb = &(setCallVibrationStrengthCb),
.setOrientationSettingsCb = &(setOrientationCb),
.setWristTiltSettingsCb = &(setWristTiltCb),
.setBLEEnabledSettingsCb = &(setBLEEnabledCb),
@ -400,19 +478,22 @@ static void parser_event_cb(gadget_bridge_event_data_t *gadget_bridge_event_data
break;
case GADGET_BRIDGE_EVENT_TYPE_NOTIFY:
{
// Let's retrieve the time from the watch :
struct tm date_time;
tls_get_rtc(&date_time);
if(persistency_get_settings()->notification.notification_enabled)
{
// Let's retrieve the time from the watch :
struct tm date_time;
tls_get_rtc(&date_time);
notification_screen_notify(&notificationScreen, gadget_bridge_event_data->notification.handle,
mktime(&date_time),
gadget_bridge_event_data->notification.notification_type,
gadget_bridge_event_data->notification.title,
gadget_bridge_event_data->notification.body);
notification_screen_notify(&notificationScreen, gadget_bridge_event_data->notification.handle,
mktime(&date_time),
gadget_bridge_event_data->notification.notification_type,
gadget_bridge_event_data->notification.title,
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
gadget_bridge_event_data->notification.title = NULL;
gadget_bridge_event_data->notification.body = 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.body = NULL;
}
}
break;
default:
@ -554,6 +635,30 @@ static void sendMusicPlaybackBLECommandCb(MusicPlaybackCtrlAction_e musicPlaybac
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;
void gfx_task(void *param)
@ -598,7 +703,7 @@ void gfx_task(void *param)
struct tm curr_time = {
.tm_mday = 1,
.tm_mon = 1,
.tm_year = 22, // Starting from 2000
.tm_year = 122, // Starting from 1900
};
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));
notification_screen_init(&notificationScreen);
notification_screen_register_on_state_change_cb(&notificationScreen, &(notification_on_state_change_cb));
settings_screen_init(&settingsScreen);
settings_screen_register_on_state_change_cb(&settingsScreen, &(settings_screen_on_state_change_cb));
@ -660,30 +766,16 @@ void gfx_task(void *param)
for(;;)
{
/* Actions to perform when the watch is active only */
if(!_is_in_ble_sleep_mode)
/* Actions to perform when the watch is active only, not in BLE sleep */
if(!watch_power_management_check_current_power_state_is(WATCH_POWER_STATE_BLE_SLEEP))
{
lv_timer_handler();
/* 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(clk.cpuclk != 40)
{
tls_sys_clk_set(CPU_CLK_40M);
APP_LOG_DEBUG("CPU 40MHz");
}
}
watch_power_management_change_power_state(WATCH_POWER_STATE_IDLE);
else
{
if(clk.cpuclk != 160)
{
tls_sys_clk_set(CPU_CLK_160M);
APP_LOG_DEBUG("CPU 160MHz");
}
}
watch_power_management_change_power_state(WATCH_POWER_STATE_FULL_SPEED);
/* Will wake the display up after some ms to avoid seeing the second hand jumping */
_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 :-( */
if(is_ble_modem_on())
{
APP_LOG_DEBUG("Entering BLE sleep mode");
/* We can stop the lvgl timer */
APP_LOG_TRACE("Stopping LVGL tick timer");
lv_port_tick_stop();
_is_in_ble_sleep_mode = true;
watch_power_management_change_power_state(WATCH_POWER_STATE_BLE_SLEEP);
}
else
{
@ -724,9 +812,10 @@ void gfx_task(void *param)
/* Let's sleep for real */
tls_pmu_sleep_start();
us_delay(100);
if(watch_peripherals_wakeup_source_is_user())
{
APP_LOG_INFO("User IO wakeup !");
/* Just to clear it off */
tls_pmu_timer0_stop();
watch_peripherals_wakeup_source_is_timer();
@ -734,7 +823,7 @@ void gfx_task(void *param)
}
/* 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());
@ -796,17 +885,30 @@ void gfx_task(void *param)
}
}
bool wrist_tilt = false ,touch_screen_touch = false;
if((wrist_tilt = watch_peripherals_accelerometer_wrist_wakeup_interrupt()) || ((touch_screen_touch = lv_port_indev_touched()) && _is_in_ble_sleep_mode))
bool wrist_tilt = false ,touch_screen_touch = false, notification_received = false;
if(
(wrist_tilt = watch_peripherals_accelerometer_wrist_wakeup_interrupt()) ||
(notification_received = notification_screen_new_notification_available(&notificationScreen)) ||
((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)
APP_LOG_DEBUG("Touch screen touch");
if(_is_in_ble_sleep_mode)
if(wrist_tilt)
{
_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();
watch_face_force_sync(&watchFace);