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 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.
|
- 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
|
## Hass Screen Saver Kindle
|
||||||
|
|
||||||
- The [main repository](https://github.com/sibbl/hass-lovelace-kindle-screensaver/tree/main)
|
- 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 machine import Pin, SPI
|
||||||
from network_manager import NetworkManager
|
from network_manager import NetworkManager
|
||||||
import time
|
import time
|
||||||
import ntptime
|
|
||||||
import inky_frame
|
import inky_frame
|
||||||
import pngdec
|
import pngdec
|
||||||
import gc
|
import gc
|
||||||
|
@ -32,15 +31,14 @@ import inky_frame
|
||||||
import uasyncio
|
import uasyncio
|
||||||
global graphics
|
global graphics
|
||||||
|
|
||||||
def display_image(j):
|
def display_image(j, CONFIG.FILENAME):
|
||||||
# Open the PNG file
|
# Open the PNG file
|
||||||
j.open_file(CONFIG.FILENAME)
|
j.open_file(CONFIG.FILENAME)
|
||||||
# Decode the PNG
|
# Decode the PNG
|
||||||
j.decode()
|
j.decode()
|
||||||
|
|
||||||
# write the date/time at the top
|
# write the date/time at the top
|
||||||
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
|
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time())
|
||||||
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
|
|
||||||
graphics.set_pen(0)
|
graphics.set_pen(0)
|
||||||
graphics.set_font('sans')
|
graphics.set_font('sans')
|
||||||
# display.text(text, x, y, wordwrap, scale, angle, spacing)
|
# 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)
|
graphics.text(text, 5, 16 + HEIGHT, 400, 2)
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def fetch():
|
def fetch(url):
|
||||||
""" Fetch the image, store it onboard.
|
""" Fetch the image, store it onboard.
|
||||||
Returns False at first error.
|
Returns False at first error.
|
||||||
Returns True only if everything succeeds.
|
Returns True only if everything succeeds.
|
||||||
|
@ -76,40 +74,29 @@ def fetch():
|
||||||
return False
|
return False
|
||||||
inky_frame.button_b.led_off()
|
inky_frame.button_b.led_off()
|
||||||
|
|
||||||
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
|
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time())
|
||||||
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
|
|
||||||
print(f"{hour:02}:{minute:02} {year}-{month}-{day}")
|
print(f"{hour:02}:{minute:02} {year}-{month}-{day}")
|
||||||
|
|
||||||
count = 0
|
|
||||||
if year < 2023:
|
if year < 2023:
|
||||||
# blink d when we are setting the time
|
# blink b when we are setting the time
|
||||||
inky_frame.button_d.led_on()
|
inky_frame.button_b.led_on()
|
||||||
ntptime.host = '0.us.pool.ntp.org'
|
inky_frame.set_time() # set time from network
|
||||||
while count < 5:
|
inky_frame.button_b.led_off()
|
||||||
try:
|
|
||||||
inky_frame.set_time() # set time from network
|
|
||||||
except OSError as e:
|
|
||||||
print( "x", end="" )
|
|
||||||
count += 1
|
|
||||||
inky_frame.button_d.led_off()
|
|
||||||
|
|
||||||
if count >= 5:
|
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
|
||||||
# turn on E to indicate error. gets turned off later.
|
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds)
|
||||||
inky_frame.button_e.led_on()
|
|
||||||
|
|
||||||
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
|
|
||||||
|
|
||||||
# don't bother updating before 06:00 or after 23:00
|
# don't bother updating before 06:00 or after 23:00
|
||||||
if hour < 5 or hour > 22:
|
if hour < 5 or hour > 22:
|
||||||
print(f"hour {hour:02}, no need to fetch")
|
print("no need to fetch")
|
||||||
return False
|
return False
|
||||||
del year, month, day, hour, minute, second, tz_seconds, count
|
del year, month, day, hour, minute, second, tz_seconds
|
||||||
print( "fetching " + CONFIG.IMG_URL )
|
print( "fetching " + url )
|
||||||
inky_frame.button_c.led_on()
|
inky_frame.button_c.led_on()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Grab the image
|
# Grab the image
|
||||||
socket = urequest.urlopen(CONFIG.IMG_URL)
|
socket = urequest.urlopen(url)
|
||||||
gc.collect()
|
gc.collect()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print("Unable open URL. OSErr: ")
|
print("Unable open URL. OSErr: ")
|
||||||
|
@ -174,7 +161,7 @@ while True:
|
||||||
mount_sd()
|
mount_sd()
|
||||||
gc.collect()
|
gc.collect()
|
||||||
inky_frame.button_a.led_off()
|
inky_frame.button_a.led_off()
|
||||||
if fetch():
|
if fetch(CONFIG.IMG_URL):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
inky_frame.button_e.led_on()
|
inky_frame.button_e.led_on()
|
||||||
|
|
||||||
|
@ -184,7 +171,7 @@ while True:
|
||||||
# Create a new PNG decoder for our PicoGraphics
|
# Create a new PNG decoder for our PicoGraphics
|
||||||
j = pngdec.PNG(graphics)
|
j = pngdec.PNG(graphics)
|
||||||
|
|
||||||
display_image(j)
|
display_image(j, CONFIG.FILENAME)
|
||||||
# Display the result
|
# Display the result
|
||||||
graphics.update()
|
graphics.update()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue