From 45a73c48d6e21794492114c2c67642d74de018a5 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 24 Oct 2013 18:34:56 +0200 Subject: [PATCH] RPi inputs are VERY sensible to electromagnetic parasites so we add a timer to the gpio_play function so that we are sure it is a human who is playing... --- piplayer/player.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/piplayer/player.py b/piplayer/player.py index b906a71..d6a3da0 100644 --- a/piplayer/player.py +++ b/piplayer/player.py @@ -46,6 +46,7 @@ class PiPlayer(object): looping = False auto_next = False alsa_device = 'hw:0' + parasite_filter_time = '0.02' def __init__(self, play_dir): # Playlist @@ -155,14 +156,20 @@ class PiPlayer(object): self.pipeline.set_state(gst.STATE_PLAYING) if DEBUG: print self.play_id, self.uri - + + def parasite_filter(self): + import RPi.GPIO as GPIO + time.sleep(self.parasite_filter_time) + return GPIO.input(self.gpio_channel_play): + def play(self): if not self.playing: - self.pipeline.set_state(gst.STATE_PLAYING) - self.playing = True + if self.parasite_filter(): + self.pipeline.set_state(gst.STATE_PLAYING) + self.playing = True elif self.auto_next: self.next() - + def stop(self): if self.playing: self.pipeline.set_state(gst.STATE_NULL) -- 2.39.5