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

More OSX strangeness? hat switch set to 0, won't init? #42

Open
RootlessAgrarian opened this issue Apr 6, 2017 · 0 comments
Open

More OSX strangeness? hat switch set to 0, won't init? #42

RootlessAgrarian opened this issue Apr 6, 2017 · 0 comments

Comments

@RootlessAgrarian
Copy link

RootlessAgrarian commented Apr 6, 2017

I'm figuring out slowly how to replicate my favourite USB controllers using Arduino plus this very useful library (many thanks Matt!). Ran into three issues. I would have posted them as three separate issues but for some reason the github interface will not let me post any additional issues, so I'm editing this one.

  1. though Joystick lib is capable of creating a USB controller with 11 axes, OSX does not appear to recognise more than 8. I use JoystickShow (a minimal USB controller debug tool) to reveal all axes, hats and switches on attached devices. Even if I have enabled every axis in the Joystick device, OSX sees only axes 0 through 7. This is probably an OSX limitation so no action is possible other than an OS-specific note in the README.

  2. When I create a Multi Axis joystick instance with exactly one hat switch, for some reason that hat switch is pegged to the "up" position (0 degrees).
    I thought I had just not initialised it properly. So I added
    Joystick.setHatSwitch(0,JOYSTICK_HATSWITCH_RELEASE);
    per the doco. This was accepted by the compiler so I think there are no typos, but it had no effect on the hat switch, still pegged to the up or 0-deg position. I have not pursued this problem further because of the far more distressing issue A gamepad support #3, below:

  3. For some reason, as yet I have no idea why, there is some kind of crosstalk between the Joystick device and mouse movement on my OSX machine. When I drive X axis or Z axis, and I assume Y does this also, my mouse pointer travels up and left and gets pinned in the upper left hand corner of the screen. Moreover, even after I have returned the axis value to zero, the mouse is still trying to rush off the upper left corner of the screen. The only way I can get it back is to reset the Leonardo running the Joystick sketch. After a reset all is well until the very first write to the Joystick axis, after which the mouse pointer goes mad again. I have changed the USB HID number thinking that it might be conflicting with the other Leonardo (mouse and keyboard control): changed it from Default to 0x4 hoping this would stop the mouse hijack. So far no luck.

Here are the relevant snippets of the code. Basically it receives a number over i2c from another Leonardo (also a USB HID, but Keyboard/Mouse type) and uses this value to set a Joystick device axis value. I can see the axis value changing using JoystickShow app, but I have no idea why mouse control is being hijacked; particularly I don't understand why the mouse continues to go nuts after the axis value returns to zero. The mad mouse behaviour did not happen when I used a default instantiation "Joystick_ Joystick;"

Am I doing something stupid?

#include <Joystick.h>
// Create the Joystick
Joystick_ Joystick(0x04, 
  JOYSTICK_TYPE_MULTI_AXIS, 12, 0,
  true, true, true, false, false, false,
  false, false, false, false, false);
// create a multi axis controller that looks just exactly like a driving force gt
// with three axes 0 1 2, a hat (removed because it's pegged at 0 deg), and a bunch of buttons
// looks fine in JoystickShow
(...)
(in setup:)
 Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  Joystick.begin();
  delay(100);
  Joystick.setZAxisRange(0,255);
(...)
(in loop:)
   Joystick.setZAxis(tval);

[update] SOLUTION to item 3: the device type cannot be MULTI_AXIS, at least not in OSX. Even though JoystickShow seems to see both options as identical, if I use JOYSTICK_TYPE_JOYSTICK instead of JOYSTICK_TYPE_MULTI_AXIS the mouse hijacking problem goes away -- and zowie, I can finally get a commercial game to see the xaxis input from my arduino setup. The problem of the hat pegged at zero, however, remains. I will investigate that further as soon as I have some time.

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

No branches or pull requests

1 participant