diff options
author | Ingar <ingar@telenet.be> | 2022-02-27 11:59:40 +0100 |
---|---|---|
committer | Ingar <ingar@telenet.be> | 2022-02-27 12:00:40 +0100 |
commit | ba5673c7e1c4c2334adecd44e75ab9d1e9ba0183 (patch) | |
tree | 2a78d64554f84ad8bc7b5bd1028dfb061ec48e9e | |
parent | 34c18bf246aed981b2cc6e0e068a5286155837e8 (diff) |
Added script to handle soft button events.
-rw-r--r-- | buttonctl/buttonctl.py | 16 | ||||
-rw-r--r-- | buttonctl/systemd/button.service | 10 |
2 files changed, 26 insertions, 0 deletions
diff --git a/buttonctl/buttonctl.py b/buttonctl/buttonctl.py new file mode 100644 index 0000000..26878f1 --- /dev/null +++ b/buttonctl/buttonctl.py @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import RPi.GPIO as GPIO +import subprocess + + +GPIO.setmode(GPIO.BCM) +GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.wait_for_edge(26, GPIO.FALLING) + +print ('button pressed') + +subprocess.call(['ledctl', 'boot'], shell=False) + +subprocess.call(['shutdown', '-h', 'now'], shell=False) + diff --git a/buttonctl/systemd/button.service b/buttonctl/systemd/button.service new file mode 100644 index 0000000..e77edd2 --- /dev/null +++ b/buttonctl/systemd/button.service @@ -0,0 +1,10 @@ +[Unit] +Description=watching soft button +After=local-fs.target + +[Service] +Type=simple +ExecStart=/usr/bin/buttonctl + +[Install] +WantedBy=multi-user.target |