black, lint, add font!
This commit is contained in:
parent
68fb289d2c
commit
28bd3dc93a
2 changed files with 37 additions and 29 deletions
BIN
Matrix_Portal_Learn_Stats/IBMPlexMono-Medium-24_jep.bdf.zip
Normal file
BIN
Matrix_Portal_Learn_Stats/IBMPlexMono-Medium-24_jep.bdf.zip
Normal file
Binary file not shown.
|
|
@ -1,60 +1,68 @@
|
|||
import time
|
||||
import board
|
||||
from random import randrange
|
||||
import rtc
|
||||
import board
|
||||
import terminalio
|
||||
from adafruit_matrixportal.matrixportal import MatrixPortal
|
||||
|
||||
# --- Data Setup --- #
|
||||
GUIDE_INDEX = 0
|
||||
# Number of guides to fetch and display from the Adafruit Learning System
|
||||
DISPLAY_NUM_GUIDES = 5
|
||||
DATA_SOURCE = "https://learn.adafruit.com/api/guides/new.json?count=%d"%DISPLAY_NUM_GUIDES
|
||||
# Data source URL
|
||||
DATA_SOURCE = (
|
||||
"https://learn.adafruit.com/api/guides/new.json?count=%d" % DISPLAY_NUM_GUIDES
|
||||
)
|
||||
TITLE_DATA_LOCATION = ["guides"]
|
||||
TAGLINE_DATA_LOCATION = ["guides", GUIDE_INDEX, "guide", "tagline"]
|
||||
|
||||
# the current working directory (where this file is)
|
||||
cwd = ("/" + __file__).rsplit("/", 1)[0]
|
||||
|
||||
matrixportal = MatrixPortal(
|
||||
url=DATA_SOURCE,
|
||||
json_path=TITLE_DATA_LOCATION,
|
||||
status_neopixel=board.NEOPIXEL,
|
||||
debug=True
|
||||
)
|
||||
|
||||
# --- Display Setup --- #
|
||||
|
||||
# Colors for guide name
|
||||
colors = [0xff0000, 0xffa500, 0xffff00,
|
||||
0x008000, 0x0000ff, 0x4b0082,
|
||||
0xee82ee]
|
||||
colors = [0xFFA500, 0xFFFF00, 0x008000, 0x0000FF, 0x4B0082, 0xEE82EE]
|
||||
|
||||
# Delay for scrolling the text
|
||||
SCROLL_DELAY = 0.03
|
||||
# id = 0, title
|
||||
matrixportal.add_text(
|
||||
text_font=terminalio.FONT,
|
||||
text_position=((matrixportal.graphics.display.width // 3) - 1, (matrixportal.graphics.display.height // 3) - 1),
|
||||
text_color=0x800000,
|
||||
text_scale = 2
|
||||
)
|
||||
|
||||
# id = 1, author
|
||||
FONT = "/IBMPlexMono-Medium-24_jep.bdf"
|
||||
|
||||
# Learn guide count (ID = 0)
|
||||
matrixportal.add_text(
|
||||
text_font=FONT,
|
||||
text_position=(
|
||||
(matrixportal.graphics.display.width // 12) - 1,
|
||||
(matrixportal.graphics.display.height // 2) - 4,
|
||||
),
|
||||
text_color=0x800000,
|
||||
)
|
||||
matrixportal.preload_font("0123456789")
|
||||
|
||||
# Learn guide title (ID = 1)
|
||||
matrixportal.add_text(
|
||||
text_font=terminalio.FONT,
|
||||
text_position=(2, 25),
|
||||
text_color=0x000080,
|
||||
scrolling = True
|
||||
scrolling=True,
|
||||
)
|
||||
|
||||
|
||||
def get_guide_info(index):
|
||||
"""Parses JSON data returned by the DATA_SOURCE
|
||||
to obtain the ALS guide title and number of guides and
|
||||
sets the text labels.
|
||||
:param int index: Guide index to display
|
||||
|
||||
"""
|
||||
if index > DISPLAY_NUM_GUIDES:
|
||||
raise RuntimeError("Provided index may not be larger than DISPLAY_NUM_GUIDES.")
|
||||
print("Obtaining guide info for guide %d..."%index)
|
||||
print("Obtaining guide info for guide %d..." % index)
|
||||
|
||||
# Traverse JSON data for title
|
||||
guide_count = matrixportal.network.json_traverse(als_data.json(), ["guide_count"])
|
||||
|
||||
# Set guide count
|
||||
matrixportal.set_text(guide_count, 0)
|
||||
|
||||
|
|
@ -72,21 +80,21 @@ def get_guide_info(index):
|
|||
matrixportal.set_text(guide_title, 1)
|
||||
|
||||
|
||||
refresh_time = None
|
||||
guide_idx = 0
|
||||
prv_hour = 0
|
||||
refresh_time = None
|
||||
while True:
|
||||
|
||||
if (not refresh_time) or (time.monotonic() - refresh_time) > 3600:
|
||||
if (not refresh_time) or (time.monotonic() - refresh_time) > 900:
|
||||
try:
|
||||
print("obtaining time from adafruit.io server...")
|
||||
matrixportal.get_local_time()
|
||||
refresh_time = time.monotonic()
|
||||
except RuntimeError as e:
|
||||
print("Retrying! - ", e)
|
||||
print("Unable to obtain time from Adafruit IO, retrying - ", e)
|
||||
continue
|
||||
|
||||
if time.localtime()[3] != prv_hour:
|
||||
print("New Hour, fetching new data...")
|
||||
# Fetch and store guide info response
|
||||
als_data = matrixportal.network.fetch(DATA_SOURCE)
|
||||
prv_hour = time.localtime()[3]
|
||||
|
|
@ -95,9 +103,9 @@ while True:
|
|||
if guide_idx < DISPLAY_NUM_GUIDES:
|
||||
get_guide_info(guide_idx)
|
||||
|
||||
# Scroll the scrollable text blocks
|
||||
# Scroll the scrollable text block
|
||||
matrixportal.scroll_text(SCROLL_DELAY)
|
||||
guide_idx += 1
|
||||
else:
|
||||
guide_idx = 0
|
||||
time.sleep(0.5)
|
||||
time.sleep(0.05)
|
||||
|
|
|
|||
Loading…
Reference in a new issue