From b43d0fdfa750c20fdcda92f5cb26eb166cf875f6 Mon Sep 17 00:00:00 2001 From: Diony Rosa Date: Thu, 3 Sep 2015 23:02:33 -0400 Subject: [PATCH 1/3] Gave the raspi GPIO pins reasonable names. --- buttons.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/buttons.py b/buttons.py index 23187a5..904f41d 100644 --- a/buttons.py +++ b/buttons.py @@ -32,17 +32,43 @@ def blip(): blipper.loadfile(sndfile) ## setup pins -pins = [4,17,18,23,22] -names = {4:'back',17:'fwd',18:'down',23:'pause',22:'up'} -pianobar_cmds = {4:'' ,17:'n', 18:'(', 23:'p', 22:')'} -bemix_cmds = {4:'prev' ,17:'next', 18:'voldown', 23:'pause', 22:'volup'} +BUTTON_LEFT = 4 +BUTTON_UP = 22 +BUTTON_RIGHT = 17 +BUTTON_DOWN = 18 +BUTTON_CENTER = 23 + +pin_names = { + BUTTON_LEFT: 'back', + BUTTON_RIGHT: 'forward', + BUTTON_DOWN: 'down', + BUTTON_UP: 'up', + BUTTON_CENTER: 'pause' +} + +pianobar_cmds = { + BUTTON_LEFT: '', + BUTTON_RIGHT:'n', + BUTTON_DOWN:'(', + BUTTON_CENTER:'p', + BUTTON_UP:')' +} + +bemix_cmds = { + BUTTON_LEFT:'prev', + BUTTON_RIGHT:'next', + BUTTON_DOWN:'voldown', + BUTTON_CENTER:'pause', + BUTTON_UP:'volup' +} + wait = 0 press = 0 delay = .25 print "Setting up pins..." -for pin in pins: - GPIO.setup(pin,GPIO.IN) +for pin_number in pin_names.keys(): + GPIO.setup(pin_number,GPIO.IN) print "Started polling." frame = 0 From bbd0c0cc456e3a466ecfc987bdd072582d4280ec Mon Sep 17 00:00:00 2001 From: Diony Rosa Date: Fri, 4 Sep 2015 20:58:41 -0400 Subject: [PATCH 2/3] Added whitespace to button mapping dictionaries and fixed misnamed variable. --- buttons.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/buttons.py b/buttons.py index 904f41d..e43c437 100644 --- a/buttons.py +++ b/buttons.py @@ -46,20 +46,22 @@ def blip(): BUTTON_CENTER: 'pause' } +pin_numbers = pin_names.keys() + pianobar_cmds = { BUTTON_LEFT: '', - BUTTON_RIGHT:'n', - BUTTON_DOWN:'(', - BUTTON_CENTER:'p', - BUTTON_UP:')' + BUTTON_RIGHT: 'n', + BUTTON_DOWN: '(', + BUTTON_CENTER: 'p', + BUTTON_UP: ')' } bemix_cmds = { - BUTTON_LEFT:'prev', - BUTTON_RIGHT:'next', - BUTTON_DOWN:'voldown', - BUTTON_CENTER:'pause', - BUTTON_UP:'volup' + BUTTON_LEFT: 'prev', + BUTTON_RIGHT: 'next', + BUTTON_DOWN: 'voldown', + BUTTON_CENTER: 'pause', + BUTTON_UP: 'volup' } wait = 0 @@ -67,8 +69,8 @@ def blip(): delay = .25 print "Setting up pins..." -for pin_number in pin_names.keys(): - GPIO.setup(pin_number,GPIO.IN) +for pin in pin_numbers: + GPIO.setup(pin, GPIO.IN) print "Started polling." frame = 0 @@ -78,7 +80,7 @@ def blip(): pass frame += 1 - for pin in pins: + for pin in pin_numbers: if GPIO.input(pin) and (time.time()-wait >= 0 or pin != press): print names[pin] blip() From 61bb4714e6713921f61462d10284dc76c651df17 Mon Sep 17 00:00:00 2001 From: Diony Rosa Date: Fri, 4 Sep 2015 21:01:41 -0400 Subject: [PATCH 3/3] s/names/pin_names/ --- buttons.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttons.py b/buttons.py index e43c437..85383bf 100644 --- a/buttons.py +++ b/buttons.py @@ -82,7 +82,7 @@ def blip(): for pin in pin_numbers: if GPIO.input(pin) and (time.time()-wait >= 0 or pin != press): - print names[pin] + print pin_names[pin] blip() # pianowrite(pianobar_cmds[pin]) bemix_remote_command(bemix_cmds[pin])