Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Encoder support and new GPIO Pinout to enchance compatibility with I2S DAC #350

Merged
merged 6 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions misc/sampleconfigs/gpio-buttons.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ from gpiozero import Button
from signal import pause
from subprocess import check_call

# 2018-10-31
# Added the function on holding volume + - buttons to change the volume in 0.3s interval
#
# 2018-10-15
# this script has the `pull_up=True` for all pins. See the following link for additional info:
# https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/259#issuecomment-430007446
Expand Down Expand Up @@ -38,23 +35,19 @@ def def_halt():
check_call("./scripts/playout_controls.sh -c=playerpause", shell=True)

shut = Button(3, hold_time=2)
vol0 = Button(13,pull_up=True)
volU = Button(16,pull_up=True,hold_time=0.3,hold_repeat=True)
volD = Button(19,pull_up=True,hold_time=0.3,hold_repeat=True)
next = Button(26,pull_up=True)
prev = Button(20,pull_up=True)
halt = Button(21,pull_up=True)
#vol0 = Button(13,pull_up=True)
#volU = Button(16,pull_up=True)
#volD = Button(19,pull_up=True)
#next = Button(26,pull_up=True)
#prev = Button(20,pull_up=True)
halt = Button(24,pull_up=True)

shut.when_held = def_shutdown
vol0.when_pressed = def_vol0
volU.when_pressed = def_volU
#When the Volume Up button was held for more than 0.3 seconds every 0.3 seconds he will call a ra$
volU.when_held = def_volU
volD.when_pressed = def_volD
#When the Volume Down button was held for more than 0.3 seconds every 0.3 seconds he will lower t$
volD.when_held = def_volD
next.when_pressed = def_next
prev.when_pressed = def_prev
#vol0.when_pressed = def_vol0
#volU.when_pressed = def_volU
#volD.when_pressed = def_volD
#next.when_pressed = def_next
#prev.when_pressed = def_prev
halt.when_pressed = def_halt

pause()
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ After=network.target iptables.service firewalld.service
[Service]
Restart=always
WorkingDirectory=/home/pi/RPi-Jukebox-RFID
ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py
ExecStart=/usr/bin/python2 /home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py
User=pi
Group=pi

[Install]
WantedBy=multi-user.target
27 changes: 3 additions & 24 deletions scripts/ky040.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,28 @@

class KY040:

def __init__(self, arg_clockPin, arg_dataPin, arg_switchPin=None, arg_rotaryCallbackCW=None, arg_rotaryCallbackCCW=None, arg_switchCallback=None, arg_rotaryBouncetime=100, arg_switchBouncetime=200):
def __init__(self, arg_clockPin, arg_dataPin, arg_rotaryCallbackCW=None, arg_rotaryCallbackCCW=None, arg_rotaryBouncetime=100, arg_switchBouncetime=100):
# persist values
self.clockPin = arg_clockPin
self.dataPin = arg_dataPin
self.switchPin = arg_switchPin
self.rotaryCallbackCW = arg_rotaryCallbackCW
self.rotaryCallbackCCW = arg_rotaryCallbackCCW
self.switchCallback = arg_switchCallback
self.rotaryBouncetime = arg_rotaryBouncetime
self.switchBouncetime = arg_switchBouncetime

# setup pins
# data and clock have pullups at the PCB
GPIO.setup(self.clockPin, GPIO.IN)
GPIO.setup(self.dataPin, GPIO.IN)

if None != self.switchPin:
GPIO.setup(self.switchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(self.clockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(self.dataPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def start(self):
GPIO.add_event_detect(self.clockPin, GPIO.FALLING, callback=self._clockCallback, bouncetime=self.rotaryBouncetime)

if None != self.switchPin:
GPIO.add_event_detect(self.switchPin, GPIO.FALLING, callback=self._switchCallback, bouncetime=self.switchBouncetime)

def stop(self):
GPIO.remove_event_detect(self.clockPin)

if None != self.switchPin:
GPIO.remove_event_detect(self.switchPin)

def _clockCallback(self, pin):
if GPIO.input(self.clockPin) == 0:
data = GPIO.input(self.dataPin)
if data == 1:
self.rotaryCallbackCCW()
else:
self.rotaryCallbackCW()

def _switchCallback(self, pin):
if None == self.switchPin:
return

if GPIO.input(self.switchPin) == 0:
self.switchCallback()

29 changes: 19 additions & 10 deletions scripts/rotary-encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,42 @@
from subprocess import check_call


def rotaryChangeCW():
def rotaryChangeCWVol():
check_call("./scripts/playout_controls.sh -c=volumeup", shell=True)

def rotaryChangeCCW():
def rotaryChangeCCWVol():
check_call("./scripts/playout_controls.sh -c=volumedown", shell=True)

def switchPressed(dummy):
check_call("./scripts/playout_controls.sh -c=mute", shell=True)
def rotaryChangeCWTrack():
check_call("./scripts/playout_controls.sh -c=playernext", shell=True)

def rotaryChangeCCWTrack():
check_call("./scripts/playout_controls.sh -c=playerprev", shell=True)


if __name__ == "__main__":

CLOCKPIN = 5
DATAPIN = 6
SWITCHPIN = 13
CLOCKPINVol = 27
DATAPINVol = 17

CLOCKPINTrack = 22
DATAPINTrack = 23

GPIO.setmode(GPIO.BCM)

ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, rotaryChangeCW, rotaryChangeCCW, switchPressed)
ky040Vol = KY040(CLOCKPINVol, DATAPINVol, rotaryChangeCWVol, rotaryChangeCCWVol)

ky040Track = KY040(CLOCKPINTrack, DATAPINTrack, rotaryChangeCWTrack, rotaryChangeCCWTrack)

ky040.start()
ky040Vol.start()
ky040Track.start()

try:
while True:
time.sleep(0.2)
finally:
ky040.stop()
ky040Vol.stop()
ky040Track.stop()
GPIO.cleanup()


Expand Down