Hi all,
I'm hoping someone has achieved this, or maybe knows how to do it.
I have a mouse hitched up to a Leonardo & USB Host Shield 2.0. The idea is to take the mouse data, manipulate it, and then send it to a PC as Gamepad input, and I already have this working, but... I need to reduce the sensitivity of the mouse's X and Y data, either that or raise the limit of the mouse
To keep things simple in essence, the mouse is going to be travelling faster than if I were using it normally, but I'm finding the mouse easily hits the -127 to 127, 8bit limit.
My research often shows that I likely need to adjust my settings so that the mouse/host board uses 16bit instead, but none of the examples have shown me quite how to achieve it.
I've seen Joystick.set[X/Y]AxisRange(xxx,xxx) but there doesn't seem to be a mouse equivalent.
In the attached sketch, I've used it to set the "Joystick" at -512 to 512 - If I could achieve this with the mouse as well, that would make a huge difference
Lastly, I was previously given advice to use a Teensy 4.1, but the Leonardo setup was the first to show signs of success, so I used that instead - What I'm saying is, if I need to scrap the Leonardo and use different board(s), I'm happy and willing to do so...
Any help very much appreciated.
Here's my current sketch:
#include <hidboot.h>
#include <usbhub.h>
#include <Joystick.h>
// Create Joystick
Joystick_ Joystick;
void updateXYAxis(unsigned int xAxis,unsigned int yAxis)
{
Joystick.setXAxis(xAxis);
Joystick.setYAxis(yAxis);
}
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
class MouseRptParser : public MouseReportParser
{
protected:
void OnMouseMove (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
Serial.print("dx=");
Serial.print(mi->dX, DEC);
Serial.print(" dy=");
Serial.println(mi->dY, DEC);
updateXYAxis(mi->dX, mi->dY);
};
USB Usb;
USBHub Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);
MouseRptParser Prs;
void setup()
{
Serial.begin( 115200 );
Joystick.setXAxisRange(-512, 512);
Joystick.setYAxisRange(-512, 512);
Joystick.begin();
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
HidMouse.SetReportParser(0, &Prs);
}
void loop()
{
Usb.Task();
}
Thanks and best regards,
Steve