[Issue #4] - Added blinking colon to signify that the clock is not frozen; also moved to a more "event-driven" approach to refreshing the display to cut down on wasted display cycles
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2026-09-07 22:10:46 -04:00
parent 0d8178375b
commit 9545c01150
+28 -20
View File
@@ -88,30 +88,38 @@ def calculate_x_spacing(text, scale=1):
DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
TIME_Y = 12 # Keep vertical placement consistent TIME_Y = 12 # Keep vertical placement consistent
last_second = -1
while True: while True:
# 1. Compute time
local_epoch = time.time() + (Config.UTC_OFFSET * 3600) local_epoch = time.time() + (Config.UTC_OFFSET * 3600)
year, month, day, hour_24, minute, _, weekday, _ = time.localtime(local_epoch) year, month, day, hour_24, minute, second, weekday, _ = time.localtime(local_epoch)
# 1. Format time string and period # 2. Only redraw if the second has actually changed
if Config.USE_24_HOUR: if second != last_second:
time_str = f"{hour_24:02d}:{minute:02d}" last_second = second
period = None
else:
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. Render time and AM/PM sep = ":" if second % 2 == 0 else " "
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)
if period: if Config.USE_24_HOUR:
oled.text(period, time_x + (len(time_str) * 16) + 4, TIME_Y + 8) time_str = f"{hour_24:02d}{sep}{minute:02d}"
period = None
else:
hour_12 = hour_24 % 12 or 12
time_str = f"{hour_12}{sep}{minute:02d}"
period = "AM" if hour_24 < 12 else "PM"
# 3. Render date centered underneath oled.fill(0)
date_str = f"{DAYS[weekday]} {year}-{month:02d}-{day:02d}" time_x = calculate_x_spacing(time_str, scale=2)
oled.text(date_str, calculate_x_spacing(date_str), 42) draw_scaled_text(oled, time_str, x=time_x, y=TIME_Y, scale=2)
oled.show() if period:
time.sleep(0.5) oled.text(period, time_x + (len(time_str) * 16) + 4, TIME_Y + 8)
date_str = f"{DAYS[weekday]} {year}-{month:02d}-{day:02d}"
oled.text(date_str, calculate_x_spacing(date_str), 42)
oled.show()
# 3. Sleep in small increments to catch the exact second boundary with minimal latency
time.sleep_ms(20)