aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorD Delmar Davis <don@suspectdevices.com>2024-08-23 22:35:55 -0700
committerD Delmar Davis <don@suspectdevices.com>2024-08-23 22:35:55 -0700
commit672efbf2f146c3a9c9df73d252f296f82e503624 (patch)
tree20575b6630f7079a64f3f84482d04339ba5487c6
parent2b8325f5129f277a06a0db8eda7a0f0be0b90941 (diff)
push a draft
-rwxr-xr-xbin/clock.py69
1 files changed, 53 insertions, 16 deletions
diff --git a/bin/clock.py b/bin/clock.py
index b66b286..09b7bb0 100755
--- a/bin/clock.py
+++ b/bin/clock.py
@@ -14,6 +14,9 @@ import digitalio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1305
from datetime import datetime
+import math
+import atexit
+import signal
displayIsOff = False;
@@ -40,17 +43,43 @@ x = 0
# Load default font.
font = ImageFont.load_default()
+def draw_clock(t: datetime):
+ ctop=top+3
+ cbottom=bottom-1
+ center=(cbottom-ctop)/2
+ h=t.hour
+ m=t.minute
+ ml = center * 0.9 #fix later
+ hl = center * 0.6
+ a = 90.0 - (m / 60.0) * 360.0
+ r = a * math.pi / 180.0
+ mx = int(math.cos(r) * ml)
+ my = -int(math.sin(r) * ml)
+
+ a = 90.0 - ((h + (m/60) )/ 12.0) * 360.0
+ r = a * math.pi / 180.0
+ hx = int(math.cos(r) * hl)
+ hy = -int(math.sin(r) * hl)
+
+ print(h, ":" ,m)
+ draw.ellipse((ctop, ctop, cbottom, cbottom), fill = 0, outline =255)
+ draw.line([center,center,center+mx,center+my], fill=255, width=0)
+ draw.line([center,center,center+hx,center+hy], fill=255, width=0)
+
+
+ # Draw a black filled box to clear the image.
while True:
+ try:
thetime=datetime.now()
if(displayIsOff):
- if (thetime.hour<=18 and thetime.hour>=6):
+ if (thetime.hour<=22 and thetime.hour>=6):
disp.poweron()
disp.fill(0)
disp.show()
- displayIsOff=False
- else:
- if (thetime.hour>19 or thetime.hour<6):
+ displayIsOff=False
+ else:
+ if (thetime.hour>23 or thetime.hour<6):
disp.poweroff()
displayIsOff=True
@@ -58,23 +87,31 @@ while True:
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=0)
- cmd = "hostname -I | cut -d' ' -f1"
- IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
- cmd = "date +%X\ %d%b%y"
- TimeDate = subprocess.check_output(cmd, shell=True).decode("utf-8")
- cmd = "fetchtemp.py"
- LocalTemp = subprocess.check_output(cmd, shell=True).decode("utf-8")
+ #cmd = "hostname -I | cut -d' ' -f1"
+ #IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
+ #cmd = "date +%X\ %d%b%y"
+ #TimeDate = subprocess.check_output(cmd, shell=True).decode("utf-8")
+ #cmd = "fetchtemp.py"
+ #LocalTemp = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = 'gathertemps.py'
PromData = subprocess.check_output(cmd, shell=True).decode("utf-8")
-
+ temps=PromData.split()
# Write four lines of text.
-
- draw.text((x, top + 0), "IP: " + IP, font=font, fill=255)
- draw.text((x, top + 8), TimeDate, font=font, fill=255)
- draw.text((x, top + 16), LocalTemp, font=font, fill=255)
- draw.text((x, top + 25), PromData, font=font, fill=255)
+ draw_clock(thetime)
+ draw.text((x+50, top + 0), temps[0], font=font, fill=255)
+ draw.text((x+50, top + 8), temps[1], font=font, fill=255)
+ draw.text((x+50, top + 16),temps[2], font=font, fill=255)
+ draw.text((x+50, top + 25),temps[3], font=font, fill=255)
# Display image.
disp.image(image)
disp.show()
time.sleep(0.1)
+
+ draw.rectangle((0, 0, width, height), outline=0, fill=0)
+ disp.poweroff()
+
+# except KeyboardInterrupt:
+# draw.rectangle((0, 0, width, height), outline=0, fill=0)
+# disp.poweroff()
+# exit()