commit 257b6f213bea8c566cd6f253ae361e8e4fd34b7c Author: Kevin Matz Date: Fri Nov 1 10:34:57 2019 -0400 initial comit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b9d187 --- /dev/null +++ b/.gitignore @@ -0,0 +1,115 @@ +# Antlr4 +*.interp +*.tokens + +# 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 +MANIFEST + +# 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/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# 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 + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..208fa6b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "baconscript"] + path = baconscript + url = https://git.company235.com/kevin/baconscript.git diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..6645769 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright © `2019` `Kevin Matz (kevin@company235.com)` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3358054 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# onsetswitch +Use buttons connected to a Rasberry Pi GPIO to trigger Hog 4 comment macros. + +This readme assumes that you have: +1. a working and updated Rasberry Pi, +1. with ssh access already set up, +1. and a static IP address on HogNet. + +Beginner users will also want: +* Internet access on HogNet during setup. + +## Installing + +``` +cd /home/pi +git clone https://git.company235.com/kevin/onsetswitch.git +cd onsetswitch +``` + +## Configuring + +### Input +Connect one side of the button to ground, the other to a GPIO pin. + +![](https://gpiozero.readthedocs.io/en/stable/_images/button_bb.svg) + +Configure the buttons: +``` +nano buttons.cfg +``` + +### Output + +Configure the Hog4 OSC server: +``` +nano server.cfg +``` + +## Enabling on Boot +Link the onsetswitch service file to systemd: +``` +sudo ln -s buttons.service /lib/systemd/system/buttons.service +``` + +Enable the service at startup: +``` +sudo systemctl daemon-reload +sudo systemctl enable buttons.service +``` + +Reboot the Rasberry Pi: +``` +sudo reboot +``` diff --git a/baconscript b/baconscript new file mode 160000 index 0000000..c1a7ad4 --- /dev/null +++ b/baconscript @@ -0,0 +1 @@ +Subproject commit c1a7ad48b2ea848f59717832f938a3687b88e781 diff --git a/buttond.py b/buttond.py new file mode 100755 index 0000000..240a704 --- /dev/null +++ b/buttond.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""buttond.py: Watch a Rasberry Pi GPIO button. Exec Hog4 comment macros.""" + +__author__ = "Kevin Matz" +__copyright__ = "Copyright 2019, Company 235, LLC" +__credits__ = ["Kevin Matz"] + +__license__ = "MIT" +__version__ = "3.9" +__maintainer__ = "Kevin Matz" +__email__ = "kevin@company235.com" + +__status__ = "Prototype" + +import configparser +from baconscript.comment import comment +from gpiozero import Button, GPIODeviceError +from signal import pause + +# use mock pins when not working on Pi hardware +# from gpiozero.pins.mock import MockFactory +# from gpiozero import Device +# Device.pin_factory = MockFactory() + +# empty button directory +_buttons = {} + +# open config file +config = configparser.ConfigParser(allow_no_value=False) +config.read('buttons.cfg') +# set up each buttons +for b in config.get('button', 'names').split(','): + try: + # move to config section + c = config[b] + # read macro values + closed = c.get('close', None) + opened = c.get('open', None) + # set up button on pin + _buttons[b] = Button(c.getint("pin", None)) + # connect button callbacks to anonymous functions + _buttons[b].when_pressed = lambda: comment(closed) + _buttons[b].when_released = lambda: comment(opened) + except (KeyError, GPIODeviceError) as e: + print('Error configuring button', b, e) + continue + +if __name__ == '__main__': + pause() diff --git a/buttons.cfg b/buttons.cfg new file mode 100644 index 0000000..fd54fd6 --- /dev/null +++ b/buttons.cfg @@ -0,0 +1,17 @@ +[button] + names=switch1,switch2,switch3 + +[switch1] + pin: 4 + close: "gm21/2" + open: "gm21/1" + +[switch2] + pin: 5 + close: "gm22/2" + open: "gm22/1" + +[switch3] + pin: 6 + close: "gm23/2" + open: "gm23/1" diff --git a/buttons.service b/buttons.service new file mode 100644 index 0000000..a6fcacd --- /dev/null +++ b/buttons.service @@ -0,0 +1,10 @@ +[Unit] +Description=OSC Button Watcher +After=multi-user.target + +[Service] +Type=idle +ExecStart=/usr/bin/python3 /home/pi/onsetswitch/buttond.py + +[Install] +WantedBy=multi-user.target diff --git a/server.cfg b/server.cfg new file mode 120000 index 0000000..a98ed94 --- /dev/null +++ b/server.cfg @@ -0,0 +1 @@ +baconscript/server.cfg \ No newline at end of file