Skip to content

Commit 0169adc

Browse files
Merge pull request adafruit#1384 from adafruit/pb-magtag-fixes
Update fonts to PCF, minor buglet fixes
2 parents 4f927ea + b6e38a7 commit 0169adc

15 files changed

+37
-9808
lines changed

MagTag_NextBus/bitmaps/lowbatt.bmp

-2.83 KB
Binary file not shown.

MagTag_NextBus/code.py

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@
6060
except:
6161
TIME_ZONE = None # Use IP geolocation
6262

63-
# Battery level to indicate near-empty, time to recharge.
64-
LOW_BATT_VOLTAGE = 2.45
65-
6663

6764
# SOME UTILITY FUNCTIONS ---------------------------------------------------
6865

@@ -150,12 +147,11 @@ def hh_mm(time_struct, twelve_hour=True):
150147
GRAPHICS = Graphics(auto_refresh=False)
151148
DISPLAY = GRAPHICS.display
152149

153-
FONT_SMALL = bitmap_font.load_font('/fonts/Impact-16.bdf')
154-
FONT_MEDIUM = bitmap_font.load_font('/fonts/Impact-24.bdf')
155-
FONT_LARGE = bitmap_font.load_font('/fonts/Impact-30.bdf')
150+
FONT_SMALL = bitmap_font.load_font('/fonts/Impact-16.pcf')
151+
FONT_MEDIUM = bitmap_font.load_font('/fonts/Impact-24.pcf')
152+
FONT_LARGE = bitmap_font.load_font('/fonts/Impact-30.pcf')
156153

157-
# Two displayio groups are created. First is the "main" group which holds
158-
# all the labels for the stops and predictions...
154+
# displayio group holds all the labels for the stops and predictions...
159155
GROUP = displayio.Group(max_size=14)
160156
GROUP.append(fillrect(0, 0, DISPLAY.width, DISPLAY.height, 0xFFFFFF))
161157
# Clear the screen ASAP before populating rest of group (erase any old
@@ -164,32 +160,6 @@ def hh_mm(time_struct, twelve_hour=True):
164160
DISPLAY.refresh()
165161
time.sleep(5) # Don't allow another refresh() too soon
166162

167-
# Second group is the low battery display. Populate this one now,
168-
# then we'll get back to the main group with the stop data in a moment...
169-
BATT_GROUP = displayio.Group(max_size=3)
170-
BATT_GROUP.append(fillrect(0, 0, DISPLAY.width, DISPLAY.height, 0xFFFFFF))
171-
try:
172-
# Attempt loading low-battery icon, centered on screen
173-
# pylint: disable=no-member
174-
FILE = open('bitmaps/lowbatt.bmp', 'rb')
175-
BATT_BITMAP = displayio.OnDiskBitmap(FILE)
176-
BATT_ICON_TILEGRID = displayio.TileGrid(
177-
BATT_BITMAP, pixel_shader=displayio.ColorConverter())
178-
BATT_ICON_TILEGRID.x = (DISPLAY.width - BATT_BITMAP.width + 1) // 2
179-
BATT_ICON_TILEGRID.y = (DISPLAY.height - BATT_BITMAP.height + 1) // 2
180-
# onDiskBitmap seems to treat black as transparent...image won't
181-
# show correctly on white background, so make an in-between rect
182-
# to fill the area behind the battery icon with black.
183-
BATT_GROUP.append(fillrect(BATT_ICON_TILEGRID.x, BATT_ICON_TILEGRID.y,
184-
BATT_BITMAP.width, BATT_BITMAP.height, 0))
185-
BATT_GROUP.append(BATT_ICON_TILEGRID)
186-
except:
187-
# If load fails, fall back on text low-batt message
188-
TEXT = Label(FONT_MEDIUM, text='LOW BATTERY', color=0)
189-
TEXT.anchor_point = (0.5, 0.5)
190-
TEXT.anchored_position = (DISPLAY.width // 2, DISPLAY.height // 2)
191-
BATT_GROUP.append(TEXT)
192-
193163
# Populate list of NextBus objects from STOPS[] and generate initial text
194164
# labels (these get positioned in a second pass later)...
195165
STOP_LIST = []
@@ -247,17 +217,6 @@ def hh_mm(time_struct, twelve_hour=True):
247217

248218
while True:
249219

250-
# If battery is low, DO NOT SHOW PREDICTIONS. Because the display
251-
# persists without power, information shown could "look right" but
252-
# actually be WAY out of date. Instead, display low-battery indicator
253-
# once and then wait for battery recharge or USB power.
254-
if PERIPHERALS.battery < LOW_BATT_VOLTAGE:
255-
DISPLAY.show(BATT_GROUP)
256-
DISPLAY.refresh()
257-
while PERIPHERALS.battery < LOW_BATT_VOLTAGE:
258-
time.sleep(60)
259-
DISPLAY.show(GROUP)
260-
261220
# Periodically sync clock with time server
262221
if time.monotonic() - LAST_SYNC_TIME >= CLOCK_SYNC_INTERVAL:
263222
try:

0 commit comments

Comments
 (0)