PDA

View Full Version : Teensy 3.1 mouse resets to center of screen.



pepijndevos
03-21-2014, 08:58 PM
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?


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);
}
}

PaulStoffregen
03-21-2014, 09:42 PM
Maybe this is caused by the new positioning API?


Yes.



Does the Teensy register itself as a Wacom-style device?


Yes, it is.



Is there a way to stop that and make it play nice with other input devices?


Not without editing the USB code. Even then, I'm not sure if it's possible to build a hybrid of the 2 approaches. Maybe with multiple HID reports and other trickery?

pepijndevos
03-21-2014, 10:59 PM
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.

pepijndevos
03-22-2014, 01:17 PM
I think I found the bit to change.

Compare



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



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?

pepijndevos
04-04-2014, 06:15 PM
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.

Kaizien
04-05-2014, 08:55 PM
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?

PaulStoffregen
04-06-2014, 09:11 AM
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.

Kaizien
04-07-2014, 03:00 PM
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!

Kaizien
04-07-2014, 06:08 PM
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

Kaizien
04-09-2014, 08:50 PM
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?

rootScript
04-11-2014, 12:21 AM
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

#define DEFAULT_XRES 2560
#define DEFAULT_YRES 1440
In my sketch code I use:

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?

rootScript
04-20-2014, 03:02 PM
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 TypeIs this still in your plans for the next release, Paul?

HDm Tehsmeely
04-20-2014, 11:31 PM
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.

Kaizien
04-29-2014, 05:41 PM
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.

rootScript
05-04-2014, 02:12 AM
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" :)

PaulStoffregen
05-04-2014, 11:31 AM
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.

dude8604
05-06-2014, 06:35 AM
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.

Kaizien
05-13-2014, 09:02 PM
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?

PaulStoffregen
05-13-2014, 09:09 PM
Any updates on when we may see the patch/update?

This is on my list for Teensyduino 1.19, likely mid-June time frame.

frankstripod
05-19-2014, 08:48 PM
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.

PaulStoffregen
05-26-2014, 10:45 PM
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.

PaulStoffregen
05-26-2014, 10:59 PM
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?

rootScript
05-27-2014, 12:45 PM
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

PaulStoffregen
05-27-2014, 02:34 PM
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.

rootScript
05-27-2014, 06:59 PM
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).

frankstripod
05-28-2014, 12:02 AM
Works great! Using Arduino 1.0.5-r2 and Teensyduino 1.18 with a Teensy 3.1 on Win7. Tested Mouse.set_buttons, Mouse.screenSize, and Mouse.moveTo(x, y); all worked great and did not interfere with my project code.
Just got my Teensy 3.1 from your site and I love it!
I was sorry to see you previously got very help little testing. I also have Arduino 1.0.5 and Teensyduino 1.18 running on Puppy Linux Slacko 5.6.0, and planning to update Puppy and try installing on Ubuntu (soon I hope). Would testing there help? Are there other ways I can help?
Thank you so much for working on this!

PaulStoffregen
05-28-2014, 12:42 AM
Thanks for testing. It's really a huge help! :-)

The absolute positioning doesn't work at all on my Ubuntu 12.04 system. I think it might be a Linux or X11 bug? Works fine on my mac.

Kaizien
06-03-2014, 06:40 PM
Thanks for testing. It's really a huge help! :-)

The absolute positioning doesn't work at all on my Ubuntu 12.04 system. I think it might be a Linux or X11 bug? Works fine on my mac.


Hey! I tested it on my machine too (Windows 8.1 64bit) and so far so good! I have only tested the mouse right and left .click commands, but no more resetting to the center of my screen.

Great work!