Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch/inky launcher 57 update #626

Merged
merged 5 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def draw():
graphics.text("Participants: " + str(text[2]), 400, HEIGHT - 45, WIDTH - 20, 2)
else:
graphics.set_pen(4)
graphics.rectangle(0, 175, 640, 25)
graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40)
graphics.set_pen(1)
graphics.text("Unable to get data! Check your network settings in secrets.py", 5, 180, 600, 2)
graphics.text("Unable to get activity data!", 5, (HEIGHT // 2) - 15, WIDTH, 2)
graphics.text("Check your network settings in secrets.py", 5, (HEIGHT // 2) + 2, WIDTH, 2)

graphics.update()

Expand Down
47 changes: 29 additions & 18 deletions micropython/examples/inky_frame/inkylauncher/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
import gc
import time
from machine import reset
import inky_helper as ih

# Uncomment the line for your Inky Frame display size
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"

# Create a secrets.py with your Wifi details to be able to get the time
#
# secrets.py should contain:
Expand All @@ -20,6 +23,13 @@


def launcher():

# Apply an offset for the Inky Frame 5.7".
if HEIGHT == 448:
y_offset = 20
else:
y_offset = 0

# Draws the menu
graphics.set_pen(1)
graphics.clear()
Expand All @@ -28,42 +38,43 @@ def launcher():
graphics.set_pen(5)
graphics.rectangle(0, 0, WIDTH, 50)
graphics.set_pen(0)
graphics.text("Launcher", 245, 10, WIDTH, 4)
len = graphics.measure_text("Launcher", 4) // 2
graphics.text("Launcher", (WIDTH // 2 - len), 10, WIDTH, 4)

graphics.set_pen(4)
graphics.rectangle(30, 60, WIDTH - 100, 50)
graphics.rectangle(30, HEIGHT - (340 + y_offset), WIDTH - 100, 50)
graphics.set_pen(1)
graphics.text("A. NASA Picture of the Day", 35, 75, 600, 3)
graphics.text("A. NASA Picture of the Day", 35, HEIGHT - (325 + y_offset), 600, 3)

graphics.set_pen(6)
graphics.rectangle(30, 120, WIDTH - 150, 50)
graphics.rectangle(30, HEIGHT - (280 + y_offset), WIDTH - 150, 50)
graphics.set_pen(1)
graphics.text("B. Word Clock", 35, 135, 600, 3)
graphics.text("B. Word Clock", 35, HEIGHT - (265 + y_offset), 600, 3)

graphics.set_pen(2)
graphics.rectangle(30, 180, WIDTH - 200, 50)
graphics.rectangle(30, HEIGHT - (220 + y_offset), WIDTH - 200, 50)
graphics.set_pen(1)
graphics.text("C. Daily Activity", 35, 195, 600, 3)
graphics.text("C. Daily Activity", 35, HEIGHT - (205 + y_offset), 600, 3)

graphics.set_pen(3)
graphics.rectangle(30, 240, WIDTH - 250, 50)
graphics.rectangle(30, HEIGHT - (160 + y_offset), WIDTH - 250, 50)
graphics.set_pen(1)
graphics.text("D. Headlines", 35, 255, 600, 3)
graphics.text("D. Headlines", 35, HEIGHT - (145 + y_offset), 600, 3)

graphics.set_pen(0)
graphics.rectangle(30, 300, WIDTH - 300, 50)
graphics.rectangle(30, HEIGHT - (100 + y_offset), WIDTH - 300, 50)
graphics.set_pen(1)
graphics.text("E. Random Joke", 35, 315, 600, 3)
graphics.text("E. Random Joke", 35, HEIGHT - (85 + y_offset), 600, 3)

graphics.set_pen(7)
graphics.rectangle(WIDTH - 100, 60, 70, 50)
graphics.rectangle(WIDTH - 150, 120, 120, 50)
graphics.rectangle(WIDTH - 200, 180, 170, 50)
graphics.rectangle(WIDTH - 250, 240, 220, 50)
graphics.rectangle(WIDTH - 300, 300, 270, 50)
graphics.rectangle(WIDTH - 100, HEIGHT - (340 + y_offset), 70, 50)
graphics.rectangle(WIDTH - 150, HEIGHT - (280 + y_offset), 120, 50)
graphics.rectangle(WIDTH - 200, HEIGHT - (220 + y_offset), 170, 50)
graphics.rectangle(WIDTH - 250, HEIGHT - (160 + y_offset), 220, 50)
graphics.rectangle(WIDTH - 300, HEIGHT - (100 + y_offset), 270, 50)

graphics.set_pen(0)
graphics.text("Hold A + E, then press Reset, to return to the Launcher", 65, 370, 600, 2)
graphics.text("Hold A + E, then press Reset, to return to the Launcher", 65, HEIGHT - 30, 600, 2)

ih.led_warn.on()
graphics.update()
Expand Down
26 changes: 17 additions & 9 deletions micropython/examples/inky_frame/inkylauncher/nasa_apod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
gc.collect()

graphics = None
WIDTH = None
HEIGHT = None

WIDTH, HEIGHT = 0, 0
FILENAME = "nasa-apod-daily"

FILENAME = "nasa-apod-640x400-daily"
IMG_URL = "https://pimoroni.github.io/feed2image/nasa-apod-640x400-daily.jpg"
# A Demo Key is used in this example and is IP rate limited. You can get your own API Key from https://api.nasa.gov/
API_URL = "https://api.nasa.gov/planetary/apod?api_key=CgQGiTiyzQWEfkPgZ4btNM1FTLZQP5DeSfEwbVr7"
API_URL = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY"

# Length of time between updates in minutes.
# Frequent updates will reduce battery life!
Expand All @@ -24,14 +24,21 @@

def show_error(text):
graphics.set_pen(4)
graphics.rectangle(0, 10, 640, 35)
graphics.rectangle(0, 10, WIDTH, 35)
graphics.set_pen(1)
graphics.text(text, 5, 16, 400, 2)


def update():
global apod_title

if HEIGHT == 448:
# Image for Inky Frame 5.7
IMG_URL = "https://pimoroni.github.io/feed2image/nasa-apod-daily.jpg"
elif HEIGHT == 400:
# Image for Inky Frame 4.0
IMG_URL = "https://pimoroni.github.io/feed2image/nasa-apod-640x400-daily.jpg"

try:
# Grab the data
socket = urequest.urlopen(API_URL)
Expand Down Expand Up @@ -76,14 +83,15 @@ def draw():
jpeg.decode()
except OSError:
graphics.set_pen(4)
graphics.rectangle(0, 170, 640, 25)
graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40)
graphics.set_pen(1)
graphics.text("Unable to display image! Check your network settings in secrets.py", 5, 175, 600, 2)
graphics.text("Unable to display image!", 5, (HEIGHT // 2) - 15, WIDTH, 2)
graphics.text("Check your network settings in secrets.py", 5, (HEIGHT // 2) + 2, WIDTH, 2)

graphics.set_pen(0)
graphics.rectangle(0, 375, 640, 25)
graphics.rectangle(0, HEIGHT - 25, WIDTH, 25)
graphics.set_pen(1)
graphics.text(apod_title, 5, 380, 400, 2)
graphics.text(apod_title, 5, HEIGHT - 20, WIDTH, 2)

gc.collect()

Expand Down
16 changes: 9 additions & 7 deletions micropython/examples/inky_frame/inkylauncher/news_headlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
UPDATE_INTERVAL = 90

graphics = None
WIDTH = None
HEIGHT = None
code = qrcode.QRCode()


Expand Down Expand Up @@ -125,7 +127,6 @@ def update():

def draw():
global feed
WIDTH, HEIGHT = graphics.get_bounds()
graphics.set_font("bitmap8")

# Clear the screen
Expand All @@ -140,24 +141,25 @@ def draw():
graphics.text("Headlines from BBC News:", 10, 10, 320, 3)

graphics.set_pen(4)
graphics.text(feed[0]["title"], 10, 70, WIDTH - 150, 3 if graphics.measure_text(feed[0]["title"]) < 600 else 2)
graphics.text(feed[1]["title"], 130, 260, WIDTH - 140, 3 if graphics.measure_text(feed[1]["title"]) < 600 else 2)
graphics.text(feed[0]["title"], 10, 70, WIDTH - 150, 3 if graphics.measure_text(feed[0]["title"]) < WIDTH else 2)
graphics.text(feed[1]["title"], 130, 260, WIDTH - 140, 3 if graphics.measure_text(feed[1]["title"]) < WIDTH else 2)

graphics.set_pen(3)
graphics.text(feed[0]["description"], 10, 135 if graphics.measure_text(feed[0]["title"]) < 650 else 90, WIDTH - 150, 2)
graphics.text(feed[1]["description"], 130, 320 if graphics.measure_text(feed[1]["title"]) < 650 else 230, WIDTH - 145, 2)

graphics.line(10, 215, 620, 215)
graphics.line(10, 215, WIDTH - 10, 215)

code.set_text(feed[0]["guid"])
draw_qr_code(530, 65, 100, code)
draw_qr_code(WIDTH - 110, 65, 100, code)
code.set_text(feed[1]["guid"])
draw_qr_code(10, 265, 100, code)

else:
graphics.set_pen(4)
graphics.rectangle(0, 170, 640, 25)
graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40)
graphics.set_pen(1)
graphics.text("Unable to display news! Check your network settings in secrets.py", 5, 175, 600, 2)
graphics.text("Unable to display news feed!", 5, (HEIGHT // 2) - 15, WIDTH, 2)
graphics.text("Check your network settings in secrets.py", 5, (HEIGHT // 2) + 2, WIDTH, 2)

graphics.update()
32 changes: 0 additions & 32 deletions micropython/examples/inky_frame/inkylauncher/ntp.py

This file was deleted.

5 changes: 3 additions & 2 deletions micropython/examples/inky_frame/inkylauncher/random_joke.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def draw():
jpeg.decode()
except OSError:
graphics.set_pen(4)
graphics.rectangle(0, 170, 640, 25)
graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40)
graphics.set_pen(1)
graphics.text("Unable to display image! Check your network settings in secrets.py", 5, 175, 600, 2)
graphics.text("Unable to display random joke!", 5, (HEIGHT // 2) - 15, WIDTH, 2)
graphics.text("Check your network settings in secrets.py", 5, (HEIGHT // 2) + 2, WIDTH, 2)

graphics.update()
26 changes: 19 additions & 7 deletions micropython/examples/inky_frame/inkylauncher/word_clock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ntp
import machine
import ntptime

# Length of time between updates in minutes.
UPDATE_INTERVAL = 15
Expand Down Expand Up @@ -34,7 +34,7 @@ def approx_time(hours, minutes):
def update():
global time_string
# grab the current time from the ntp server and update the Pico RTC
ntp.fetch()
ntptime.settime()

current_t = rtc.datetime()
time_string = approx_time(current_t[4] - 12 if current_t[4] > 12 else current_t[4], current_t[5])
Expand All @@ -56,8 +56,20 @@ def draw():
graphics.clear()
graphics.set_pen(6)

x = 10
y = 10
# Values for the layout and spacing
if WIDTH == 640: # Inky Frame 4.0"
default_x = 5
x = default_x
y = 10
line_space = 70
letter_space = 40
else: # Inky Frame 5.7"
default_x = 20
x = default_x
y = 40
line_space = 65
letter_space = 35

scale = 5
spacing = 2

Expand All @@ -71,10 +83,10 @@ def draw():
for letter in word:
text_length = graphics.measure_text(letter, scale, spacing)
if not x + text_length <= WIDTH:
y += 70
x = 5
y += line_space
x = default_x

graphics.text(letter.upper(), x, y, 640, scale, spacing)
x += 40
x += letter_space

graphics.update()