Skip to content

Instantly share code, notes, and snippets.

@MDAR
Last active December 31, 2025 17:54
Show Gist options
  • Select an option

  • Save MDAR/7d88b8c4a5789bb452365efc606d27a8 to your computer and use it in GitHub Desktop.

Select an option

Save MDAR/7d88b8c4a5789bb452365efc606d27a8 to your computer and use it in GitHub Desktop.
HID / Joystick / GamePad events via C App

I created a Flow for the basics of Visca control for PTZ cameras, but it soon became apparent that I really needed a joystick for a more human feel to the camera movements.

Having looked for a few hours, I came across a bit of C Code written by Jason White some years ago.

It took me less than 30 seconds to get the code up and running on an Odroid C4, running Diet-Pi and Node-RED, installed from the dietpi-software menu.

Starting the app from within Node-RED gave me all the events I needed.

When connected with a basic Thrustmaster joystick, this flow takes the event data from a slightly tweaked version of Jason's code and turns it into :-

  • Main Axis

    • Raw X&Y data
    • Compass position (8 point)
    • Direction in degrees
    • Pan and Tilt % (as in, Tilt = % of forward or back travel)
  • Throttle position

    • Value between 0 and 65534
    • % value
  • Thumb joystick (Binary)

    • 4 compass points and Center
  • All other button events

    • This thrustmaster has 4 buttons, but the app and flow will output whatever is available
  • Any other Axis data should be available for you to do something with, just by changing / copying the main function node (I've added notes in the function to help me remember what each section does, so that should help anyone expand the features)

The tweaked version of the C-Code is saved in the Comment node. With instructions on how to compile Just save it to your machine and compile it.

(I run it as root because I'm lazy and I know the machine is safe, you may have to grant permissions to the HID device path if using a different user to start Node-RED)

Joystick Flow

[
{
"id": "934f234194014ac6",
"type": "change",
"z": "7074ef48a0c87a56",
"name": "",
"rules": [
{
"t": "set",
"p": "payload.distance",
"pt": "msg",
"to": "throttle",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1050,
"y": 360,
"wires": [
[]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment