Teensy 3.1 mouse resets to center of screen.

When I run below example code on my Teensy(duino) 3.1 connected to my Mac, it jumps to the center, and any movement with my real mouse is ignored/reset.
In other words, the Teensy is positioning my cursor absolute instead of relative.

Even if I only use the scroll or click function, it jumps right back to where the Teensy thinks it should be.

Maybe this is caused by the new positioning API?
Does the Teensy register itself as a Wacom-style device?
Is there a way to stop that and make it play nice with other input devices?

Code:
void setup() { } // no setup needed
void loop() {
  int i;
  for (i=0; i<40; i++) {
    Mouse.move(2, -1);
    delay(25);
  }
  for (i=0; i<40; i++) {
    Mouse.move(2, 2);
    delay(25);
  }
  for (i=0; i<40; i++) {
    Mouse.move(-4, -1);
    delay(25);
  }
}
 
You could maybe make the screen size setup call change the device mode?
Without setting the screen size, it's a mouse, after setting the screen size it's a Wacom.
Or maybe it can be both, seeing that it is already a mouse, keyboard, joystick and serial console at the same time.

As it is now, it is kind of impossible to use for anything other than a complete, one and only mouse.

Slightly related, I noticed my Wacom gives floating point coordinates.
Could the Teensy do that?
More buttons would also be nice...
Anyway, lets focus on getting back relative movement first.

Any chance this will be fixed, or should I just hack it?
I guess I'll need to read the USB HID spec to understand how to change the code.
Or maybe I can forward-port the Teensy 2.0 code, which supposedly did not have this problem.
 
I think I found the bit to change.

Compare

Code:
        0x09, 0x30,                     //   Usage (X)
        0x09, 0x31,                     //   Usage (Y)
        0x15, 0x00,                     //   Logical Minimum (0)
        0x26, 0xFF, 0x7F,               //   Logical Maximum (32767)
        0x75, 0x10,                     //   Report Size (16),
        0x95, 0x02,                     //   Report Count (2),
        0x81, 0x02,                     //   Input (Data, Variable, Absolute)

With the Teensy 2.0

Code:
	0x09, 0x30,			//   Usage (X)
	0x09, 0x31,			//   Usage (Y)
	0x15, 0x81,			//   Logical Minimum (-127)
	0x25, 0x7F,			//   Logical Maximum (127)
	0x75, 0x08,			//   Report Size (8),
	0x95, 0x02,			//   Report Count (2),
	0x81, 0x06,			//   Input (Data, Variable, Relative)

Then of course the rest of the code needs to be changed to output relative changes.
But that is normal C code without too much bit twiddling.

From there I can see two ways to support both modes.
  • You could add a #define TABLET_INTERFACE that would use the absolute mode and make MOUSE_INTERFACE do the expected thing.
  • You could add a relative entry to config_descriptor, and default to that. Then switch to the absolute one after screen size has been set. This is just a matter of picking the other endpoint to write to.

So Teensy is not really open source is it? I mean, can I submit a patch?
Or should I do a quick hack and wait for an official fix?
 
I finished my mouse, but this prevents me from playing games with it for the same reasons you can't play games with a tablet.
The game will reset the cursor to the center of the screen every frame, and then the mouse will reset it to a fixed position on the screen.
 
I finished my mouse, but this prevents me from playing games with it for the same reasons you can't play games with a tablet.
The game will reset the cursor to the center of the screen every frame, and then the mouse will reset it to a fixed position on the screen.

I'm running into the same problem... why the heck did they make the teensy 3.1 an 'absolute' mouse? I don't understand that... I'm stuck at a stand still on my project (converting over from a leonardo prototype) right now because of this issue.

Anyone out there have any input?
 
I'm running into the same problem... why the heck did they make the teensy 3.1 an 'absolute' mouse?

Well, because many people requested this feature. They made well reasoned arguments as to why only relative positioning wasn't useful.

Obviously absolute positioning isn't working out as well as was hoped. I'm really sorry it's not working. If you could take a moment to explain in more detail, a better understanding of the problem might really help me to come up with a better solution that addresses everyone's needs.

For 1.19 or 1.20, I'm going to investigate either a relative+absolute hybrid, or both as different options in Tools > USB Type.


I'm stuck at a stand still on my project

While not ideal, reverting to 1.17 can at least get you un-stuck for this project.

There's no direct link to the old versions, but they are still on the server. Just go to the Teensyduino downloads page and right-click on the link. In Firefox, use "Copy Link Location". The other browsers probably have similar features. Then paste the link into your address bar. Edit the 3 digit version number within the link before you press Enter to download it.

Older installers may not "know" about the changes added by newer ones, so the "Next" button may not enable within the installer when you select Arduino. If this happens, just download a fresh copy from www.arduino.cc and extract it somewhere else on your computer, and then install to that fresh copy.

Yeah, not ideal, but at least it'll let you get this project moving.
 
Well, because many people requested this feature. They made well reasoned arguments as to why only relative positioning wasn't useful.

Obviously absolute positioning isn't working out as well as was hoped. I'm really sorry it's not working. If you could take a moment to explain in more detail, a better understanding of the problem might really help me to come up with a better solution that addresses everyone's needs.

For 1.19 or 1.20, I'm going to investigate either a relative+absolute hybrid, or both as different options in Tools > USB Type.




While not ideal, reverting to 1.17 can at least get you un-stuck for this project.

There's no direct link to the old versions, but they are still on the server. Just go to the Teensyduino downloads page and right-click on the link. In Firefox, use "Copy Link Location". The other browsers probably have similar features. Then paste the link into your address bar. Edit the 3 digit version number within the link before you press Enter to download it.

Older installers may not "know" about the changes added by newer ones, so the "Next" button may not enable within the installer when you select Arduino. If this happens, just download a fresh copy from www.arduino.cc and extract it somewhere else on your computer, and then install to that fresh copy.

Yeah, not ideal, but at least it'll let you get this project moving.

Thanks for your response! I reread what I posted and I came off sounding a lot harsher than I meant to! I apologize! You have an amazing product that I am really loving in my project (I have teensy 3.1).

Before I received your response here, I actually already tried the previous version driver install (exactly how you said to haha :p) ! The problem I ran into was that with the 1.17 drivers, the IDE didn't have the teensy 3.1 as a selection option (the board versions in the IDE went up to teensy 3.0).

From there I tried pulling out the hid.cpp and some other .cpp files associated with relative mouse function, then reinstalling the newest version of the installer. Then replaced the new installer's hid.cpp and mouse files with the 1.17 files. Nothing came of it though, the mouse was still in absolute mode, I must have missed something or I may have done something wrong.

So I guess my question for you now would be is there (A): a way to get the 1.17 files to work with teensy 3.1? or (B): A list of the previous files from version 1.17 that I could copy over to the new install to replace absolute mouse mode with relative mouse mode?

my project is now all complete except for the mouse working! All wired up and everything. I have two options as far as mouse movement input goes -- if you had other solutions in mind -- analog joystick and 5 way digital switch. so maybe there is a solution that I am just missing?

Thanks so much for your help!
 
to follow up with my previous post: Which files would I need to copy over from the old installation files 1.16 to the new installation to replace the absolute mouse? (1.16 doesnt recognize teensy 3.1, just up to teensy 3.0)

right now here are the files that I have found referencing either the absolute mouse or the relative mouse functions. let me know if there are more:

#1: usb_desc.c
#2: usb_mouse.h
#3: usb_mouse.c
#4: cores / usb_serial_hid / usb.c (not sure if this is needed)

I found these references in these previous forum posts:
http://forum.pjrc.com/threads/25117-Mouse-scrolling-in-Linux-Debian-Wheezy
http://forum.pjrc.com/threads/17218-USB-Mouse-Absolute-Coordinates
 
to follow up with my previous post: Which files would I need to copy over from the old installation files 1.16 to the new installation to replace the absolute mouse? (1.16 doesnt recognize teensy 3.1, just up to teensy 3.0)

right now here are the files that I have found referencing either the absolute mouse or the relative mouse functions. let me know if there are more:

#1: usb_desc.c
#2: usb_mouse.h
#3: usb_mouse.c
#4: cores / usb_serial_hid / usb.c (not sure if this is needed)

I found these references in these previous forum posts:
http://forum.pjrc.com/threads/25117-Mouse-scrolling-in-Linux-Debian-Wheezy
http://forum.pjrc.com/threads/17218-USB-Mouse-Absolute-Coordinates



any movement on this PaulStoffregen? ideas?
 
I am using 1.17 on OSX 10.8.5, and find the same thing as Paul, in that the mouse pointer resets to centre of the screen once, when first plugged in.

But if I use Mouse.screenSize(2560, 1440, true) in my sketch, then the mouse will reset more than once.

I have a few questions:
These lines are in Arduino.app/Contents/Resources/Java/hardware/teensy/cores/teensy3/usb_mouse.c
Code:
#define DEFAULT_XRES 2560
#define DEFAULT_YRES 1440
In my sketch code I use:
Code:
Mouse.screenSize(2560, 1440, true)
Do the lines in the usb_mouse.c achieve the same things as the lines in my sketch?

How would we get the current XY position of the mouse pointer? can we use the current XY to set the startup/initialise position instead of the centre of the screen?
Where does the mouse position get set to the centre of the screen, anyway?
 
Last edited:
Does anyone know why the mouse position get sets to the centre of the screen, when using absolute?
Surely if this is because we are now using absolute positioning, and the centre is the initial start position, can't we just add the current XY mouse position to the absolute values on initialisation?
I hope that makes sense?

@PaulStoffregen
For 1.19 or 1.20, I'm going to investigate either a relative+absolute hybrid, or both as different options in Tools > USB Type
Is this still in your plans for the next release, Paul?
 
I'm running into the same problem, but this is just for click emulation, I'm not interested in moving the mouse using the teensy.
Looking at the c code for teensyduino, even the click function calls move(0,0,0), which is essentially a null package for the USB serial. however with the absolute positioning it resets it to 0,0 (which i presume is center of screen)
This really needs resolving, my basic C is not good enough to hack the code (if it's even possible) to make this work.
 
Does anyone know why the mouse position get sets to the centre of the screen, when using absolute?
Surely if this is because we are now using absolute positioning, and the centre is the initial start position, can't we just add the current XY mouse position to the absolute values on initialisation?
I hope that makes sense?

@PaulStoffregen
Is this still in your plans for the next release, Paul?


been silent for the last month on any help. unfortunate really, these teensy's are useless to me without a function that previous versions had. oh well, time to move on and return these extras I have, or ebay them.
 
Hello Paul,
If some people originally requested absolute positioning, and as many of us now find that relative positioning appears to be more useful.
Would it be possible for you to post a fix so that we can use relative mouse positioning (or a hybrid solution), please?

At the moment if you use a Teensy 3.1 as a HID mouse, and have another regular mouse plugged in, you get two cursors in different position fighting against each other. As most mice are usually relative, if you plug 2 regular mice in, one just follows from the others position.
Also, if you use a Teensy solo, the cursor moves to the middle of the screen (as this thread outlines)

I am guessing that this thread has been quiet, because you are busy, and I am sure that work is appreciated. It would also be appreciated, if you could update this thread with some news, please, as the current mouse HID implementation is very frustrating for some :)

Obviously absolute positioning isn't working out as well as was hoped. I'm really sorry it's not working. If you could take a moment to explain in more detail, a better understanding of the problem might really help me to come up with a better solution that addresses everyone's needs.
For those having issues (as I myself am), it might be useful to give some feedback as to whether you would like just a relative positioning solution, or a hybrid of absolute & relative positioning; and any other insights/suggestions you have, that will allow Paul "to come up with a better solution that addresses everyone's needs" :)
 
Last edited:
Would it be possible for you to post a fix so that we can use relative mouse positioning (or a hybrid solution), please?

A hybrid approach is near the top of my list of stuff to do after Maker Faire.

My plan is to release 1.19 with only fixes, and then add new features for 1.20.
 
Is there a way around this using raw HID mode? Or is that a lot more complicated?

Also, Paul, any idea when a fix might be released? Thanks.
 
Is there a way around this using raw HID mode? Or is that a lot more complicated?

Also, Paul, any idea when a fix might be released? Thanks.

I ended up just switching back to my leonardo in the meantime while we wait for the update... Strapped it on the outside of the enclosure just for mouse functionality. lol... the enclosure space was perfect for the teensy3.1.

Any updates on when we may see the patch/update?
 
This is a problem for my project also. I personally always use multiple pointing devices. I just ordered the Teensy 3.1 and am starting to have second thoughts. I don't want to return it, because I would eventually like to use it in other projects also. I am new at this, and this is my first microcontroller, so can anyone explain the benefits of an absolute mouse? Just some links to other project problems would be fine, so I can understand their viewpoint. Thank you Paul for addressing this problem and working on it. I will patiently wait for 1.19 for now.
 
I've been working on a relative+absolute hybrid, so absolute positioning will only be used with Mouse.moveTo(). Hopefully this will solve the problems reported on this thread, but still allow people to use moveTo() for applications that need absolute positioning.

Here's the latest code. Please give this a try and let me know how they work for you? Just copy these to hardware/teensy/cores/teensy3.
 

Attachments

  • usb_de.c
    44.1 KB · Views: 194
  • usb_mouse.c
    7.4 KB · Views: 204
Opps, that file should be named "usb_desc.c", not "usb_de.c". You'll need to fix the name when copying it to hardware/teensy/cores/teensy3.

I'm planning to publish this code in version 1.19, with the first beta released soon (maybe even later today).

Please help with testing this. I got very little help/testing with the change to absolute positioning in 1.18. I'd really like to get this problem fully resolved in 1.19, so please let me know how this works for you?
 
I'd really like to get this problem fully resolved in 1.19, so please let me know how this works for you?
I just tried with Teensy 3.1 & Arduino 1.0.5 using Teensyduino 1.18.
The mouse works as expected for me so far, when I plug in my Teensy 'mouse' it pick up the current mouse position, & does not reset to the centre of the screen.

When I plug in a second mouse, both mice continue their positions from the others. If i move them both in the same direction, the mouse cursor position appears to be additive (both positions added together).

If I plug in a Wacom tablet, the wacom works fine mapping it's absolute position on the tablet to the absolute position on the screen, and the Teensy 'mouse' happily picks up relative position from the Wacom cursor.

In regards to my tests, I have ONLY used Relative positioning code with my Teensy 3.1

THANK YOU Paul,
:)
Carlos
 
Great news. Thanks for testing. :)

Have you tried Mouse.screenSize(width, height) and Mouse.moveTo(x, y) on the Teensy? Hopefully that will also work for absolute positioning.
 
Have you tried Mouse.screenSize(width, height) and Mouse.moveTo(x, y) on the Teensy? Hopefully that will also work for absolute positioning.
I have a Nintendo DS touch screen (4 wire) somewhere. Once I find it, I will test out the absolute positioning (Hopefully within a few days).
 
Back
Top