Inky Frame: Update examples to support 4.0".

This commit is contained in:
Phil Howard 2022-10-03 13:46:43 +01:00
parent 6aa1bbd271
commit 14fec0406d
6 changed files with 21 additions and 13 deletions

View File

@ -4,7 +4,8 @@ from network_manager import NetworkManager
import uasyncio
import ujson
from urllib import urequest
from picographics import PicoGraphics, DISPLAY_INKY_FRAME
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
from machine import Pin
from pimoroni_i2c import PimoroniI2C
from pcf85063a import PCF85063A
@ -38,7 +39,7 @@ def status_handler(mode, status, ip):
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
gc.collect()
graphics = PicoGraphics(DISPLAY_INKY_FRAME)
graphics = PicoGraphics(DISPLAY)
WIDTH, HEIGHT = graphics.get_bounds()
gc.collect()

View File

@ -1,4 +1,5 @@
from picographics import PicoGraphics, DISPLAY_INKY_FRAME
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
from network_manager import NetworkManager
import uasyncio
from urllib import urequest
@ -27,7 +28,7 @@ URL = "http://feeds.bbci.co.uk/news/technology/rss.xml"
# Frequent updates will reduce battery life!
UPDATE_INTERVAL = 60 * 1
graphics = PicoGraphics(DISPLAY_INKY_FRAME)
graphics = PicoGraphics(DISPLAY)
WIDTH, HEIGHT = graphics.get_bounds()
graphics.set_font("bitmap8")
code = qrcode.QRCode()

View File

@ -8,7 +8,8 @@ import sdcard
import WIFI_CONFIG
from urllib import urequest
from network_manager import NetworkManager
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
"""
random placekitten (from a very small set)

View File

@ -5,7 +5,8 @@ import uasyncio
import WIFI_CONFIG
from urllib import urequest
from network_manager import NetworkManager
from picographics import PicoGraphics, DISPLAY_INKY_FRAME
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
ENDPOINT = "https://en.wikiquote.org/w/api.php?format=json&action=expandtemplates&prop=wikitext&text={{{{Wikiquote:Quote%20of%20the%20day/{3}%20{2},%20{0}}}}}"
@ -31,7 +32,7 @@ def status_handler(mode, status, ip):
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
gc.collect()
graphics = PicoGraphics(DISPLAY_INKY_FRAME)
graphics = PicoGraphics(DISPLAY)
WIDTH, HEIGHT = graphics.get_bounds()
graphics.set_font("bitmap8")
gc.collect()

View File

@ -6,7 +6,8 @@ import jpegdec
import WIFI_CONFIG
import uasyncio
from network_manager import NetworkManager
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
from urllib import urequest
@ -27,7 +28,7 @@ WIDTH, HEIGHT = graphics.get_bounds()
FILENAME = "/sd/random-joke.jpg"
JOKE_IDS = "https://pimoroni.github.io/feed2image/jokeapi-ids.txt"
JOKE_IMG = "https://pimoroni.github.io/feed2image/jokeapi-{}-600x448.jpg"
JOKE_IMG = "https://pimoroni.github.io/feed2image/jokeapi-{}-{}x{}.jpg"
import sdcard # noqa: E402 - putting this at the top causes an MBEDTLS OOM error!?
sd_spi = machine.SPI(0, sck=machine.Pin(18, machine.Pin.OUT), mosi=machine.Pin(19, machine.Pin.OUT), miso=machine.Pin(16, machine.Pin.OUT))
@ -59,7 +60,7 @@ socket.close()
print("Random joke ID: {}".format(random_joke_id))
url = JOKE_IMG.format(random_joke_id)
url = JOKE_IMG.format(random_joke_id, WIDTH, HEIGHT)
socket = urequest.urlopen(url)

View File

@ -1,6 +1,5 @@
import gc
import uos
import random
import machine
import jpegdec
import uasyncio
@ -8,7 +7,8 @@ import sdcard
import WIFI_CONFIG
from urllib import urequest
from network_manager import NetworkManager
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
"""
xkcd daily
@ -46,7 +46,10 @@ uos.mount(sd, "/sd")
gc.collect() # Claw back some RAM!
url = ENDPOINT.format(WIDTH, HEIGHT + random.randint(0, 10))
url = ENDPOINT
if (WIDTH, HEIGHT) != (600, 448):
url = url.replace("xkcd-", f"xkcd-{WIDTH}x{HEIGHT}-")
socket = urequest.urlopen(url)