From 14fec0406d94b423435065cdd4091bc94c6e0771 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 3 Oct 2022 13:46:43 +0100 Subject: [PATCH] Inky Frame: Update examples to support 4.0". --- .../examples/inky_frame/inky_frame_daily_activity.py | 5 +++-- micropython/examples/inky_frame/inky_frame_news.py | 5 +++-- .../examples/inky_frame/inky_frame_placekitten.py | 3 ++- .../examples/inky_frame/inky_frame_quote_of_the_day.py | 5 +++-- .../examples/inky_frame/inky_frame_random_joke.py | 7 ++++--- micropython/examples/inky_frame/inky_frame_xkcd_daily.py | 9 ++++++--- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/micropython/examples/inky_frame/inky_frame_daily_activity.py b/micropython/examples/inky_frame/inky_frame_daily_activity.py index cdb73277..7e1b039e 100644 --- a/micropython/examples/inky_frame/inky_frame_daily_activity.py +++ b/micropython/examples/inky_frame/inky_frame_daily_activity.py @@ -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() diff --git a/micropython/examples/inky_frame/inky_frame_news.py b/micropython/examples/inky_frame/inky_frame_news.py index 14f8d828..5340d444 100644 --- a/micropython/examples/inky_frame/inky_frame_news.py +++ b/micropython/examples/inky_frame/inky_frame_news.py @@ -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() diff --git a/micropython/examples/inky_frame/inky_frame_placekitten.py b/micropython/examples/inky_frame/inky_frame_placekitten.py index 8c6f9366..5d3ba880 100644 --- a/micropython/examples/inky_frame/inky_frame_placekitten.py +++ b/micropython/examples/inky_frame/inky_frame_placekitten.py @@ -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) diff --git a/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py b/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py index 76269889..886d10e9 100644 --- a/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py +++ b/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py @@ -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() diff --git a/micropython/examples/inky_frame/inky_frame_random_joke.py b/micropython/examples/inky_frame/inky_frame_random_joke.py index 4eb7cbc5..23eb606d 100644 --- a/micropython/examples/inky_frame/inky_frame_random_joke.py +++ b/micropython/examples/inky_frame/inky_frame_random_joke.py @@ -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) diff --git a/micropython/examples/inky_frame/inky_frame_xkcd_daily.py b/micropython/examples/inky_frame/inky_frame_xkcd_daily.py index 9b1d1d29..3eff8bb9 100644 --- a/micropython/examples/inky_frame/inky_frame_xkcd_daily.py +++ b/micropython/examples/inky_frame/inky_frame_xkcd_daily.py @@ -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)