As I am still testing the GUI using a keyboard, I haven't started on the GPIO input. I am actually using my
Radiation King Radio sub-project as a way to work out how that will work. The radiation king has Rotary Encoder, i2c ADC and i2C GPIOs inputs.
Alerting the code isn't straight forward, and you would do well to go watch a few primers on PyGame from YouTube as I am still learning it myself.
Basically PyGame has an event queue, and a set of actions that occur if a event occurs. Using an event queue is a way of having non-blocking code that just check if something happened and then reacts to that even later.
You need to code to check the input, and then post an event to the queue based on that input. And have an action handles that does something if that even pops up on the queue.
In the case of Volume Up:
In /pybboy/core.py there is "def handle_action(self, action):" and " def handle_event(self, event):" These same calls are found in other parts of the code depending on what is needed for a particular screen. In the case of core.py it handles the radio events that I want to work regardless of what screen you may be on. (Such as volume control)
Code:
elif event.key == pygame.K_PAGEUP: # Volume up
settings.radio.handle_radio_event(event)
This line basically watches for the event.key "pygame.K_PAGEUP", and then calls "/modules/radio/def handle_radio_event(self, event):"
Code:
if event.key == pygame.K_PAGEUP:
if hasattr(self, 'active_station') and self.active_station:
self.active_station.volume_up()
One of the things I am trying to do is optimize the call code a bit to isn't reliant on so many sub-calls, but a certain amount of that is needed to allow for unique things to happen on screens such as as the map.
The code on GitHub is also still very much a work in progress.
If you look in the settings.py file you will find commented out:
Code:
# Using GPIO.BCM as mode
# GPIO 23 pin16 reboot
# GPIO 25 pin 22 blank screen do not use
GPIO_ACTIONS = {
This is some of the code that enables GPIO input on the Pi. But on my project I have no GPIO pins due to the screen so I have to use i2C input, which is part of the reason I am doing the Radiation King, as a prototype for the various input functions I need without working about the screen since it is just a radio.