aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2025-03-14 09:14:11 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2025-03-14 09:14:11 +0100
commit7fa4fb1c86067b9a7e4f8923e26744dbf0f43017 (patch)
tree236028bc61c7663f640f474374eddeef902538a9
parent9ad87e3baa2b19303e05abaf2ae93ea0651e2d97 (diff)
Clock face with hardcoded timezone
-rw-r--r--gd_clock.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/gd_clock.py b/gd_clock.py
index c3a91dc..09d7412 100644
--- a/gd_clock.py
+++ b/gd_clock.py
@@ -1,11 +1,13 @@
import board
import json
import os
+import rtc
import time
import wifi
import adafruit_connection_manager
import adafruit_minimqtt.adafruit_minimqtt as MQTT
+import adafruit_ntp
import colours
import neopixel
@@ -75,9 +77,34 @@ class StatusRing:
status_ring = StatusRing()
+class ClockFace:
+ offset_hours = 1
+ offset_min = 0
+
+ def start(self, clock):
+ print("Starting clock face mode")
+ clock.brightness = 0.1
+ pixels.brightness = clock.brightness
+ pixels.fill((0, 0, 0))
+
+ def loop(self, clock):
+ now = time.localtime()
+ hour = (now.tm_hour + self.offset_hours) % 12
+ minutes = (now.tm_min + self.offset_min) % 60 // 5
+ pixels.fill((0, 0, 0))
+ if hour == minutes:
+ pixels[hour] = (64, 0, 64)
+ else:
+ pixels[hour] = (0, 0, 64)
+ pixels[minutes] = (64, 0, 0)
+
+
+clock_face = ClockFace()
+
+
class GD_Clock:
brightness = 0.1
- current_mode = rainbow
+ current_mode = clock_face
batteries = {}
def connected(self, client, userdata, flags, rc):
@@ -99,6 +126,9 @@ class GD_Clock:
value = payload.get("value", None)
kwargs = payload.get("kwargs", {})
if cmd == "mode":
+ if value == "clock":
+ self.current_mode = clock_face
+ self.current_mode.start(self)
if value == "flashlight":
self.current_mode = flashlight
self.current_mode.start(self)
@@ -153,6 +183,10 @@ print("Connected to WiFi")
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
+ntp = adafruit_ntp.NTP(pool, tz_offset=0, cache_seconds=3600)
+
+rtc.RTC().datetime = ntp.datetime
+
mqtt_client = MQTT.MQTT(
broker=os.getenv('MQTT_HOST'),
socket_pool=pool,