|
| 1 | +/* |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2023 CarpeNoctem |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +#include <stdlib.h> |
| 26 | +#include <string.h> |
| 27 | +#include "french_revolutionary_face.h" |
| 28 | + |
| 29 | +void french_revolutionary_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { |
| 30 | + (void) settings; |
| 31 | + (void) watch_face_index; |
| 32 | + if (*context_ptr == NULL) { |
| 33 | + *context_ptr = malloc(sizeof(french_revolutionary_state_t)); |
| 34 | + memset(*context_ptr, 0, sizeof(french_revolutionary_state_t)); |
| 35 | + // Do any one-time tasks in here; the inside of this conditional happens only at boot. |
| 36 | + french_revolutionary_state_t *state = (french_revolutionary_state_t *)*context_ptr; |
| 37 | + state->use_am_pm = false; |
| 38 | + state->show_seconds = true; |
| 39 | + state->display_type = 0; |
| 40 | + state->colon_set_after_splash = false; |
| 41 | + } |
| 42 | + // Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep. |
| 43 | +} |
| 44 | + |
| 45 | +void french_revolutionary_face_activate(movement_settings_t *settings, void *context) { |
| 46 | + (void) settings; |
| 47 | + french_revolutionary_state_t *state = (french_revolutionary_state_t *)context; |
| 48 | + |
| 49 | + // Handle any tasks related to your watch face coming on screen. |
| 50 | + state->colon_set_after_splash = false; |
| 51 | +} |
| 52 | + |
| 53 | +bool french_revolutionary_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { |
| 54 | + french_revolutionary_state_t *state = (french_revolutionary_state_t *)context; |
| 55 | + |
| 56 | + char buf[11]; |
| 57 | + watch_date_time date_time; |
| 58 | + fr_decimal_time decimal_time; |
| 59 | + |
| 60 | + switch (event.event_type) { |
| 61 | + case EVENT_ACTIVATE: |
| 62 | + // Initial UI - Show a quick "splash screen" |
| 63 | + watch_clear_display(); |
| 64 | + watch_display_string("FR dECimL", 0); |
| 65 | + break; |
| 66 | + case EVENT_TICK: |
| 67 | + case EVENT_LOW_ENERGY_UPDATE: |
| 68 | + |
| 69 | + date_time = watch_rtc_get_date_time(); |
| 70 | + |
| 71 | + decimal_time = get_decimal_time(&date_time); |
| 72 | + |
| 73 | + set_display_buffer(buf, state, &decimal_time, &date_time); |
| 74 | + |
| 75 | + // If we're in low-energy mode, don't write out the seconds. Also start the LE tick animation if it's not already going. |
| 76 | + if (event.event_type == EVENT_LOW_ENERGY_UPDATE) { |
| 77 | + buf[8] = ' '; |
| 78 | + buf[9] = ' '; |
| 79 | + if (!watch_tick_animation_is_running()) { watch_start_tick_animation(500); } |
| 80 | + } |
| 81 | + |
| 82 | + // Update the display with our decimal time |
| 83 | + watch_display_string(buf, 0); |
| 84 | + |
| 85 | + // Oh, and a one-off to set the colon after the "splash screen" |
| 86 | + if (!state->colon_set_after_splash) { |
| 87 | + watch_set_colon(); |
| 88 | + state->colon_set_after_splash = true; |
| 89 | + } |
| 90 | + break; |
| 91 | + case EVENT_ALARM_BUTTON_UP: |
| 92 | + state->display_type += 1 ; // cycle through the display types |
| 93 | + if (state->display_type > 2) { state->display_type = 0; } // but return to 0 after 2 |
| 94 | + break; |
| 95 | + case EVENT_ALARM_LONG_PRESS: |
| 96 | + // I originally had chiming on the decimal-hour enabled, and this would enable/disable that chime, just like on |
| 97 | + // the simple clock and decimal time faces. But because decimal seconds don't always line up with normal seconds, |
| 98 | + // I assume the (decimal-)hourly chime could sometimes be missed. Additionally, I need this button for other purposes, |
| 99 | + // now that I added seconds on/off toggle and upper normal-time with the ability to toggle that between 12/24hr format. |
| 100 | + state->show_seconds = !state->show_seconds; |
| 101 | + if (!state->show_seconds) { watch_display_string(" ", 8); } |
| 102 | + else { watch_display_string("--", 8); } |
| 103 | + break; |
| 104 | + case EVENT_LIGHT_LONG_PRESS: |
| 105 | + // In case anyone really wants that upper time in 12-hour format. I thought about using the global setting (settings->bit.clock_mode_24h) |
| 106 | + // for this preference, but thought someone who prefers 12-hour format normally, might prefer 24hr when compared to a 10hr decimal day, |
| 107 | + // so this is separate for now. |
| 108 | + state->use_am_pm = !state->use_am_pm; |
| 109 | + if (state->use_am_pm) { |
| 110 | + watch_clear_indicator(WATCH_INDICATOR_24H); |
| 111 | + date_time = watch_rtc_get_date_time(); |
| 112 | + if (date_time.unit.hour < 12) { watch_clear_indicator(WATCH_INDICATOR_PM); } |
| 113 | + else { watch_set_indicator(WATCH_INDICATOR_PM); } |
| 114 | + } else { |
| 115 | + watch_clear_indicator(WATCH_INDICATOR_PM); |
| 116 | + watch_set_indicator(WATCH_INDICATOR_24H); |
| 117 | + } |
| 118 | + break; |
| 119 | + default: |
| 120 | + // Movement's default loop handler will step in for any cases you don't handle above: |
| 121 | + // * EVENT_LIGHT_BUTTON_DOWN lights the LED |
| 122 | + // * EVENT_MODE_BUTTON_UP moves to the next watch face in the list |
| 123 | + // * EVENT_MODE_LONG_PRESS returns to the first watch face (or skips to the secondary watch face, if configured) |
| 124 | + // You can override any of these behaviors by adding a case for these events to this switch statement. |
| 125 | + return movement_default_loop_handler(event, settings); |
| 126 | + } |
| 127 | + |
| 128 | + // return true if the watch can enter standby mode. Generally speaking, you should always return true. |
| 129 | + // Exceptions: |
| 130 | + // * If you are displaying a color using the low-level watch_set_led_color function, you should return false. |
| 131 | + // * If you are sounding the buzzer using the low-level watch_set_buzzer_on function, you should return false. |
| 132 | + // Note that if you are driving the LED or buzzer using Movement functions like movement_illuminate_led or |
| 133 | + // movement_play_alarm, you can still return true. This guidance only applies to the low-level watch_ functions. |
| 134 | + return true; |
| 135 | +} |
| 136 | + |
| 137 | +void french_revolutionary_face_resign(movement_settings_t *settings, void *context) { |
| 138 | + (void) settings; |
| 139 | + (void) context; |
| 140 | + |
| 141 | + // handle any cleanup before your watch face goes off-screen. |
| 142 | +} |
| 143 | + |
| 144 | +// Calculate decimal time from normal (24hr) time |
| 145 | +fr_decimal_time get_decimal_time(watch_date_time *date_time) { |
| 146 | + uint32_t current_24hr_secs, current_decimal_seconds; |
| 147 | + fr_decimal_time decimal_time; |
| 148 | + // Current 24-hr time in seconds (There are 86400 of these in a day.) |
| 149 | + current_24hr_secs = date_time->unit.hour * 3600 + date_time->unit.minute * 60 + date_time->unit.second; |
| 150 | + |
| 151 | + // Current Decimal Time in seconds. There are 100000 seconds in a 10-hr decimal-time day. |
| 152 | + // current_decimal_seconds = current_24hr_seconds * 100000 / 86400, or = current_24_seconds * 1000 / 864; |
| 153 | + // By chopping the extra zeros off the end, we can use uint32 instead of uint64. |
| 154 | + current_decimal_seconds = current_24hr_secs * 1000 / 864; |
| 155 | + |
| 156 | + decimal_time.hour = current_decimal_seconds / 10000; |
| 157 | + // Remove the hours from total seconds and keep the remainder for below. |
| 158 | + current_decimal_seconds = current_decimal_seconds - decimal_time.hour * 10000; |
| 159 | + |
| 160 | + decimal_time.minute = current_decimal_seconds / 100; |
| 161 | + // Remove the minutes from total seconds and keep the remaining seconds |
| 162 | + // Note: I think I used an extra seconds variable here because sprintf or movement weren't liking a uint32... |
| 163 | + decimal_time.second = current_decimal_seconds - decimal_time.minute * 100; |
| 164 | + return decimal_time; |
| 165 | +} |
| 166 | + |
| 167 | +// Fills in the display buffer, depending on the currently-selected display option (and sub-options): |
| 168 | +// - Decimal-time only |
| 169 | +// - Decimal-time with date in top-right |
| 170 | +// - Decimal-time with normal time in the top (minutes first, then hours, due to display limitations) |
| 171 | +// TODO: There is some power-saving stuff that simple clock does here around not redrawing characters that haven't changed, but we're not doing that here. |
| 172 | +// I'll try to add that optimization could be added in a future commit. |
| 173 | +void set_display_buffer(char *buf, french_revolutionary_state_t *state, fr_decimal_time *decimal_time, watch_date_time *date_time) { |
| 174 | + switch (state->display_type) { |
| 175 | + // Decimal time only |
| 176 | + case 0: |
| 177 | + // Originally I had the day slot set to "FR" (French Revolutionary time), but my brain kept thinking "Friday" whenever I saw it, |
| 178 | + // so I changed it to dT (Decimal Time) to avoid that confusion. Apologies to anyone who has the other decimal_time face and this one |
| 179 | + // installed concurrently. Maybe the splash screen will help a little. |
| 180 | + sprintf( buf, "dT %2d%02d%02d", decimal_time->hour, decimal_time->minute, decimal_time->second ); |
| 181 | + watch_clear_indicator(WATCH_INDICATOR_PM); |
| 182 | + watch_clear_indicator(WATCH_INDICATOR_24H); |
| 183 | + break; |
| 184 | + // Decimal time and date |
| 185 | + case 1: |
| 186 | + sprintf( buf, "dT%2d%2d%02d%02d", date_time->unit.day, decimal_time->hour, decimal_time->minute, decimal_time->second ); |
| 187 | + watch_clear_indicator(WATCH_INDICATOR_PM); |
| 188 | + watch_clear_indicator(WATCH_INDICATOR_24H); |
| 189 | + break; |
| 190 | + // Decimal time on bottom, normal time above |
| 191 | + case 2: |
| 192 | + if (state->use_am_pm) { |
| 193 | + // if we are in 12 hour mode, do some cleanup. |
| 194 | + watch_clear_indicator(WATCH_INDICATOR_24H); |
| 195 | + if (date_time->unit.hour < 12) { |
| 196 | + watch_clear_indicator(WATCH_INDICATOR_PM); |
| 197 | + } else { |
| 198 | + watch_set_indicator(WATCH_INDICATOR_PM); |
| 199 | + } |
| 200 | + date_time->unit.hour %= 12; |
| 201 | + if (date_time->unit.hour == 0) date_time->unit.hour = 12; |
| 202 | + } else { |
| 203 | + watch_clear_indicator(WATCH_INDICATOR_PM); |
| 204 | + watch_set_indicator(WATCH_INDICATOR_24H); |
| 205 | + } |
| 206 | + // Note, the date digits don't display a leading zero well, so we don't use it. |
| 207 | + sprintf( buf, "%02d%2d%2d%02d%02d", date_time->unit.minute, date_time->unit.hour, decimal_time->hour, decimal_time->minute, decimal_time->second ); |
| 208 | + |
| 209 | + // Make the second character of the Day area more readable |
| 210 | + buf[1] = fix_character_one(buf[1]); |
| 211 | + break; |
| 212 | + } |
| 213 | + // Finally, if show_seconds is disabled, trim those off. |
| 214 | + if (!state->show_seconds) { |
| 215 | + buf[8] = ' '; |
| 216 | + buf[9] = ' '; |
| 217 | + } |
| 218 | +} |
| 219 | + |
| 220 | +// Sadly, the second character of the Day field cannot show all numbers, so we make some replacements. |
| 221 | +// See https://www.sensorwatch.net/docs/wig/display/#limitations-of-the-weekday-digits |
| 222 | +char fix_character_one(char digit) { |
| 223 | + char return_char = digit; // We don't need to update this for 0, 1, 3, 7 and 8. |
| 224 | + switch(digit) { |
| 225 | + case '2': |
| 226 | + // Roman numeral / tally representation of 2 |
| 227 | + return_char = '|'; // Thanks, Joey, for already having this in the character set. |
| 228 | + break; |
| 229 | + case '4': |
| 230 | + // Looks almost like a 4 - just missing the top-left segment. |
| 231 | + // 0b01000110 |
| 232 | + return_char = '&'; // Slight hack - I want 0b01000110, but 0b01000100 is already in the character set and will do, since B and C segments are linked in this position. |
| 233 | + break; |
| 234 | + case '5': |
| 235 | + return_char = 'F'; // F for Five |
| 236 | + break; |
| 237 | + case '6': |
| 238 | + return_char = 'E'; // Looks almost like a 6 - just missing the bottom-right segment. Not super happy with it, but liked it best of the options I tried. |
| 239 | + break; |
| 240 | + case '9': |
| 241 | + return_char = 'N'; // N for Nine |
| 242 | + break; |
| 243 | + } |
| 244 | + return return_char; |
| 245 | +} |
0 commit comments