pimoroni / mopidy-raspberry-gpio

Mopidy GPIO Control Plugin for the Raspberry Pi (Using RPi.GPIO)
Apache License 2.0
21 stars 25 forks source link

Change play/pause toggle to play/stop (option) #6

Closed wildestpixel closed 4 years ago

wildestpixel commented 4 years ago

Checking whether this is possible as behaviour on the button via mopidy core is similar to mpc toggle and keeps the alsa device locked, meaning if you wanted to for example stream Raspotify or Shairport-sync you need firstly to unlock the device with equivalent mpc stop or mpc clear.

I'm presently achieving this by running a script in GoCoEdit via Applewatch, but would work better with an option like

def handle_play_stop(self, config):
        if self.core.playback.get_state().get() == core.PlaybackState.PLAYING:
            self.core.playback.stop()
        else:
            self.core.playback.play()

This possible simply editing /usr/local/lib/python3.7/dist-packages/mopidy_raspberry_gpio/frontend.py and the gpio options in mopidy.conf ?

Gadgetoid commented 4 years ago

Indeed it's possible. As you might have guessed, any function that is added to frontend.py can be bound to a button press by editing mopidy.conf, so there's no reason why your snippet can't be added to this library.

Do you want to raise this addition as a pull request? I'd be happy to review/merge it.

wildestpixel commented 4 years ago

Reopen this - needed to add to /usr/local/lib/python3.7/dist-packages/mopidy_raspberry_gpio/pinconfig.py the allowed defined function

valid_events = ValidList(
        ["play_pause", "play_stop", "prev", "next", "volume_up", "volume_down"]

And now successfully working on my rotated to 270 display (so power cable leads out to the rear) with the following GPIO assignment

[raspberry-gpio]
enabled = true
bcm5 = volume_up,active_low,250
bcm6 = next,active_low,250
bcm16 = volume_down,active_low,250
bcm20 = play_stop,active_low,250
bcm24 = play_stop,active_low,250

(For users of both board revisions)

Submitted pull request, failing on flake8 and black - possibly based on dirty edit of quotation marks.

Gadgetoid commented 4 years ago

Second time's a charm, eh! Thanks for testing and feeding back with the fix- suffice to say... things are hectic still, and I'm not firing on all cylinders.