I've got a Pi 3b that I originally planned to be a dedicated Steam Link. I already followed these instructions to set up a DS4 controller to control it, and it's working just fine so far: https://pimylifeup.com/raspberry-pi-playstation-controllers/ (the section named "Pairing your PS4 Controller via BluetoothCTL"). Now that I have the Pi setup, I've been having all these ideas of things that I could do with it. I'd like to write a script or program that launches at startup that listens for DS4 input and launches different applications when a button is pressed. For example, pressing X could launch Steam Link, at which point Steam Link should be responsible for dealing with the controller input. Only when Link closes would it them return to my original program which would then wait to launch a new application, like a media player or something.
I cannot find easy-to-decipher information on how I would even go about doing something like this. I write a lot of C and C# code, but mostly for embedded architectures or Windows. I don't have a lot of experience with Linux, and even less with scripting languages. To give a psuedocode idea of what I'm trying to do, rc.local will launch the program:
*print list of available commands to user* *open bluetooth comm bus for pre-determined MAC_ADDRESS* do *wait for bluetooth input* switch(bluetooth input) case "X": run steamlink case "∆": run mediaplayer case "": *send rumble command to controller* case "Options + Share": bShutDown = TRUE while(bShutDown = FALSE); shutdown -h now
If this were RS232 and a .NET program, I'd just create a SerialPort object with the right comm port and baud rate, and then I'd be able to register for input events. So what is the equivalent for bluetooth on the Pi?