MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JOYSTICK_TYPE_MULTI_AXIS detected as mouse at the same time

hbarrocas opened this issue · comments

Description of Issue

While attempting to use an Arduino Micro with the JoystickLibrary on JOYSTICK_TYPE_MULTI_AXIS mode, the computer immediately locks its mouse pointer to the Arduino's signal. Joystick still operates as a joystick in parallel with the mouse actions.

I've tried the other modes (JOYSTICK_TYPE_(...)) and they don't hijack the mouse pointer.

I plan to use multiple axis to read a flight sim chair (flight controls, throttle, breaks, mixture and prop pitch control) so, not sure if the other modes are capable, apart from having a dead zone, undesirable for my purpose.

Technical Details

  • Arduino Board: Arduino Micro
  • Host OS: Linux (debian 11.5)
  • Arduino IDE Version: 1.8.13

Sketch File that Reproduces Issue

#include "Joystick.h"

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, 
  JOYSTICK_TYPE_MULTI_AXIS, 32, 0,
  true, true, false, false, false, false,
  true, true, true, true, false);

/* Switch connections to Arduino */
const int sw_col[] = {2, 3, 4, 5, 6};
const int sw_row[] = {7, 11, 12, 13};
/* Analog controls' connections to Arduino */
const int analog[] = {A0, A8, A9, A1, A2, A3, A4, A5};
/* Switch readings: 1 array value per row */
int switches[4];
int ax_reading[8];
int ax_cal_lo[8] = {0, 408, 409, 400, 0, 0, 0, 0};
int ax_cal_hi[8] = {1023, 495, 485, 500, 1023, 1023, 1023, 1023};

void read_switches() {
  // sw_col pins are set up as INPUT_PULLUPs at setup() time.
  for (int row = 0; row < 4; row++) {
    pinMode(sw_row[row], OUTPUT);
    digitalWrite(sw_row[row], LOW);
    for (int col = 0; col < 5; col++) {
      int state = digitalRead(sw_col[col]);
      bitWrite(switches[row], col, !state);
      if (state) Joystick.releaseButton(5*row+col);
      else Joystick.pressButton(5*row+col);
    }
    pinMode(sw_row[row], INPUT_PULLUP);
  }
}


void calibrate() {
  // DISREGARD - NOT YET USED
  while (bitRead(switches[0], 0));
  while (!bitRead(switches[0], 0));
}

void setup() {

 
  // Configure inputs
  for (int col = 0; col < 5; col++) pinMode(sw_col[col], INPUT_PULLUP);
  for (int ax = 0; ax < 8; ax++) pinMode(analog[ax], INPUT);

  // begin in FALSE - autoSendState = OFF. state of joystick sent via Joystick.sendState() at
  // the end of the loop.
  Joystick.begin(false);
  
  // Detect if a calibration has been requested
  read_switches();
  if (bitRead(switches[0], 0) == 1) calibrate();

}

void loop() {
  for (int ax = 0; ax < 8; ax++)
    ax_reading[ax] = analogRead(analog[ax]);
    
  read_switches();

  Joystick.setYAxis(map(ax_reading[1], ax_cal_lo[1], ax_cal_hi[1], -127, 127));
  Joystick.setXAxis(map(ax_reading[2], ax_cal_lo[2], ax_cal_hi[2], -127, 127));
  Joystick.setThrottle(map(ax_reading[3], ax_cal_lo[3], ax_cal_hi[3], 0, 255));

  Joystick.sendState();
}

Additional context

I've read somewhere that there's an xorg-joystick driver intended to read a joystick as a mouse pointer and, being similar to my issue I've double-checked, and said driver is not installed on my xorg.

Thanks for your help.