[Issue #1] - Simplified some of the logic for the main loop with the new 24-hour option
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -86,40 +86,30 @@ def calculate_x_spacing(text, scale=1):
|
|||||||
|
|
||||||
# --- Main Loop ---
|
# --- Main Loop ---
|
||||||
DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
|
DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
|
||||||
|
TIME_Y = 12 # Keep vertical placement consistent
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
local_epoch = time.time() + (Config.UTC_OFFSET * 3600)
|
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)
|
# 1. Format time string and period
|
||||||
|
|
||||||
# Draw 24-hour time
|
|
||||||
if Config.USE_24_HOUR:
|
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}"
|
time_str = f"{hour_24:02d}:{minute:02d}"
|
||||||
|
period = None
|
||||||
# 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)
|
|
||||||
else:
|
else:
|
||||||
# 1. Determine AM/PM and 12-hour format
|
hour_12 = hour_24 % 12 or 12 # Replaces the 4-line if hour_12 == 0 block
|
||||||
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)
|
|
||||||
time_str = f"{hour_12}:{minute:02d}"
|
time_str = f"{hour_12}:{minute:02d}"
|
||||||
|
period = "AM" if hour_24 < 12 else "PM"
|
||||||
|
|
||||||
# 2. Draw 2x scaled time
|
# 2. Render time and AM/PM
|
||||||
time_x = calculate_x_spacing(time_str, 2)
|
oled.fill(0)
|
||||||
draw_scaled_text(oled, time_str, x=time_x, y=12, scale=2)
|
time_x = calculate_x_spacing(time_str, scale=2)
|
||||||
# 3. Draw AM/PM in standard 1x font (aligned with the bottom of the 16px digits)
|
draw_scaled_text(oled, time_str, x=time_x, y=TIME_Y, scale=2)
|
||||||
oled.text(period, time_x + (len(time_str) * 16) + 4, 12 + 8)
|
|
||||||
|
|
||||||
# 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}"
|
date_str = f"{DAYS[weekday]} {year}-{month:02d}-{day:02d}"
|
||||||
oled.text(date_str, calculate_x_spacing(date_str), 42)
|
oled.text(date_str, calculate_x_spacing(date_str), 42)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user