-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardware_watcher.py
More file actions
35 lines (25 loc) · 854 Bytes
/
hardware_watcher.py
File metadata and controls
35 lines (25 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import RPi.GPIO as GPIO
class HookedPin:
def __init__(self, pin, callback):
self.pin = pin
self.hooked = False
self.callback = callback
def send(self, delay):
pass
class ImportWatcher:
def __init__(self):
self.hooked_pins = {}
def hook_gpio(self, hooked_pin):
self.hooked_pins[hooked_pin.pin] = hooked_pin
def refresh(self):
for pin, hookedPin in self.hooked_pins:
if not hookedPin.hooked:
GPIO.setup(hookedPin.pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
hookedPin.hooked = True
def watch_pins(self):
for pin, hookedPin in self.hooked_pins:
if GPIO.input(hookedPin.pin):
hookedPin.callback()
def send_to_pin(self, pin, delay):
self.hooked_pins[pin].send(delay)
pass