Open ColdFrontWI opened 4 years ago
For what it's worth, I realized shortly after posting this that you can write a custom function that does this. That said, it's a pretty ugly brute-force approach, and I think there may be a more elegant / efficient way to manage it with a native function in the libary.
A couple of comments on this program:
Code below...
Thanks! Eric
// Function declaration
void setAxis(int axisIndex, int axisSetValue);
void setup()
{
// Some code here
}
void loop()
{
// Some code here
}
// The function itself
void setAxis(int axisIndex, int axisSetValue)
{
if(axisIndex == 0)
JS1.setXAxis(axisSetValue);
else if(axisIndex == 1)
JS1.setYAxis(axisSetValue);
else if(axisIndex == 2)
JS1.setZAxis(axisSetValue);
else if(axisIndex == 3)
JS1.setRxAxis(axisSetValue);
else if(axisIndex == 4)
JS1.setRyAxis(axisSetValue);
else if(axisIndex == 5)
JS1.setRzAxis(axisSetValue);
// NOTE RUDDER AND THROTTLE SWAPPED
// THROTTLE WORKS AS 7th AXIS, RUDDER DOES NOT
else if(axisIndex == 7) // Note it's 7
JS1.setRudder(axisSetValue);
else if(axisIndex == 6) // Note it's 6
JS1.setThrottle(axisSetValue);
else if(axisIndex == 8)
JS1.setAccelerator(axisSetValue);
else if(axisIndex == 9)
JS1.setBrake(axisSetValue);
else if(axisIndex == 10)
JS1.setSteering(axisSetValue);
}
Describe your feature request
A way to set axis values base on a numeric index rather than a specific axis name to allow looping. This could come in the form of a new function:
Additional context
I am using the library to create game controllers, and it is fantastic! One challenge is that I have to duplicate the code for each axis. I would like to be able to write a loop to apply the same code to all of the axes. Here's what I'm thinking:
Current version, has to be repeated for every axis.
New function, would allow for looping over as many axes as you wanted. This would be especially nice with more complex code, e.g. smoothing via a rolling average.
Thanks, Eric