hello guys,
i m currently trying to get my mouse input using an arduino r4 minima official edition with a usb host shield bought on aliexpress, and move this input to my pc using the Mouse library
i found this code online :
#include <hidboot.h>
#include <usbhub.h>
#include <Mouse.h>
#include <SPI.h>
// Signed char can be between -128 to 127
int xDecal = 0;
int yDecal = 0;
int negMax = -127;
int posMax = 127;
// Mouse
int lmb = 0;
int rmb = 0;
int mmb = 0;
class MouseRptParser : public MouseReportParser {
protected:
void OnMouseMove(MOUSEINFO *mi);
void OnLeftButtonUp(MOUSEINFO *mi);
void OnLeftButtonDown(MOUSEINFO *mi);
void OnRightButtonUp(MOUSEINFO *mi);
void OnRightButtonDown(MOUSEINFO *mi);
void OnMiddleButtonUp(MOUSEINFO *mi);
void OnMiddleButtonDown(MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi) {
xDecal = mi->dX;
yDecal = mi->dY;
};
void MouseRptParser::OnLeftButtonUp(MOUSEINFO *mi) {
lmb = 0;
};
void MouseRptParser::OnLeftButtonDown(MOUSEINFO *mi) {
lmb = 1;
};
void MouseRptParser::OnRightButtonUp(MOUSEINFO *mi) {
rmb = 0;
};
void MouseRptParser::OnRightButtonDown(MOUSEINFO *mi) {
rmb = 1;
};
void MouseRptParser::OnMiddleButtonUp(MOUSEINFO *mi) {
mmb = 0;
};
void MouseRptParser::OnMiddleButtonDown(MOUSEINFO *mi) {
mmb = 1;
};
USB Usb;
USBHub Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);
MouseRptParser MousePrs;
void setup() {
Mouse.begin();
Serial.begin(1000000);
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay(200);
HidMouse.SetReportParser(0, &MousePrs);
}
void loop() {
xDecal = 0;
yDecal = 0;
Usb.Task();
// Left Mouse
if (lmb == 0) {
Mouse.release(MOUSE_LEFT);
} else if (lmb == 1) {
Mouse.press(MOUSE_LEFT);
}
// Right Mouse
if (rmb == 0) {
Mouse.release(MOUSE_RIGHT);
} else if (rmb == 1) {
Mouse.press(MOUSE_RIGHT);
}
// Middle Mouse
if (mmb == 0) {
Mouse.release(MOUSE_MIDDLE);
} else if (mmb == 1) {
Mouse.press(MOUSE_MIDDLE);
}
Serial.print("x = ");
Serial.print(xDecal);
Serial.print(" y = ");
Serial.println(yDecal);
Mouse.move(xDecal, yDecal);
}
and it works for the most part, i only have one issue, but a big one : the x output is normal, but the y is only 0 or -1. I spend hours trying to figure it out, but no solutions yet
my mouse is an endgame XM1r, but the programm run fine on my brother's mouse, which is a razer deathadder V2.
at this point, i m completly lost, and i hope guy you ll be able to help me.
also i m not english so i could be not really clear sometimes don t hesitate to ask me to explain again
have a good day !