prev vs. jump
This commit is contained in:
+17
-4
@@ -15,7 +15,6 @@ SOUND_OK = "/home/pi/piplayer2/sounds/ok.mp3"
|
||||
SOUND_SCAN_FAIL = "/home/pi/piplayer2/sounds/fail.mp3"
|
||||
SOUND_PLAYBACK_ERROR = "/home/pi/piplayer2/sounds/error.mp3"
|
||||
QR_SCANNER_TIMEOUT = 3
|
||||
BUTTON_PAUSE = 400
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s.%(msecs)d %(levelname)s - %(message)s')
|
||||
@@ -40,9 +39,23 @@ GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
|
||||
|
||||
position = 0
|
||||
|
||||
def btn1_callback(channel):
|
||||
logging.debug('PREV_CALLBACK')
|
||||
out, err = subprocess.Popen(['mocp','--info'], stdout=subprocess.PIPE).communicate()
|
||||
info = out.splitlines()
|
||||
for s in info:
|
||||
s = s.decode("utf-8")
|
||||
if s.startswith('CurrentSec'):
|
||||
position = s[s.rfind(' ')+1:]
|
||||
logging.debug(int(position))
|
||||
if (int(position) < 4):
|
||||
logging.debug('mocp --previous')
|
||||
subprocess.call(["mocp", "--previous"])
|
||||
else:
|
||||
logging.debug('mocp --jump 0s')
|
||||
subprocess.call(["mocp", "--jump", "0s"])
|
||||
|
||||
def btn2_callback(channel):
|
||||
logging.debug('mocp --toggle-pause')
|
||||
@@ -54,9 +67,9 @@ def btn3_callback(channel):
|
||||
|
||||
|
||||
|
||||
GPIO.add_event_detect(9, GPIO.FALLING, callback=btn1_callback, bouncetime=BUTTON_PAUSE)
|
||||
GPIO.add_event_detect(10, GPIO.FALLING, callback=btn2_callback, bouncetime=BUTTON_PAUSE)
|
||||
GPIO.add_event_detect(11, GPIO.FALLING, callback=btn3_callback, bouncetime=BUTTON_PAUSE)
|
||||
GPIO.add_event_detect(9, GPIO.FALLING, callback=btn1_callback, bouncetime=1000)
|
||||
GPIO.add_event_detect(10, GPIO.FALLING, callback=btn2_callback, bouncetime=400)
|
||||
GPIO.add_event_detect(11, GPIO.FALLING, callback=btn3_callback, bouncetime=400)
|
||||
|
||||
try:
|
||||
logging.info('Start moc server')
|
||||
|
||||
Reference in New Issue
Block a user