From 40a238b140c960f575193edaa9d73648ed710488 Mon Sep 17 00:00:00 2001 From: James McKenzie Date: Sun, 7 Apr 2024 15:42:46 +0100 Subject: missing parts of metric face --- main/metric.patch | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) diff --git a/main/metric.patch b/main/metric.patch index 0ff3dc7..df2993a 100644 --- a/main/metric.patch +++ b/main/metric.patch @@ -34,3 +34,264 @@ index 3557110..17fe809 100644 // New includes go above this line. #endif // MOVEMENT_FACES_H_ +diff --git a/movement/watch_faces/complication/metric_face.c b/movement/watch_faces/complication/metric_face.c +new file mode 100644 +index 0000000..9eaafbf +--- /dev/null ++++ b/movement/watch_faces/complication/metric_face.c +@@ -0,0 +1,198 @@ ++#include ++#include ++#include ++#include "watch.h" ++#include "watch_utility.h" ++#include "vsop87a_micro.h" // smaller size, less accurate ++#include "vsop87a_milli.h" ++#include "astrolib.h" ++#include "metric_face.h" ++ ++#define RATIO 8 ++ ++#include "equinox.c" ++ ++static const char *days[10] = ++ { "Pr", "Du", "Tr", "Qa", "Qi", "SH", "Sp", "Oc", "No", "De" }; ++ ++ ++static uint32_t ++jd_to_timestamp (double tjd) ++{ ++ tjd -= 2440587.5; ++ tjd *= 86400.; ++ return (uint32_t) floor (tjd); ++} ++ ++static uint32_t ++timestamp_start_of_year (int y) ++{ ++ double julian_equinox = autumnal_equinox (y); ++ julian_equinox += (2.3372305555 / 360); /* Offset of paris meridian from greenwich meridian */ ++ return jd_to_timestamp (julian_equinox); ++} ++ ++static int ++days_since_equinox (watch_date_time date_time) ++{ ++ uint32_t now = watch_utility_date_time_to_unix_time (date_time, 0); ++ uint32_t start_of_year = ++ timestamp_start_of_year (date_time.unit.year + 2020); ++ ++ start_of_year/=86400; ++ start_of_year*=86400; ++ ++ if (start_of_year > now) ++ start_of_year = ++ timestamp_start_of_year (date_time.unit.year + 2020 - 1); ++ ++ now -= start_of_year; ++ ++ now /= 86400; ++ ++ return (int) now; ++} ++ ++static void ++calculate_metric_date (metric_state_t * state, watch_date_time date_time) ++{ ++ int dse = days_since_equinox (date_time); ++ ++ state->m_day = (dse % 30) + 1; ++ state->m_wday = (dse % 10); ++ state->c_day = date_time.unit.day; ++ ++} ++ ++ ++static uint32_t ++date_time_to_ds (watch_date_time dt) ++{ ++ uint32_t ret; ++ ret = dt.unit.hour; ++ ret *= 60; ++ ret += dt.unit.minute; ++ ret *= 60; ++ ret += dt.unit.second; ++ return ret; ++} ++ ++static void ++_metric_face_sync (movement_settings_t * settings, metric_state_t * state) ++{ ++ watch_date_time date_time = watch_rtc_get_date_time (); ++ ++ (void) settings; ++ ++ if (date_time.unit.day != state->c_day) ++ calculate_metric_date (state, date_time); ++ ++ state->dt = date_time_to_ds (date_time) * RATIO; ++ state->resync_at = state->dt * (3600 * RATIO); ++ if (state->resync_at > (86400 * RATIO)) ++ state->resync_at = (86400 * RATIO); ++ ++} ++ ++static void ++_metric_face_update (movement_event_t event, movement_settings_t * settings, ++ metric_state_t * state, int show_secs) ++{ ++ uint64_t v; ++ char buf[14]; ++ ++ (void) event; ++ ++ if (state->dt >= state->resync_at) ++ _metric_face_sync (settings, state); ++ ++ v = state->dt; ++ v *= (uint64_t) 100000; ++ v /= (uint64_t) (RATIO * 86400); ++ ++ ++#if 0 ++ { ++ watch_date_time date_time = watch_rtc_get_date_time (); ++ printf ("%d %d\n", state->dt, date_time_to_ds (date_time) * RATIO); ++ } ++#endif ++ ++ ++ sprintf (buf, "%s%2d %05d", days[state->m_wday], (int) state->m_day, ++ (int) v); ++ ++ if (!show_secs) ++ { ++ buf[8] = ' '; ++ buf[9] = ' '; ++ } ++ ++ watch_display_string (buf, 0); ++} ++ ++void ++metric_face_setup (movement_settings_t * settings, uint8_t watch_face_index, ++ void **context_ptr) ++{ ++ (void) settings; ++ (void) watch_face_index; ++ if (*context_ptr == NULL) ++ { ++ *context_ptr = malloc (sizeof (metric_state_t)); ++ memset (*context_ptr, 0, sizeof (metric_state_t)); ++ } ++} ++ ++void ++metric_face_activate (movement_settings_t * settings, void *context) ++{ ++ metric_state_t *state = (metric_state_t *) context; ++ (void) settings; ++ movement_request_tick_frequency (RATIO); ++ state->resync_at = 0; ++} ++ ++bool ++metric_face_loop (movement_event_t event, movement_settings_t * settings, ++ void *context) ++{ ++ (void) settings; ++ metric_state_t *state = (metric_state_t *) context; ++ ++ switch (event.event_type) ++ { ++ case EVENT_ACTIVATE: ++ watch_set_colon (); ++ /*fall through */ ++ case EVENT_TICK: ++ state->dt++; ++ _metric_face_update (event, settings, state, 1); ++ break; ++ case EVENT_LOW_ENERGY_UPDATE: ++ state->dt += RATIO * 60; ++ _metric_face_update (event, settings, state, 0); ++ break; ++ case EVENT_ALARM_BUTTON_UP: ++ break; ++ case EVENT_ALARM_LONG_PRESS: ++ break; ++ case EVENT_TIMEOUT: ++ state->resync_at = 0; ++ break; ++ default: ++ movement_default_loop_handler (event, settings); ++ break; ++ } ++ ++ return true; ++} ++ ++void ++metric_face_resign (movement_settings_t * settings, void *context) ++{ ++ (void) settings; ++ metric_state_t *state = (metric_state_t *) context; ++ state->resync_at = 0; ++ state->c_day = 0; ++} +diff --git a/movement/watch_faces/complication/metric_face.h b/movement/watch_faces/complication/metric_face.h +new file mode 100644 +index 0000000..1968e38 +--- /dev/null ++++ b/movement/watch_faces/complication/metric_face.h +@@ -0,0 +1,51 @@ ++/* ++ * MIT License ++ * ++ * Copyright (c) 2022 Joey Castillo ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a copy ++ * of this software and associated documentation files (the "Software"), to deal ++ * in the Software without restriction, including without limitation the rights ++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++ * copies of the Software, and to permit persons to whom the Software is ++ * furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in all ++ * copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ++ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ++ * SOFTWARE. ++ */ ++ ++#ifndef METRIC_FACE_H_ ++#define METRIC_FACE_H_ ++ ++#include "movement.h" ++ ++typedef struct { ++ uint32_t dt; ++ uint32_t resync_at; ++ uint32_t m_day; ++ uint32_t m_wday; ++ uint32_t c_day; ++} metric_state_t; ++ ++void metric_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); ++void metric_face_activate(movement_settings_t *settings, void *context); ++bool metric_face_loop(movement_event_t event, movement_settings_t *settings, void *context); ++void metric_face_resign(movement_settings_t *settings, void *context); ++ ++#define metric_face ((const watch_face_t){ \ ++ metric_face_setup, \ ++ metric_face_activate, \ ++ metric_face_loop, \ ++ metric_face_resign, \ ++ NULL, \ ++}) ++ ++#endif // METRIC_FACE_H_ -- cgit v1.2.3