Commit fee893a7 authored by justin's avatar justin
Browse files

Merge branch 'add-power-button-support' into 'master'

Create boxomon-rpi and add power-button configuration scripts.

See merge request justin/boxomon!4
parents b38b2543 940458bc
Pipeline #419 passed with stages
in 2 minutes and 25 seconds
......@@ -24,7 +24,12 @@ A birthday gift (long-running) for my girlfriend! Boxomon is a cute toy that, wh
## Version 0.2.2
- Tweaks to text to make the app as close to the original as possible.
## Version 0.3.0
- Edge-deployed device - a true Boxomon-successor!
- Deployed on a raspberry PI with minimal effort, autostarting Chromium, configuring a PiTFT Plus touchscreen, and adding button support.
# Future work
- Improved styling on the web interace
- Tracking of if the message has been seen that day
- Authentication and authorization
- Edge-deployed device - a true Boxomon2
apiVersion: v1
appVersion: "0.2.2"
appVersion: "0.3.0"
description: A Helm chart for Kubernetes to deploy the boxomon backend
name: backend
version: 0.2.2
version: 0.3.0
apiVersion: v1
appVersion: "0.2.2"
appVersion: "0.3.0"
description: A Helm chart for Kubernetes
name: frontend
version: 0.2.2
version: 0.3.0
# -*- coding: utf-8 -*-
from collections import defaultdict
from gpiozero import Button, PWMOutputDevice
from signal import pause
from subprocess import check_call
def check_held(state_dict, threshold=2.0):
result = state_dict.get('held', 0) > threshold
state_dict['held'] = 0
return result
def check_shutdown(state_dict):
print('Checking shutdown:', state_dict)
if check_held(state_dict):
check_call(['systemctl', 'halt'])
def check_restart(state_dict):
print('Checking restart:', state_dict)
if check_held(state_dict):
check_call(['systemctl', 'reboot'])
def toggle_screen(state_dict):
print('Checking screen toggle:', state_dict)
def set_held(state_dict, delta=0.05):
print('Setting hold:', state_dict)
state_dict['held'] = state_dict.get('held', 0) + delta
def configure_button(button_spec_dict, button_state_dict):
button = Button(button_spec_dict['button'], hold_time=0.05, hold_repeat=True)
button.when_held = lambda: button_spec_dict['onhold'](state_dict=button_state_dict)
button.when_released = lambda: button_spec_dict['onrelease'](state_dict=button_state_dict)
return button
def main():
"shutdown": {
"button": 17,
"onhold": set_held,
"onrelease": check_shutdown
"reboot": {
'button' : 22,
'onhold': set_held,
'onrelease': check_restart
"screen toggle": {
'button': 23,
'onhold': lambda state_dict: None,
'onrelease': toggle_screen
STATE = defaultdict(dict)
buttons = {}
screen_pin = PWMOutputDevice(18, initial_value=1)
for name, conf_dict in CONFIG.items():
state_dict = STATE[name]
state_dict['screen'] = screen_pin
buttons[name] = configure_button(conf_dict, STATE[name])
pause() # wait forever
if __name__ == "__main__":
Description=GPIO shutdown button
\ No newline at end of file
sudo apt install python3-gpiozero
sudo mkdir -p /usr/local/bin
sudo cp $SCRIPT_FILE /usr/local/bin/$SCRIPT_FILE
sudo cp $SERVICE_FILE /etc/systemd/system/$SERVICE_FILE
sudo systemctl daemon-reload
sudo systemctl enable $SERVICE_FILE
sudo systemctl start $SERVICE_FILE
sudo systemctl restart $SERVICE_FILE
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment