this repo has no description
0
fork

Configure Feed

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

decimal clock

alice e18201f2 3a3dde54

+139 -37
+64
src/c/clock_decimal.c
··· 1 + #include "clock_decimal.h" 2 + #include <pebble.h> 3 + #include <stdio.h> 4 + #include <time.h> 5 + 6 + #define DECIMAL_FONT FONT_KEY_GOTHIC_18_BOLD 7 + 8 + static char s_buffer[10]; // Buffer for time string HH:MM:SS.ss 9 + 10 + // Function to calculate French Revolutionary Time using integer math 11 + static void calculate_decimal_time(time_t system_seconds, int *decimal_hour, int *decimal_minute, int *decimal_second) { 12 + // Standard time has 86400 seconds per day. 13 + // Decimal time has 100000 decimal seconds per day. 14 + 15 + // Get the time structure for the current day 16 + struct tm *current_tm = localtime(&system_seconds); 17 + 18 + // Calculate standard seconds elapsed since midnight 19 + uint32_t seconds_today = current_tm->tm_hour * 3600 + current_tm->tm_min * 60 + current_tm->tm_sec; 20 + 21 + // Convert standard seconds today to decimal seconds today using 64-bit integer math 22 + // total_decimal_seconds = (seconds_today * 100000) / 86400 23 + uint64_t total_decimal_seconds = ((uint64_t)seconds_today * 100000ULL) / 86400ULL; 24 + 25 + // Calculate decimal hours, minutes, seconds using integer division and modulo 26 + *decimal_hour = (int)(total_decimal_seconds / 10000ULL); 27 + uint64_t remainder = total_decimal_seconds % 10000ULL; 28 + *decimal_minute = (int)(remainder / 100ULL); 29 + *decimal_second = (int)(remainder % 100ULL); 30 + } 31 + 32 + // Updates the decimal time TextLayer 33 + void clock_decimal_update(TextLayer *text_layer, time_t system_seconds) { 34 + int decimal_hour, decimal_minute, decimal_second; 35 + calculate_decimal_time(system_seconds, &decimal_hour, &decimal_minute, &decimal_second); 36 + 37 + // Format the time string (e.g., H:MM:SS) 38 + snprintf(s_buffer, sizeof(s_buffer), "%d:%02d:%02d", decimal_hour, decimal_minute, decimal_second); 39 + 40 + APP_LOG(APP_LOG_LEVEL_DEBUG, "Decimal Update: %s", s_buffer); 41 + // Display this time on the TextLayer 42 + text_layer_set_text(text_layer, s_buffer); 43 + } 44 + 45 + // Initializes the decimal time TextLayer 46 + TextLayer* clock_decimal_init(GRect bounds, Layer *window_layer) { 47 + TextLayer *text_layer = text_layer_create(bounds); 48 + text_layer_set_background_color(text_layer, GColorClear); 49 + text_layer_set_text_color(text_layer, GColorBlack); 50 + text_layer_set_font(text_layer, fonts_get_system_font(DECIMAL_FONT)); 51 + text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); 52 + layer_add_child(window_layer, text_layer_get_layer(text_layer)); 53 + 54 + // Initialize with placeholder or current time 55 + time_t temp = time(NULL); 56 + clock_decimal_update(text_layer, temp); 57 + 58 + return text_layer; 59 + } 60 + 61 + // Deinitializes the decimal time TextLayer 62 + void clock_decimal_deinit(TextLayer *text_layer) { 63 + text_layer_destroy(text_layer); 64 + }
+12
src/c/clock_decimal.h
··· 1 + #pragma once 2 + 3 + #include <pebble.h> 4 + 5 + // Initializes the decimal time TextLayer 6 + TextLayer* clock_decimal_init(GRect bounds, Layer *window_layer); 7 + 8 + // Updates the decimal time TextLayer 9 + void clock_decimal_update(TextLayer *text_layer, time_t system_seconds); 10 + 11 + // Deinitializes the decimal time TextLayer 12 + void clock_decimal_deinit(TextLayer *text_layer);
+63 -37
src/c/watchface.c
··· 2 2 #include <stdlib.h> 3 3 #include <time.h> 4 4 5 + // Enable logging - Removed incorrect define, APP_LOG is in pebble.h 6 + 5 7 // --- Clock Module Includes --- 6 8 #include "clock_beat.h" 7 - #include "clock_noonzone.h" 9 + // #include "clock_noonzone.h" // Removed 8 10 #include "clock_closest_noon.h" 9 11 #include "clock_tid.h" 12 + #include "clock_decimal.h" 10 13 11 14 // --- Window and Layer Globals --- 12 15 static Window *s_main_window; 13 16 static TextLayer *s_beat_layer; // Layer for Swatch Beat Time 14 17 static TextLayer *s_tid_layer; // Layer for TID Time 15 - static TextLayer *s_noonzone_layer; // Layer for Noon Zone Time 18 + // static TextLayer *s_noonzone_layer; // Layer for Noon Zone Time // Removed 16 19 static TextLayer *s_closest_noon_layer; // Layer for Closest-to-Noon TZ 20 + static TextLayer *s_decimal_layer; // Layer for Decimal Time 17 21 18 22 // --- Pebble Window Management --- 19 23 ··· 27 31 // Update both time displays 28 32 clock_beat_update(s_beat_layer, seconds); 29 33 clock_tid_update(s_tid_layer, seconds, milliseconds); 30 - clock_noonzone_update(s_noonzone_layer, seconds); 34 + // clock_noonzone_update(s_noonzone_layer, seconds); // Removed 31 35 clock_closest_noon_update(s_closest_noon_layer, seconds); 36 + clock_decimal_update(s_decimal_layer, seconds); 32 37 } 33 38 34 39 static void main_window_load(Window *window) { 35 40 Layer *window_layer = window_get_root_layer(window); 36 41 GRect bounds = layer_get_bounds(window_layer); 42 + APP_LOG(APP_LOG_LEVEL_DEBUG, "Bounds: H=%d, W=%d", bounds.size.h, bounds.size.w); 37 43 38 - // Define layout constants (adjust heights based on font sizes) 39 - const int16_t v_padding = 1; // Tighten padding for 4 layers 40 - // Allocate heights roughly - adjust based on visual results 41 - const int16_t beat_h = 28; 42 - const int16_t noonzone_h = 26; 43 - const int16_t closest_h = 26; 44 - const int16_t tid_h = 26; 45 - // Calculate total height needed (excluding top/bottom margins provided by layer positioning) 46 - const int16_t total_inner_h = beat_h + noonzone_h + closest_h + tid_h + 3 * v_padding; 47 - // Distribute remaining vertical space as top/bottom margin 48 - const int16_t top_margin = (bounds.size.h - total_inner_h) / 2; 49 - 50 - // Font sizes (adjust as needed) 44 + // Define layout constants for 4 layers 45 + const int num_layers = 4; 46 + const int16_t v_padding = 2; // Slightly more padding maybe 47 + // Calculate available height for layers after removing padding 48 + const int16_t total_available_h = bounds.size.h - (num_layers - 1) * v_padding; 49 + // Distribute height equally among layers 50 + const int16_t layer_h = total_available_h / num_layers; 51 + APP_LOG(APP_LOG_LEVEL_DEBUG, "Total Available H: %d, Layer H: %d", total_available_h, layer_h); 52 + // Verify calculation result 53 + if (layer_h <= 0) { 54 + APP_LOG(APP_LOG_LEVEL_ERROR, "Error: Calculated Layer Height <= 0"); 55 + // Handle error or default to a minimal height 56 + // layer_h = 10; // Example fallback 57 + } 58 + 59 + // Font sizes (adjust as needed - removed noonzone) 51 60 #define BEAT_FONT FONT_KEY_GOTHIC_24_BOLD 52 - #define NOONZONE_FONT FONT_KEY_GOTHIC_18_BOLD // Smaller for longer name 53 - #define CLOSEST_FONT FONT_KEY_GOTHIC_18_BOLD // Smaller for city name 54 - #define TID_FONT FONT_KEY_GOTHIC_18_BOLD // Smaller TID 61 + // #define NOONZONE_FONT FONT_KEY_GOTHIC_18_BOLD // Removed 62 + #define CLOSEST_FONT FONT_KEY_GOTHIC_18_BOLD 63 + #define TID_FONT FONT_KEY_GOTHIC_18_BOLD 64 + #define DECIMAL_FONT FONT_KEY_GOTHIC_18_BOLD 55 65 56 - // Calculate Y positions 57 - int16_t current_y = top_margin; 58 - int16_t beat_y = current_y; 59 - current_y += beat_h + v_padding; 60 - int16_t noonzone_y = current_y; 61 - current_y += noonzone_h + v_padding; 62 - int16_t closest_y = current_y; 63 - current_y += closest_h + v_padding; 64 - int16_t tid_y = current_y; 66 + // Calculate Y positions based on new layout 67 + // Beat: Top 68 + int16_t beat_y = 0; 65 69 66 - // Create Beat Time TextLayer (Top) 67 - s_beat_layer = clock_beat_init(GRect(0, beat_y, bounds.size.w, beat_h), window_layer); 70 + // TID: Bottom 71 + int16_t tid_y = bounds.size.h - layer_h; 68 72 69 - // Create Noon Zone Time TextLayer (Middle) 70 - s_noonzone_layer = clock_noonzone_init(GRect(0, noonzone_y, bounds.size.w, noonzone_h), window_layer); 73 + // Closest Noon: Above TID 74 + int16_t closest_y = tid_y - layer_h - v_padding; 71 75 72 - // Create Closest Noon Time TextLayer (Middle-Bottom) 73 - s_closest_noon_layer = clock_closest_noon_init(GRect(0, closest_y, bounds.size.w, closest_h), window_layer); 76 + // Decimal: Halfway between bottom of Beat and top of Closest Noon 77 + // Bottom of Beat = beat_y + layer_h = layer_h 78 + // Top of Closest Noon = closest_y 79 + // Midpoint = (bottom_of_beat + top_of_closest_noon) / 2 80 + // Adjust for decimal layer height: Midpoint - layer_h / 2 81 + int16_t decimal_midpoint = (layer_h + closest_y) / 2; 82 + int16_t decimal_y = decimal_midpoint - (layer_h / 2); 83 + 84 + APP_LOG(APP_LOG_LEVEL_DEBUG, "Y Positions: Beat=%d, Decimal=%d, Closest=%d, TID=%d", beat_y, decimal_y, closest_y, tid_y); 74 85 75 - // Create TID TextLayer (Bottom) 76 - s_tid_layer = clock_tid_init(GRect(0, tid_y, bounds.size.w, tid_h), window_layer); 86 + // Create Layers in new order 87 + // Beat Time TextLayer (Top) 88 + s_beat_layer = clock_beat_init(GRect(0, beat_y, bounds.size.w, layer_h), window_layer); 89 + 90 + // Decimal Time TextLayer (Middle) 91 + s_decimal_layer = clock_decimal_init(GRect(0, decimal_y, bounds.size.w, layer_h), window_layer); 92 + 93 + // Closest Noon Time TextLayer (Middle-Bottom) 94 + s_closest_noon_layer = clock_closest_noon_init(GRect(0, closest_y, bounds.size.w, layer_h), window_layer); 95 + 96 + // TID TextLayer (Bottom) 97 + s_tid_layer = clock_tid_init(GRect(0, tid_y, bounds.size.w, layer_h), window_layer); 98 + 99 + // // Create Noon Zone Time TextLayer // Removed 100 + // s_noonzone_layer = clock_noonzone_init(GRect(0, noonzone_y, bounds.size.w, layer_h), window_layer); 101 + 77 102 } 78 103 79 104 static void main_window_unload(Window *window) { 80 105 // Destroy TextLayers 81 106 clock_beat_deinit(s_beat_layer); 82 - clock_noonzone_deinit(s_noonzone_layer); 107 + // clock_noonzone_deinit(s_noonzone_layer); // Removed 83 108 clock_closest_noon_deinit(s_closest_noon_layer); 84 109 clock_tid_deinit(s_tid_layer); 110 + clock_decimal_deinit(s_decimal_layer); 85 111 } 86 112 87 113 static void init() {