W800_Smart_Watch/src/W800 SDK v1.00.08/app/gfx/watch_face.h

96 lines
2.8 KiB
C

#ifndef WATCH_FACE_H
#define WATCH_FACE_H
#include "lvgl.h"
#include <time.h>
typedef void (*DateTimeCb_t)(struct tm * const dateTime);
typedef uint8_t (*BatteryIndicatorCb_t)(void);
typedef struct DateWindow
{
lv_obj_t *dateWindowWidget;
char dateWindowText[3];
} DateWindow_t;
typedef struct WatchHand
{
lv_obj_t *handImg;
float handAngle;
}WatchHand_t;
typedef struct BatteryIndicator
{
lv_obj_t *label;
lv_obj_t *battery_arc;
char text[7];
} BatteryIndicator_t;
/* Watch face context object */
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
WatchHand_t hourHand;
WatchHand_t minuteHand;
WatchHand_t secondHand;
WatchHand_t mediumHand24h;
lv_timer_t *handAnimationTimer;
lv_obj_t *display;
DateWindow_t dateWindow;
BatteryIndicator_t batteryIndicator;
struct tm dateTime;
} WatchFace_t;
/* Initializes the watch face context object */
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.
*/
void watch_face_register_date_time_cb(WatchFace_t * const watchFace, DateTimeCb_t 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.
*/
void watch_face_register_battery_indicator_cb(WatchFace_t * const watchFace, BatteryIndicatorCb_t BatteryIndicatorCb);
/**
* @brief Graphically builds the watch face
*
* @param watchFace a pointer to the watch face context structure.
*/
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.
*/
void watch_face_set_battery_indicator(WatchFace_t * const watchFace, uint8_t percentage);
/**
* @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 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);
#endif // WATCH_FACE_H