Saturday, December 31, 2022

Some C++ hacking

Happy new year (in a few hours...) everyone! :)

Over the past few days, I've been hacking the Raspberry Pi C++ display code to make it more manageable. Previously, it was a pile of spaghetti that grew like a mushroom. Now I have a new repo for the code:

https://github.com/airball-aero/airball-display

In particular, I needed to add support for an adjustment knob, and this required dealing with Linux input events and multi-threading and what not, and if I had not cleaned up the code first, it would have been well nigh unintelligible.

The basic abstraction I added is a class Application which contains an instance of IEventQueue. The event queue acts like any other in a GUI app -- GUI events are posted to it by various threads, and the paint thread processes these events and paints, according to the frame rate. A better or worse human than I would have made the event queue a singleton, but I am worse or better than that, and am for now trying to stick to my "singletons are evil" religion.

This allowed me to add a bunch of code in class Settings so there is very rudimentary support for a (usually USB) adjustment knob -- either a commodity one like this; an Adafruit Rotary Trinkey for more embedded cases; and a custom circuit for even more embedded cases. By using the Linux HID support, I can just plug in via USB and don't have to deal with reading button presses via GPIOs and what-not.

It works, at least on my PC. I'm calling it a night. Here's to a productive and happy 2023!!! <3

No comments :

Post a Comment