From d3c6194e0fdc985748b558b76fd1734d2e35c288 Mon Sep 17 00:00:00 2001 From: Justin Richards Date: Sun, 27 Oct 2019 19:11:36 -0500 Subject: [PATCH] adding gpio plugin Signed-off-by: Justin Richards --- pwnagotchi/plugins/default/gpio_buttons.py | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pwnagotchi/plugins/default/gpio_buttons.py diff --git a/pwnagotchi/plugins/default/gpio_buttons.py b/pwnagotchi/plugins/default/gpio_buttons.py new file mode 100644 index 0000000..d9860d1 --- /dev/null +++ b/pwnagotchi/plugins/default/gpio_buttons.py @@ -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=300) + logging.info("Added command: %s to GPIO #%d", command, gpio)