diff options
| author | D Delmar Davis <don@suspectdevices.com> | 2024-08-21 21:56:56 -0700 |
|---|---|---|
| committer | D Delmar Davis <don@suspectdevices.com> | 2024-08-21 21:56:56 -0700 |
| commit | 2b8325f5129f277a06a0db8eda7a0f0be0b90941 (patch) | |
| tree | a7bcca599db9f31f50207e98043fcf36c77938c6 /bin/clock.py | |
| parent | 85eb7b012a0d5a4a69e65037a9d97caebec15328 (diff) | |
analog clockstuff
Diffstat (limited to 'bin/clock.py')
| -rwxr-xr-x | bin/clock.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/bin/clock.py b/bin/clock.py new file mode 100755 index 0000000..b66b286 --- /dev/null +++ b/bin/clock.py @@ -0,0 +1,80 @@ +#!/usr/bin/python +#--------------------------------------------------------------------- clock.py +# Display date and time as well as indoor and outdoor temperatures +# +# (C) D Delmar Davis 2023 +# +# Note: POC lots of hard coded foo here.... + +import time +import subprocess +from board import SCL, SDA, D4 +import busio +import digitalio +from PIL import Image, ImageDraw, ImageFont +import adafruit_ssd1305 +from datetime import datetime + +displayIsOff = False; + +oled_reset = digitalio.DigitalInOut(D4) +i2c = busio.I2C(SCL, SDA) +disp = adafruit_ssd1305.SSD1305_I2C(128, 32, i2c, reset=oled_reset) +disp.fill(0) +disp.show() + +width = disp.width +height = disp.height +image = Image.new("1", (width, height)) +draw = ImageDraw.Draw(image) +draw.rectangle((0, 0, width, height), outline=0, fill=0) + +# Define some constants to allow easy resizing of shapes. +padding = -2 +top = padding +bottom = height - padding +# Move left to right keeping track of the current x position for drawing shapes. +x = 0 + + +# Load default font. +font = ImageFont.load_default() + + +while True: + thetime=datetime.now() + if(displayIsOff): + if (thetime.hour<=18 and thetime.hour>=6): + disp.poweron() + disp.fill(0) + disp.show() + displayIsOff=False + else: + if (thetime.hour>19 or thetime.hour<6): + disp.poweroff() + displayIsOff=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 = 'gathertemps.py' + PromData = subprocess.check_output(cmd, shell=True).decode("utf-8") + + # 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) + + # Display image. + disp.image(image) + disp.show() + time.sleep(0.1) |
