[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
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -88,20 +88,27 @@ def calculate_x_spacing(text, scale=1):
|
||||
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, _, weekday, _ = time.localtime(local_epoch)
|
||||
last_second = -1
|
||||
|
||||
while True:
|
||||
# 1. Compute time
|
||||
local_epoch = time.time() + (Config.UTC_OFFSET * 3600)
|
||||
year, month, day, hour_24, minute, second, weekday, _ = time.localtime(local_epoch)
|
||||
|
||||
# 2. Only redraw if the second has actually changed
|
||||
if second != last_second:
|
||||
last_second = second
|
||||
|
||||
sep = ":" if second % 2 == 0 else " "
|
||||
|
||||
# 1. Format time string and period
|
||||
if Config.USE_24_HOUR:
|
||||
time_str = f"{hour_24:02d}:{minute:02d}"
|
||||
time_str = f"{hour_24:02d}{sep}{minute:02d}"
|
||||
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}"
|
||||
hour_12 = hour_24 % 12 or 12
|
||||
time_str = f"{hour_12}{sep}{minute:02d}"
|
||||
period = "AM" if hour_24 < 12 else "PM"
|
||||
|
||||
# 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)
|
||||
@@ -109,9 +116,10 @@ while True:
|
||||
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)
|
||||
|
||||
oled.show()
|
||||
time.sleep(0.5)
|
||||
|
||||
# 3. Sleep in small increments to catch the exact second boundary with minimal latency
|
||||
time.sleep_ms(20)
|
||||
|
||||
Reference in New Issue
Block a user