From 8495d9723dea25e7101557c5ccc8519bdaf82091 Mon Sep 17 00:00:00 2001 From: anschrammh Date: Tue, 29 Apr 2025 07:43:22 +0200 Subject: [PATCH] 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. --- src/W800_SDK_v1.00.10/app/gfx/watch_face.c | 66 ++++++++++++++++++++-- src/W800_SDK_v1.00.10/app/gfx/watch_face.h | 51 ++++++++++------- 2 files changed, 94 insertions(+), 23 deletions(-) diff --git a/src/W800_SDK_v1.00.10/app/gfx/watch_face.c b/src/W800_SDK_v1.00.10/app/gfx/watch_face.c index 6899a72..60514a3 100644 --- a/src/W800_SDK_v1.00.10/app/gfx/watch_face.c +++ b/src/W800_SDK_v1.00.10/app/gfx/watch_face.c @@ -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) diff --git a/src/W800_SDK_v1.00.10/app/gfx/watch_face.h b/src/W800_SDK_v1.00.10/app/gfx/watch_face.h index b566e9f..812d257 100644 --- a/src/W800_SDK_v1.00.10/app/gfx/watch_face.h +++ b/src/W800_SDK_v1.00.10/app/gfx/watch_face.h @@ -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; @@ -88,7 +100,7 @@ void watch_face_init(WatchFace_t * const watchFace); /** * @brief Registers a call back function used by the watch face to retrieve the time and date - * + * * @param watchFace a pointer to the watch face context structure. * @param DateTimeCb a pointer to a function having the right definition. */ @@ -97,7 +109,7 @@ void watch_face_register_date_time_cb(WatchFace_t * const watchFace, DateTimeCb_ /** * @brief Registers a call back function used to refresh the battery indicator. * The refreshing is done every minute or every time the @ref watch_face_force_sync is called. - * + * * @param watchFace a pointer to the watch face context structure. * @param BatteryIndicatorCb a pointer to a function having the right definition. */ @@ -119,16 +131,9 @@ 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. - * + * * @param watchFace a pointer to the watch face context structure. * @param levelInPercent the level to set the indicator to in percent. * @param batteryState the current state of the battery : BATTERY_STATE_DISCHARGING, BATTERY_STATE_CHARGING or BATTERY_STATE_CHARGED @@ -137,7 +142,7 @@ void watch_face_set_battery_indicator(WatchFace_t * const watchFace, uint8_t lev /** * @brief Sets the current bluetooth state to display on the watch face - * + * * @param watchFace a pointer to the watch face context structure. * @param bluetoothState the state of the bluetooth modem to show, can be : BLUETOOTH_STATE_OFF, BLUETOOTH_STATE_ON or BLUETOOTH_STATE_CONNECTED */ @@ -145,31 +150,39 @@ void watch_face_set_bluetooth_indicator(WatchFace_t * const watchFace, Bluetooth /** * @brief Shows the current step count passed as parameter on the watch face. - * + * * @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 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 Returns true if the watch face screen is currently being used and displayed. + * @brief Show or hide the hour and minute hand on the watch face. * * @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 + * @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. */ bool watch_face_is_in_use(WatchFace_t * const watchFace); /** * @brief Frees all resources used by the WatchFace object. - * + * * @param watchFace a pointer to the watch face context structure. */ void watch_face_destroy(WatchFace_t * const watchFace);