kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Merge pull request #626 from pimoroni/patch/inky-launcher-57-update
Patch/inky launcher 57 updatepull/636/head
commit
c98d0daaf4
|
@ -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()
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
@ -20,6 +23,13 @@ graphics.set_font("bitmap8")
|
|||
|
||||
|
||||
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()
|
||||
|
@ -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()
|
||||
|
|
|
@ -6,13 +6,13 @@ from ujson import load
|
|||
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!
|
||||
|
@ -24,7 +24,7 @@ apod_title = None
|
|||
|
||||
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)
|
||||
|
||||
|
@ -32,6 +32,13 @@ def show_error(text):
|
|||
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)
|
||||
|
@ -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()
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ URL = "http://feeds.bbci.co.uk/news/technology/rss.xml"
|
|||
UPDATE_INTERVAL = 90
|
||||
|
||||
graphics = None
|
||||
WIDTH = None
|
||||
HEIGHT = None
|
||||
code = qrcode.QRCode()
|
||||
|
||||
|
||||
|
@ -125,7 +127,6 @@ def update():
|
|||
|
||||
def draw():
|
||||
global feed
|
||||
WIDTH, HEIGHT = graphics.get_bounds()
|
||||
graphics.set_font("bitmap8")
|
||||
|
||||
# Clear the screen
|
||||
|
@ -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()
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
import machine
|
||||
import time
|
||||
import usocket
|
||||
import struct
|
||||
|
||||
|
||||
def fetch(synch_with_rtc=True, timeout=10):
|
||||
ntp_host = "pool.ntp.org"
|
||||
|
||||
timestamp = None
|
||||
try:
|
||||
query = bytearray(48)
|
||||
query[0] = 0x1b
|
||||
address = usocket.getaddrinfo(ntp_host, 123)[0][-1]
|
||||
socket = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
|
||||
socket.settimeout(timeout)
|
||||
socket.sendto(query, address)
|
||||
data = socket.recv(48)
|
||||
socket.close()
|
||||
local_epoch = 2208988800 # selected by Chris - blame him. :-D
|
||||
timestamp = struct.unpack("!I", data[40:44])[0] - local_epoch
|
||||
timestamp = time.gmtime(timestamp)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
# if requested set the machines RTC to the fetched timestamp
|
||||
if synch_with_rtc:
|
||||
machine.RTC().datetime((
|
||||
timestamp[0], timestamp[1], timestamp[2], timestamp[6],
|
||||
timestamp[3], timestamp[4], timestamp[5], 0))
|
||||
|
||||
return timestamp
|
|
@ -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()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import ntp
|
||||
import machine
|
||||
import ntptime
|
||||
|
||||
# Length of time between updates in minutes.
|
||||
UPDATE_INTERVAL = 15
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
|
Ładowanie…
Reference in New Issue