Skip to content

Commit

Permalink
replaced busy waiting with event-driven button listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Orbiter authored Feb 28, 2019
1 parent f96e9f2 commit b477c3d
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions main/hardware_components/rpi_wake_button.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import time
import logging
import RPi.GPIO as GPIO

from .wake_button import WakeButton


logger = logging.getLogger(__name__)


class RaspberryPiWakeButton(WakeButton):

def __init__(self):
super().__init__()
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(17, GPIO.FALLING, callback=self.button_detected, bouncetime=300)

def button_detected(channel, foo):
super().on_detected()

def run(self):
while True:
is_input = GPIO.input(17)
if is_input:
time.sleep(0.2)
continue
# Button pressed
logger.debug('WakeButton is pressed')
self.on_detected()
time.sleep(0.2)
pass

0 comments on commit b477c3d

Please sign in to comment.