Compare commits
No commits in common. "4ff4f3f1227ef2da901d0868e532b4dd35a914f1" and "890f288e99cb4bc971d6d1edd0e5993d14062371" have entirely different histories.
4ff4f3f122
...
890f288e99
|
@ -28,11 +28,6 @@ These are all web sites, videos, and references I used when putting it together.
|
|||
- I pulled the Wifi connection code from [RTC Clock Demo](https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/inky_frame/inky_frame_rtc_demo.py)
|
||||
- I couldn't find any examples or documentation for how to use [pngdec](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/pngdec), which is the library for decoding and displaying PNG images. Luckily, it works a lot like [jpegdec](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/jpegdec) and so I used the same APIs and it worked.
|
||||
|
||||
## Home Assistant
|
||||
|
||||
* [HACS](https://hacs.xyz/): extra customisation framework that basically all Home Assistant users should have
|
||||
* [Kiosk Mode](https://github.com/maykar/kiosk-mode): installs a "kiosk" mode of a Lovelace dashboard that hides the menu bars and stuff. Perfect for this application.
|
||||
|
||||
## Hass Screen Saver Kindle
|
||||
|
||||
- The [main repository](https://github.com/sibbl/hass-lovelace-kindle-screensaver/tree/main)
|
||||
|
|
|
@ -21,7 +21,6 @@ from urllib import urequest
|
|||
from machine import Pin, SPI
|
||||
from network_manager import NetworkManager
|
||||
import time
|
||||
import ntptime
|
||||
import inky_frame
|
||||
import pngdec
|
||||
import gc
|
||||
|
@ -32,15 +31,14 @@ import inky_frame
|
|||
import uasyncio
|
||||
global graphics
|
||||
|
||||
def display_image(j):
|
||||
def display_image(j, CONFIG.FILENAME):
|
||||
# Open the PNG file
|
||||
j.open_file(CONFIG.FILENAME)
|
||||
# Decode the PNG
|
||||
j.decode()
|
||||
|
||||
# write the date/time at the top
|
||||
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
|
||||
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
|
||||
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time())
|
||||
graphics.set_pen(0)
|
||||
graphics.set_font('sans')
|
||||
# display.text(text, x, y, wordwrap, scale, angle, spacing)
|
||||
|
@ -57,7 +55,7 @@ def show_error(text,y):
|
|||
graphics.text(text, 5, 16 + HEIGHT, 400, 2)
|
||||
gc.collect()
|
||||
|
||||
def fetch():
|
||||
def fetch(url):
|
||||
""" Fetch the image, store it onboard.
|
||||
Returns False at first error.
|
||||
Returns True only if everything succeeds.
|
||||
|
@ -76,40 +74,29 @@ def fetch():
|
|||
return False
|
||||
inky_frame.button_b.led_off()
|
||||
|
||||
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
|
||||
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
|
||||
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time())
|
||||
print(f"{hour:02}:{minute:02} {year}-{month}-{day}")
|
||||
|
||||
count = 0
|
||||
if year < 2023:
|
||||
# blink d when we are setting the time
|
||||
inky_frame.button_d.led_on()
|
||||
ntptime.host = '0.us.pool.ntp.org'
|
||||
while count < 5:
|
||||
try:
|
||||
inky_frame.set_time() # set time from network
|
||||
except OSError as e:
|
||||
print( "x", end="" )
|
||||
count += 1
|
||||
inky_frame.button_d.led_off()
|
||||
# blink b when we are setting the time
|
||||
inky_frame.button_b.led_on()
|
||||
inky_frame.set_time() # set time from network
|
||||
inky_frame.button_b.led_off()
|
||||
|
||||
if count >= 5:
|
||||
# turn on E to indicate error. gets turned off later.
|
||||
inky_frame.button_e.led_on()
|
||||
|
||||
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
|
||||
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
|
||||
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds)
|
||||
|
||||
# don't bother updating before 06:00 or after 23:00
|
||||
if hour < 5 or hour > 22:
|
||||
print(f"hour {hour:02}, no need to fetch")
|
||||
print("no need to fetch")
|
||||
return False
|
||||
del year, month, day, hour, minute, second, tz_seconds, count
|
||||
print( "fetching " + CONFIG.IMG_URL )
|
||||
del year, month, day, hour, minute, second, tz_seconds
|
||||
print( "fetching " + url )
|
||||
inky_frame.button_c.led_on()
|
||||
|
||||
try:
|
||||
# Grab the image
|
||||
socket = urequest.urlopen(CONFIG.IMG_URL)
|
||||
socket = urequest.urlopen(url)
|
||||
gc.collect()
|
||||
except OSError as e:
|
||||
print("Unable open URL. OSErr: ")
|
||||
|
@ -174,7 +161,7 @@ while True:
|
|||
mount_sd()
|
||||
gc.collect()
|
||||
inky_frame.button_a.led_off()
|
||||
if fetch():
|
||||
if fetch(CONFIG.IMG_URL):
|
||||
gc.collect()
|
||||
inky_frame.button_e.led_on()
|
||||
|
||||
|
@ -184,7 +171,7 @@ while True:
|
|||
# Create a new PNG decoder for our PicoGraphics
|
||||
j = pngdec.PNG(graphics)
|
||||
|
||||
display_image(j)
|
||||
display_image(j, CONFIG.FILENAME)
|
||||
# Display the result
|
||||
graphics.update()
|
||||
|
||||
|
|
Loading…
Reference in New Issue