1
0
mirror of https://github.com/AG7GN/nexus-utilities.git synced 2025-05-15 22:20:09 -07:00

New shutdown_button script

This commit is contained in:
Steve Magnuson 2019-10-02 16:32:04 -07:00
parent 8be144831f
commit afa5a47786
3 changed files with 80 additions and 2 deletions

View File

@ -1,6 +1,6 @@
# Hampi Utilities
VERSION 20190923
VERSION 20191002
This is a collection of utilities for the Hampi image. These scripts will only work on the Hampi image.
Some scripts are specific to the [Nexus DR-X](http://wb7fhc.com/nexus-dr-x.html) board.
@ -23,6 +23,8 @@ Some scripts are specific to the [Nexus DR-X](http://wb7fhc.com/nexus-dr-x.html)
[watchdog-tnc.sh](#watchdog-tnc-script)
[shutdown_button.py](#shutdown-button-script)
## Installation
### Easy Install
@ -129,3 +131,30 @@ To change it to trim log entries older than 2 weeks ago rather than yesterday, t
# This one igates only
*/2 * * * * /usr/local/bin/watchdog-tnc.sh igate >/dev/null 2>&1
## Shutdown Button Script
`shutdown_button.py` monitors the shutdown button found on the DigiLink REV DS and [Nexus DR-X](http://wb7fhc.com/nexus-dr-x.html) boards. It reboots the Pi if the button is pressed more than 2 but less than 5 seconds, or shuts down the Pi if the button is pressed for more than 5 seconds.
Your Hampi image already has the systemd service file for the shutdown script installed and enabled. No further action is required to enable it, but __for documentation purposes only__, here's how to enable the service:
- As sudo, create a file called `/etc/systemd/system/shutdown_button.service` with the following text:
[Unit]
Description=GPIO shutdown button
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/python3 /usr/local/bin/shutdown_button.py
[Install]
WantedBy=multi-user.target
- Run these commands in a Terminal to enable the service:
sudo systemctl enable shutdown_button.service
sudo systemctl start shutdown_button.service

View File

@ -1 +1 @@
VERSION="1.1.3"
VERSION="1.2.0"

49
shutdown_button.py Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/python3
# Version 2.0.1
# Original script by Stewart C. Russell via https://github.com/scruss/shutdown_button
# Modified by Steve Magnuson, AG7GN to control LED on different GPIO during Button
# press.
# -*- coding: utf-8 -*-
# example gpiozero code that could be used to have a reboot
# and a shutdown function on one GPIO button
# scruss - 2017-10
use_button=26 # Button on use_button (BCM GPIO 26 by default)
from gpiozero import Button
from gpiozero import LED
from signal import pause
from subprocess import check_call
held_for=0.0
led=LED(24) # LED on BCM GPIO 24
def rls():
global held_for
if (held_for > 5.0):
check_call(['/sbin/poweroff'])
elif (held_for > 2.0):
check_call(['/sbin/reboot'])
else:
held_for = 0.0
def hld():
# callback for when button is held
# is called every hold_time seconds
global held_for
# need to use max() as held_time resets to zero on last callback
held_for = max(held_for, button.held_time + button.hold_time)
if (held_for > 5.0):
led.off()
elif (held_for > 2.0):
led.on()
else:
led.off()
button=Button(use_button, hold_time=1.0, hold_repeat=True)
button.when_held = hld
button.when_released = rls
pause() # wait forever