Skip to content

Commit 740aa14

Browse files
helgibbonsGadgetoid
authored andcommitted
Add I75 placekitten example
1 parent 3bc0f01 commit 740aa14

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import WIFI_CONFIG
2+
from network_manager import NetworkManager
3+
import uasyncio
4+
from urllib import urequest
5+
from interstate75 import Interstate75, DISPLAY_INTERSTATE75_128X64
6+
import jpegdec
7+
import random
8+
9+
"""
10+
Grab a random image from PlaceKitten.com
11+
and display it on Interstate 75 W.
12+
"""
13+
14+
i75 = Interstate75(display=DISPLAY_INTERSTATE75_128X64)
15+
graphics = i75.display
16+
17+
WIDTH = i75.width
18+
HEIGHT = i75.height
19+
FILENAME = "placekitten.jpg"
20+
ENDPOINT = "http://placekitten.com/{0}/{1}"
21+
22+
# some colours to draw with
23+
WHITE = graphics.create_pen(255, 255, 255)
24+
BLACK = graphics.create_pen(0, 0, 0)
25+
26+
27+
def status_handler(mode, status, ip):
28+
graphics.set_font("bitmap8")
29+
graphics.set_pen(BLACK)
30+
graphics.clear()
31+
graphics.set_pen(WHITE)
32+
graphics.text("Network: {}".format(WIFI_CONFIG.SSID), 2, 2, scale=1)
33+
status_text = "Connecting..."
34+
if status is not None:
35+
if status:
36+
status_text = "Connection successful!"
37+
else:
38+
status_text = "Connection failed!"
39+
40+
graphics.text(status_text, 2, 12, scale=1)
41+
graphics.text("IP: {}".format(ip), 2, 22, scale=1)
42+
i75.update(graphics)
43+
44+
45+
# connect to wifi
46+
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
47+
uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK))
48+
49+
url = ENDPOINT.format(WIDTH, HEIGHT + random.randint(0, 10))
50+
print("Requesting URL: {}".format(url))
51+
socket = urequest.urlopen(url)
52+
53+
# Load the image data into RAM (if you have enough!)
54+
data = bytearray(1024 * 10)
55+
socket.readinto(data)
56+
socket.close()
57+
58+
# draw the image
59+
jpeg = jpegdec.JPEG(graphics)
60+
jpeg.open_RAM(data)
61+
jpeg.decode(0, 0)
62+
63+
"""
64+
# draw a box with the URL - only really works on looooong displays
65+
graphics.set_pen(BLACK)
66+
graphics.rectangle(0, HEIGHT - 7, WIDTH, 7)
67+
graphics.set_font("bitmap6")
68+
graphics.set_pen(WHITE)
69+
graphics.text(url, 1, HEIGHT - 7, scale=1)
70+
"""
71+
72+
# update the display
73+
i75.update(graphics)

0 commit comments

Comments
 (0)