···11+#include "clock_decimal.h"
22+#include <pebble.h>
33+#include <stdio.h>
44+#include <time.h>
55+66+#define DECIMAL_FONT FONT_KEY_GOTHIC_18_BOLD
77+88+static char s_buffer[10]; // Buffer for time string HH:MM:SS.ss
99+1010+// Function to calculate French Revolutionary Time using integer math
1111+static void calculate_decimal_time(time_t system_seconds, int *decimal_hour, int *decimal_minute, int *decimal_second) {
1212+ // Standard time has 86400 seconds per day.
1313+ // Decimal time has 100000 decimal seconds per day.
1414+1515+ // Get the time structure for the current day
1616+ struct tm *current_tm = localtime(&system_seconds);
1717+1818+ // Calculate standard seconds elapsed since midnight
1919+ uint32_t seconds_today = current_tm->tm_hour * 3600 + current_tm->tm_min * 60 + current_tm->tm_sec;
2020+2121+ // Convert standard seconds today to decimal seconds today using 64-bit integer math
2222+ // total_decimal_seconds = (seconds_today * 100000) / 86400
2323+ uint64_t total_decimal_seconds = ((uint64_t)seconds_today * 100000ULL) / 86400ULL;
2424+2525+ // Calculate decimal hours, minutes, seconds using integer division and modulo
2626+ *decimal_hour = (int)(total_decimal_seconds / 10000ULL);
2727+ uint64_t remainder = total_decimal_seconds % 10000ULL;
2828+ *decimal_minute = (int)(remainder / 100ULL);
2929+ *decimal_second = (int)(remainder % 100ULL);
3030+}
3131+3232+// Updates the decimal time TextLayer
3333+void clock_decimal_update(TextLayer *text_layer, time_t system_seconds) {
3434+ int decimal_hour, decimal_minute, decimal_second;
3535+ calculate_decimal_time(system_seconds, &decimal_hour, &decimal_minute, &decimal_second);
3636+3737+ // Format the time string (e.g., H:MM:SS)
3838+ snprintf(s_buffer, sizeof(s_buffer), "%d:%02d:%02d", decimal_hour, decimal_minute, decimal_second);
3939+4040+ APP_LOG(APP_LOG_LEVEL_DEBUG, "Decimal Update: %s", s_buffer);
4141+ // Display this time on the TextLayer
4242+ text_layer_set_text(text_layer, s_buffer);
4343+}
4444+4545+// Initializes the decimal time TextLayer
4646+TextLayer* clock_decimal_init(GRect bounds, Layer *window_layer) {
4747+ TextLayer *text_layer = text_layer_create(bounds);
4848+ text_layer_set_background_color(text_layer, GColorClear);
4949+ text_layer_set_text_color(text_layer, GColorBlack);
5050+ text_layer_set_font(text_layer, fonts_get_system_font(DECIMAL_FONT));
5151+ text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
5252+ layer_add_child(window_layer, text_layer_get_layer(text_layer));
5353+5454+ // Initialize with placeholder or current time
5555+ time_t temp = time(NULL);
5656+ clock_decimal_update(text_layer, temp);
5757+5858+ return text_layer;
5959+}
6060+6161+// Deinitializes the decimal time TextLayer
6262+void clock_decimal_deinit(TextLayer *text_layer) {
6363+ text_layer_destroy(text_layer);
6464+}
+12
src/c/clock_decimal.h
···11+#pragma once
22+33+#include <pebble.h>
44+55+// Initializes the decimal time TextLayer
66+TextLayer* clock_decimal_init(GRect bounds, Layer *window_layer);
77+88+// Updates the decimal time TextLayer
99+void clock_decimal_update(TextLayer *text_layer, time_t system_seconds);
1010+1111+// Deinitializes the decimal time TextLayer
1212+void clock_decimal_deinit(TextLayer *text_layer);
+63-37
src/c/watchface.c
···22#include <stdlib.h>
33#include <time.h>
4455+// Enable logging - Removed incorrect define, APP_LOG is in pebble.h
66+57// --- Clock Module Includes ---
68#include "clock_beat.h"
77-#include "clock_noonzone.h"
99+// #include "clock_noonzone.h" // Removed
810#include "clock_closest_noon.h"
911#include "clock_tid.h"
1212+#include "clock_decimal.h"
10131114// --- Window and Layer Globals ---
1215static Window *s_main_window;
1316static TextLayer *s_beat_layer; // Layer for Swatch Beat Time
1417static TextLayer *s_tid_layer; // Layer for TID Time
1515-static TextLayer *s_noonzone_layer; // Layer for Noon Zone Time
1818+// static TextLayer *s_noonzone_layer; // Layer for Noon Zone Time // Removed
1619static TextLayer *s_closest_noon_layer; // Layer for Closest-to-Noon TZ
2020+static TextLayer *s_decimal_layer; // Layer for Decimal Time
17211822// --- Pebble Window Management ---
1923···2731 // Update both time displays
2832 clock_beat_update(s_beat_layer, seconds);
2933 clock_tid_update(s_tid_layer, seconds, milliseconds);
3030- clock_noonzone_update(s_noonzone_layer, seconds);
3434+ // clock_noonzone_update(s_noonzone_layer, seconds); // Removed
3135 clock_closest_noon_update(s_closest_noon_layer, seconds);
3636+ clock_decimal_update(s_decimal_layer, seconds);
3237}
33383439static void main_window_load(Window *window) {
3540 Layer *window_layer = window_get_root_layer(window);
3641 GRect bounds = layer_get_bounds(window_layer);
4242+ APP_LOG(APP_LOG_LEVEL_DEBUG, "Bounds: H=%d, W=%d", bounds.size.h, bounds.size.w);
37433838- // Define layout constants (adjust heights based on font sizes)
3939- const int16_t v_padding = 1; // Tighten padding for 4 layers
4040- // Allocate heights roughly - adjust based on visual results
4141- const int16_t beat_h = 28;
4242- const int16_t noonzone_h = 26;
4343- const int16_t closest_h = 26;
4444- const int16_t tid_h = 26;
4545- // Calculate total height needed (excluding top/bottom margins provided by layer positioning)
4646- const int16_t total_inner_h = beat_h + noonzone_h + closest_h + tid_h + 3 * v_padding;
4747- // Distribute remaining vertical space as top/bottom margin
4848- const int16_t top_margin = (bounds.size.h - total_inner_h) / 2;
4949-5050- // Font sizes (adjust as needed)
4444+ // Define layout constants for 4 layers
4545+ const int num_layers = 4;
4646+ const int16_t v_padding = 2; // Slightly more padding maybe
4747+ // Calculate available height for layers after removing padding
4848+ const int16_t total_available_h = bounds.size.h - (num_layers - 1) * v_padding;
4949+ // Distribute height equally among layers
5050+ const int16_t layer_h = total_available_h / num_layers;
5151+ APP_LOG(APP_LOG_LEVEL_DEBUG, "Total Available H: %d, Layer H: %d", total_available_h, layer_h);
5252+ // Verify calculation result
5353+ if (layer_h <= 0) {
5454+ APP_LOG(APP_LOG_LEVEL_ERROR, "Error: Calculated Layer Height <= 0");
5555+ // Handle error or default to a minimal height
5656+ // layer_h = 10; // Example fallback
5757+ }
5858+5959+ // Font sizes (adjust as needed - removed noonzone)
5160 #define BEAT_FONT FONT_KEY_GOTHIC_24_BOLD
5252- #define NOONZONE_FONT FONT_KEY_GOTHIC_18_BOLD // Smaller for longer name
5353- #define CLOSEST_FONT FONT_KEY_GOTHIC_18_BOLD // Smaller for city name
5454- #define TID_FONT FONT_KEY_GOTHIC_18_BOLD // Smaller TID
6161+ // #define NOONZONE_FONT FONT_KEY_GOTHIC_18_BOLD // Removed
6262+ #define CLOSEST_FONT FONT_KEY_GOTHIC_18_BOLD
6363+ #define TID_FONT FONT_KEY_GOTHIC_18_BOLD
6464+ #define DECIMAL_FONT FONT_KEY_GOTHIC_18_BOLD
55655656- // Calculate Y positions
5757- int16_t current_y = top_margin;
5858- int16_t beat_y = current_y;
5959- current_y += beat_h + v_padding;
6060- int16_t noonzone_y = current_y;
6161- current_y += noonzone_h + v_padding;
6262- int16_t closest_y = current_y;
6363- current_y += closest_h + v_padding;
6464- int16_t tid_y = current_y;
6666+ // Calculate Y positions based on new layout
6767+ // Beat: Top
6868+ int16_t beat_y = 0;
65696666- // Create Beat Time TextLayer (Top)
6767- s_beat_layer = clock_beat_init(GRect(0, beat_y, bounds.size.w, beat_h), window_layer);
7070+ // TID: Bottom
7171+ int16_t tid_y = bounds.size.h - layer_h;
68726969- // Create Noon Zone Time TextLayer (Middle)
7070- s_noonzone_layer = clock_noonzone_init(GRect(0, noonzone_y, bounds.size.w, noonzone_h), window_layer);
7373+ // Closest Noon: Above TID
7474+ int16_t closest_y = tid_y - layer_h - v_padding;
71757272- // Create Closest Noon Time TextLayer (Middle-Bottom)
7373- s_closest_noon_layer = clock_closest_noon_init(GRect(0, closest_y, bounds.size.w, closest_h), window_layer);
7676+ // Decimal: Halfway between bottom of Beat and top of Closest Noon
7777+ // Bottom of Beat = beat_y + layer_h = layer_h
7878+ // Top of Closest Noon = closest_y
7979+ // Midpoint = (bottom_of_beat + top_of_closest_noon) / 2
8080+ // Adjust for decimal layer height: Midpoint - layer_h / 2
8181+ int16_t decimal_midpoint = (layer_h + closest_y) / 2;
8282+ int16_t decimal_y = decimal_midpoint - (layer_h / 2);
8383+8484+ APP_LOG(APP_LOG_LEVEL_DEBUG, "Y Positions: Beat=%d, Decimal=%d, Closest=%d, TID=%d", beat_y, decimal_y, closest_y, tid_y);
74857575- // Create TID TextLayer (Bottom)
7676- s_tid_layer = clock_tid_init(GRect(0, tid_y, bounds.size.w, tid_h), window_layer);
8686+ // Create Layers in new order
8787+ // Beat Time TextLayer (Top)
8888+ s_beat_layer = clock_beat_init(GRect(0, beat_y, bounds.size.w, layer_h), window_layer);
8989+9090+ // Decimal Time TextLayer (Middle)
9191+ s_decimal_layer = clock_decimal_init(GRect(0, decimal_y, bounds.size.w, layer_h), window_layer);
9292+9393+ // Closest Noon Time TextLayer (Middle-Bottom)
9494+ s_closest_noon_layer = clock_closest_noon_init(GRect(0, closest_y, bounds.size.w, layer_h), window_layer);
9595+9696+ // TID TextLayer (Bottom)
9797+ s_tid_layer = clock_tid_init(GRect(0, tid_y, bounds.size.w, layer_h), window_layer);
9898+9999+ // // Create Noon Zone Time TextLayer // Removed
100100+ // s_noonzone_layer = clock_noonzone_init(GRect(0, noonzone_y, bounds.size.w, layer_h), window_layer);
101101+77102}
7810379104static void main_window_unload(Window *window) {
80105 // Destroy TextLayers
81106 clock_beat_deinit(s_beat_layer);
8282- clock_noonzone_deinit(s_noonzone_layer);
107107+ // clock_noonzone_deinit(s_noonzone_layer); // Removed
83108 clock_closest_noon_deinit(s_closest_noon_layer);
84109 clock_tid_deinit(s_tid_layer);
110110+ clock_decimal_deinit(s_decimal_layer);
85111}
8611287113static void init() {