]> git.earman.xyz Git - sensor-watch.git/commitdiff
nicer time zone names on new LCD
authorJoey Castillo <joeycastillo@utexas.edu>
Sat, 8 Mar 2025 22:17:40 +0000 (17:17 -0500)
committerJoey Castillo <joeycastillo@utexas.edu>
Sat, 8 Mar 2025 22:17:40 +0000 (17:17 -0500)
watch-faces/clock/world_clock_face.c
watch-faces/settings/set_time_face.c
watch-library/shared/watch/watch_utility.c
watch-library/shared/watch/watch_utility.h

index 2e8db394162ee9fe19e8286583ff5fe442900d0b..3bb6cbe28b2333378f9261e535a2b4f3c534f7cc 100644 (file)
@@ -169,7 +169,7 @@ static bool _world_clock_face_do_settings_mode(movement_event_t event, world_clo
     sprintf(buf, "%c%c  %s",
         movement_valid_position_0_chars[state->settings.bit.char_0],
         movement_valid_position_1_chars[state->settings.bit.char_1],
-        (char *) (zone_names + 8 * state->settings.bit.timezone_index));
+        watch_utility_time_zone_name_at_index(state->settings.bit.timezone_index));
     watch_clear_indicator(WATCH_INDICATOR_PM);
 
     // blink up the parameter we're setting
index c501956b0baf0a60d39fb6ab42c72db9d2a3201d..f8f7ed313317a2095e66d88a735ce47484815b90 100644 (file)
@@ -140,7 +140,7 @@ bool set_time_face_loop(movement_event_t event, void *context) {
             sprintf(buf, "%2d%02d  ", hours % 100, minutes % 100);
             watch_set_colon();
         } else {
-            sprintf(buf, "%s", (char *) (zone_names + 8 * movement_get_timezone_index()));
+            sprintf(buf, "%s", watch_utility_time_zone_name_at_index(movement_get_timezone_index()));
             watch_clear_colon();
         }
     } else if (current_page < 4) {
index b2b7fa2501d1a4d3c25847891e056262d4785dc6..013078a8e1d92d0302ea8b63f9184a9f2423d40a 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <math.h>
 #include "watch_utility.h"
+#include "zones.h"
 
 const char * watch_utility_get_weekday(watch_date_time_t date_time) {
     static const char weekdays[7][3] = {"MO", "TU", "WE", "TH", "FR", "SA", "SU"};
@@ -328,3 +329,71 @@ uint8_t watch_utility_days_in_month(uint8_t month, uint16_t year) {
         days += 1;
     return days;
 }
+
+char _scratch_timezone[7] = {0};
+
+char *watch_utility_time_zone_name_at_index(int32_t tzindex) {
+    char *zone_in_rom = (zone_names + 8 * tzindex);
+
+    if (watch_get_lcd_type() != WATCH_LCD_TYPE_CUSTOM) {
+        // classic LCD can get a pointer to ROM
+        return zone_in_rom;
+    } else {
+        // otherwise handle tweaks for custom LCD
+        strncpy(_scratch_timezone, zone_in_rom, 7);
+
+        // D, B and T can all be displayed in position 1
+        if (_scratch_timezone[0] == 'D') _scratch_timezone[0] = 'd';
+        if (_scratch_timezone[0] == 'B') _scratch_timezone[0] = 'b';
+        if (_scratch_timezone[0] == '+') _scratch_timezone[0] = 't';
+
+        // Fake M had to be lowercase before; now can be uppercase.
+        if (_scratch_timezone[0] == 'n' && _scratch_timezone[1] == '&') {
+            _scratch_timezone[0] = 'N';
+            _scratch_timezone[1] = '7';
+        }
+
+        // Other edgier cases:
+        switch (tzindex) {
+            case 8: // New York
+                strncpy(_scratch_timezone, "NuYork", 7);
+                break;
+            case 13: // St John's
+                _scratch_timezone[2] = 'J';
+                _scratch_timezone[3] = 'o';
+                _scratch_timezone[4] = 'h';
+                _scratch_timezone[5] = 'n';
+                break;
+            case 15: // UTC
+                strncpy(_scratch_timezone, " UTC  ", 7);
+                break;
+            case 16: // London
+                strncpy(_scratch_timezone, "London", 7);
+                break;
+            case 17: // Lagos
+                strncpy(_scratch_timezone, "Lagos ", 7);
+                break;
+            case 24: // Riyadh
+                strncpy(_scratch_timezone, "Riyadh", 7);
+                break;
+            case 25: // Moscow
+                _scratch_timezone[4] = 'O';
+                _scratch_timezone[5] = 'W';
+                break;
+            case 30: // Yangon / Burma
+                strncpy(_scratch_timezone, " burma", 7);
+                break;
+            case 41: // Hobart
+                strncpy(_scratch_timezone, "Hobart", 7);
+                break;
+            case 42: // Sydney
+                _scratch_timezone[2] = 'd';
+                break;
+            case 43: // Guam
+                _scratch_timezone[4] = 'M';
+                _scratch_timezone[5] = ' ';
+                break;
+        }
+    }
+    return _scratch_timezone;
+}
index 63f6a545e5087a79f561b66adb2a1baf0a40d1bf..61c292b4cf8a1158096e8dde6d751d57ca462cfd 100644 (file)
@@ -174,4 +174,9 @@ uint32_t watch_utility_offset_timestamp(uint32_t now, int8_t hours, int8_t minut
  */
 uint8_t watch_utility_days_in_month(uint8_t month, uint16_t year);
 
+/** @brief Returns a null-terminated six-character string representing the time zone name at a given index.
+ * @param tzindex The index of the time zone
+ */
+char * watch_utility_time_zone_name_at_index(int32_t tzindex);
+
 #endif