From 2e5e094bb38ee15f65b97db674fc2623ce3b99c7 Mon Sep 17 00:00:00 2001 From: PrimmR Date: Sun, 6 Jul 2025 16:47:12 +0100 Subject: [PATCH] Update Kitchen Conversions Face for Second Movement (#24) * Basic second movement support * Switch alarm and light button functionality --- movement_faces.h | 1 + watch-faces.mk | 1 + .../complication/kitchen_conversions_face.c | 113 ++++++++++-------- .../complication/kitchen_conversions_face.h | 10 +- 4 files changed, 72 insertions(+), 53 deletions(-) rename {legacy/watch_faces => watch-faces}/complication/kitchen_conversions_face.c (77%) rename {legacy/watch_faces => watch-faces}/complication/kitchen_conversions_face.h (91%) diff --git a/movement_faces.h b/movement_faces.h index d2d36e4a..23ffc44e 100644 --- a/movement_faces.h +++ b/movement_faces.h @@ -51,6 +51,7 @@ #include "nanosec_face.h" #include "mars_time_face.h" #include "peek_memory_face.h" +#include "kitchen_conversions_face.h" #include "periodic_table_face.h" #include "squash_face.h" #include "totp_face.h" diff --git a/watch-faces.mk b/watch-faces.mk index 2c60f09b..71a939d9 100644 --- a/watch-faces.mk +++ b/watch-faces.mk @@ -28,5 +28,6 @@ SRCS += \ ./watch-faces/settings/nanosec_face.c \ ./watch-faces/io/chirpy_demo_face.c \ ./watch-faces/io/irda_upload_face.c \ + ./watch-faces/complication/kitchen_conversions_face.c \ ./watch-faces/complication/periodic_table_face.c \ # New watch faces go above this line. diff --git a/legacy/watch_faces/complication/kitchen_conversions_face.c b/watch-faces/complication/kitchen_conversions_face.c similarity index 77% rename from legacy/watch_faces/complication/kitchen_conversions_face.c rename to watch-faces/complication/kitchen_conversions_face.c index 5c1d1dd8..7428de3b 100644 --- a/legacy/watch_faces/complication/kitchen_conversions_face.c +++ b/watch-faces/complication/kitchen_conversions_face.c @@ -26,6 +26,8 @@ #include #include "kitchen_conversions_face.h" +#include "watch_common_display.h" + typedef struct { char name[6]; // Name to display on selection @@ -41,8 +43,9 @@ typedef struct #define TEMP 1 #define VOL 2 -// Names of measurements -static char measures[MEASURES_COUNT][6] = {"WeIght", " Temp", " VOL"}; +// Names of measurements (classic & custom LCD) +static char measures[MEASURES_COUNT][7] = {"n&ass", " Temp", " VOL"}; +static char measures_custom[MEASURES_COUNT][7] = {"n&ass", " temp", "Volume"}; // Number of items in each category #define WEIGHT_COUNT 4 @@ -63,6 +66,12 @@ static const unit temps[TEMP_COUNT] = { {"Gas Mk", 25., 25., 250}, }; +static const unit temps_custom[TEMP_COUNT] = { + {" #C", 1.8, 1.8, 32}, + {" #F", 1., 1., 0}, // BASE + {"Gas Mk", 25., 25., 250}, +}; + static const unit vols[VOL_COUNT] = { {" n&L", 1., 1., 0}, // BASE (ml) {" L", 1000., 1000., 0}, @@ -89,7 +98,7 @@ static void reset_state(kitchen_conversions_state_t *state) state->to_is_us = movement_use_imperial_units(); state->selection_value = 0; state->selection_index = 0; - state->light_held = false; + state->alarm_held = false; } void kitchen_conversions_face_setup(uint8_t watch_face_index, void **context_ptr) @@ -111,7 +120,7 @@ void kitchen_conversions_face_activate(void *context) // Handle any tasks related to your watch face coming on screen. movement_request_tick_frequency(TICK_FREQ); - reset_state(state, settings); + reset_state(state); } // Increments index pointer by 1, wrapping @@ -136,7 +145,7 @@ static unit *get_unit_list(uint8_t measurement_i) return (unit *)weights; case TEMP: - return (unit *)temps; + return (unit *)(watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM ? temps_custom : temps); case VOL: return (unit *)vols; @@ -163,7 +172,11 @@ static void increment_input(kitchen_conversions_state_t *state) // Displays the list of units in the selected category static void display_units(uint8_t measurement_i, uint8_t list_i) { - watch_display_string(get_unit_list(measurement_i)[list_i].name, 4); + // Slighly hacky way to improve ml display on new LCD + if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM && measurement_i == VOL && list_i == 0) + watch_display_text(WATCH_POSITION_BOTTOM, " mL"); + else + watch_display_text(WATCH_POSITION_BOTTOM, get_unit_list(measurement_i)[list_i].name); } static void display(kitchen_conversions_state_t *state, uint8_t subsec) @@ -174,8 +187,9 @@ static void display(kitchen_conversions_state_t *state, uint8_t subsec) { case measurement: { - watch_display_string("Un", 0); - watch_display_string(measures[state->measurement_i], 4); + watch_display_text_with_fallback(WATCH_POSITION_TOP, "Unit", "Un"); + char* measurement_name = (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM ? measures_custom : measures)[state->measurement_i]; + watch_display_text(WATCH_POSITION_BOTTOM, measurement_name); } break; @@ -185,14 +199,15 @@ static void display(kitchen_conversions_state_t *state, uint8_t subsec) // Display Fr if non-locale specific, else display locale and F if (state->measurement_i == VOL) { - watch_display_string("F", 3); + watch_display_text(WATCH_POSITION_TOP_RIGHT, " F"); + char *locale_custom = state->from_is_us ? "USA" : "IMP"; char *locale = state->from_is_us ? "A " : "GB"; - watch_display_string(locale, 0); + watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, locale_custom, locale); } else { - watch_display_string("Fr", 0); + watch_display_text_with_fallback(WATCH_POSITION_TOP, "Frm", "Fr"); } break; @@ -200,17 +215,17 @@ static void display(kitchen_conversions_state_t *state, uint8_t subsec) case to: display_units(state->measurement_i, state->to_i); - // Display To if non-locale specific, else display locale and T - if (state->measurement_i == VOL) - { - watch_display_string("T", 3); + // Display to if non-locale specific, else display locale and 't' + if (state->measurement_i == VOL) { + watch_display_text(WATCH_POSITION_TOP_RIGHT, " T"); + char *locale_custom = state->to_is_us ? "USA" : "IMP"; char *locale = state->to_is_us ? "A " : "GB"; - watch_display_string(locale, 0); + watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, locale_custom, locale); } else { - watch_display_string("To", 0); + watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, " to", "to"); } break; @@ -218,22 +233,23 @@ static void display(kitchen_conversions_state_t *state, uint8_t subsec) case input: { char buf[7]; - sprintf(buf, "%06lu", state->selection_value); - watch_display_string(buf, 4); + sprintf(buf, "%06u", state->selection_value); + watch_display_text(WATCH_POSITION_BOTTOM, buf); // Only allow ints for Gas Mk if (state->measurement_i == TEMP && state->from_i == 2) { - watch_display_string(" ", 8); + watch_display_character(' ', 8); + watch_display_character(' ', 9); } // Blink digit (on & off) twice a second if (subsec % 2) { - watch_display_string(" ", 4 + state->selection_index); + watch_display_character(' ', 4 + state->selection_index); } - watch_display_string("In", 0); + watch_display_text_with_fallback(WATCH_POSITION_TOP, "Input", "In"); } break; @@ -253,7 +269,7 @@ static void display(kitchen_conversions_state_t *state, uint8_t subsec) if (conversion >= 1000000 || conversion < lower_bound) { watch_set_indicator(WATCH_INDICATOR_BELL); - watch_display_string("Err", 5); + watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, " Error", " Err"); if (movement_button_should_sound()) watch_buzzer_play_sequence(calc_fail_seq, NULL); @@ -262,23 +278,24 @@ static void display(kitchen_conversions_state_t *state, uint8_t subsec) { uint32_t rounded = conversion + .5; char buf[7]; - sprintf(buf, "%6lu", rounded); - watch_display_string(buf, 4); + sprintf(buf, "%6u", rounded); + watch_display_text(WATCH_POSITION_BOTTOM, buf); // Make sure LSDs always filled if (rounded < 10) { - watch_display_string("00", 7); + watch_display_character('0', 7); + watch_display_character('0', 8); } else if (rounded < 100) { - watch_display_string("0", 7); + watch_display_character('0', 7); } if (movement_button_should_sound()) watch_buzzer_play_sequence(calc_success_seq, NULL); } - watch_display_string("=", 1); + watch_display_text_with_fallback(WATCH_POSITION_TOP, "Res =", " ="); } break; @@ -296,20 +313,20 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) { case EVENT_ACTIVATE: // Initial UI - display(state, settings, event.subsecond); + display(state, event.subsecond); break; case EVENT_TICK: // Update for blink animation on input if (state->pg == input) { - display(state, settings, event.subsecond); + display(state, event.subsecond); // Increments input twice a second when light button held - if (state->light_held && event.subsecond % 2) + if (state->alarm_held && event.subsecond % 2) increment_input(state); } break; - case EVENT_LIGHT_BUTTON_UP: + case EVENT_ALARM_BUTTON_UP: // Cycles options switch (state->pg) { @@ -335,13 +352,13 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) // Light button does nothing on final screen if (state->pg != result) - display(state, settings, event.subsecond); + display(state, event.subsecond); - state->light_held = false; + state->alarm_held = false; break; - case EVENT_ALARM_BUTTON_UP: + case EVENT_LIGHT_BUTTON_UP: // Increments selected digit if (state->pg == input) { @@ -355,7 +372,7 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) else { state->pg++; - display(state, settings, event.subsecond); + display(state, event.subsecond); } } // Moves forward 1 page @@ -363,7 +380,7 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) { if (state->pg == SCREEN_NUM - 1) { - reset_state(state, settings); + reset_state(state); } else { @@ -375,13 +392,13 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) watch_buzzer_play_note(BUZZER_NOTE_C7, 50); } - display(state, settings, event.subsecond); + display(state, event.subsecond); - state->light_held = false; + state->alarm_held = false; break; - case EVENT_ALARM_LONG_PRESS: + case EVENT_LIGHT_LONG_PRESS: // Moves backwards through pages, resetting certain values if (state->pg != measurement) { @@ -415,17 +432,17 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) } state->pg--; - display(state, settings, event.subsecond); + display(state, event.subsecond); // Play beep if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_C8, 50); - state->light_held = false; + state->alarm_held = false; } break; - case EVENT_LIGHT_LONG_PRESS: + case EVENT_ALARM_LONG_PRESS: // Switch between locales if (state->measurement_i == VOL) { @@ -440,7 +457,7 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) if (state->pg == from || state->pg == to) { - display(state, settings, event.subsecond); + display(state, event.subsecond); // Play bleep if (movement_button_should_sound()) @@ -448,14 +465,14 @@ bool kitchen_conversions_face_loop(movement_event_t event, void *context) } } - // Sets flag to increment input digit when light held + // Sets flag to increment input digit when alarm button held if (state->pg == input) - state->light_held = true; + state->alarm_held = true; break; - case EVENT_LIGHT_LONG_UP: - state->light_held = false; + case EVENT_ALARM_LONG_UP: + state->alarm_held = false; break; case EVENT_TIMEOUT: diff --git a/legacy/watch_faces/complication/kitchen_conversions_face.h b/watch-faces/complication/kitchen_conversions_face.h similarity index 91% rename from legacy/watch_faces/complication/kitchen_conversions_face.h rename to watch-faces/complication/kitchen_conversions_face.h index 33c6cf4c..6f4251c9 100644 --- a/legacy/watch_faces/complication/kitchen_conversions_face.h +++ b/watch-faces/complication/kitchen_conversions_face.h @@ -33,13 +33,13 @@ * * How to use * ---------- - * Short press the alarm button to move forward through menus, and long press to move backwards + * Short press the light button to move forward through menus, and long press to move backwards * - * Press the light button to cycle through options in the menus + * Press the alarm button to cycle through options in the menus * - * When inputting a number, the light button moves forward one place and the alarm button increments a digit by one + * When inputting a number, the light button moves forward one place and the alarm button increments the value of the selected digit * - * To convert between Imperial (GB) and US (A) measurements of volume, hold the light button + * To convert between Imperial (GB) and US (A) measurements of volume, hold the alarm button * */ @@ -68,7 +68,7 @@ typedef struct bool to_is_us; uint32_t selection_value; uint8_t selection_index; - bool light_held; + bool alarm_held; } kitchen_conversions_state_t; void kitchen_conversions_face_setup(uint8_t watch_face_index, void **context_ptr);