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

Rotary Encoder not working correctly #14

Closed alpex8 closed 3 years ago

alpex8 commented 3 years ago

I'm trying to use the rotary encoder function. As there isn't a release including it I built the package myself and installed it. Afterwards I set up the buttons and the rotary encoder following the README. I double checked using the correct GPIOs.

The Push Buttons are working as expected. However the volume meter only can be used to decrease the volume. This is my config:

[raspberry-gpio]
enabled = true
bcm23 = volume_up,active_low,20,rotenc_id=vol,step=1
bcm24 = volume_down,active_low,20,rotenc_id=vol,step=1
bcm27 = play_pause,active_low,250
bcm17 = next,active_low,250
bcm22 = prev,active_low,250

By switching volume_up and volume_down I can switch the direction in which the volume meter will decrease the volume. So since both directions are doing something, I think that this isn't a connectivity issue. I assume that it's a software issue.

Can you point me in a direction, what I can do to fix this? Maybe @martinfelis can help here.

Thanks

alpex8 commented 3 years ago

I added some debug log messages. Turned out the rotary encoder is working, but the call for setting the volume up just does nothing:

Here are the messages when turning clockwise:

DEBUG    2021-09-08 11:18:26,491 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  Received GPIO event on pin 24
DEBUG    2021-09-08 11:18:26,491 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  current state (None, None)
DEBUG    2021-09-08 11:18:26,492 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  next state (1, 0)
DEBUG    2021-09-08 11:18:26,492 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  KeyError occurred on retrieving direction and/or event
DEBUG    2021-09-08 11:18:26,764 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  Received GPIO event on pin 23
DEBUG    2021-09-08 11:18:26,765 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  current state (1, 0)
DEBUG    2021-09-08 11:18:26,766 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  next state (0, 1)
DEBUG    2021-09-08 11:18:26,766 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  KeyError occurred on retrieving direction and/or event
DEBUG    2021-09-08 11:18:26,820 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  Received GPIO event on pin 24
DEBUG    2021-09-08 11:18:26,820 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  current state (0, 1)
DEBUG    2021-09-08 11:18:26,821 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  next state (0, 0)
DEBUG    2021-09-08 11:18:26,821 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  retrieved direction 1, event volume_up
DEBUG    2021-09-08 11:18:26,822 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  Trying to dispatch current event to handler handle_volume_up
DEBUG    2021-09-08 11:18:26,826 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  setting volume up to 26

This are the messages when turning counter clock wise:

EBUG    2021-09-08 11:18:59,059 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  Received GPIO event on pin 23
DEBUG    2021-09-08 11:18:59,059 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  current state (1, 0)
DEBUG    2021-09-08 11:18:59,060 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  next state (0, 0)
DEBUG    2021-09-08 11:18:59,061 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  retrieved direction 0, event volume_down
DEBUG    2021-09-08 11:18:59,061 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  Trying to dispatch current event to handler handle_volume_down
DEBUG    2021-09-08 11:18:59,065 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  setting volume down to 24
DEBUG    2021-09-08 11:18:59,067 [32496:Dummy-21] mopidy_raspberry_gpio.frontend
  Received GPIO event on pin 24
DEBUG    2021-09-08 11:18:59,075 [32496:AlsaMixer-1] mopidy.mixer
  Mixer event: volume_changed(volume=23)
DEBUG    2021-09-08 11:18:59,075 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  current state (0, 0)
DEBUG    2021-09-08 11:18:59,078 [32496:AlsaMixer-1] mopidy.listener
  Sending volume_changed to MixerListener: {'volume': 23}
DEBUG    2021-09-08 11:18:59,082 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  next state (0, 0)
DEBUG    2021-09-08 11:18:59,084 [32496:Core-11] mopidy.listener
  Sending volume_changed to CoreListener: {'volume': 23}
DEBUG    2021-09-08 11:18:59,086 [32496:Dummy-21] mopidy_raspberry_gpio.rotencoder
  KeyError occurred on retrieving direction and/or event
DEBUG    2021-09-08 11:18:59,089 [32496:MpdFrontend-18] mopidy.listener
  Sending mixer to MpdSession: {}

In case of turning the volume down the call of self.core.mixer.set_volume(volume) somehow isn't picked up by mopidy.mixer and mopidy.listener

alpex8 commented 3 years ago

Problem not related to this extension. It's an issue of the alsamixer extension (https://github.com/mopidy/mopidy-alsamixer/issues/19).