From 7f0d2e03d91b945600e2dc8ef87ba1bc13ca6f35 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 17 Oct 2024 11:45:42 -0500 Subject: [PATCH 1/2] add example messages file. support uppercase in messages. gracefully handle invalid characters. --- .../spirit_board.py | 19 +++++++++++++------ .../spirit_messages.txt | 4 ++++ TFT_Spirit_Board/pyportal/spirit_board.py | 19 +++++++++++++------ TFT_Spirit_Board/pyportal/spirit_messages.txt | 4 ++++ .../pyportal_titano/spirit_board.py | 19 +++++++++++++------ .../pyportal_titano/spirit_messages.txt | 4 ++++ 6 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_messages.txt create mode 100644 TFT_Spirit_Board/pyportal/spirit_messages.txt create mode 100644 TFT_Spirit_Board/pyportal_titano/spirit_messages.txt diff --git a/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py b/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py index 18ec02828..5633587f4 100644 --- a/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py +++ b/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py @@ -240,6 +240,8 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over the words in the message for index, word in enumerate(message_words): print(f"index: {index}, word: {word}") + # send it to lowercase to get rid of capital letters + word = word.lower() # if the current word is one of the full words on the board if word in SpiritBoard.FULL_WORDS: @@ -269,12 +271,17 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over each character in the word for character in word: - # slide the planchette to the current characters location - self.slide_planchette(SpiritBoard.LOCATIONS[character], - delay=delay, step_size=step_size) - - # pause after we arrive - time.sleep(0.5) + # if the character is in our locations mapping + if character in SpiritBoard.LOCATIONS.keys(): + # slide the planchette to the current characters location + self.slide_planchette(SpiritBoard.LOCATIONS[character], + delay=delay, step_size=step_size) + + # pause after we arrive + time.sleep(0.5) + else: + # character is not in our mapping + print(f"Skipping '{character}', it's not on the board.") # if we are not skipping spaces, and we are not done with the message if not skip_spaces and index < len(message_words) - 1: diff --git a/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_messages.txt b/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_messages.txt new file mode 100644 index 000000000..7125df197 --- /dev/null +++ b/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_messages.txt @@ -0,0 +1,4 @@ +hello world +spirits are near +i <3 circuitpython +goodbye \ No newline at end of file diff --git a/TFT_Spirit_Board/pyportal/spirit_board.py b/TFT_Spirit_Board/pyportal/spirit_board.py index 18ec02828..5633587f4 100644 --- a/TFT_Spirit_Board/pyportal/spirit_board.py +++ b/TFT_Spirit_Board/pyportal/spirit_board.py @@ -240,6 +240,8 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over the words in the message for index, word in enumerate(message_words): print(f"index: {index}, word: {word}") + # send it to lowercase to get rid of capital letters + word = word.lower() # if the current word is one of the full words on the board if word in SpiritBoard.FULL_WORDS: @@ -269,12 +271,17 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over each character in the word for character in word: - # slide the planchette to the current characters location - self.slide_planchette(SpiritBoard.LOCATIONS[character], - delay=delay, step_size=step_size) - - # pause after we arrive - time.sleep(0.5) + # if the character is in our locations mapping + if character in SpiritBoard.LOCATIONS.keys(): + # slide the planchette to the current characters location + self.slide_planchette(SpiritBoard.LOCATIONS[character], + delay=delay, step_size=step_size) + + # pause after we arrive + time.sleep(0.5) + else: + # character is not in our mapping + print(f"Skipping '{character}', it's not on the board.") # if we are not skipping spaces, and we are not done with the message if not skip_spaces and index < len(message_words) - 1: diff --git a/TFT_Spirit_Board/pyportal/spirit_messages.txt b/TFT_Spirit_Board/pyportal/spirit_messages.txt new file mode 100644 index 000000000..7125df197 --- /dev/null +++ b/TFT_Spirit_Board/pyportal/spirit_messages.txt @@ -0,0 +1,4 @@ +hello world +spirits are near +i <3 circuitpython +goodbye \ No newline at end of file diff --git a/TFT_Spirit_Board/pyportal_titano/spirit_board.py b/TFT_Spirit_Board/pyportal_titano/spirit_board.py index 18ec02828..5633587f4 100644 --- a/TFT_Spirit_Board/pyportal_titano/spirit_board.py +++ b/TFT_Spirit_Board/pyportal_titano/spirit_board.py @@ -240,6 +240,8 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over the words in the message for index, word in enumerate(message_words): print(f"index: {index}, word: {word}") + # send it to lowercase to get rid of capital letters + word = word.lower() # if the current word is one of the full words on the board if word in SpiritBoard.FULL_WORDS: @@ -269,12 +271,17 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over each character in the word for character in word: - # slide the planchette to the current characters location - self.slide_planchette(SpiritBoard.LOCATIONS[character], - delay=delay, step_size=step_size) - - # pause after we arrive - time.sleep(0.5) + # if the character is in our locations mapping + if character in SpiritBoard.LOCATIONS.keys(): + # slide the planchette to the current characters location + self.slide_planchette(SpiritBoard.LOCATIONS[character], + delay=delay, step_size=step_size) + + # pause after we arrive + time.sleep(0.5) + else: + # character is not in our mapping + print(f"Skipping '{character}', it's not on the board.") # if we are not skipping spaces, and we are not done with the message if not skip_spaces and index < len(message_words) - 1: diff --git a/TFT_Spirit_Board/pyportal_titano/spirit_messages.txt b/TFT_Spirit_Board/pyportal_titano/spirit_messages.txt new file mode 100644 index 000000000..7125df197 --- /dev/null +++ b/TFT_Spirit_Board/pyportal_titano/spirit_messages.txt @@ -0,0 +1,4 @@ +hello world +spirits are near +i <3 circuitpython +goodbye \ No newline at end of file From 8a7026c5a9c973e8b200d562c4deb41fab2db90b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 17 Oct 2024 11:53:05 -0500 Subject: [PATCH 2/2] remove usage of keys() --- .../esp32s3_s2_tft_featherwing_480x320/spirit_board.py | 2 +- TFT_Spirit_Board/pyportal/spirit_board.py | 2 +- TFT_Spirit_Board/pyportal_titano/spirit_board.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py b/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py index 5633587f4..9a889f608 100644 --- a/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py +++ b/TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/spirit_board.py @@ -272,7 +272,7 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over each character in the word for character in word: # if the character is in our locations mapping - if character in SpiritBoard.LOCATIONS.keys(): + if character in SpiritBoard.LOCATIONS: # slide the planchette to the current characters location self.slide_planchette(SpiritBoard.LOCATIONS[character], delay=delay, step_size=step_size) diff --git a/TFT_Spirit_Board/pyportal/spirit_board.py b/TFT_Spirit_Board/pyportal/spirit_board.py index 5633587f4..9a889f608 100644 --- a/TFT_Spirit_Board/pyportal/spirit_board.py +++ b/TFT_Spirit_Board/pyportal/spirit_board.py @@ -272,7 +272,7 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over each character in the word for character in word: # if the character is in our locations mapping - if character in SpiritBoard.LOCATIONS.keys(): + if character in SpiritBoard.LOCATIONS: # slide the planchette to the current characters location self.slide_planchette(SpiritBoard.LOCATIONS[character], delay=delay, step_size=step_size) diff --git a/TFT_Spirit_Board/pyportal_titano/spirit_board.py b/TFT_Spirit_Board/pyportal_titano/spirit_board.py index 5633587f4..9a889f608 100644 --- a/TFT_Spirit_Board/pyportal_titano/spirit_board.py +++ b/TFT_Spirit_Board/pyportal_titano/spirit_board.py @@ -272,7 +272,7 @@ def write_message(self, message, skip_spaces=True, step_size=6, delay=0.02): # loop over each character in the word for character in word: # if the character is in our locations mapping - if character in SpiritBoard.LOCATIONS.keys(): + if character in SpiritBoard.LOCATIONS: # slide the planchette to the current characters location self.slide_planchette(SpiritBoard.LOCATIONS[character], delay=delay, step_size=step_size)