diff --git a/main.py b/main.py index 57f1a48..e1aadd8 100644 --- a/main.py +++ b/main.py @@ -86,40 +86,30 @@ def calculate_x_spacing(text, scale=1): # --- Main Loop --- DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] +TIME_Y = 12 # Keep vertical placement consistent while True: local_epoch = time.time() + (Config.UTC_OFFSET * 3600) - year, month, day, hour_24, minute, second, weekday, _ = time.localtime(local_epoch) + year, month, day, hour_24, minute, _, weekday, _ = time.localtime(local_epoch) - oled.fill(0) - - # Draw 24-hour time + # 1. Format time string and period if Config.USE_24_HOUR: - # Time string (HH:MM:SS is 8 chars -> 8 chars * 8px * 2x = 128px wide) time_str = f"{hour_24:02d}:{minute:02d}" - - # Draw time at 2x scale (16px high, spans 128px across) - time_x = calculate_x_spacing(time_str, 2) - draw_scaled_text(oled, time_str, x=time_x, y=14, scale=2) - - # Draw 12-hour time (AM/PM) + period = None else: - # 1. Determine AM/PM and 12-hour format - period = "AM" if hour_24 < 12 else "PM" - hour_12 = hour_24 % 12 - if hour_12 == 0: - hour_12 = 12 - - # Format time without leading zero (or use {:2d} for alignment) + hour_12 = hour_24 % 12 or 12 # Replaces the 4-line if hour_12 == 0 block time_str = f"{hour_12}:{minute:02d}" + period = "AM" if hour_24 < 12 else "PM" - # 2. Draw 2x scaled time - time_x = calculate_x_spacing(time_str, 2) - draw_scaled_text(oled, time_str, x=time_x, y=12, scale=2) - # 3. Draw AM/PM in standard 1x font (aligned with the bottom of the 16px digits) - oled.text(period, time_x + (len(time_str) * 16) + 4, 12 + 8) + # 2. Render time and AM/PM + oled.fill(0) + time_x = calculate_x_spacing(time_str, scale=2) + draw_scaled_text(oled, time_str, x=time_x, y=TIME_Y, scale=2) - # 4. Draw date centered horizontally underneath + if period: + oled.text(period, time_x + (len(time_str) * 16) + 4, TIME_Y + 8) + + # 3. Render date centered underneath date_str = f"{DAYS[weekday]} {year}-{month:02d}-{day:02d}" oled.text(date_str, calculate_x_spacing(date_str), 42)