Trying to modify the native mouse methods so that it can use absolute, rather than the relative values it currently uses. This is so it can function as a touch screen pointer, and NOT a mouse.

Am using this modified HID.cpp file here


Mostly works, but the author has mapped to the maximum and minimum possible int values, (-32768 to 32767) and no matter what permutation of values I use with the native map method, I can't get it to work properly.

Has anyone wrestled with this problem and has a solution?

Since posting found another possible solution http://forum.arduino.cc/index.php/topic,94140.0.html

However with this solution the mouse movements are WAY too coarse for any monitor with a resolution above 100x100. Tried changing the LOGICAL_MAXIMUM value in HID.cpp but that alone doesn't work. Any C++ gurus possibly able to have a look?

Going back to the first solution this is the map method calls I am using, which should theoretically work!. TAR_WIDTH is the horizontal display resolution of my target monitor. TAR_HEIGHT is the vertical display resolution

xPos2= map(xPos, 0, TAR_WIDTH, -32768, 32767);
yPos2= map(yPos, 0, TAR_HEIGHT, -32768, 32767);

What happens is that when the x value is roughly -2800 or less than, I've reached the left edge of my monitor

Ditto for y, when less than or equal to -2800, I've reached the top.

Moving to the right and or down, once I reach roughly a value of 5000, x, OR y, the mouse wraps back to the left or top edge.

This value of 5000 represents only about 2/3 the width of my target monitor so I'm never able to fully map my mouse movement. Make sense?

So in summary, if I use solution1, I need to figure out how to fully map to my monitor. If solution 2, the movement is too coarse(and the mouseclick doesn't work).

  • You need to explain the nature of the failure. What is your source of data and what is it's range? What is this plugged into, and what range of values does that see? Commented Jul 30, 2014 at 18:08
  • Modified my question, found an alternative mod, but the problem now is that the movement is WAY too coarse for any monitor with a resolution greater than 100x100 pixels
    – Bachalo
    Commented Jul 30, 2014 at 18:40
  • 1
    You still need to tell us what the sensor is and what its unscaled output values are. Perhaps you should make an ordinary (USB-serial) arduino sketch which just logs the raw (and perhaps also mapped) values to the serial console so you can play with the sensor and see what raw values it generates and if that is scaling to what you want. Then once you have nice numbers you can switch back to the HID program. Commented Jul 30, 2014 at 20:27
  • The input values aren't the problem. Its how the absolute Mouse Move hack of HID.cpp is handling these values. I'm feeding in via i2c from a RPi. Input values are accurate.
    – Bachalo
    Commented Jul 30, 2014 at 22:55
  • 1
    did you solved your problem? I have the same issue with modified HID.cpp + USBAPI.h. Scaling seem to work ok, but what I see on the screen is not an absolute value movement...
    – user8159
    Commented Mar 30, 2015 at 7:54


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.