Skip to content

Commit 1c4b493

Browse files
authored
Merge pull request #2911 from FoamyGuy/tft_spirit_board
Spirit Board Tweaks
2 parents 8e74f2a + 64a0ba8 commit 1c4b493

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# pylint: disable=import-error
1414
from adafruit_anchored_tilegrid import AnchoredTileGrid
15+
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError
1516

1617

1718
class SpiritBoard(displayio.Group):
@@ -220,12 +221,13 @@ def slide_planchette(self, target_location, delay=0.1, step_size=4):
220221
# want to update the display
221222
self._display.auto_refresh = True
222223

223-
def write_message(self, message, skip_spaces=True, step_size=6):
224+
def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02):
224225
"""
225226
226227
:param string message: The message to output with the planchette
227228
:param skip_spaces: Whether to skip space characters
228229
:param step_size: How big of a step to take with each movement
230+
:param delay: How many seconds to sleep between each movement step
229231
:return: None
230232
"""
231233
# ignore empty messages
@@ -248,7 +250,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
248250
for location in SpiritBoard.LOCATIONS[word]:
249251
print(f"sliding to: {location}")
250252
# slide the planchette to each point
251-
self.slide_planchette(location, delay=0.02, step_size=step_size)
253+
self.slide_planchette(location, delay=delay, step_size=step_size)
252254

253255
# pause at each point
254256
time.sleep(0.25)
@@ -257,7 +259,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
257259
elif isinstance(SpiritBoard.LOCATIONS[word], tuple):
258260
# slide the planchette to the point
259261
self.slide_planchette(SpiritBoard.LOCATIONS[word],
260-
delay=0.02, step_size=step_size)
262+
delay=delay, step_size=step_size)
261263

262264
# pause at the point
263265
time.sleep(0.5)
@@ -269,7 +271,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
269271
for character in word:
270272
# slide the planchette to the current characters location
271273
self.slide_planchette(SpiritBoard.LOCATIONS[character],
272-
delay=0.02, step_size=step_size)
274+
delay=delay, step_size=step_size)
273275

274276
# pause after we arrive
275277
time.sleep(0.5)
@@ -279,14 +281,14 @@ def write_message(self, message, skip_spaces=True, step_size=6):
279281
# handle the space
280282
# slide the planchette to the empty space location.
281283
self.slide_planchette(SpiritBoard.LOCATIONS[" "],
282-
delay=0.02, step_size=step_size)
284+
delay=delay, step_size=step_size)
283285

284286
# pause after we arrive
285287
time.sleep(0.5)
286288

287289
# after we've shown the whole message
288290
# slide the planchette back to it's home location
289-
self.slide_planchette(SpiritBoard.LOCATIONS["home"], delay=0.02, step_size=6)
291+
self.slide_planchette(SpiritBoard.LOCATIONS["home"], delay=delay, step_size=step_size)
290292

291293
@staticmethod
292294
def sync_with_io(io) -> list:
@@ -382,7 +384,7 @@ def get_messages(io) -> list:
382384
"""
383385
try:
384386
return SpiritBoard.sync_with_io(io)
385-
except (OSError, RuntimeError):
386-
print("Caught OSError. Will try again next time.\n"
387+
except (OSError, RuntimeError, AdafruitIO_RequestError) as e:
388+
print(f"Caught Exception: {type(e)} - {e}.\nWill try again next time.\n"
387389
"Falling back to spirit_messages.txt file.")
388390
return SpiritBoard.read_local_messages_file()

TFT_Spirit_Board/pyportal/spirit_board.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# pylint: disable=import-error
1414
from adafruit_anchored_tilegrid import AnchoredTileGrid
15+
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError
1516

1617

1718
class SpiritBoard(displayio.Group):
@@ -220,12 +221,13 @@ def slide_planchette(self, target_location, delay=0.1, step_size=4):
220221
# want to update the display
221222
self._display.auto_refresh = True
222223

223-
def write_message(self, message, skip_spaces=True, step_size=6):
224+
def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02):
224225
"""
225226
226227
:param string message: The message to output with the planchette
227228
:param skip_spaces: Whether to skip space characters
228229
:param step_size: How big of a step to take with each movement
230+
:param delay: How many seconds to sleep between each movement step
229231
:return: None
230232
"""
231233
# ignore empty messages
@@ -248,7 +250,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
248250
for location in SpiritBoard.LOCATIONS[word]:
249251
print(f"sliding to: {location}")
250252
# slide the planchette to each point
251-
self.slide_planchette(location, delay=0.02, step_size=step_size)
253+
self.slide_planchette(location, delay=delay, step_size=step_size)
252254

253255
# pause at each point
254256
time.sleep(0.25)
@@ -257,7 +259,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
257259
elif isinstance(SpiritBoard.LOCATIONS[word], tuple):
258260
# slide the planchette to the point
259261
self.slide_planchette(SpiritBoard.LOCATIONS[word],
260-
delay=0.02, step_size=step_size)
262+
delay=delay, step_size=step_size)
261263

262264
# pause at the point
263265
time.sleep(0.5)
@@ -269,7 +271,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
269271
for character in word:
270272
# slide the planchette to the current characters location
271273
self.slide_planchette(SpiritBoard.LOCATIONS[character],
272-
delay=0.02, step_size=step_size)
274+
delay=delay, step_size=step_size)
273275

274276
# pause after we arrive
275277
time.sleep(0.5)
@@ -279,14 +281,14 @@ def write_message(self, message, skip_spaces=True, step_size=6):
279281
# handle the space
280282
# slide the planchette to the empty space location.
281283
self.slide_planchette(SpiritBoard.LOCATIONS[" "],
282-
delay=0.02, step_size=step_size)
284+
delay=delay, step_size=step_size)
283285

284286
# pause after we arrive
285287
time.sleep(0.5)
286288

287289
# after we've shown the whole message
288290
# slide the planchette back to it's home location
289-
self.slide_planchette(SpiritBoard.LOCATIONS["home"], delay=0.02, step_size=6)
291+
self.slide_planchette(SpiritBoard.LOCATIONS["home"], delay=delay, step_size=step_size)
290292

291293
@staticmethod
292294
def sync_with_io(io) -> list:
@@ -382,7 +384,7 @@ def get_messages(io) -> list:
382384
"""
383385
try:
384386
return SpiritBoard.sync_with_io(io)
385-
except (OSError, RuntimeError):
386-
print("Caught OSError. Will try again next time.\n"
387+
except (OSError, RuntimeError, AdafruitIO_RequestError) as e:
388+
print(f"Caught Exception: {type(e)} - {e}.\nWill try again next time.\n"
387389
"Falling back to spirit_messages.txt file.")
388390
return SpiritBoard.read_local_messages_file()

TFT_Spirit_Board/pyportal_titano/spirit_board.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# pylint: disable=import-error
1414
from adafruit_anchored_tilegrid import AnchoredTileGrid
15+
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError
1516

1617

1718
class SpiritBoard(displayio.Group):
@@ -220,12 +221,13 @@ def slide_planchette(self, target_location, delay=0.1, step_size=4):
220221
# want to update the display
221222
self._display.auto_refresh = True
222223

223-
def write_message(self, message, skip_spaces=True, step_size=6):
224+
def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02):
224225
"""
225226
226227
:param string message: The message to output with the planchette
227228
:param skip_spaces: Whether to skip space characters
228229
:param step_size: How big of a step to take with each movement
230+
:param delay: How many seconds to sleep between each movement step
229231
:return: None
230232
"""
231233
# ignore empty messages
@@ -248,7 +250,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
248250
for location in SpiritBoard.LOCATIONS[word]:
249251
print(f"sliding to: {location}")
250252
# slide the planchette to each point
251-
self.slide_planchette(location, delay=0.02, step_size=step_size)
253+
self.slide_planchette(location, delay=delay, step_size=step_size)
252254

253255
# pause at each point
254256
time.sleep(0.25)
@@ -257,7 +259,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
257259
elif isinstance(SpiritBoard.LOCATIONS[word], tuple):
258260
# slide the planchette to the point
259261
self.slide_planchette(SpiritBoard.LOCATIONS[word],
260-
delay=0.02, step_size=step_size)
262+
delay=delay, step_size=step_size)
261263

262264
# pause at the point
263265
time.sleep(0.5)
@@ -269,7 +271,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
269271
for character in word:
270272
# slide the planchette to the current characters location
271273
self.slide_planchette(SpiritBoard.LOCATIONS[character],
272-
delay=0.02, step_size=step_size)
274+
delay=delay, step_size=step_size)
273275

274276
# pause after we arrive
275277
time.sleep(0.5)
@@ -279,14 +281,14 @@ def write_message(self, message, skip_spaces=True, step_size=6):
279281
# handle the space
280282
# slide the planchette to the empty space location.
281283
self.slide_planchette(SpiritBoard.LOCATIONS[" "],
282-
delay=0.02, step_size=step_size)
284+
delay=delay, step_size=step_size)
283285

284286
# pause after we arrive
285287
time.sleep(0.5)
286288

287289
# after we've shown the whole message
288290
# slide the planchette back to it's home location
289-
self.slide_planchette(SpiritBoard.LOCATIONS["home"], delay=0.02, step_size=6)
291+
self.slide_planchette(SpiritBoard.LOCATIONS["home"], delay=delay, step_size=step_size)
290292

291293
@staticmethod
292294
def sync_with_io(io) -> list:
@@ -382,7 +384,7 @@ def get_messages(io) -> list:
382384
"""
383385
try:
384386
return SpiritBoard.sync_with_io(io)
385-
except (OSError, RuntimeError):
386-
print("Caught OSError. Will try again next time.\n"
387+
except (OSError, RuntimeError, AdafruitIO_RequestError) as e:
388+
print(f"Caught Exception: {type(e)} - {e}.\nWill try again next time.\n"
387389
"Falling back to spirit_messages.txt file.")
388390
return SpiritBoard.read_local_messages_file()

0 commit comments

Comments
 (0)