diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-11-22 17:35:50 -0500 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-11-22 17:35:50 -0500 |
commit | 7817e6696e438c8af74342ef10b576975a0e5448 (patch) | |
tree | 865dd18e9d77e404ed5bd44af87e33a2d7d44ef3 /movement/watch_faces/complications | |
parent | 0ca729eaba7cdca543bc563912095df98f2b3786 (diff) | |
parent | 25815ed4f649f3b908dbc40c926997eec2b095e8 (diff) | |
download | Sensor-Watch-7817e6696e438c8af74342ef10b576975a0e5448.tar.gz Sensor-Watch-7817e6696e438c8af74342ef10b576975a0e5448.tar.bz2 Sensor-Watch-7817e6696e438c8af74342ef10b576975a0e5448.zip |
Merge branch 'main' of github.com:joeycastillo/Sensor-Watch into main
Diffstat (limited to 'movement/watch_faces/complications')
-rw-r--r-- | movement/watch_faces/complications/beats_face.c | 2 | ||||
-rw-r--r-- | movement/watch_faces/complications/day_one_face.c | 177 | ||||
-rw-r--r-- | movement/watch_faces/complications/day_one_face.h | 31 | ||||
-rw-r--r-- | movement/watch_faces/complications/stopwatch_face.c | 76 | ||||
-rw-r--r-- | movement/watch_faces/complications/stopwatch_face.h | 26 |
5 files changed, 312 insertions, 0 deletions
diff --git a/movement/watch_faces/complications/beats_face.c b/movement/watch_faces/complications/beats_face.c index 73a82719..95a9aaef 100644 --- a/movement/watch_faces/complications/beats_face.c +++ b/movement/watch_faces/complications/beats_face.c @@ -26,6 +26,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void watch_date_time date_time; switch (event.event_type) { + case EVENT_ACTIVATE: case EVENT_TICK: date_time = watch_rtc_get_date_time(); beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, UTC_OFFSET); @@ -34,6 +35,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void watch_display_string(buf, 0); break; case EVENT_LOW_ENERGY_UPDATE: + if (!watch_tick_animation_is_running()) watch_start_tick_animation(432); date_time = watch_rtc_get_date_time(); beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, UTC_OFFSET); sprintf(buf, "bt %4d ", (int)beats); diff --git a/movement/watch_faces/complications/day_one_face.c b/movement/watch_faces/complications/day_one_face.c new file mode 100644 index 00000000..146f3f6f --- /dev/null +++ b/movement/watch_faces/complications/day_one_face.c @@ -0,0 +1,177 @@ +#include <stdlib.h> +#include <string.h> +#include "day_one_face.h" +#include "watch.h" + +uint32_t _day_one_face_juliandaynum(uint16_t year, uint16_t month, uint16_t day) { + // from here: https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation + return (1461 * (year + 4800 + (month - 14) / 12)) / 4 + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 - (3 * ((year + 4900 + (month - 14) / 12) / 100))/4 + day - 32075; +} + +void _day_one_face_update(day_one_state_t state) { + char buf[14]; + watch_date_time date_time = watch_rtc_get_date_time(); + uint32_t julian_date = _day_one_face_juliandaynum(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day); + uint32_t julian_birthdate = _day_one_face_juliandaynum(state.birth_year, state.birth_month, state.birth_day); + sprintf(buf, "DA %6ld", julian_date - julian_birthdate); + watch_display_string(buf, 0); +} + +void day_one_face_setup(movement_settings_t *settings, void ** context_ptr) { + (void) settings; + if (*context_ptr == NULL) { + *context_ptr = malloc(sizeof(day_one_state_t)); + memset(*context_ptr, 0, sizeof(day_one_state_t)); + movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2); + if (movement_birthdate.reg == 0) { + // if birth date is totally blank, set a reasonable starting date. this works well for anyone under 63, but + // you can keep pressing to go back to 1900; just pass the current year. also picked this date because if you + // set it to 1959-01-02, it counts up from the launch of Luna-1, the first spacecraft to leave the well. + movement_birthdate.bit.year = 1959; + movement_birthdate.bit.month = 1; + movement_birthdate.bit.day = 1; + watch_store_backup_data(movement_birthdate.reg, 2); + } + } +} + +void day_one_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + day_one_state_t *state = (day_one_state_t *)context; + + // stash the current year, useful in birthday setting mode. + watch_date_time date_time = watch_rtc_get_date_time(); + state->current_year = date_time.unit.year + WATCH_RTC_REFERENCE_YEAR; + // reset the current page to 0, display days alive. + state->current_page = 0; + + // fetch the user's birth date from the birthday register. + movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2); + state->birth_year = movement_birthdate.bit.year; + state->birth_month = movement_birthdate.bit.month; + state->birth_day = movement_birthdate.bit.day; +} + +bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + day_one_state_t *state = (day_one_state_t *)context; + + const uint8_t days_in_month[12] = {31, 29, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31}; + char buf[6]; + + switch (event.event_type) { + case EVENT_ACTIVATE: + _day_one_face_update(*state); + break; + case EVENT_LOW_ENERGY_UPDATE: + case EVENT_TICK: + if (state->current_page != 0) { + // if in settings mode, update whatever the current page is + switch (state->current_page) { + case 1: + watch_display_string("YR ", 0); + if (event.subsecond % 2) { + sprintf(buf, "%4d", state->birth_year); + watch_display_string(buf, 4); + } + break; + case 2: + watch_display_string("MO ", 0); + if (event.subsecond % 2) { + sprintf(buf, "%2d", state->birth_month); + watch_display_string(buf, 4); + } + break; + case 3: + watch_display_string("DA ", 0); + if (event.subsecond % 2) { + sprintf(buf, "%2d", state->birth_day); + watch_display_string(buf, 6); + } + break; + } + } else { + // otherwise, check if we have to update. the display only needs to change at midnight! + watch_date_time date_time = watch_rtc_get_date_time(); + if (date_time.unit.hour == 0 && date_time.unit.minute == 0 && date_time.unit.second == 0) { + _day_one_face_update(*state); + } + } + break; + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_BUTTON_DOWN: + // only illuminate if we're in display mode + if (state->current_page == 0) movement_illuminate_led(); + break; + case EVENT_LIGHT_BUTTON_UP: + // otherwise use the light button to advance settings pages. + if (state->current_page != 0) { + // go to next setting page... + state->current_page = (state->current_page + 1) % 4; + if (state->current_page == 0) { + // ...unless we've been pushed back to display mode. + movement_request_tick_frequency(1); + // force display since it normally won't update til midnight. + _day_one_face_update(*state); + } + } + break; + case EVENT_ALARM_BUTTON_UP: + // if we are on a settings page, increment whatever value we're setting. + if (state->current_page != 0) { + state->birthday_changed = true; + switch (state->current_page) { + case 1: + state->birth_year = state->birth_year + 1; + if (state->birth_year > state->current_year) state->birth_year = 1900; + break; + case 2: + state->birth_month = (state->birth_month % 12) + 1; + break; + case 3: + state->birth_day = state->birth_day + 1; + if (state->birth_day == 0 || state->birth_day > days_in_month[state->birth_month - 1]) { + state->birth_day = 1; + } + break; + } + } + break; + case EVENT_ALARM_LONG_PRESS: + // if we aren't already in settings mode, put us there. + if (state->current_page == 0) { + state->current_page++; + movement_request_tick_frequency(4); + } + break; + case EVENT_TIMEOUT: + // return home if we're on a settings page (this saves our changes when we resign). + if (state->current_page != 0) { + movement_move_to_face(0); + } + default: + break; + } + + return true; +} + +void day_one_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + day_one_state_t *state = (day_one_state_t *)context; + + movement_request_tick_frequency(1); + + // if the user changed their birth date, store it to the birth date register + if (state->birthday_changed) { + day_one_state_t *state = (day_one_state_t *)context; + movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2); + movement_birthdate.bit.year = state->birth_year; + movement_birthdate.bit.month = state->birth_month; + movement_birthdate.bit.day = state->birth_day; + watch_store_backup_data(movement_birthdate.reg, 2); + state->birthday_changed = false; + } +} diff --git a/movement/watch_faces/complications/day_one_face.h b/movement/watch_faces/complications/day_one_face.h new file mode 100644 index 00000000..06c7816e --- /dev/null +++ b/movement/watch_faces/complications/day_one_face.h @@ -0,0 +1,31 @@ +#ifndef DAY_ONE_FACE_H_ +#define DAY_ONE_FACE_H_ + +#include "movement.h" + +// The Day One face is designed to count upwards from the wearer's date of birth. It also functions as an +// interface for setting the birth date register, which other watch faces can use for various purposes. + +typedef struct { + uint8_t current_page; + uint16_t current_year; + uint16_t birth_year; + uint8_t birth_month; + uint8_t birth_day; + bool birthday_changed; +} day_one_state_t; + +void day_one_face_setup(movement_settings_t *settings, void ** context_ptr); +void day_one_face_activate(movement_settings_t *settings, void *context); +bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void day_one_face_resign(movement_settings_t *settings, void *context); + +static const watch_face_t day_one_face = { + day_one_face_setup, + day_one_face_activate, + day_one_face_loop, + day_one_face_resign, + NULL +}; + +#endif // DAY_ONE_FACE_H_ diff --git a/movement/watch_faces/complications/stopwatch_face.c b/movement/watch_faces/complications/stopwatch_face.c new file mode 100644 index 00000000..d1d1ee73 --- /dev/null +++ b/movement/watch_faces/complications/stopwatch_face.c @@ -0,0 +1,76 @@ +#include <stdlib.h> +#include <string.h> +#include "stopwatch_face.h" +#include "watch.h" + +void stopwatch_face_setup(movement_settings_t *settings, void ** context_ptr) { + (void) settings; + if (*context_ptr == NULL) *context_ptr = malloc(sizeof(stopwatch_state_t)); +} + +void stopwatch_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + memset(context, 0, sizeof(stopwatch_state_t)); +} + +bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + + stopwatch_state_t *stopwatch_state = (stopwatch_state_t *)context; + char buf[14]; + + switch (event.event_type) { + case EVENT_ACTIVATE: + watch_set_colon(); + stopwatch_state->running = false; + watch_display_string("st 00000", 0); + break; + case EVENT_TICK: + if (stopwatch_state->running) { + stopwatch_state->seconds++; + if (stopwatch_state->seconds == 60) { + stopwatch_state->minutes++; + stopwatch_state->seconds = 0; + } + if (stopwatch_state->minutes == 60) { + stopwatch_state->hours++; + stopwatch_state->minutes = 0; + } + } + + sprintf(buf, "st%2d%02d%02d", stopwatch_state->hours, stopwatch_state->minutes, stopwatch_state->seconds); + watch_display_string(buf, 0); + break; + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_BUTTON_DOWN: + movement_illuminate_led(); + if (!stopwatch_state->running) { + stopwatch_state->seconds = 0; + stopwatch_state->minutes = 0; + stopwatch_state->hours = 0; + watch_display_string("st 00000", 0); + } + break; + case EVENT_ALARM_BUTTON_DOWN: + stopwatch_state->running = !stopwatch_state->running; + break; + case EVENT_TIMEOUT: + // explicitly ignore the timeout event so we stay on screen + break; + case EVENT_LOW_ENERGY_UPDATE: + stopwatch_state->running = false; + watch_set_indicator(WATCH_INDICATOR_BELL); + break; + default: + break; + } + + return true; +} + +void stopwatch_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +}
\ No newline at end of file diff --git a/movement/watch_faces/complications/stopwatch_face.h b/movement/watch_faces/complications/stopwatch_face.h new file mode 100644 index 00000000..537c01ce --- /dev/null +++ b/movement/watch_faces/complications/stopwatch_face.h @@ -0,0 +1,26 @@ +#ifndef STOPWATCH_FACE_H_ +#define STOPWATCH_FACE_H_ + +#include "movement.h" + +typedef struct { + bool running; + uint8_t seconds; + uint8_t minutes; + uint8_t hours; +} stopwatch_state_t; + +void stopwatch_face_setup(movement_settings_t *settings, void ** context_ptr); +void stopwatch_face_activate(movement_settings_t *settings, void *context); +bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void stopwatch_face_resign(movement_settings_t *settings, void *context); + +static const watch_face_t stopwatch_face = { + stopwatch_face_setup, + stopwatch_face_activate, + stopwatch_face_loop, + stopwatch_face_resign, + NULL +}; + +#endif // STOPWATCH_FACE_H_
\ No newline at end of file |