mirror of
https://github.com/Febbweiss/mopidy-touchscreen.git
synced 2026-03-04 22:25:39 +00:00
GPIO pins working
This commit is contained in:
@@ -32,6 +32,11 @@ class Extension(ext.Extension):
|
|||||||
schema['fullscreen'] = config.Boolean()
|
schema['fullscreen'] = config.Boolean()
|
||||||
schema['cache_dir'] = config.Path()
|
schema['cache_dir'] = config.Path()
|
||||||
schema['gpio'] = config.Boolean()
|
schema['gpio'] = config.Boolean()
|
||||||
|
schema['gpio_left'] = config.Integer()
|
||||||
|
schema['gpio_right'] = config.Integer()
|
||||||
|
schema['gpio_up'] = config.Integer()
|
||||||
|
schema['gpio_down'] = config.Integer()
|
||||||
|
schema['gpio_enter'] = config.Integer()
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
def setup(self, registry):
|
def setup(self, registry):
|
||||||
|
|||||||
@@ -5,4 +5,9 @@ screen_height = 240
|
|||||||
cursor = True
|
cursor = True
|
||||||
fullscreen = False
|
fullscreen = False
|
||||||
cache_dir = $XDG_CACHE_DIR/mopidy/touchscreen
|
cache_dir = $XDG_CACHE_DIR/mopidy/touchscreen
|
||||||
gpio = False
|
gpio = False
|
||||||
|
gpio_left = 4
|
||||||
|
gpio_right = 27
|
||||||
|
gpio_up = 22
|
||||||
|
gpio_down = 23
|
||||||
|
gpio_enter = 24
|
||||||
|
|||||||
@@ -7,32 +7,28 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class GPIOManager():
|
class GPIOManager():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, pins):
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
# Left Button
|
# Left Button
|
||||||
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
GPIO.setup(pins['left'], GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
GPIO.add_event_detect(4, GPIO.BOTH, callback=left, bouncetime=30)
|
GPIO.add_event_detect(pins['left'], GPIO.BOTH, callback=left, bouncetime=30)
|
||||||
|
|
||||||
# Right Button
|
# Right Button
|
||||||
GPIO.setup(21, GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
GPIO.setup(pins['right'], GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
GPIO.add_event_detect(21, GPIO.BOTH, callback=right, bouncetime=30)
|
GPIO.add_event_detect(pins['right'], GPIO.BOTH, callback=right, bouncetime=30)
|
||||||
|
|
||||||
# Up Button
|
# Up Button
|
||||||
GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
GPIO.setup(pins['up'], GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
GPIO.add_event_detect(22, GPIO.BOTH, callback=up, bouncetime=30)
|
GPIO.add_event_detect(pins['up'], GPIO.BOTH, callback=up, bouncetime=30)
|
||||||
|
|
||||||
# Down Button
|
# Down Button
|
||||||
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
GPIO.setup(pins['down'], GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
GPIO.add_event_detect(23, GPIO.BOTH, callback=right, bouncetime=30)
|
GPIO.add_event_detect(pins['down'], GPIO.BOTH, callback=right, bouncetime=30)
|
||||||
|
|
||||||
# Enter Button
|
# Enter Button
|
||||||
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
GPIO.setup(pins['enter'], GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
GPIO.add_event_detect(24, GPIO.BOTH, callback=right, bouncetime=30)
|
GPIO.add_event_detect(pins['enter'], GPIO.BOTH, callback=right, bouncetime=30)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def right(channel):
|
def right(channel):
|
||||||
@@ -45,6 +41,7 @@ def right(channel):
|
|||||||
event = pygame.event.Event(type, dict)
|
event = pygame.event.Event(type, dict)
|
||||||
pygame.event.post(event)
|
pygame.event.post(event)
|
||||||
|
|
||||||
|
|
||||||
def left(channel):
|
def left(channel):
|
||||||
dict = {}
|
dict = {}
|
||||||
if GPIO.input(channel) == 1:
|
if GPIO.input(channel) == 1:
|
||||||
@@ -55,6 +52,7 @@ def left(channel):
|
|||||||
event = pygame.event.Event(type, dict)
|
event = pygame.event.Event(type, dict)
|
||||||
pygame.event.post(event)
|
pygame.event.post(event)
|
||||||
|
|
||||||
|
|
||||||
def down(channel):
|
def down(channel):
|
||||||
dict = {}
|
dict = {}
|
||||||
if GPIO.input(channel) == 1:
|
if GPIO.input(channel) == 1:
|
||||||
@@ -65,6 +63,7 @@ def down(channel):
|
|||||||
event = pygame.event.Event(type, dict)
|
event = pygame.event.Event(type, dict)
|
||||||
pygame.event.post(event)
|
pygame.event.post(event)
|
||||||
|
|
||||||
|
|
||||||
def up(channel):
|
def up(channel):
|
||||||
dict = {}
|
dict = {}
|
||||||
if GPIO.input(channel) == 1:
|
if GPIO.input(channel) == 1:
|
||||||
@@ -75,6 +74,7 @@ def up(channel):
|
|||||||
event = pygame.event.Event(type, dict)
|
event = pygame.event.Event(type, dict)
|
||||||
pygame.event.post(event)
|
pygame.event.post(event)
|
||||||
|
|
||||||
|
|
||||||
def enter(channel):
|
def enter(channel):
|
||||||
dict = {}
|
dict = {}
|
||||||
if GPIO.input(channel) == 1:
|
if GPIO.input(channel) == 1:
|
||||||
|
|||||||
@@ -32,7 +32,13 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener):
|
|||||||
self.gpio = config['touchscreen']['gpio']
|
self.gpio = config['touchscreen']['gpio']
|
||||||
if self.gpio:
|
if self.gpio:
|
||||||
from .gpio_inpput_manager import GPIOManager
|
from .gpio_inpput_manager import GPIOManager
|
||||||
self.gpio_manager = GPIOManager()
|
pins = {}
|
||||||
|
pins['left'] = config['touchscreen']['gpio_left']
|
||||||
|
pins['right'] = config['touchscreen']['gpio_right']
|
||||||
|
pins['up'] = config['touchscreen']['gpio_up']
|
||||||
|
pins['down'] = config['touchscreen']['gpio_down']
|
||||||
|
pins['enter'] = config['touchscreen']['gpio_enter']
|
||||||
|
self.gpio_manager = GPIOManager(pins)
|
||||||
|
|
||||||
def start_thread(self):
|
def start_thread(self):
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|||||||
Reference in New Issue
Block a user