Skip to content

Commit 7768399

Browse files
authored
Merge branch 'master' into master
2 parents a2e2938 + 67e8073 commit 7768399

File tree

3 files changed

+113
-2
lines changed

3 files changed

+113
-2
lines changed

CircuitPython_JEplayer_mp3/code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def auto_next(self):
234234
@staticmethod
235235
def has_any_mp3s(folder):
236236
"""True if the folder contains at least one item ending in .mp3"""
237-
return any(fn.lower().endswith(".mp3") for fn in os.listdir(folder))
237+
return any(not fn.startswith(".") and fn.lower().endswith(".mp3") for fn in os.listdir(folder))
238238

239239
def choose_folder(self, base='/sd'):
240240
"""Let the user choose a folder within a base directory"""
@@ -493,7 +493,7 @@ def longest_common_prefix(seq):
493493

494494
def play_folder(location):
495495
"""Play everything within a given folder"""
496-
playlist = [d for d in os.listdir(location) if d.lower().endswith('.mp3')]
496+
playlist = [d for d in os.listdir(location) if not d.startswith('.') and d.lower().endswith('.mp3')]
497497
if not playlist:
498498
# hmm, no mp3s in a folder? Well, don't crash okay?
499499
del playlist
Binary file not shown.

Matrix_Portal_Learn_Stats/code.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import time
2+
from random import randrange
3+
import board
4+
import terminalio
5+
from adafruit_matrixportal.matrixportal import MatrixPortal
6+
7+
# --- Data Setup --- #
8+
# Number of guides to fetch and display from the Adafruit Learning System
9+
DISPLAY_NUM_GUIDES = 5
10+
# Data source URL
11+
DATA_SOURCE = (
12+
"https://learn.adafruit.com/api/guides/new.json?count=%d" % DISPLAY_NUM_GUIDES
13+
)
14+
TITLE_DATA_LOCATION = ["guides"]
15+
16+
matrixportal = MatrixPortal(
17+
url=DATA_SOURCE,
18+
json_path=TITLE_DATA_LOCATION,
19+
status_neopixel=board.NEOPIXEL,
20+
)
21+
22+
# --- Display Setup --- #
23+
24+
# Colors for guide name
25+
colors = [0xFFA500, 0xFFFF00, 0x008000, 0x0000FF, 0x4B0082, 0xEE82EE]
26+
27+
# Delay for scrolling the text
28+
SCROLL_DELAY = 0.03
29+
30+
FONT = "/IBMPlexMono-Medium-24_jep.bdf"
31+
32+
# Learn guide count (ID = 0)
33+
matrixportal.add_text(
34+
text_font=FONT,
35+
text_position=(
36+
(matrixportal.graphics.display.width // 12) - 1,
37+
(matrixportal.graphics.display.height // 2) - 4,
38+
),
39+
text_color=0x800000,
40+
)
41+
matrixportal.preload_font("0123456789")
42+
43+
# Learn guide title (ID = 1)
44+
matrixportal.add_text(
45+
text_font=terminalio.FONT,
46+
text_position=(2, 25),
47+
text_color=0x000080,
48+
scrolling=True,
49+
)
50+
51+
52+
def get_guide_info(index):
53+
"""Parses JSON data returned by the DATA_SOURCE
54+
to obtain the ALS guide title and number of guides and
55+
sets the text labels.
56+
:param int index: Guide index to display
57+
58+
"""
59+
if index > DISPLAY_NUM_GUIDES:
60+
raise RuntimeError("Provided index may not be larger than DISPLAY_NUM_GUIDES.")
61+
print("Obtaining guide info for guide %d..." % index)
62+
63+
# Traverse JSON data for title
64+
guide_count = matrixportal.network.json_traverse(als_data.json(), ["guide_count"])
65+
66+
# Set guide count
67+
matrixportal.set_text(guide_count, 0)
68+
69+
guides = matrixportal.network.json_traverse(als_data.json(), TITLE_DATA_LOCATION)
70+
guide_title = guides[index]["guide"]["title"]
71+
print("Guide Title", guide_title)
72+
73+
# Select color for title text
74+
color_index = randrange(0, len(colors))
75+
76+
# Set the title text color
77+
matrixportal.set_text_color(colors[color_index], 1)
78+
79+
# Set the title text
80+
matrixportal.set_text(guide_title, 1)
81+
82+
83+
refresh_time = None
84+
guide_idx = 0
85+
prv_hour = 0
86+
while True:
87+
if (not refresh_time) or (time.monotonic() - refresh_time) > 900:
88+
try:
89+
print("obtaining time from adafruit.io server...")
90+
matrixportal.get_local_time()
91+
refresh_time = time.monotonic()
92+
except RuntimeError as e:
93+
print("Unable to obtain time from Adafruit IO, retrying - ", e)
94+
continue
95+
96+
if time.localtime()[3] != prv_hour:
97+
print("New Hour, fetching new data...")
98+
# Fetch and store guide info response
99+
als_data = matrixportal.network.fetch(DATA_SOURCE)
100+
prv_hour = time.localtime()[3]
101+
102+
# Cycle through guides retrieved
103+
if guide_idx < DISPLAY_NUM_GUIDES:
104+
get_guide_info(guide_idx)
105+
106+
# Scroll the scrollable text block
107+
matrixportal.scroll_text(SCROLL_DELAY)
108+
guide_idx += 1
109+
else:
110+
guide_idx = 0
111+
time.sleep(0.05)

0 commit comments

Comments
 (0)