commit
7189f3c461
@ -83,6 +83,12 @@ main:
|
|||||||
enabled: false
|
enabled: false
|
||||||
#The IP Address of your phone with Paw Server running, default (option is empty) is 192.168.44.1
|
#The IP Address of your phone with Paw Server running, default (option is empty) is 192.168.44.1
|
||||||
ip: ''
|
ip: ''
|
||||||
|
gpio_buttons:
|
||||||
|
enabled: false
|
||||||
|
#The following is a list of the GPIO number for your button, and the command you want to run when it is pressed
|
||||||
|
gpios:
|
||||||
|
- 20: 'sudo touch /root/.pwnagotchi-auto && sudo systemctl restart pwnagotchi'
|
||||||
|
- 21: 'shutdown -h now'
|
||||||
# monitor interface to use
|
# monitor interface to use
|
||||||
iface: mon0
|
iface: mon0
|
||||||
# command to run to bring the mon interface up in case it's not up already
|
# command to run to bring the mon interface up in case it's not up already
|
||||||
|
38
pwnagotchi/plugins/default/gpio_buttons.py
Normal file
38
pwnagotchi/plugins/default/gpio_buttons.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
__author__ = 'ratmandu@gmail.com'
|
||||||
|
__version__ = '1.0.0'
|
||||||
|
__name__ = 'gpio_buttons'
|
||||||
|
__license__ = 'GPL3'
|
||||||
|
__description__ = 'GPIO Button support plugin'
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
running = False
|
||||||
|
OPTIONS = dict()
|
||||||
|
GPIOs = {}
|
||||||
|
COMMANDs = None
|
||||||
|
|
||||||
|
def runCommand(channel):
|
||||||
|
command = GPIOs[channel]
|
||||||
|
logging.info(f"Button Pressed! Running command: {command}")
|
||||||
|
process = subprocess.Popen(command, shell=True, stdin=None, stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash")
|
||||||
|
process.wait()
|
||||||
|
|
||||||
|
|
||||||
|
def on_loaded():
|
||||||
|
logging.info("GPIO Button plugin loaded.")
|
||||||
|
|
||||||
|
#get list of GPIOs
|
||||||
|
gpios = OPTIONS['gpios']
|
||||||
|
|
||||||
|
#set gpio numbering
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
|
for i in gpios:
|
||||||
|
gpio = list(i)[0]
|
||||||
|
command = i[gpio]
|
||||||
|
GPIOs[gpio] = command
|
||||||
|
GPIO.setup(gpio, GPIO.IN, GPIO.PUD_UP)
|
||||||
|
GPIO.add_event_detect(gpio, GPIO.FALLING, callback=runCommand, bouncetime=250)
|
||||||
|
logging.info("Added command: %s to GPIO #%d", command, gpio)
|
Loading…
x
Reference in New Issue
Block a user