Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed all the bools for axis in constructor and adapted it to bitwise flags #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maduranma
Copy link

Hi,

I opened this issue a few days ago: #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant