I’m working on building my own mopidy extension for controlling playback with many buttons and potentiometers with the Raspberry Pi. Because the Raspberry Pi does not have analog input I’m using an analog-to-digital-converter, which I readout with SPI and this Adafruit Module.
My extension needs to continuously (in a
while True loop) read values from the ADC. I set it up to work as follows: if a specific value of one ADC channel is bigger than X I want to call a function, e.g.
self.core.playback.play(). This works in principle. I tried two options:
- running the loop in a simple while loop, which will block all other mopidy actions (Thought maybe Mopidy starts each frontend extension in its own thread),
- running the loop in a new thread will enable mopidy to work on its own and my extension also works on a separate thread - but if i want to stop mopidy with systemctl, it will not properly stop since the separate thread is not stopped and therefore the service will finally ‘fail’ after timeout.
Do I maybe need to run my extension as a
pykka.ThreadingActor ? If so, how? Any ideas of how to solve this issue?