Add Input Since Flig has its inseparable companion Dinky (sometimes invisible for human eyes), input controller needed to be split between two at some occasions. For instance when they work together and there's some Humans input needed. Simple idea was to dedicate two, otherwise completely neglected buttons of PS4 controller, namely 'Share' and 'Options', to switch whole controller functions to two. Not only switch controller functions but send digested values from controller to two different MQTT topics: joystick/changes and joystick/arm.

But, how to find out which mode we are in currently? One way would be to 'test' some movement and see what is moving - Flig or Dinky's robotic arm, but that's not quite good.

Ideally we would have some indicator, somewhere, to tell us what is selected. And, luckily, PS4 has a RGB LED built in. All we need to find out how to control it!

A bit of search on the internet revealed that Linux kernel already has drivers for it and control of that LED is nicely provided in /proc filesystem under /sys/class/leds. There are sub directories in that directory that end with ':red', ':green' and ':blue' and in there are several files of which 'brightness' is the one we need.

Writing values from 0-255 in those files changes particular RGB component of the LED. But, those files are accessible only by root. Luckily, by default 'pi' user can do sudo command (is 'sudoer') so, my tiny python method ended up looking like this:

    def change_colour(r: int, g: int, b: int) -> None:
        leds = os.listdir("/sys/class/leds")
        for ledfile in leds:
            if ledfile.endswith(":red") and os.path.exists(f"/sys/class/leds/{ledfile}/brightness"):
                os.system(f"sudo bash -c \"echo {r} > /sys/class/leds/{ledfile}/brightness\"")
            if ledfile.endswith(":green") and os.path.exists(f"/sys/class/leds/{ledfile}/brightness"):
                os.system(f"sudo bash -c \"echo {g} > /sys/class/leds/{ledfile}/brightness\"")
            if ledfile.endswith(":blue") and os.path.exists(f"/sys/class/leds/{ledfile}/brightness"):
                os.system(f"sudo bash -c \"echo {b} > /sys/class/leds/{ledfile}/brightness\"")

And the result is stunning:

PS4 Colour Change