summaryrefslogtreecommitdiffstats
path: root/movement/watch_faces
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-05-02 18:39:45 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2022-05-02 18:39:45 -0500
commitcd405735351035df657b64547b3dfc6a3d59db56 (patch)
tree1cdd5e6b0d0434d20f71045178a1e5e7377eb56f /movement/watch_faces
parent0004c30f422e702fd184a54e9f1d55da878bcd0f (diff)
parent35d1f5e647ac1b5fcccdb43ec58058587dd5301b (diff)
downloadSensor-Watch-cd405735351035df657b64547b3dfc6a3d59db56.tar.gz
Sensor-Watch-cd405735351035df657b64547b3dfc6a3d59db56.tar.bz2
Sensor-Watch-cd405735351035df657b64547b3dfc6a3d59db56.zip
Merge branch 'main' of github.com:joeycastillo/Sensor-Watch into motion-express
Diffstat (limited to 'movement/watch_faces')
-rw-r--r--movement/watch_faces/clock/mars_time_face.c165
-rw-r--r--movement/watch_faces/clock/mars_time_face.h58
-rw-r--r--movement/watch_faces/clock/simple_clock_face.c4
-rw-r--r--movement/watch_faces/clock/world_clock_face.c17
-rw-r--r--movement/watch_faces/complication/astronomy_face.c280
-rw-r--r--movement/watch_faces/complication/astronomy_face.h68
-rw-r--r--movement/watch_faces/complication/countdown_face.c10
-rw-r--r--movement/watch_faces/complication/counter_face.c90
-rw-r--r--movement/watch_faces/complication/counter_face.h51
-rw-r--r--movement/watch_faces/complication/moon_phase_face.c2
-rw-r--r--movement/watch_faces/complication/orrery_face.c232
-rw-r--r--movement/watch_faces/complication/orrery_face.h59
-rw-r--r--movement/watch_faces/complication/pulsometer_face.c2
-rw-r--r--movement/watch_faces/complication/sunrise_sunset_face.c4
-rw-r--r--movement/watch_faces/complication/tomato_face.c191
-rw-r--r--movement/watch_faces/complication/tomato_face.h63
-rw-r--r--movement/watch_faces/demo/lis2dw_logging_face.c (renamed from movement/watch_faces/demo/lis2dh_logging_face.c)83
-rw-r--r--movement/watch_faces/demo/lis2dw_logging_face.h (renamed from movement/watch_faces/demo/lis2dh_logging_face.h)36
-rw-r--r--movement/watch_faces/demo/voltage_face.c11
-rw-r--r--movement/watch_faces/sensor/thermistor_readout_face.c2
-rw-r--r--movement/watch_faces/sensor/thermistor_testing_face.c88
-rw-r--r--movement/watch_faces/sensor/thermistor_testing_face.h43
-rw-r--r--movement/watch_faces/settings/set_time_face.c4
23 files changed, 1471 insertions, 92 deletions
diff --git a/movement/watch_faces/clock/mars_time_face.c b/movement/watch_faces/clock/mars_time_face.c
new file mode 100644
index 00000000..7753ae72
--- /dev/null
+++ b/movement/watch_faces/clock/mars_time_face.c
@@ -0,0 +1,165 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "watch_utility.h"
+#include "mars_time_face.h"
+
+// note: lander coordinates come from Mars24's `marslandmarks.xml` file
+static double site_longitudes[MARS_TIME_NUM_SITES] = {
+ 0, // Mars Coordinated Time, at the meridian
+ 360.0 - 109.9, // Zhurong lander site
+ 360.0 - 77.45088572, // Perseverance lander site
+ 360.0 - 135.623447, // InSight lander site
+ 360.0 - 137.441635, // Curiosity lander site
+};
+
+static char site_names[MARS_TIME_NUM_SITES][3] = {
+ "MC",
+ "ZH",
+ "PE",
+ "IN",
+ "CU",
+};
+
+static uint16_t landing_sols[MARS_TIME_NUM_SITES] = {
+ 0,
+ 52387,
+ 52304,
+ 51511,
+ 49269,
+};
+
+typedef struct {
+ uint8_t hour;
+ uint8_t minute;
+ uint8_t second;
+} mars_clock_hms_t;
+
+static void _h_to_hms(mars_clock_hms_t *date_time, double h) {
+ unsigned int seconds = (unsigned int)(h * 3600.0);
+ date_time->hour = seconds / 3600;
+ seconds = seconds % 3600;
+ date_time->minute = floor(seconds / 60);
+ date_time->second = round(seconds % 60);
+}
+
+static void _update(movement_settings_t *settings, mars_time_state_t *state) {
+ char buf[11];
+ watch_date_time date_time = watch_rtc_get_date_time();
+ uint32_t now = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
+ // TODO: I'm skipping over some steps here.
+ // https://www.giss.nasa.gov/tools/mars24/help/algorithm.html
+ double jdut = 2440587.5 + ((double)now / 86400.0);
+ double jdtt = jdut + ((37.0 + 32.184) / 86400.0);
+ double jd2k = jdtt - 2451545.0;
+ double msd = ((jd2k - 4.5) / 1.0274912517) + 44796.0 - 0.0009626;
+ double mtc = fmod(24 * msd, 24);
+ double lmt;
+
+ if (state->current_site == 0) {
+ lmt = mtc;
+ } else {
+ double longitude = site_longitudes[state->current_site];
+ double lmst = mtc - ((longitude * 24.0) / 360.0);
+ lmt = fmod(lmst + 24, 24);
+ }
+
+ if (state->displaying_sol) {
+ // TODO: this is not right, mission sol should turn over at midnight local time?
+ uint16_t sol = floor(msd) - landing_sols[state->current_site];
+ if (sol < 1000) sprintf(&buf[0], "%s Sol%3d", site_names[state->current_site], sol);
+ else sprintf(&buf[0], "%s $%6d", site_names[state->current_site], sol);
+ watch_clear_colon();
+ watch_clear_indicator(WATCH_INDICATOR_24H);
+ } else {
+ mars_clock_hms_t mars_time;
+ _h_to_hms(&mars_time, lmt);
+ sprintf(&buf[0], "%s %02d%02d%02d", site_names[state->current_site], mars_time.hour, mars_time.minute, mars_time.second);
+ watch_set_colon();
+ watch_set_indicator(WATCH_INDICATOR_24H);
+ }
+
+ watch_display_string(buf, 0);
+}
+
+void mars_time_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(mars_time_state_t));
+ memset(*context_ptr, 0, sizeof(mars_time_state_t));
+ }
+}
+
+void mars_time_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ mars_time_state_t *state = (mars_time_state_t *)context;
+ (void) state;
+}
+
+bool mars_time_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ mars_time_state_t *state = (mars_time_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ case EVENT_TICK:
+ _update(settings, state);
+ break;
+ case EVENT_MODE_BUTTON_UP:
+ movement_move_to_next_face();
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ state->displaying_sol = !state->displaying_sol;
+ _update(settings, state);
+ break;
+ case EVENT_LIGHT_LONG_PRESS:
+ movement_illuminate_led();
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ state->current_site = (state->current_site + 1) % MARS_TIME_NUM_SITES;
+ _update(settings, state);
+ break;
+ case EVENT_TIMEOUT:
+ // TODO: make this lower power so we can avoid timeout
+ movement_move_to_face(0);
+ break;
+ case EVENT_LOW_ENERGY_UPDATE:
+ // TODO: low energy update
+ // watch_start_tick_animation(500);
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+void mars_time_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
diff --git a/movement/watch_faces/clock/mars_time_face.h b/movement/watch_faces/clock/mars_time_face.h
new file mode 100644
index 00000000..d34792e9
--- /dev/null
+++ b/movement/watch_faces/clock/mars_time_face.h
@@ -0,0 +1,58 @@
+/*
+ * 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 MARS_TIME_FACE_H_
+#define MARS_TIME_FACE_H_
+
+#include "movement.h"
+
+typedef enum {
+ MARS_TIME_MERIDIAN,
+ MARS_TIME_ZHURONG_SITE,
+ MARS_TIME_PERSEVERANCE_SITE,
+ MARS_TIME_INSIGHT_SITE,
+ MARS_TIME_CURIOSITY_SITE,
+ MARS_TIME_NUM_SITES,
+} mars_time_site_t;
+
+typedef struct {
+ mars_time_site_t current_site;
+ bool displaying_sol;
+} mars_time_state_t;
+
+void mars_time_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void mars_time_face_activate(movement_settings_t *settings, void *context);
+bool mars_time_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void mars_time_face_resign(movement_settings_t *settings, void *context);
+
+#define mars_time_face ((const watch_face_t){ \
+ mars_time_face_setup, \
+ mars_time_face_activate, \
+ mars_time_face_loop, \
+ mars_time_face_resign, \
+ NULL, \
+})
+
+#endif // MARS_TIME_FACE_H_
+
diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c
index ac9e2a1f..23f36672 100644
--- a/movement/watch_faces/clock/simple_clock_face.c
+++ b/movement/watch_faces/clock/simple_clock_face.c
@@ -82,11 +82,11 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
// ...and set the LAP indicator if low.
if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP);
- if (date_time.reg >> 6 == previous_date_time >> 6 && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
+ if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before seconds is the same, don't waste cycles setting those segments.
pos = 8;
sprintf(buf, "%02d", date_time.unit.second);
- } else if (date_time.reg >> 12 == previous_date_time >> 12 && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
+ } else if ((date_time.reg >> 12) == (previous_date_time >> 12) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before minutes is the same.
pos = 6;
sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second);
diff --git a/movement/watch_faces/clock/world_clock_face.c b/movement/watch_faces/clock/world_clock_face.c
index f0f7e954..4004bab2 100644
--- a/movement/watch_faces/clock/world_clock_face.c
+++ b/movement/watch_faces/clock/world_clock_face.c
@@ -44,14 +44,11 @@ void world_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_in
}
void world_clock_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
world_clock_state_t *state = (world_clock_state_t *)context;
state->current_screen = 0;
- state->previous_date_time = 0xFFFFFFFF;
if (watch_tick_animation_is_running()) watch_stop_tick_animation();
- if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
-
- watch_set_colon();
}
static bool world_clock_face_do_display_mode(movement_event_t event, movement_settings_t *settings, world_clock_state_t *state) {
@@ -63,6 +60,10 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
watch_date_time date_time;
switch (event.event_type) {
case EVENT_ACTIVATE:
+ if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
+ watch_set_colon();
+ state->previous_date_time = 0xFFFFFFFF;
+ // fall through
case EVENT_TICK:
case EVENT_LOW_ENERGY_UPDATE:
date_time = watch_rtc_get_date_time();
@@ -71,11 +72,11 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
previous_date_time = state->previous_date_time;
state->previous_date_time = date_time.reg;
- if (date_time.reg >> 6 == previous_date_time >> 6 && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
+ if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before seconds is the same, don't waste cycles setting those segments.
pos = 8;
sprintf(buf, "%02d", date_time.unit.second);
- } else if (date_time.reg >> 12 == previous_date_time >> 12 && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
+ } else if ((date_time.reg >> 12) == (previous_date_time >> 12) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before minutes is the same.
pos = 6;
sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second);
@@ -140,9 +141,9 @@ static bool _world_clock_face_do_settings_mode(movement_event_t event, movement_
if (state->current_screen > 3) {
movement_request_tick_frequency(1);
state->current_screen = 0;
- state->previous_date_time = 0xFFFFFFFF;
if (state->backup_register) watch_store_backup_data(state->settings.reg, state->backup_register);
- world_clock_face_do_display_mode(event, settings, state);
+ event.event_type = EVENT_ACTIVATE;
+ return world_clock_face_do_display_mode(event, settings, state);
}
break;
case EVENT_ALARM_BUTTON_DOWN:
diff --git a/movement/watch_faces/complication/astronomy_face.c b/movement/watch_faces/complication/astronomy_face.c
new file mode 100644
index 00000000..50e5221b
--- /dev/null
+++ b/movement/watch_faces/complication/astronomy_face.c
@@ -0,0 +1,280 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "astronomy_face.h"
+#include "watch_utility.h"
+
+#if __EMSCRIPTEN__
+#include <emscripten.h>
+#endif
+
+#define NUM_AVAILABLE_BODIES 9
+
+static const char astronomy_available_celestial_bodies[NUM_AVAILABLE_BODIES] = {
+ ASTRO_BODY_SUN,
+ ASTRO_BODY_MERCURY,
+ ASTRO_BODY_VENUS,
+ ASTRO_BODY_MOON,
+ ASTRO_BODY_MARS,
+ ASTRO_BODY_JUPITER,
+ ASTRO_BODY_SATURN,
+ ASTRO_BODY_URANUS,
+ ASTRO_BODY_NEPTUNE
+};
+
+static const char astronomy_celestial_body_names[NUM_AVAILABLE_BODIES][3] = {
+ "SO", // Sol
+ "ME", // Mercury
+ "VE", // Venus
+ "LU", // Moon (Luna)
+ "MA", // Mars
+ "JU", // Jupiter
+ "SA", // Saturn
+ "UR", // Uranus
+ "NE" // Neptune
+};
+
+static void _astronomy_face_recalculate(movement_settings_t *settings, astronomy_state_t *state) {
+#if __EMSCRIPTEN__
+ int16_t browser_lat = EM_ASM_INT({
+ return lat;
+ });
+ int16_t browser_lon = EM_ASM_INT({
+ return lon;
+ });
+ if ((watch_get_backup_data(1) == 0) && (browser_lat || browser_lon)) {
+ movement_location_t browser_loc;
+ browser_loc.bit.latitude = browser_lat;
+ browser_loc.bit.longitude = browser_lon;
+ watch_store_backup_data(browser_loc.reg, 1);
+ double lat = (double)browser_lat / 100.0;
+ double lon = (double)browser_lon / 100.0;
+ state->latitude_radians = astro_degrees_to_radians(lat);
+ state->longitude_radians = astro_degrees_to_radians(lon);
+ }
+#endif
+
+ watch_date_time date_time = watch_rtc_get_date_time();
+ uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
+ date_time = watch_utility_date_time_from_unix_time(timestamp, 0);
+ double jd = astro_convert_date_to_julian_date(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
+
+ astro_equatorial_coordinates_t radec_precession = astro_get_ra_dec(jd, astronomy_available_celestial_bodies[state->active_body_index], state->latitude_radians, state->longitude_radians, true);
+ printf("\nParams to convert: %f %f %f %f %f\n",
+ jd,
+ astro_radians_to_degrees(state->latitude_radians),
+ astro_radians_to_degrees(state->longitude_radians),
+ astro_radians_to_degrees(radec_precession.right_ascension),
+ astro_radians_to_degrees(radec_precession.declination));
+
+ astro_horizontal_coordinates_t horiz = astro_ra_dec_to_alt_az(jd, state->latitude_radians, state->longitude_radians, radec_precession.right_ascension, radec_precession.declination);
+ astro_equatorial_coordinates_t radec = astro_get_ra_dec(jd, astronomy_available_celestial_bodies[state->active_body_index], state->latitude_radians, state->longitude_radians, false);
+ state->altitude = astro_radians_to_degrees(horiz.altitude);
+ state->azimuth = astro_radians_to_degrees(horiz.azimuth);
+ state->right_ascension = astro_radians_to_hms(radec.right_ascension);
+ state->declination = astro_radians_to_dms(radec.declination);
+ state->distance = radec.distance;
+
+ printf("Calculated coordinates for %s on %f: \n\tRA = %f / %2dh %2dm %2ds\n\tDec = %f / %3d° %3d' %3d\"\n\tAzi = %f\n\tAlt = %f\n\tDst = %f AU\n",
+ astronomy_celestial_body_names[state->active_body_index],
+ jd,
+ astro_radians_to_degrees(radec.right_ascension),
+ state->right_ascension.hours,
+ state->right_ascension.minutes,
+ state->right_ascension.seconds,
+ astro_radians_to_degrees(radec.declination),
+ state->declination.degrees,
+ state->declination.minutes,
+ state->declination.seconds,
+ state->altitude,
+ state->azimuth,
+ state->distance);
+}
+
+static void _astronomy_face_update(movement_event_t event, movement_settings_t *settings, astronomy_state_t *state) {
+ char buf[16];
+ switch (state->mode) {
+ case ASTRONOMY_MODE_SELECTING_BODY:
+ watch_clear_colon();
+ watch_display_string(" Astro", 4);
+ if (event.subsecond % 2) {
+ watch_display_string((char *)astronomy_celestial_body_names[state->active_body_index], 0);
+ } else {
+ watch_display_string(" ", 0);
+ }
+ if (event.subsecond == 0) {
+ watch_display_string(" ", 2);
+ switch (state->animation_state) {
+ case 0:
+ watch_set_pixel(0, 7);
+ watch_set_pixel(2, 6);
+ break;
+ case 1:
+ watch_set_pixel(1, 7);
+ watch_set_pixel(2, 9);
+ break;
+ case 2:
+ watch_set_pixel(2, 7);
+ watch_set_pixel(0, 9);
+ break;
+ }
+ state->animation_state = (state->animation_state + 1) % 3;
+ }
+ break;
+ case ASTRONOMY_MODE_CALCULATING:
+ watch_clear_display();
+ // this takes a moment and locks the UI, flash C for "Calculating"
+ watch_start_character_blink('C', 100);
+ _astronomy_face_recalculate(settings, state);
+ watch_stop_blink();
+ state->mode = ASTRONOMY_MODE_DISPLAYING_ALT;
+ // fall through
+ case ASTRONOMY_MODE_DISPLAYING_ALT:
+ sprintf(buf, "%saL%6d", astronomy_celestial_body_names[state->active_body_index], (int16_t)round(state->altitude * 100));
+ watch_display_string(buf, 0);
+ break;
+ case ASTRONOMY_MODE_DISPLAYING_AZI:
+ sprintf(buf, "%saZ%6d", astronomy_celestial_body_names[state->active_body_index], (int16_t)round(state->azimuth * 100));
+ watch_display_string(buf, 0);
+ break;
+ case ASTRONOMY_MODE_DISPLAYING_RA:
+ watch_set_colon();
+ sprintf(buf, "ra H%02d%02d%02d", state->right_ascension.hours, state->right_ascension.minutes, state->right_ascension.seconds);
+ watch_display_string(buf, 0);
+ break;
+ case ASTRONOMY_MODE_DISPLAYING_DEC:
+ watch_clear_colon();
+ sprintf(buf, "de %3d%2d%2d", state->declination.degrees, state->declination.minutes, state->declination.seconds);
+ watch_display_string(buf, 0);
+ break;
+ case ASTRONOMY_MODE_DISPLAYING_DIST:
+ if (state->distance >= 0.00668456) {
+ // if >= 1,000,000 kilometers (all planets), we display distance in AU.
+ sprintf(buf, "diAU%6d", (uint16_t)round(state->distance * 100));
+ } else {
+ // otherwise distance in kilometers fits in 6 digits. This mode will only happen for Luna.
+ sprintf(buf, "di K%6ld", (uint32_t)round(state->distance * 149597871.0));
+ }
+ watch_display_string(buf, 0);
+ break;
+ case ASTRONOMY_MODE_NUM_MODES:
+ // this case does not happen, but we need it to silence a warning.
+ break;
+ }
+}
+
+void astronomy_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(astronomy_state_t));
+ memset(*context_ptr, 0, sizeof(astronomy_state_t));
+ }
+}
+
+void astronomy_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ astronomy_state_t *state = (astronomy_state_t *)context;
+ movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
+ int16_t lat_centi = (int16_t)movement_location.bit.latitude;
+ int16_t lon_centi = (int16_t)movement_location.bit.longitude;
+ double lat = (double)lat_centi / 100.0;
+ double lon = (double)lon_centi / 100.0;
+ state->latitude_radians = astro_degrees_to_radians(lat);
+ state->longitude_radians = astro_degrees_to_radians(lon);
+
+ movement_request_tick_frequency(4);
+}
+
+bool astronomy_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ astronomy_state_t *state = (astronomy_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ case EVENT_TICK:
+ _astronomy_face_update(event, settings, state);
+ break;
+ case EVENT_MODE_BUTTON_UP:
+ // You shouldn't need to change this case; Mode almost always moves to the next watch face.
+ movement_move_to_next_face();
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ // If you have other uses for the Light button, you can opt not to illuminate the LED for this event.
+ movement_illuminate_led();
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ switch (state->mode) {
+ case ASTRONOMY_MODE_SELECTING_BODY:
+ // advance to next celestial body (move to calculations with a long press)
+ state->active_body_index = (state->active_body_index + 1) % NUM_AVAILABLE_BODIES;
+ break;
+ case ASTRONOMY_MODE_CALCULATING:
+ // ignore button press during calculations
+ break;
+ case ASTRONOMY_MODE_DISPLAYING_DIST:
+ // at last mode, wrap around
+ state->mode = ASTRONOMY_MODE_DISPLAYING_ALT;
+ break;
+ default:
+ // otherwise, advance to next mode
+ state->mode++;
+ break;
+ }
+ _astronomy_face_update(event, settings, state);
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ if (state->mode == ASTRONOMY_MODE_SELECTING_BODY) {
+ // celestial body selected! this triggers a calculation in the update method.
+ state->mode = ASTRONOMY_MODE_CALCULATING;
+ movement_request_tick_frequency(1);
+ _astronomy_face_update(event, settings, state);
+ } else if (state->mode != ASTRONOMY_MODE_CALCULATING) {
+ // in all modes except "doing a calculation", return to the selection screen.
+ state->mode = ASTRONOMY_MODE_SELECTING_BODY;
+ movement_request_tick_frequency(4);
+ _astronomy_face_update(event, settings, state);
+ }
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ case EVENT_LOW_ENERGY_UPDATE:
+ // TODO?
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+void astronomy_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ astronomy_state_t *state = (astronomy_state_t *)context;
+ state->mode = ASTRONOMY_MODE_SELECTING_BODY;
+}
diff --git a/movement/watch_faces/complication/astronomy_face.h b/movement/watch_faces/complication/astronomy_face.h
new file mode 100644
index 00000000..f956955b
--- /dev/null
+++ b/movement/watch_faces/complication/astronomy_face.h
@@ -0,0 +1,68 @@
+/*
+ * 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 ASTRONOMY_FACE_H_
+#define ASTRONOMY_FACE_H_
+
+#include "movement.h"
+#include "astrolib.h"
+
+typedef enum {
+ ASTRONOMY_MODE_SELECTING_BODY = 0,
+ ASTRONOMY_MODE_CALCULATING,
+ ASTRONOMY_MODE_DISPLAYING_ALT,
+ ASTRONOMY_MODE_DISPLAYING_AZI,
+ ASTRONOMY_MODE_DISPLAYING_RA,
+ ASTRONOMY_MODE_DISPLAYING_DEC,
+ ASTRONOMY_MODE_DISPLAYING_DIST,
+ ASTRONOMY_MODE_NUM_MODES
+} astronomy_mode_t;
+
+typedef struct {
+ astronomy_mode_t mode;
+ uint8_t active_body_index;
+ uint8_t animation_state;
+ double latitude_radians; // this is the user location
+ double longitude_radians; // but in radians
+ astro_angle_hms_t right_ascension;
+ astro_angle_dms_t declination;
+ double altitude; // in decimal degrees
+ double azimuth; // in decimal degrees
+ double distance; // in AU
+} astronomy_state_t;
+
+void astronomy_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void astronomy_face_activate(movement_settings_t *settings, void *context);
+bool astronomy_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void astronomy_face_resign(movement_settings_t *settings, void *context);
+
+#define astronomy_face ((const watch_face_t){ \
+ astronomy_face_setup, \
+ astronomy_face_activate, \
+ astronomy_face_loop, \
+ astronomy_face_resign, \
+ NULL, \
+})
+
+#endif // ASTRONOMY_FACE_H_
diff --git a/movement/watch_faces/complication/countdown_face.c b/movement/watch_faces/complication/countdown_face.c
index a910e96c..81836f37 100644
--- a/movement/watch_faces/complication/countdown_face.c
+++ b/movement/watch_faces/complication/countdown_face.c
@@ -35,14 +35,6 @@
#define DEFAULT_MINUTES 3
-static uint32_t offset_date_time(uint32_t now, int8_t hours, int8_t minutes, int8_t seconds) {
- uint32_t new = now;
- new += hours * 60 * 60;
- new += minutes * 60;
- new += seconds;
- return new;
-}
-
static inline int32_t get_tz_offset(movement_settings_t *settings) {
return movement_timezone_offsets[settings->bit.time_zone] * 60;
}
@@ -52,7 +44,7 @@ static void start(countdown_state_t *state, movement_settings_t *settings) {
state->mode = cd_running;
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
- state->target_ts = offset_date_time(state->now_ts, 0, state->minutes, state->seconds);
+ state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, state->minutes, state->seconds);
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
movement_schedule_background_task(target_dt);
watch_set_indicator(WATCH_INDICATOR_BELL);
diff --git a/movement/watch_faces/complication/counter_face.c b/movement/watch_faces/complication/counter_face.c
new file mode 100644
index 00000000..ac0388ab
--- /dev/null
+++ b/movement/watch_faces/complication/counter_face.c
@@ -0,0 +1,90 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Shogo Okamoto
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "counter_face.h"
+#include "watch.h"
+
+void counter_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(counter_state_t));
+ memset(*context_ptr, 0, sizeof(counter_state_t));
+ }
+}
+
+void counter_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
+bool counter_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ (void) settings;
+
+ counter_state_t *state = (counter_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_MODE_BUTTON_UP:
+ movement_move_to_next_face();
+ break;
+ case EVENT_LIGHT_BUTTON_DOWN:
+ movement_illuminate_led();
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ state->counter_idx++; // increment counter index
+ if (state->counter_idx>99) { //0-99
+ state->counter_idx=0;//reset counter index
+ }
+ print_counter(state);
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ state->counter_idx=0; // reset counter index
+ print_counter(state);
+ break;
+ case EVENT_ACTIVATE:
+ print_counter(state);
+ break;
+ case EVENT_TIMEOUT:
+ // ignore timeout
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+// print counter index at the center of display.
+void print_counter(counter_state_t *state) {
+ char buf[14];
+ sprintf(buf, "CO %02d", state->counter_idx); // center of LCD display
+ watch_display_string(buf, 0);
+}
+
+void counter_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
diff --git a/movement/watch_faces/complication/counter_face.h b/movement/watch_faces/complication/counter_face.h
new file mode 100644
index 00000000..2d389a15
--- /dev/null
+++ b/movement/watch_faces/complication/counter_face.h
@@ -0,0 +1,51 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Shogo Okamoto
+ *
+ * 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 COUNTER_FACE_H_
+#define COUNTER_FACE_H_
+
+#include "movement.h"
+
+// Counter face is designed to count the number of running laps during excercises.
+typedef struct {
+ uint8_t counter_idx;
+} counter_state_t;
+
+
+void counter_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void counter_face_activate(movement_settings_t *settings, void *context);
+bool counter_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void counter_face_resign(movement_settings_t *settings, void *context);
+
+void print_counter(counter_state_t *state);
+
+#define counter_face ((const watch_face_t){ \
+ counter_face_setup, \
+ counter_face_activate, \
+ counter_face_loop, \
+ counter_face_resign, \
+ NULL, \
+})
+
+#endif // COUNTER_FACE_H_
diff --git a/movement/watch_faces/complication/moon_phase_face.c b/movement/watch_faces/complication/moon_phase_face.c
index 0ff7b254..eb919375 100644
--- a/movement/watch_faces/complication/moon_phase_face.c
+++ b/movement/watch_faces/complication/moon_phase_face.c
@@ -158,7 +158,7 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings,
case EVENT_MODE_BUTTON_UP:
movement_move_to_next_face();
break;
- case EVENT_LIGHT_BUTTON_UP:
+ case EVENT_LIGHT_BUTTON_DOWN:
movement_illuminate_led();
break;
case EVENT_ALARM_BUTTON_UP:
diff --git a/movement/watch_faces/complication/orrery_face.c b/movement/watch_faces/complication/orrery_face.c
new file mode 100644
index 00000000..3afced98
--- /dev/null
+++ b/movement/watch_faces/complication/orrery_face.c
@@ -0,0 +1,232 @@
+/*
+ * 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.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "orrery_face.h"
+#include "watch.h"
+#include "watch_utility.h"
+#include "vsop87a_micro.h" // smaller size, less accurate
+#include "vsop87a_milli.h"
+#include "astrolib.h"
+
+#define NUM_AVAILABLE_BODIES 9
+
+static const char orrery_celestial_body_names[NUM_AVAILABLE_BODIES][3] = {
+ "ME", // Mercury
+ "VE", // Venus
+ "EA", // Earth
+ "LU", // Moon (Luna)
+ "MA", // Mars
+ "JU", // Jupiter
+ "SA", // Saturn
+ "UR", // Uranus
+ "NE" // Neptune
+};
+
+static void _orrery_face_recalculate(movement_settings_t *settings, orrery_state_t *state) {
+ watch_date_time date_time = watch_rtc_get_date_time();
+ uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
+ date_time = watch_utility_date_time_from_unix_time(timestamp, 0);
+ double jd = astro_convert_date_to_julian_date(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
+ double et = astro_convert_jd_to_julian_millenia_since_j2000(jd);
+ double r[3] = {0};
+
+ switch(state->active_body_index) {
+ case 0:
+ vsop87a_milli_getMercury(et, r);
+ break;
+ case 1:
+ vsop87a_milli_getVenus(et, r);
+ break;
+ case 2:
+ vsop87a_milli_getEarth(et, r);
+ break;
+ case 3:
+ {
+ double earth[3];
+ double emb[3];
+ vsop87a_milli_getEarth(et, earth);
+ vsop87a_milli_getEmb(et, emb);
+ vsop87a_milli_getMoon(earth, emb, r);
+ }
+ break;
+ case 4:
+ vsop87a_milli_getMars(et, r);
+ break;
+ case 5:
+ vsop87a_milli_getJupiter(et, r);
+ break;
+ case 6:
+ vsop87a_milli_getSaturn(et, r);
+ break;
+ case 7:
+ vsop87a_milli_getUranus(et, r);
+ break;
+ case 8:
+ vsop87a_milli_getNeptune(et, r);
+ break;
+ }
+ state->coords[0] = r[0];
+ state->coords[1] = r[1];
+ state->coords[2] = r[2];
+}
+
+static void _orrery_face_update(movement_event_t event, movement_settings_t *settings, orrery_state_t *state) {
+ char buf[11];
+ switch (state->mode) {
+ case ORRERY_MODE_SELECTING_BODY:
+ watch_display_string("Orrery", 4);
+ if (event.subsecond % 2) {
+ watch_display_string((char *)orrery_celestial_body_names[state->active_body_index], 0);
+ } else {
+ watch_display_string(" ", 0);
+ }
+ if (event.subsecond == 0) {
+ watch_display_string(" ", 2);
+ switch (state->animation_state) {
+ case 0:
+ watch_set_pixel(0, 7);
+ watch_set_pixel(2, 6);
+ break;
+ case 1:
+ watch_set_pixel(1, 7);
+ watch_set_pixel(2, 9);
+ break;
+ case 2:
+ watch_set_pixel(2, 7);
+ watch_set_pixel(0, 9);
+ break;
+ }
+ state->animation_state = (state->animation_state + 1) % 3;
+ }
+ break;
+ case ORRERY_MODE_CALCULATING:
+ watch_clear_display();
+ // this takes a moment and locks the UI, flash C for "Calculating"
+ watch_start_character_blink('C', 100);
+ _orrery_face_recalculate(settings, state);
+ watch_stop_blink();
+ state->mode = ORRERY_MODE_DISPLAYING_X;
+ // fall through
+ case ORRERY_MODE_DISPLAYING_X:
+ sprintf(buf, "%s X%6d", orrery_celestial_body_names[state->active_body_index], (int16_t)round(state->coords[0] * 100));
+ watch_display_string(buf, 0);
+ break;
+ case ORRERY_MODE_DISPLAYING_Y:
+ sprintf(buf, "%s Y%6d", orrery_celestial_body_names[state->active_body_index], (int16_t)round(state->coords[1] * 100));
+ watch_display_string(buf, 0);
+ break;
+ case ORRERY_MODE_DISPLAYING_Z:
+ sprintf(buf, "%s Z%6d", orrery_celestial_body_names[state->active_body_index], (int16_t)round(state->coords[2] * 100));
+ watch_display_string(buf, 0);
+ break;
+ case ORRERY_MODE_NUM_MODES:
+ // this case does not happen, but we need it to silence a warning.
+ break;
+ }
+}
+
+void orrery_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(orrery_state_t));
+ memset(*context_ptr, 0, sizeof(orrery_state_t));
+ }
+}
+
+void orrery_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+ movement_request_tick_frequency(4);
+}
+
+bool orrery_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ (void) settings;
+ orrery_state_t *state = (orrery_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ case EVENT_TICK:
+ _orrery_face_update(event, settings, state);
+ break;
+ case EVENT_MODE_BUTTON_UP:
+ movement_move_to_next_face();
+ break;
+ case EVENT_LIGHT_BUTTON_DOWN:
+ movement_illuminate_led();
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ switch (state->mode) {
+ case ORRERY_MODE_SELECTING_BODY:
+ // advance to next celestial body (move to calculations with a long press)
+ state->active_body_index = (state->active_body_index + 1) % NUM_AVAILABLE_BODIES;
+ break;
+ case ORRERY_MODE_CALCULATING:
+ // ignore button press during calculations
+ break;
+ case ORRERY_MODE_DISPLAYING_Z:
+ // at last mode, wrap around
+ state->mode = ORRERY_MODE_DISPLAYING_X;
+ break;
+ default:
+ // otherwise, advance to next mode
+ state->mode++;
+ break;
+ }
+ _orrery_face_update(event, settings, state);
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ if (state->mode == ORRERY_MODE_SELECTING_BODY) {
+ // celestial body selected! this triggers a calculation in the update method.
+ state->mode = ORRERY_MODE_CALCULATING;
+ movement_request_tick_frequency(1);
+ _orrery_face_update(event, settings, state);
+ } else if (state->mode != ORRERY_MODE_CALCULATING) {
+ // in all modes except "doing a calculation", return to the selection screen.
+ state->mode = ORRERY_MODE_SELECTING_BODY;
+ movement_request_tick_frequency(4);
+ _orrery_face_update(event, settings, state);
+ }
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+void orrery_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ orrery_state_t *state = (orrery_state_t *)context;
+ state->mode = ORRERY_MODE_SELECTING_BODY;
+}
diff --git a/movement/watch_faces/complication/orrery_face.h b/movement/watch_faces/complication/orrery_face.h
new file mode 100644
index 00000000..98060d97
--- /dev/null
+++ b/movement/watch_faces/complication/orrery_face.h
@@ -0,0 +1,59 @@
+/*
+ * 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 ORRERY_FACE_H_
+#define ORRERY_FACE_H_
+
+#include "movement.h"
+
+typedef enum {
+ ORRERY_MODE_SELECTING_BODY = 0,
+ ORRERY_MODE_CALCULATING,
+ ORRERY_MODE_DISPLAYING_X,
+ ORRERY_MODE_DISPLAYING_Y,
+ ORRERY_MODE_DISPLAYING_Z,
+ ORRERY_MODE_NUM_MODES
+} orrery_mode_t;
+
+typedef struct {
+ orrery_mode_t mode;
+ uint8_t active_body_index;
+ double coords[3];
+ uint8_t animation_state;
+} orrery_state_t;
+
+void orrery_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void orrery_face_activate(movement_settings_t *settings, void *context);
+bool orrery_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void orrery_face_resign(movement_settings_t *settings, void *context);
+
+#define orrery_face ((const watch_face_t){ \
+ orrery_face_setup, \
+ orrery_face_activate, \
+ orrery_face_loop, \
+ orrery_face_resign, \
+ NULL, \
+})
+
+#endif // ORRERY_FACE_H_
diff --git a/movement/watch_faces/complication/pulsometer_face.c b/movement/watch_faces/complication/pulsometer_face.c
index 28ca1a50..1d6f2086 100644
--- a/movement/watch_faces/complication/pulsometer_face.c
+++ b/movement/watch_faces/complication/pulsometer_face.c
@@ -73,7 +73,7 @@ bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings,
watch_display_string(" Alarn", 4);
break;
case 2:
- watch_display_string("+ Count ", 0);
+ watch_display_string("* Count ", 0);
break;
case 3:
watch_display_string(" 30Beats ", 0);
diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c
index fef9b4df..8dea812e 100644
--- a/movement/watch_faces/complication/sunrise_sunset_face.c
+++ b/movement/watch_faces/complication/sunrise_sunset_face.c
@@ -188,10 +188,10 @@ static void _sunrise_sunset_face_update_settings_display(movement_event_t event,
switch (state->page) {
case 1:
- sprintf(buf, "LA %c %04d", state->working_latitude.sign ? '-' : 'F', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude))); // F looks sorta like a plus sign in position 1
+ sprintf(buf, "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)));
break;
case 2:
- sprintf(buf, "LO %c%05d", state->working_longitude.sign ? '-' : 'F', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)));
+ sprintf(buf, "LO %c%05d", state->working_longitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)));
break;
}
if (event.subsecond % 2) {
diff --git a/movement/watch_faces/complication/tomato_face.c b/movement/watch_faces/complication/tomato_face.c
new file mode 100644
index 00000000..37798daf
--- /dev/null
+++ b/movement/watch_faces/complication/tomato_face.c
@@ -0,0 +1,191 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Wesley Ellis
+ *
+ * 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 NONINFtomato_ringEMENT. 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "tomato_face.h"
+#include "watch_utility.h"
+
+static uint8_t focus_min = 25;
+static uint8_t break_min = 5;
+
+static inline int32_t get_tz_offset(movement_settings_t *settings) {
+ return movement_timezone_offsets[settings->bit.time_zone] * 60;
+}
+
+static uint8_t get_length(tomato_state_t *state) {
+ uint8_t length;
+ if (state->kind == tomato_focus) {
+ length = focus_min;
+ } else {
+ length = break_min;
+ }
+
+ return length;
+}
+
+static void tomato_start(tomato_state_t *state, movement_settings_t *settings) {
+ watch_date_time now = watch_rtc_get_date_time();
+ int8_t length = (int8_t) get_length(state);
+
+ state->mode = tomato_run;
+ state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
+ state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, length, 0);
+ watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
+ movement_schedule_background_task(target_dt);
+ watch_set_indicator(WATCH_INDICATOR_BELL);
+}
+
+static void tomato_draw(tomato_state_t *state) {
+ char buf[16];
+
+ uint32_t delta;
+ div_t result;
+ uint8_t min = 0;
+ uint8_t sec = 0;
+ char kind;
+
+ if (state->kind == tomato_break) {
+ kind = 'b';
+ } else {
+ kind = 'f';
+ }
+
+ switch (state->mode) {
+ case tomato_run:
+ delta = state->target_ts - state->now_ts;
+ result = div(delta, 60);
+ min = result.quot;
+ sec = result.rem;
+ break;
+ case tomato_ready:
+ min = get_length(state);
+ sec = 0;
+ break;
+ }
+ sprintf(buf, "TO %c%2d%02d%2d", kind, min, sec, state->done_count);
+ watch_display_string(buf, 0);
+}
+
+static void tomato_reset(tomato_state_t *state) {
+ state->mode = tomato_ready;
+ movement_cancel_background_task();
+ watch_clear_indicator(WATCH_INDICATOR_BELL);
+}
+
+static void tomato_ring(tomato_state_t *state) {
+ movement_play_signal();
+ tomato_reset(state);
+ if (state->kind == tomato_focus) {
+ state->kind = tomato_break;
+ state->done_count++;
+ } else {
+ state->kind = tomato_focus;
+ }
+}
+
+void tomato_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(tomato_state_t));
+ tomato_state_t *state = (tomato_state_t*)*context_ptr;
+ memset(*context_ptr, 0, sizeof(tomato_state_t));
+ state->mode=tomato_ready;
+ state->kind= tomato_focus;
+ state->done_count = 0;
+ }
+}
+
+void tomato_face_activate(movement_settings_t *settings, void *context) {
+ tomato_state_t *state = (tomato_state_t *)context;
+ if (state->mode == tomato_run) {
+ watch_date_time now = watch_rtc_get_date_time();
+ state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
+ }
+ watch_set_colon();
+}
+
+bool tomato_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ tomato_state_t *state = (tomato_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ tomato_draw(state);
+ break;
+ case EVENT_TICK:
+ if (state->mode == tomato_run) {
+ state->now_ts++;
+ }
+ tomato_draw(state);
+ break;
+ case EVENT_MODE_BUTTON_UP:
+ movement_move_to_next_face();
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ movement_illuminate_led();
+ if (state->mode == tomato_ready) {
+ if (state->kind == tomato_break) {
+ state->kind = tomato_focus;
+ } else {
+ state->kind = tomato_break;
+ }
+ }
+ tomato_draw(state);
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ switch(state->mode) {
+ case tomato_run:
+ tomato_reset(state);
+ break;
+ case tomato_ready:
+ tomato_start(state, settings);
+ break;
+ }
+ tomato_draw(state);
+
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ state->done_count = 0;
+ break;
+ case EVENT_BACKGROUND_TASK:
+ tomato_ring(state);
+ tomato_draw(state);
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+void tomato_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
diff --git a/movement/watch_faces/complication/tomato_face.h b/movement/watch_faces/complication/tomato_face.h
new file mode 100644
index 00000000..5404ad11
--- /dev/null
+++ b/movement/watch_faces/complication/tomato_face.h
@@ -0,0 +1,63 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Wesley Ellis
+ *
+ * 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 TOMATO_FACE_H_
+#define TOMATO_FACE_H_
+
+#include "movement.h"
+
+typedef enum {
+ tomato_ready,
+ tomato_run,
+ // to_pause, // TODO implement pausing
+} tomato_mode;
+
+typedef enum {
+ tomato_break,
+ tomato_focus,
+} tomato_kind;
+
+typedef struct {
+ uint32_t target_ts;
+ uint32_t now_ts;
+ tomato_mode mode;
+ tomato_kind kind;
+ uint8_t done_count;
+} tomato_state_t;
+
+void tomato_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void tomato_face_activate(movement_settings_t *settings, void *context);
+bool tomato_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void tomato_face_resign(movement_settings_t *settings, void *context);
+
+#define tomato_face ((const watch_face_t){ \
+ tomato_face_setup, \
+ tomato_face_activate, \
+ tomato_face_loop, \
+ tomato_face_resign, \
+ NULL, \
+})
+
+#endif // TOMATO_FACE_H_
+
diff --git a/movement/watch_faces/demo/lis2dh_logging_face.c b/movement/watch_faces/demo/lis2dw_logging_face.c
index 31d1cad7..0e63e41e 100644
--- a/movement/watch_faces/demo/lis2dh_logging_face.c
+++ b/movement/watch_faces/demo/lis2dw_logging_face.c
@@ -24,8 +24,8 @@
#include <stdlib.h>
#include <string.h>
-#include "lis2dh_logging_face.h"
-#include "lis2dh.h"
+#include "lis2dw_logging_face.h"
+#include "lis2dw.h"
#include "watch.h"
// This watch face is just for testing; if we want to build accelerometer support, it will likely have to be part of Movement itself.
@@ -36,14 +36,14 @@
// Pressing the alarm button enters the log mode, where the main display shows the number of interrupts detected in each of the last
// 24 hours (the hour is shown in the top right digit and AM/PM indicator, if the clock is set to 12 hour mode)
-static void _lis2dh_logging_face_update_display(movement_settings_t *settings, lis2dh_logger_state_t *logger_state, lis2dh_interrupt_state interrupt_state) {
+static void _lis2dw_logging_face_update_display(movement_settings_t *settings, lis2dw_logger_state_t *logger_state, lis2dw_wakeup_source wakeup_source) {
char buf[14];
char time_indication_character;
int8_t pos;
watch_date_time date_time;
if (logger_state->log_ticks) {
- pos = (logger_state->data_points - 1 - logger_state->display_index) % LIS2DH_LOGGING_NUM_DATA_POINTS;
+ pos = (logger_state->data_points - 1 - logger_state->display_index) % LIS2DW_LOGGING_NUM_DATA_POINTS;
if (pos < 0) {
watch_clear_colon();
sprintf(buf, "NO data ");
@@ -80,9 +80,9 @@ static void _lis2dh_logging_face_update_display(movement_settings_t *settings, l
if ((59 - date_time.unit.second) < 10) time_indication_character = '0' + (59 - date_time.unit.second);
else time_indication_character = (date_time.unit.second % 2) ? 'i' : '_';
sprintf(buf, "%c%c%c%c%2d%2d%2d",
- (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) ? 'Y' : ' ',
- (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) ? 'X' : ' ',
- (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) ? 'Z' : ' ',
+ (wakeup_source & LIS2DW_WAKEUP_SRC_WAKEUP_Y) ? 'Y' : ' ',
+ (wakeup_source & LIS2DW_WAKEUP_SRC_WAKEUP_X) ? 'X' : ' ',
+ (wakeup_source & LIS2DW_WAKEUP_SRC_WAKEUP_Z) ? 'Z' : ' ',
time_indication_character,
logger_state->interrupts[0],
logger_state->interrupts[1],
@@ -91,7 +91,7 @@ static void _lis2dh_logging_face_update_display(movement_settings_t *settings, l
watch_display_string(buf, 0);
}
-static void _lis2dh_logging_face_log_data(lis2dh_logger_state_t *logger_state) {
+static void _lis2dw_logging_face_log_data(lis2dw_logger_state_t *logger_state) {
watch_date_time date_time = watch_rtc_get_date_time();
// we get this call 15 minutes late; i.e. at 6:15 we're logging events for 6:00.
// so: if we're at the top of the hour, roll the hour back too (7:00 task logs data for 6:45)
@@ -100,7 +100,7 @@ static void _lis2dh_logging_face_log_data(lis2dh_logger_state_t *logger_state) {
// // then roll the minute back.
date_time.unit.minute = (date_time.unit.minute + 45) % 60;
- size_t pos = logger_state->data_points % LIS2DH_LOGGING_NUM_DATA_POINTS;
+ size_t pos = logger_state->data_points % LIS2DW_LOGGING_NUM_DATA_POINTS;
logger_state->data[pos].timestamp.reg = date_time.reg;
logger_state->data[pos].x_interrupts = logger_state->x_interrupts_this_hour;
logger_state->data[pos].y_interrupts = logger_state->y_interrupts_this_hour;
@@ -111,28 +111,25 @@ static void _lis2dh_logging_face_log_data(lis2dh_logger_state_t *logger_state) {
logger_state->z_interrupts_this_hour = 0;
}
-void lis2dh_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
+void lis2dw_logging_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(lis2dh_logger_state_t));
- memset(*context_ptr, 0, sizeof(lis2dh_logger_state_t));
- gpio_set_pin_direction(A0, GPIO_DIRECTION_OUT);
- gpio_set_pin_function(A0, GPIO_PIN_FUNCTION_OFF);
- gpio_set_pin_level(A0, true);
+ *context_ptr = malloc(sizeof(lis2dw_logger_state_t));
+ memset(*context_ptr, 0, sizeof(lis2dw_logger_state_t));
watch_enable_i2c();
- lis2dh_begin();
- lis2dh_set_data_rate(LIS2DH_DATA_RATE_10_HZ);
- lis2dh_configure_aoi_int1(
- LIS2DH_INTERRUPT_CONFIGURATION_OR |
- LIS2DH_INTERRUPT_CONFIGURATION_X_HIGH_ENABLE |
- LIS2DH_INTERRUPT_CONFIGURATION_Y_HIGH_ENABLE |
- LIS2DH_INTERRUPT_CONFIGURATION_Z_HIGH_ENABLE, 96, 0, true);
+ lis2dw_begin();
+ lis2dw_set_low_power_mode(LIS2DW_LP_MODE_2); // lowest power 14-bit mode, 25 Hz is 3.5 µA @ 1.8V w/ low noise, 3µA without
+ lis2dw_set_low_noise_mode(true); // consumes a little more power
+ lis2dw_set_range(LIS2DW_CTRL6_VAL_RANGE_4G);
+ lis2dw_set_data_rate(LIS2DW_DATA_RATE_25_HZ); // is this enough for training?
+ // threshold is 1/64th of full scale, so for a FS of ±4G this is 1.25G
+ lis2dw_configure_wakeup_int1(10, true, false);
}
}
-void lis2dh_logging_face_activate(movement_settings_t *settings, void *context) {
- lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
+void lis2dw_logging_face_activate(movement_settings_t *settings, void *context) {
+ lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context;
// force two settings: never enter low energy mode, and always snap back to screen 0.
// this assumes the accelerometer face is first in the watch_faces list.
settings->bit.le_interval = 0;
@@ -140,12 +137,13 @@ void lis2dh_logging_face_activate(movement_settings_t *settings, void *context)
logger_state->display_index = 0;
logger_state->log_ticks = 0;
- watch_enable_digital_input(A1);
+ watch_enable_digital_input(A0);
}
-bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
- lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
- lis2dh_interrupt_state interrupt_state = 0;
+bool lis2dw_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context;
+ lis2dw_wakeup_source wakeup_source = 0;
+ lis2dw_interrupt_source interrupt_source = 0;
switch (event.event_type) {
case EVENT_MODE_BUTTON_UP:
@@ -157,13 +155,13 @@ bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *setti
case EVENT_LIGHT_BUTTON_DOWN:
logger_state->axis_index = (logger_state->axis_index + 1) % 4;
logger_state->log_ticks = 255;
- _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
+ _lis2dw_logging_face_update_display(settings, logger_state, wakeup_source);
break;
case EVENT_ALARM_BUTTON_UP:
- if (logger_state->log_ticks) logger_state->display_index = (logger_state->display_index + 1) % LIS2DH_LOGGING_NUM_DATA_POINTS;
+ if (logger_state->log_ticks) logger_state->display_index = (logger_state->display_index + 1) % LIS2DW_LOGGING_NUM_DATA_POINTS;
logger_state->log_ticks = 255;
logger_state->axis_index = 0;
- _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
+ _lis2dw_logging_face_update_display(settings, logger_state, wakeup_source);
break;
case EVENT_ACTIVATE:
case EVENT_TICK:
@@ -172,20 +170,21 @@ bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *setti
} else {
logger_state->display_index = 0;
}
- if (watch_get_pin_level(A1)) {
+ interrupt_source = lis2dw_get_interrupt_source();
+ if (interrupt_source) {
watch_set_indicator(WATCH_INDICATOR_SIGNAL);
- interrupt_state = lis2dh_get_int1_state();
+ wakeup_source = lis2dw_get_wakeup_source();
logger_state->interrupts[0]++;
- if (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) logger_state->x_interrupts_this_hour++;
- if (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) logger_state->y_interrupts_this_hour++;
- if (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) logger_state->z_interrupts_this_hour++;
+ if (wakeup_source & LIS2DW_WAKEUP_SRC_WAKEUP_X) logger_state->x_interrupts_this_hour++;
+ if (wakeup_source & LIS2DW_WAKEUP_SRC_WAKEUP_Y) logger_state->y_interrupts_this_hour++;
+ if (wakeup_source & LIS2DW_WAKEUP_SRC_WAKEUP_Z) logger_state->z_interrupts_this_hour++;
} else {
watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
}
- _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
+ _lis2dw_logging_face_update_display(settings, logger_state, wakeup_source);
break;
case EVENT_BACKGROUND_TASK:
- _lis2dh_logging_face_log_data(logger_state);
+ _lis2dw_logging_face_log_data(logger_state);
break;
default:
break;
@@ -194,15 +193,15 @@ bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *setti
return true;
}
-void lis2dh_logging_face_resign(movement_settings_t *settings, void *context) {
+void lis2dw_logging_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
- watch_disable_digital_input(A1);
+ watch_disable_digital_input(A0);
}
-bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context) {
+bool lis2dw_logging_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
- lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
+ lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context;
watch_date_time date_time = watch_rtc_get_date_time();
// this is kind of an abuse of the API, but, let's use the 1 minute tick to shift all our data over.
diff --git a/movement/watch_faces/demo/lis2dh_logging_face.h b/movement/watch_faces/demo/lis2dw_logging_face.h
index 49366542..f6ea85e7 100644
--- a/movement/watch_faces/demo/lis2dh_logging_face.h
+++ b/movement/watch_faces/demo/lis2dw_logging_face.h
@@ -22,20 +22,20 @@
* SOFTWARE.
*/
-#ifndef LIS2DH_LOGGING_FACE_H_
-#define LIS2DH_LOGGING_FACE_H_
+#ifndef LIS2DW_LOGGING_FACE_H_
+#define LIS2DW_LOGGING_FACE_H_
#include "movement.h"
#include "watch.h"
-#define LIS2DH_LOGGING_NUM_DATA_POINTS (96)
+#define LIS2DW_LOGGING_NUM_DATA_POINTS (96)
typedef struct {
watch_date_time timestamp;
uint32_t x_interrupts;
uint32_t y_interrupts;
uint32_t z_interrupts;
-} lis2dh_logger_data_point_t;
+} lis2dw_logger_data_point_t;
typedef struct {
uint8_t display_index; // the index we are displaying on screen
@@ -46,21 +46,21 @@ typedef struct {
uint32_t x_interrupts_this_hour; // the number of interrupts we have logged in the last hour
uint32_t y_interrupts_this_hour; // the number of interrupts we have logged in the last hour
uint32_t z_interrupts_this_hour; // the number of interrupts we have logged in the last hour
- lis2dh_logger_data_point_t data[LIS2DH_LOGGING_NUM_DATA_POINTS];
-} lis2dh_logger_state_t;
+ lis2dw_logger_data_point_t data[LIS2DW_LOGGING_NUM_DATA_POINTS];
+} lis2dw_logger_state_t;
-void lis2dh_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void lis2dh_logging_face_activate(movement_settings_t *settings, void *context);
-bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void lis2dh_logging_face_resign(movement_settings_t *settings, void *context);
-bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context);
+void lis2dw_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void lis2dw_logging_face_activate(movement_settings_t *settings, void *context);
+bool lis2dw_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void lis2dw_logging_face_resign(movement_settings_t *settings, void *context);
+bool lis2dw_logging_face_wants_background_task(movement_settings_t *settings, void *context);
-#define lis2dh_logging_face ((const watch_face_t){ \
- lis2dh_logging_face_setup, \
- lis2dh_logging_face_activate, \
- lis2dh_logging_face_loop, \
- lis2dh_logging_face_resign, \
- lis2dh_logging_face_wants_background_task, \
+#define lis2dw_logging_face ((const watch_face_t){ \
+ lis2dw_logging_face_setup, \
+ lis2dw_logging_face_activate, \
+ lis2dw_logging_face_loop, \
+ lis2dw_logging_face_resign, \
+ lis2dw_logging_face_wants_background_task, \
})
-#endif // LIS2DH_LOGGING_FACE_H_
+#endif // LIS2DW_LOGGING_FACE_H_
diff --git a/movement/watch_faces/demo/voltage_face.c b/movement/watch_faces/demo/voltage_face.c
index 24346aa3..2a568d2c 100644
--- a/movement/watch_faces/demo/voltage_face.c
+++ b/movement/watch_faces/demo/voltage_face.c
@@ -29,7 +29,11 @@
static void _voltage_face_update_display(void) {
char buf[14];
+
+ watch_enable_adc();
float voltage = (float)watch_get_vcc_voltage() / 1000.0;
+ watch_disable_adc();
+
sprintf(buf, "BA %4.2f V", voltage);
// printf("%s\n", buf);
watch_display_string(buf, 0);
@@ -44,9 +48,6 @@ void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index,
void voltage_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
- watch_enable_adc();
- // if we set the reference voltage here, watch_get_vcc_voltage won't do it over and over
- watch_set_analog_reference_voltage(ADC_REFERENCE_INTREF);
}
bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
@@ -73,6 +74,7 @@ bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, vo
}
break;
case EVENT_LOW_ENERGY_UPDATE:
+ watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
watch_display_string("BA SLEEP ", 0);
break;
default:
@@ -85,7 +87,4 @@ bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, vo
void voltage_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
- // make sure to restore the default in the end.
- watch_set_analog_reference_voltage(ADC_REFERENCE_VCC);
- watch_disable_adc();
}
diff --git a/movement/watch_faces/sensor/thermistor_readout_face.c b/movement/watch_faces/sensor/thermistor_readout_face.c
index b97c8432..28106022 100644
--- a/movement/watch_faces/sensor/thermistor_readout_face.c
+++ b/movement/watch_faces/sensor/thermistor_readout_face.c
@@ -63,7 +63,7 @@ bool thermistor_readout_face_loop(movement_event_t event, movement_settings_t *s
case EVENT_LIGHT_BUTTON_DOWN:
movement_illuminate_led();
break;
- case EVENT_ALARM_BUTTON_UP:
+ case EVENT_ALARM_BUTTON_DOWN:
settings->bit.use_imperial_units = !settings->bit.use_imperial_units;
_thermistor_readout_face_update_display(settings->bit.use_imperial_units);
break;
diff --git a/movement/watch_faces/sensor/thermistor_testing_face.c b/movement/watch_faces/sensor/thermistor_testing_face.c
new file mode 100644
index 00000000..f50e0567
--- /dev/null
+++ b/movement/watch_faces/sensor/thermistor_testing_face.c
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "thermistor_testing_face.h"
+#include "thermistor_driver.h"
+#include "watch.h"
+
+// This watch face is designed for testing temperature sensor boards.
+// It displays temperature readings at a relatively fast rate of 8 Hz,
+// and disables low energy mode so my testing device doesn't sleep.
+// You more than likely want to use thermistor_readout_face instead.
+
+static void _thermistor_testing_face_update_display(bool in_fahrenheit) {
+ thermistor_driver_enable();
+ float temperature_c = thermistor_driver_get_temperature();
+ char buf[14];
+ if (in_fahrenheit) {
+ sprintf(buf, "%4.1f#F", temperature_c * 1.8 + 32.0);
+ } else {
+ sprintf(buf, "%4.1f#C", temperature_c);
+ }
+ watch_display_string(buf, 4);
+ thermistor_driver_disable();
+}
+
+void thermistor_testing_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
+ (void) watch_face_index;
+ (void) context_ptr;
+ // force one setting: never enter low energy mode.
+ // I'm using this watch face to test the temperature sensor boards; there's no need for it.
+ settings->bit.le_interval = 0;
+}
+
+void thermistor_testing_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+ watch_display_string("TE", 0);
+ movement_request_tick_frequency(8);
+}
+
+bool thermistor_testing_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ (void) context;
+ switch (event.event_type) {
+ case EVENT_MODE_BUTTON_UP:
+ movement_move_to_next_face();
+ break;
+ case EVENT_ALARM_BUTTON_DOWN:
+ settings->bit.use_imperial_units = !settings->bit.use_imperial_units;
+ _thermistor_testing_face_update_display(settings->bit.use_imperial_units);
+ break;
+ case EVENT_ACTIVATE:
+ case EVENT_TICK:
+ _thermistor_testing_face_update_display(settings->bit.use_imperial_units);
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+void thermistor_testing_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
diff --git a/movement/watch_faces/sensor/thermistor_testing_face.h b/movement/watch_faces/sensor/thermistor_testing_face.h
new file mode 100644
index 00000000..656f58d5
--- /dev/null
+++ b/movement/watch_faces/sensor/thermistor_testing_face.h
@@ -0,0 +1,43 @@
+/*
+ * 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 THERMISTOR_TESTING_FACE_H_
+#define THERMISTOR_TESTING_FACE_H_
+
+#include "movement.h"
+
+void thermistor_testing_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void thermistor_testing_face_activate(movement_settings_t *settings, void *context);
+bool thermistor_testing_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void thermistor_testing_face_resign(movement_settings_t *settings, void *context);
+
+#define thermistor_testing_face ((const watch_face_t){ \
+ thermistor_testing_face_setup, \
+ thermistor_testing_face_activate, \
+ thermistor_testing_face_loop, \
+ thermistor_testing_face_resign, \
+ NULL, \
+})
+
+#endif // THERMISTOR_TESTING_FACE_H_
diff --git a/movement/watch_faces/settings/set_time_face.c b/movement/watch_faces/settings/set_time_face.c
index f0e7dc6c..af5421f1 100644
--- a/movement/watch_faces/settings/set_time_face.c
+++ b/movement/watch_faces/settings/set_time_face.c
@@ -102,8 +102,8 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
sprintf(buf, "%s %2d%02d%02d", set_time_face_titles[current_page], date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
} else {
sprintf(buf, "%s %2d%02d%02d", set_time_face_titles[current_page], (date_time.unit.hour % 12) ? (date_time.unit.hour % 12) : 12, date_time.unit.minute, date_time.unit.second);
- if (date_time.unit.hour > 12) watch_set_indicator(WATCH_INDICATOR_PM);
- else watch_clear_indicator(WATCH_INDICATOR_PM);
+ if (date_time.unit.hour < 12) watch_clear_indicator(WATCH_INDICATOR_PM);
+ else watch_set_indicator(WATCH_INDICATOR_PM);
}
} else if (current_page < 6) {
watch_clear_colon();