1212
1313# pylint: disable=import-error
1414from adafruit_anchored_tilegrid import AnchoredTileGrid
15+ from adafruit_io .adafruit_io_errors import AdafruitIO_RequestError
1516
1617
1718class 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 } . \n Will try again next time.\n "
387389 "Falling back to spirit_messages.txt file." )
388390 return SpiritBoard .read_local_messages_file ()
0 commit comments