aboutsummaryrefslogtreecommitdiff
path: root/bin/test.py
diff options
context:
space:
mode:
authorD Delmar Davis <don@suspectdevices.com>2024-08-21 21:56:56 -0700
committerD Delmar Davis <don@suspectdevices.com>2024-08-21 21:56:56 -0700
commit2b8325f5129f277a06a0db8eda7a0f0be0b90941 (patch)
treea7bcca599db9f31f50207e98043fcf36c77938c6 /bin/test.py
parent85eb7b012a0d5a4a69e65037a9d97caebec15328 (diff)
analog clockstuff
Diffstat (limited to 'bin/test.py')
-rw-r--r--bin/test.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/bin/test.py b/bin/test.py
new file mode 100644
index 0000000..af2e0d7
--- /dev/null
+++ b/bin/test.py
@@ -0,0 +1,97 @@
+# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
+# SPDX-License-Identifier: MIT
+
+# -*- coding: utf-8 -*-
+
+import time
+import subprocess
+import digitalio
+import board
+from PIL import Image, ImageDraw, ImageFont
+from adafruit_rgb_display import st7789
+
+
+# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
+cs_pin = digitalio.DigitalInOut(board.CE0)
+dc_pin = digitalio.DigitalInOut(board.D25)
+reset_pin = None
+
+# Config for display baudrate (default max is 24mhz):
+BAUDRATE = 64000000
+
+# Setup SPI bus using hardware SPI:
+spi = board.SPI()
+
+# Create the ST7789 display:
+disp = st7789.ST7789(
+ spi,
+ cs=cs_pin,
+ dc=dc_pin,
+ rst=reset_pin,
+ baudrate=BAUDRATE,
+ width=135,
+ height=240,
+ x_offset=53,
+ y_offset=40,
+)
+
+# Create blank image for drawing.
+# Make sure to create image with mode 'RGB' for full color.
+height = disp.width # we swap height/width to rotate it to landscape!
+width = disp.height
+image = Image.new("RGB", (width, height))
+rotation = 90
+
+# Get drawing object to draw on image.
+draw = ImageDraw.Draw(image)
+
+# Draw a black filled box to clear the image.
+draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0))
+disp.image(image, rotation)
+# Draw some shapes.
+# First 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
+
+
+# Alternatively load a TTF font. Make sure the .ttf font file is in the
+# same directory as the python script!
+# Some other nice fonts to try: http://www.dafont.com/bitmap.php
+font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 24)
+
+# Turn on the backlight
+backlight = digitalio.DigitalInOut(board.D22)
+backlight.switch_to_output()
+backlight.value = True
+
+while True:
+ # Draw a black filled box to clear the image.
+ draw.rectangle((0, 0, width, height), outline=0, fill=0)
+
+ # Shell scripts for system monitoring from here:
+ # https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
+ cmd = "hostname -I | cut -d' ' -f1"
+ IP = "IP: " + subprocess.check_output(cmd, shell=True).decode("utf-8")
+ cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}'" # pylint: disable=line-too-long
+ Temp = 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 = "localtemp.py"
+ LocalTemp = subprocess.check_output(cmd, shell=True).decode("utf-8")
+
+ # Write four lines of text.
+ y = top
+ draw.text((x, y), IP, font=font, fill="#FFFFFF")
+ y += font.getsize(IP)[1]
+ draw.text((x, y), TimeDate, font=font, fill="#FFFF00")
+ y += font.getsize(TimeDate)[1]
+ draw.text((x, y), LocalTemp, font=font, fill="#00FF00")
+ y += font.getsize(LocalTemp)[1]
+ draw.text((x, y), Temp, font=font, fill="#FF00FF")
+
+ # Display image.
+ disp.image(image, rotation)
+ time.sleep(0.1)