Added a 3 second timer to show the watch's minute and hour hands again after being hidden and added header comments to both files.

This commit is contained in:
anschrammh 2025-04-29 07:43:22 +02:00
parent 766369fa9d
commit 8495d9723d
2 changed files with 94 additions and 23 deletions

View File

@ -1,3 +1,13 @@
/**
* @file watch_face.c
* @author Anatole SCHRAMM-HENRY
* @brief Watch face source file implementing API functions.
* @version 0.1
* @date 2025-04-29
*
* @copyright MIT
*/
#include "lvgl.h"
#include "watch_face.h"
#include "menu_screen.h"
@ -99,6 +109,8 @@ static void gesture_event_cb(lv_event_t *e)
// We delete the timer
lv_timer_del(watchFace->batteryIndicator.lowBatteryAnimationTimer);
lv_timer_del(watchFace->handAnimationTimer);
// Checking if timer is not NULL here because it could have been deleted already
if(watchFace->handHideTimer)lv_timer_del(watchFace->handHideTimer);
lv_timer_del(watchFace->stepCounterRefreshTimer);
// We create the menu screen and switch to it
extern MenuScreen_t menuScreen;
@ -227,6 +239,13 @@ static void set_battery_state_icon(WatchFace_t * const watchFace)
break;
}
}
static void hide_hour_and_minutes_hand_timer_cb(lv_timer_t *timer)
{
WatchFace_t *watchFace = timer->user_data;
watchFace->handHideTimer = NULL;
watch_face_show_hour_and_minute_hands(watchFace, true);
}
static void hide_hour_and_minutes_hand_cb(lv_event_t *e)
{
@ -234,13 +253,28 @@ static void hide_hour_and_minutes_hand_cb(lv_event_t *e)
if(lv_obj_has_flag(watchFace->hourHand.handImg, LV_OBJ_FLAG_HIDDEN))
{
lv_obj_clear_flag(watchFace->hourHand.handImg, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(watchFace->minuteHand.handImg, LV_OBJ_FLAG_HIDDEN);
if(watchFace->handHideTimer)
{
/* Make the timer execute now to re-display hands
and cleanly free the timer */
lv_timer_ready(watchFace->handHideTimer);
}
}
else
{
lv_obj_add_flag(watchFace->hourHand.handImg, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(watchFace->minuteHand.handImg, LV_OBJ_FLAG_HIDDEN);
// Let's hide the hands
watch_face_show_hour_and_minute_hands(watchFace, false);
// Let's start the hand hide timer
if(watchFace->handHideTimer)
{
LV_LOG_ERROR("handHideTimer should be NULL here !");
lv_timer_del(watchFace->handHideTimer);
watchFace->handHideTimer = NULL;
}
watchFace->handHideTimer = lv_timer_create(&(hide_hour_and_minutes_hand_timer_cb), 3000, watchFace);
// After the timer expires once, delete it by setting the repeat count to 1
lv_timer_set_repeat_count(watchFace->handHideTimer, 1);
}
}
@ -584,6 +618,7 @@ void watch_face_destroy(WatchFace_t * const watchFace)
watchFace->display = NULL;
watchFace->handAnimationTimer = NULL;
watchFace->handHideTimer = NULL;
watchFace->stepCounterRefreshTimer = NULL;
watchFace->dateWindow.dateWindowWidget = NULL;
watchFace->hourHand.handImg = NULL;
@ -611,6 +646,29 @@ void watch_face_force_sync(WatchFace_t *const watchFace)
update_watch_hands_angles(watchFace, 0);
}
void watch_face_show_hour_and_minute_hands(WatchFace_t * const watchFace, bool show)
{
if(!watchFace)
{
LV_LOG_ERROR("NULL pointer given !");
return;
}
if(watch_face_is_in_use(watchFace))
{
if(show && lv_obj_has_flag(watchFace->hourHand.handImg, LV_OBJ_FLAG_HIDDEN))
{
lv_obj_clear_flag(watchFace->hourHand.handImg, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(watchFace->minuteHand.handImg, LV_OBJ_FLAG_HIDDEN);
}
else if(!show && !lv_obj_has_flag(watchFace->hourHand.handImg, LV_OBJ_FLAG_HIDDEN))
{
lv_obj_add_flag(watchFace->hourHand.handImg, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(watchFace->minuteHand.handImg, LV_OBJ_FLAG_HIDDEN);
}
}
}
bool watch_face_is_in_use(WatchFace_t * const watchFace)
{
if(!watchFace)

View File

@ -1,3 +1,13 @@
/**
* @file watch_face.h
* @author Anatole SCHRAMM-HENRY
* @brief Watch face header file exposing related APIs.
* @version 0.1
* @date 2025-04-29
*
* @copyright MIT
*/
#ifndef WATCH_FACE_H
#define WATCH_FACE_H
@ -69,7 +79,9 @@ typedef struct WatchFace
WatchHand_t minuteHand;
WatchHand_t secondHand;
WatchHand_t mediumHand24h;
lv_timer_t *handAnimationTimer, *stepCounterRefreshTimer;
lv_timer_t *handAnimationTimer;
lv_timer_t *stepCounterRefreshTimer;
lv_timer_t *handHideTimer;
lv_obj_t *display;
DateWindow_t dateWindow;
BatteryIndicator_t batteryIndicator;
@ -119,13 +131,6 @@ void watch_face_register_step_counter_indicator_cb(WatchFace_t * const watchFace
*/
void watch_face_create(WatchFace_t * const watchFace);
/**
* @brief Sets the battery indicator to the given value in percent.
*
* @param watchFace a pointer to the watch face context structure.
* @param percentage the value to set the indicator to in percent.
*/
/**
* @brief Sets the battery level in percent as well as it's current state to draw on the watch face.
*
@ -152,18 +157,26 @@ void watch_face_set_bluetooth_indicator(WatchFace_t * const watchFace, Bluetooth
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
* @brief Forces the watch face to sync up with the RTC by calling the provided date_time_cb.
*
* @param watchFace a pointer to the watch face context structure.
*/
void watch_face_force_sync(WatchFace_t * const watchFace);
/**
* @brief Show or hide the hour and minute hand on the watch face.
*
* @param watchFace a pointer to the watch face context structure.
* @param show a boolean value indicating if hands should be shown or not.
*/
void watch_face_show_hour_and_minute_hands(WatchFace_t * const watchFace, bool show);
/**
* @brief Returns true if the watch face screen is currently being used and displayed.
*
* @param watchFace a pointer to the watch face context structure.
* @return true if the watch face screen is being used
* @return false if the watch face screen is not being used/currently displayed
* @return true if the watch face screen is being used.
* @return false if the watch face screen is not being used/currently displayed.
*/
bool watch_face_is_in_use(WatchFace_t * const watchFace);