From 61987f12ff4a5dfc3fac0aaf24d14cbcf4d0eb92 Mon Sep 17 00:00:00 2001 From: 9and3r <9and3r@gmail.com> Date: Fri, 8 Aug 2014 13:43:25 +0200 Subject: [PATCH] GPIO --- mopidy_touchscreen/gpio_inpput_manager.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mopidy_touchscreen/gpio_inpput_manager.py b/mopidy_touchscreen/gpio_inpput_manager.py index a3b7c83..6b69e20 100644 --- a/mopidy_touchscreen/gpio_inpput_manager.py +++ b/mopidy_touchscreen/gpio_inpput_manager.py @@ -1,5 +1,6 @@ import RPi.GPIO as GPIO import logging +import pygame logger = logging.getLogger(__name__) @@ -9,10 +10,18 @@ class GPIOManager(): def __init__(self): GPIO.setmode(GPIO.BCM) GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP) - GPIO.add_event_detect(24, GPIO.BOTH, callback=self.printFunction, bouncetime=30) + GPIO.add_event_detect(24, GPIO.BOTH, callback=self.rigth, bouncetime=30) + + def right(self, channel): + dict = {} + if GPIO.input(channel) == 1: + dict['type'] = pygame.KEYUP + else: + dict['type'] = pygame.KEYDOWN + dict['key'] = pygame.K_RIGHT + event = pygame.event.Event(dict) + pygame.event.post(event) - def printFunction(self, channel): - logger.error(channel)