Skip to content

Spirit Board Tweaks #2911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# pylint: disable=import-error
from adafruit_anchored_tilegrid import AnchoredTileGrid
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError


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

def write_message(self, message, skip_spaces=True, step_size=6):
def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02):
"""

:param string message: The message to output with the planchette
:param skip_spaces: Whether to skip space characters
:param step_size: How big of a step to take with each movement
:param delay: How many seconds to sleep between each movement step
:return: None
"""
# ignore empty messages
Expand All @@ -248,7 +250,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
for location in SpiritBoard.LOCATIONS[word]:
print(f"sliding to: {location}")
# slide the planchette to each point
self.slide_planchette(location, delay=0.02, step_size=step_size)
self.slide_planchette(location, delay=delay, step_size=step_size)

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

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

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

# pause after we arrive
time.sleep(0.5)

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

@staticmethod
def sync_with_io(io) -> list:
Expand Down Expand Up @@ -382,7 +384,7 @@ def get_messages(io) -> list:
"""
try:
return SpiritBoard.sync_with_io(io)
except (OSError, RuntimeError):
print("Caught OSError. Will try again next time.\n"
except (OSError, RuntimeError, AdafruitIO_RequestError) as e:
print(f"Caught Exception: {type(e)} - {e}.\nWill try again next time.\n"
"Falling back to spirit_messages.txt file.")
return SpiritBoard.read_local_messages_file()
18 changes: 10 additions & 8 deletions TFT_Spirit_Board/pyportal/spirit_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# pylint: disable=import-error
from adafruit_anchored_tilegrid import AnchoredTileGrid
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError


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

def write_message(self, message, skip_spaces=True, step_size=6):
def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02):
"""

:param string message: The message to output with the planchette
:param skip_spaces: Whether to skip space characters
:param step_size: How big of a step to take with each movement
:param delay: How many seconds to sleep between each movement step
:return: None
"""
# ignore empty messages
Expand All @@ -248,7 +250,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
for location in SpiritBoard.LOCATIONS[word]:
print(f"sliding to: {location}")
# slide the planchette to each point
self.slide_planchette(location, delay=0.02, step_size=step_size)
self.slide_planchette(location, delay=delay, step_size=step_size)

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

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

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

# pause after we arrive
time.sleep(0.5)

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

@staticmethod
def sync_with_io(io) -> list:
Expand Down Expand Up @@ -382,7 +384,7 @@ def get_messages(io) -> list:
"""
try:
return SpiritBoard.sync_with_io(io)
except (OSError, RuntimeError):
print("Caught OSError. Will try again next time.\n"
except (OSError, RuntimeError, AdafruitIO_RequestError) as e:
print(f"Caught Exception: {type(e)} - {e}.\nWill try again next time.\n"
"Falling back to spirit_messages.txt file.")
return SpiritBoard.read_local_messages_file()
18 changes: 10 additions & 8 deletions TFT_Spirit_Board/pyportal_titano/spirit_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# pylint: disable=import-error
from adafruit_anchored_tilegrid import AnchoredTileGrid
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError


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

def write_message(self, message, skip_spaces=True, step_size=6):
def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02):
"""

:param string message: The message to output with the planchette
:param skip_spaces: Whether to skip space characters
:param step_size: How big of a step to take with each movement
:param delay: How many seconds to sleep between each movement step
:return: None
"""
# ignore empty messages
Expand All @@ -248,7 +250,7 @@ def write_message(self, message, skip_spaces=True, step_size=6):
for location in SpiritBoard.LOCATIONS[word]:
print(f"sliding to: {location}")
# slide the planchette to each point
self.slide_planchette(location, delay=0.02, step_size=step_size)
self.slide_planchette(location, delay=delay, step_size=step_size)

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

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

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

# pause after we arrive
time.sleep(0.5)

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

@staticmethod
def sync_with_io(io) -> list:
Expand Down Expand Up @@ -382,7 +384,7 @@ def get_messages(io) -> list:
"""
try:
return SpiritBoard.sync_with_io(io)
except (OSError, RuntimeError):
print("Caught OSError. Will try again next time.\n"
except (OSError, RuntimeError, AdafruitIO_RequestError) as e:
print(f"Caught Exception: {type(e)} - {e}.\nWill try again next time.\n"
"Falling back to spirit_messages.txt file.")
return SpiritBoard.read_local_messages_file()