2021-10-17 00:58:14 +08:00
|
|
|
#ifndef MOVEMENT_H_
|
|
|
|
#define MOVEMENT_H_
|
2021-09-28 13:06:37 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
// TODO: none of this is implemented
|
|
|
|
typedef union {
|
|
|
|
struct {
|
2021-10-17 01:48:16 +08:00
|
|
|
uint32_t reserved : 16;
|
2021-10-04 00:31:51 +08:00
|
|
|
uint32_t clock_mode_24h : 1; // determines whether clock should use 12 or 24 hour mode.
|
2021-10-04 06:49:21 +08:00
|
|
|
uint32_t button_should_sound : 1; // if true, pressing a button emits a sound.
|
2021-10-17 01:40:17 +08:00
|
|
|
uint32_t le_inactivity_interval : 3;// 0 to disable low energy mode, or an inactivity interval for going into low energy mode.
|
2021-10-04 00:31:51 +08:00
|
|
|
uint32_t led_duration : 3; // how many seconds to shine the LED for, or 0 to disable it.
|
|
|
|
uint32_t led_red_color : 4; // for general purpose illumination, the red LED value (0-15)
|
|
|
|
uint32_t led_green_color : 4; // for general purpose illumination, the green LED value (0-15)
|
2021-09-28 13:06:37 +08:00
|
|
|
} bit;
|
|
|
|
uint32_t value;
|
2021-10-17 01:23:23 +08:00
|
|
|
} movement_settings_t;
|
2021-09-28 13:06:37 +08:00
|
|
|
|
2021-10-04 12:37:58 +08:00
|
|
|
typedef enum {
|
2021-09-28 13:06:37 +08:00
|
|
|
EVENT_NONE = 0, // There is no event to report.
|
2021-10-17 01:14:52 +08:00
|
|
|
EVENT_ACTIVATE, // Your watch face is entering the foreground.
|
|
|
|
EVENT_TICK, // Most common event type. Your watch face is being called from the tick callback.
|
2021-10-17 01:40:17 +08:00
|
|
|
EVENT_LOW_POWER_TICK, // The watch is in low energy mode, and you are getting the once-per-minute tick callback.
|
2021-09-28 13:06:37 +08:00
|
|
|
EVENT_LIGHT_BUTTON_DOWN, // The light button has been pressed, but not yet released.
|
|
|
|
EVENT_LIGHT_BUTTON_UP, // The light button was pressed and released.
|
|
|
|
EVENT_LIGHT_LONG_PRESS, // The light button was held for >2 seconds, and released.
|
|
|
|
EVENT_MODE_BUTTON_DOWN, // The mode button has been pressed, but not yet released.
|
|
|
|
EVENT_MODE_BUTTON_UP, // The mode button was pressed and released.
|
|
|
|
EVENT_MODE_LONG_PRESS, // The mode button was held for >2 seconds, and released.
|
|
|
|
EVENT_ALARM_BUTTON_DOWN, // The alarm button has been pressed, but not yet released.
|
|
|
|
EVENT_ALARM_BUTTON_UP, // The alarm button was pressed and released.
|
|
|
|
EVENT_ALARM_LONG_PRESS, // The alarm button was held for >2 seconds, and released.
|
2021-10-17 01:23:23 +08:00
|
|
|
} movement_event_type_t;
|
2021-10-04 12:37:58 +08:00
|
|
|
|
2021-10-06 22:25:28 +08:00
|
|
|
typedef struct {
|
|
|
|
uint8_t event_type;
|
|
|
|
uint8_t subsecond;
|
2021-10-17 01:23:23 +08:00
|
|
|
} movement_event_t;
|
2021-09-28 13:06:37 +08:00
|
|
|
|
2021-10-17 01:23:23 +08:00
|
|
|
typedef void (*watch_face_setup)(movement_settings_t *settings, void ** context_ptr);
|
|
|
|
typedef void (*watch_face_activate)(movement_settings_t *settings, void *context);
|
|
|
|
typedef bool (*watch_face_loop)(movement_event_t event, movement_settings_t *settings, void *context);
|
|
|
|
typedef void (*watch_face_resign)(movement_settings_t *settings, void *context);
|
2021-09-28 13:06:37 +08:00
|
|
|
|
2021-10-06 22:25:28 +08:00
|
|
|
typedef struct {
|
2021-10-17 01:14:52 +08:00
|
|
|
watch_face_setup setup;
|
|
|
|
watch_face_activate activate;
|
|
|
|
watch_face_loop loop;
|
|
|
|
watch_face_resign resign;
|
2021-10-17 01:23:23 +08:00
|
|
|
} watch_face_t;
|
2021-09-28 13:06:37 +08:00
|
|
|
|
2021-10-06 22:25:28 +08:00
|
|
|
typedef struct {
|
2021-09-28 13:06:37 +08:00
|
|
|
// properties stored in BACKUP register
|
2021-10-17 01:28:52 +08:00
|
|
|
movement_settings_t settings;
|
2021-09-28 13:06:37 +08:00
|
|
|
|
|
|
|
// transient properties
|
2021-10-17 01:14:52 +08:00
|
|
|
int16_t current_watch_face;
|
2021-10-17 01:28:52 +08:00
|
|
|
int16_t next_watch_face;
|
2021-10-17 01:14:52 +08:00
|
|
|
bool watch_face_changed;
|
2021-09-28 13:06:37 +08:00
|
|
|
|
|
|
|
// LED stuff
|
|
|
|
uint8_t light_ticks;
|
|
|
|
bool led_on;
|
|
|
|
|
|
|
|
// button tracking for long press
|
|
|
|
uint8_t light_down_timestamp;
|
|
|
|
uint8_t mode_down_timestamp;
|
|
|
|
uint8_t alarm_down_timestamp;
|
2021-10-04 06:49:21 +08:00
|
|
|
|
2021-10-17 01:40:17 +08:00
|
|
|
// low energy mode countdown
|
|
|
|
int32_t le_mode_ticks;
|
2021-10-04 08:37:15 +08:00
|
|
|
|
2021-10-04 06:49:21 +08:00
|
|
|
// stuff for subsecond tracking
|
|
|
|
uint8_t tick_frequency;
|
|
|
|
uint8_t last_second;
|
|
|
|
uint8_t subsecond;
|
2021-10-17 01:23:23 +08:00
|
|
|
} movement_state_t;
|
2021-09-28 13:06:37 +08:00
|
|
|
|
2021-10-17 01:14:52 +08:00
|
|
|
void movement_move_to_face(uint8_t watch_face_index);
|
|
|
|
void movement_move_to_next_face();
|
2021-10-17 00:58:14 +08:00
|
|
|
void movement_illuminate_led();
|
|
|
|
void movement_request_tick_frequency(uint8_t freq);
|
2021-09-28 13:06:37 +08:00
|
|
|
|
2021-10-17 00:58:14 +08:00
|
|
|
#endif // MOVEMENT_H_
|