Compare commits
10 Commits
38610ea6ba
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 38af4b3c7c | |||
| ae83f8e562 | |||
| 3339bd07a2 | |||
| 3f42c61352 | |||
| 66398d4359 | |||
| 9718807fb7 | |||
| fd4bc64587 | |||
| 4ac47db102 | |||
| 8b4357c5fc | |||
| 49c043f6d6 |
+154
@@ -0,0 +1,154 @@
|
||||
# Python
|
||||
# ======
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
# node / npm / yarn
|
||||
# =================
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Editor
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Firmware
|
||||
# =======
|
||||
|
||||
# ESP-IDF
|
||||
sdkconfig
|
||||
sdkconfig.old
|
||||
|
||||
# Custom
|
||||
# ======
|
||||
|
||||
data/
|
||||
secrets.py
|
||||
secrets.h
|
||||
*.bin
|
||||
output.*
|
||||
out.*
|
||||
*.csv
|
||||
*.txt
|
||||
*.json
|
||||
|
||||
.aider*
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from vestactrl import setup_digits, board_init_uart
|
||||
import textwrap
|
||||
import urllib2
|
||||
import json
|
||||
import time
|
||||
|
||||
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]
|
||||
|
||||
special_chars = {
|
||||
' ': '`0',
|
||||
'\\w': '`1', # white
|
||||
'\\r': '`2', # red
|
||||
'\\o': '`3', # orange
|
||||
'\\y': '`4', # yellow
|
||||
'\\g': '`5', # green
|
||||
'\\b': '`6', # blue
|
||||
'\\v': '`7', # violet
|
||||
'\\d': '`8', # degree
|
||||
# '`9', # also degree
|
||||
}
|
||||
|
||||
for code, color in special_chars.items():
|
||||
lines = [line.replace(code, color) for line in lines]
|
||||
|
||||
# setup_digits handles displaying the lines on the board.
|
||||
# It will also vertically center the block of text.
|
||||
try:
|
||||
setup_digits(lines, left_to_right_swap=False, real_hw=True)
|
||||
except BaseException as e:
|
||||
print "Error setting digits:" + str(e)
|
||||
|
||||
|
||||
def poll_and_display():
|
||||
"""
|
||||
Polls the Protospace API and displays the sign message.
|
||||
"""
|
||||
last_message = ""
|
||||
url = 'https://api.my.protospace.ca/stats/'
|
||||
|
||||
while True:
|
||||
try:
|
||||
response = urllib2.urlopen(url)
|
||||
data = json.load(response)
|
||||
message = data.get('vestaboard')
|
||||
|
||||
if message and message != last_message:
|
||||
print "Updating sign with new message: " + message
|
||||
send_sign(message.encode('utf-8'))
|
||||
last_message = message
|
||||
|
||||
except (urllib2.URLError, ValueError, KeyError) as e:
|
||||
print "Error: {}".format(e)
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Initialize communication with the board.
|
||||
board_init_uart()
|
||||
poll_and_display()
|
||||
Binary file not shown.
Reference in New Issue
Block a user