this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Initial noon zone implementation

Initial tz_list.c generator

alice 50587dc7 667b94e3

+111 -8
+111 -8
src/c/watchface.c
··· 12 12 static Window *s_main_window; 13 13 static TextLayer *s_beat_layer; // Layer for Swatch Beat Time 14 14 static TextLayer *s_tid_layer; // Layer for TID Time (renamed from s_time_layer) 15 + static TextLayer *s_noonzone_layer; // Layer for Noon Zone Time 15 16 16 17 static const char S32_CHAR[] = "234567abcdefghijklmnopqrstuvwxyz"; 17 18 #define S32_CHAR_LEN (sizeof(S32_CHAR) - 1) // 32 ··· 117 118 118 119 // Clamp result just in case of edge cases (0 - 9999) 119 120 if (b > 9999) b = 9999; 120 - if (b < 0) b = 0; 121 121 return b; 122 122 } 123 123 ··· 146 146 last_beat_time = b; 147 147 } 148 148 149 + // --- Noon Zone Time Code --- 150 + static char s_noonzone_buffer[16]; // Buffer for "NAME:MM:SS\0" 151 + static int last_noonzone_update_secs = -1; // Cache full secs for update check 152 + static int last_utc_hour = -1; // Cache hour for zone name lookup 153 + static const char *last_zone_name_ptr = NULL; // Cache pointer to zone name string 154 + 155 + /** 156 + * Gets the military timezone name for the longitude where it is currently noon, 157 + * based on the provided UTC hour. 158 + * Uses caching to avoid repeated lookups for the same hour. 159 + */ 160 + static const char* get_noon_zone_name(int utc_hour) { 161 + // Check cache first 162 + if (utc_hour == last_utc_hour && last_zone_name_ptr != NULL) { 163 + return last_zone_name_ptr; 164 + } 165 + 166 + const char *name = "???"; // Default for unexpected hours 167 + switch(utc_hour){ 168 + // Cases map UTC hour to the zone where it's noon 169 + case 12: name="ZULU"; break; 170 + case 11: name="ALPHA"; break; 171 + case 10: name="BRAVO"; break; 172 + case 9: name="CHARLIE"; break; 173 + case 8: name="DELTA"; break; 174 + case 7: name="ECHO"; break; 175 + case 6: name="FOXTROT"; break; 176 + case 5: name="GOLF"; break; 177 + case 4: name="HOTEL"; break; 178 + // INDIA is skipped 179 + case 3: name="JULIET"; break; 180 + case 2: name="KILO"; break; 181 + case 1: name="LIMA"; break; 182 + case 0: name="MIKE"; break; // or YANKEE 183 + // Other half of the day (wrapping around) 184 + case 23: name="NOVEMBER"; break; 185 + case 22: name="OSCAR"; break; 186 + case 21: name="PAPA"; break; 187 + case 20: name="QUEBEC"; break; 188 + case 19: name="ROMEO"; break; 189 + case 18: name="SIERRA"; break; 190 + case 17: name="TANGO"; break; 191 + case 16: name="UNIFORM"; break; 192 + case 15: name="VICTOR"; break; 193 + case 14: name="WHISKEY"; break; 194 + case 13: name="X-RAY"; break; 195 + } 196 + 197 + // Update cache 198 + last_utc_hour = utc_hour; 199 + last_zone_name_ptr = name; 200 + return name; 201 + } 202 + 203 + /** 204 + * Updates the Noon Zone time TextLayer if the time (seconds) has changed. 205 + */ 206 + static void update_noonzone_time(time_t current_seconds_utc) { 207 + // Check if the second has changed since the last update 208 + if (current_seconds_utc == last_noonzone_update_secs) { 209 + return; 210 + } 211 + 212 + struct tm *utc_tm = gmtime(&current_seconds_utc); 213 + if (!utc_tm) { // Check if gmtime failed 214 + return; 215 + } 216 + 217 + const char *zone_name = get_noon_zone_name(utc_tm->tm_hour); 218 + 219 + // Format as NAME:MM:SS 220 + snprintf(s_noonzone_buffer, sizeof(s_noonzone_buffer), 221 + "%s:%02d:%02d", 222 + zone_name, 223 + utc_tm->tm_min, 224 + utc_tm->tm_sec); 225 + 226 + text_layer_set_text(s_noonzone_layer, s_noonzone_buffer); 227 + 228 + // Cache the time of this update 229 + last_noonzone_update_secs = current_seconds_utc; 230 + } 231 + 149 232 // --- TID Time Update --- 150 233 static char s_tid_buffer[14]; // Buffer for TID string (13 chars + null) 151 234 ··· 176 259 // Update both time displays 177 260 update_beat_time(seconds); 178 261 update_tid_time(seconds, milliseconds); 262 + update_noonzone_time(seconds); 179 263 } 180 264 181 265 static void main_window_load(Window *window) { ··· 183 267 GRect bounds = layer_get_bounds(window_layer); 184 268 185 269 // Define layout constants (adjust heights based on font sizes) 186 - const int16_t top_margin = 5; 187 - const int16_t bottom_margin = 12; 188 - const int16_t beat_layer_height = 30; // Approx height for FONT_KEY_GOTHIC_28_BOLD 189 - const int16_t tid_layer_height = 30; // Approx height for FONT_KEY_GOTHIC_24_BOLD 270 + const int16_t v_padding = 2; // Vertical padding between layers 271 + // Allocate heights roughly - adjust based on visual results 272 + const int16_t beat_h = 30; 273 + const int16_t noonzone_h = 30; 274 + const int16_t tid_h = 26; 275 + // Calculate total height needed (excluding top/bottom margins provided by layer positioning) 276 + const int16_t total_inner_h = beat_h + noonzone_h + tid_h + 2 * v_padding; 277 + // Distribute remaining vertical space as top/bottom margin 278 + const int16_t top_margin = (bounds.size.h - total_inner_h) / 2; 279 + const int16_t bottom_margin = bounds.size.h - total_inner_h - top_margin; 190 280 191 281 // Calculate Y positions 192 282 int16_t beat_y = top_margin; 193 - int16_t tid_y = bounds.size.h - tid_layer_height - bottom_margin; 283 + int16_t noonzone_y = beat_y + beat_h + v_padding; 284 + int16_t tid_y = noonzone_y + noonzone_h + v_padding; 194 285 195 286 // Create Beat Time TextLayer (Top) 196 287 s_beat_layer = text_layer_create( 197 - GRect(0, beat_y, bounds.size.w, beat_layer_height)); 288 + GRect(0, beat_y, bounds.size.w, beat_h)); 198 289 text_layer_set_background_color(s_beat_layer, GColorClear); 199 290 text_layer_set_text_color(s_beat_layer, GColorBlack); 200 291 text_layer_set_text(s_beat_layer, "@--.-"); // Initial placeholder ··· 202 293 text_layer_set_text_alignment(s_beat_layer, GTextAlignmentCenter); 203 294 layer_add_child(window_layer, text_layer_get_layer(s_beat_layer)); 204 295 296 + // Create Noon Zone Time TextLayer (Middle) 297 + s_noonzone_layer = text_layer_create( 298 + GRect(0, noonzone_y, bounds.size.w, noonzone_h)); 299 + text_layer_set_background_color(s_noonzone_layer, GColorClear); 300 + text_layer_set_text_color(s_noonzone_layer, GColorBlack); 301 + text_layer_set_text(s_noonzone_layer, "ZONE:--:--"); // Initial placeholder 302 + text_layer_set_font(s_noonzone_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // Adjust font 303 + text_layer_set_text_alignment(s_noonzone_layer, GTextAlignmentCenter); 304 + layer_add_child(window_layer, text_layer_get_layer(s_noonzone_layer)); 305 + 205 306 // Create TID TextLayer (Bottom) 206 307 s_tid_layer = text_layer_create( 207 - GRect(0, tid_y, bounds.size.w, tid_layer_height)); 308 + GRect(0, tid_y, bounds.size.w, tid_h)); 208 309 text_layer_set_background_color(s_tid_layer, GColorClear); 209 310 text_layer_set_text_color(s_tid_layer, GColorBlack); 210 311 text_layer_set_text(s_tid_layer, "loading tid..."); // Initial placeholder ··· 217 318 // Destroy TextLayers 218 319 text_layer_destroy(s_beat_layer); 219 320 text_layer_destroy(s_tid_layer); // Renamed from s_time_layer 321 + text_layer_destroy(s_noonzone_layer); 220 322 } 221 323 222 324 static void init() { ··· 237 339 time_ms(&seconds, &milliseconds); 238 340 update_beat_time(seconds); // Initial beat time 239 341 update_tid_time(seconds, milliseconds); // Initial TID time 342 + update_noonzone_time(seconds); // Initial noon zone time 240 343 241 344 242 345 // Register with TickTimerService to update every second