Added a function to the API allowing to register a step count indicator callback used to refresh the step counter of the watch face twice or three time a second.

This commit is contained in:
Th3maz1ng 2023-04-02 21:14:57 +02:00
parent ad61388bf6
commit c26a88d21c
2 changed files with 56 additions and 9 deletions

View File

@ -40,6 +40,7 @@ static void gesture_event_cb(lv_event_t * e)
// We delete the timer
lv_timer_del(watchFace->batteryIndicator.lowBatteryAnimationTimer);
lv_timer_del(watchFace->handAnimationTimer);
lv_timer_del(watchFace->stepCounterRefreshTimer);
// We create the menu screen and switch to it
extern MenuScreen_t menuScreen;
menu_screen_create(&menuScreen);
@ -135,6 +136,18 @@ static void battery_timer_anim_cb(lv_timer_t *timer)
}
}
static void step_counter_refresh_cb(lv_timer_t *timer)
{
WatchFace_t *watchFace = timer->user_data;
if(watchFace->stepCounterIndicatorCb)
{
uint32_t steps = 0;
watchFace->stepCounterIndicatorCb(&steps);
watch_face_set_step_count_indicator(watchFace, steps);
}
}
static void set_battery_state_icon(WatchFace_t * const watchFace)
{
switch(watchFace->batteryIndicator.batteryState)
@ -205,6 +218,17 @@ void watch_face_register_battery_indicator_cb(WatchFace_t *const watchFace, Batt
watchFace->batteryIndicatorCb = BatteryIndicatorCb;
}
void watch_face_register_step_counter_indicator_cb(WatchFace_t * const watchFace, StepCounterIndicatorCb_t stepCounterIndicatorCb)
{
if(!watchFace)
{
LV_LOG_ERROR("NULL pointer given !");
return;
}
watchFace->stepCounterIndicatorCb = stepCounterIndicatorCb;
}
void watch_face_create(WatchFace_t * const watchFace)
{
if(!watchFace)
@ -404,8 +428,17 @@ void watch_face_create(WatchFace_t * const watchFace)
lv_timer_del(watchFace->handAnimationTimer);
watchFace->handAnimationTimer = NULL;
}
watchFace->handAnimationTimer = lv_timer_create(&(hand_timer_anim_cb), 199, watchFace);
//We create the timer which refreshes the step counter indicator
if(watchFace->stepCounterRefreshTimer)
{
LV_LOG_ERROR("stepCounterRefreshTimer should be NULL here !");
lv_timer_del(watchFace->stepCounterRefreshTimer);
watchFace->stepCounterRefreshTimer = NULL;
}
watchFace->stepCounterRefreshTimer = lv_timer_create(&(step_counter_refresh_cb), 300, watchFace);
}
void watch_face_set_battery_indicator(WatchFace_t * const watchFace, uint8_t levelInPercent, BatteryState_e batteryState)
@ -469,7 +502,7 @@ void watch_face_set_bluetooth_indicator(WatchFace_t * const watchFace, Bluetooth
_set_bluetooth_indicator(watchFace);
}
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t step_count)
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t stepCount)
{
if(!watchFace)
{
@ -477,12 +510,12 @@ void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t
return;
}
if(step_count < 1000)
sprintf(watchFace->stepCounter.text, "%u", step_count);
else if(step_count < 9996)
sprintf(watchFace->stepCounter.text, "%.2fk", step_count/1000.0);
if(stepCount < 1000)
sprintf(watchFace->stepCounter.text, "%u", stepCount);
else if(stepCount < 9996)
sprintf(watchFace->stepCounter.text, "%.2fk", stepCount/1000.0);
else
sprintf(watchFace->stepCounter.text, "%.1fk", step_count/1000.0);
sprintf(watchFace->stepCounter.text, "%.1fk", stepCount/1000.0);
if(!watchFace->display) return;
@ -499,6 +532,7 @@ void watch_face_destroy(WatchFace_t * const watchFace)
watchFace->display = NULL;
watchFace->handAnimationTimer = NULL;
watchFace->stepCounterRefreshTimer = NULL;
watchFace->dateWindow.dateWindowWidget = NULL;
watchFace->hourHand.handImg = NULL;
watchFace->minuteHand.handImg = NULL;

View File

@ -22,6 +22,8 @@ typedef void (*DateTimeCb_t)(struct tm * const dateTime);
typedef void (*BatteryIndicatorCb_t)(uint8_t *levelInPercent, BatteryState_e *batteryState);
typedef void (*StepCounterIndicatorCb_t)(uint32_t *stepCount);
typedef struct DateWindow
{
lv_obj_t *dateWindowWidget;
@ -61,11 +63,13 @@ typedef struct WatchFace
{
DateTimeCb_t dateTimeCb; //Call back function used to retrieve the date and time needed by the watch face
BatteryIndicatorCb_t batteryIndicatorCb; //Call back function used to update the battery level every minute
StepCounterIndicatorCb_t stepCounterIndicatorCb;
WatchHand_t hourHand;
WatchHand_t minuteHand;
WatchHand_t secondHand;
WatchHand_t mediumHand24h;
lv_timer_t *handAnimationTimer;
lv_timer_t *handAnimationTimer, *stepCounterRefreshTimer;
lv_obj_t *display;
DateWindow_t dateWindow;
BatteryIndicator_t batteryIndicator;
@ -94,6 +98,15 @@ void watch_face_register_date_time_cb(WatchFace_t * const watchFace, DateTimeCb_
*/
void watch_face_register_battery_indicator_cb(WatchFace_t * const watchFace, BatteryIndicatorCb_t BatteryIndicatorCb);
/**
* @brief Registers a call back function used to refresh the step counter indicator located on the watch face.
* The refreshing will be done twice a second.
*
* @param watchFace a pointer to the watch face context structure.
* @param StepCounterIndicatorCb a pointer to a function having the right definition.
*/
void watch_face_register_step_counter_indicator_cb(WatchFace_t * const watchFace, StepCounterIndicatorCb_t stepCounterIndicatorCb);
/**
* @brief Graphically builds the watch face
*
@ -131,7 +144,7 @@ void watch_face_set_bluetooth_indicator(WatchFace_t * const watchFace, Bluetooth
* @param watchFace a pointer to the watch face context structure.
* @param step_count the step count to show on the watch face.
*/
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t step_count);
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t stepCount);
/**
* @brief Forces the watch face to sync up with the RTC by calling the provided date_time_cb