1
0
Fork 0

initial comit

This commit is contained in:
Kevin Matz 2019-11-01 10:34:57 -04:00
commit 257b6f213b
9 changed files with 277 additions and 0 deletions

115
.gitignore vendored Normal file
View File

@ -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

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "baconscript"]
path = baconscript
url = https://git.company235.com/kevin/baconscript.git

25
LICENSE.md Normal file
View File

@ -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.

54
README.md Normal file
View File

@ -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
```

1
baconscript Submodule

@ -0,0 +1 @@
Subproject commit c1a7ad48b2ea848f59717832f938a3687b88e781

51
buttond.py Executable file
View File

@ -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()

17
buttons.cfg Normal file
View File

@ -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"

10
buttons.service Normal file
View File

@ -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

1
server.cfg Symbolic link
View File

@ -0,0 +1 @@
baconscript/server.cfg