ArduinoJoystickLibrary
ArduinoJoystickLibrary copied to clipboard
Removed all the bools for axis in constructor and adapted it to bitwise flags
Hi,
I opened this issue a few days ago: https://github.com/MHeironimus/ArduinoJoystickLibrary/issues/243
As you agreed with the solution, I just adapted the constructor to accept it. I had to move the constants to the header file (that's as well included in the .cpp file).
I kept the all on by default by setting it to 255 by default:
uint8_t hatSwitchCount = JOYSTICK_DEFAULT_HATSWITCH_COUNT,
uint8_t includeAxisFlags = 255,
uint8_t includeSimulatorFlags = 255);
Here is a demo of how it would work with the new constructor:
#include <Joystick.h>
Joystick_ Joystick = Joystick_(0x03, JOYSTICK_TYPE_JOYSTICK, 0, 0, JOYSTICK_INCLUDE_X_AXIS | JOYSTICK_INCLUDE_Y_AXIS, JOYSTICK_INCLUDE_NONE);
void setup() {
Joystick.begin();
}
void loop() {
Joystick.setXAxis(analogRead(A0));
Joystick.setYAxis(analogRead(A1));
delay(30);
}
Also, I added the constant JOYSTICK_INCLUDE_NONE as you might only want to have buttons, hat switches or just axis on the simulator flag or the axis flag. The value of this flag is 0 as that overrides the default 255 (all).
If you consider this good, I can write/correct the docs and examples.