feat: Add protosign script with send_sign for Vestaboard
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
33
protosign.py
33
protosign.py
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from vestactrl import setup_digits, board_init_uart
|
||||
import textwrap
|
||||
|
||||
def send_sign(text):
|
||||
"""
|
||||
Wraps and sends text to the Vestaboard.
|
||||
"""
|
||||
COLS = 22
|
||||
ROWS = 6
|
||||
|
||||
# Wrap text to fit the board's width.
|
||||
lines = textwrap.wrap(text, width=COLS)
|
||||
|
||||
# Truncate if the message is too long for the board's height.
|
||||
if len(lines) > ROWS:
|
||||
lines = lines[:ROWS]
|
||||
|
||||
# The board controller expects spaces to be replaced with `0 for a blank character.
|
||||
board_lines = [line.replace(' ', '`0') for line in lines]
|
||||
|
||||
# setup_digits handles displaying the lines on the board.
|
||||
# It will also vertically center the block of text.
|
||||
setup_digits(board_lines, left_to_right_swap=False, real_hw=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Initialize communication with the board.
|
||||
board_init_uart()
|
||||
message = "This is a test of the protosign script. This message should wrap across multiple lines and be truncated if it is too long to fit on the display."
|
||||
send_sign(message)
|
||||
|
Reference in New Issue
Block a user