From: Guillaume Pellerin Date: Thu, 24 Oct 2013 16:34:56 +0000 (+0200) Subject: RPi inputs are VERY sensible to electromagnetic parasites so we add a timer to the... X-Git-Tag: 0.3.1~2^2~2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=45a73c48d6e21794492114c2c67642d74de018a5;p=piplayer.git 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... --- 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)