-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced busy waiting with event-driven button listener
- Loading branch information
Showing
1 changed file
with
6 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |