Circuit python adafruit_hid.mouse mystery

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
DrMikeG
 
Posts: 8
Joined: Fri Sep 18, 2015 4:25 pm

Circuit python adafruit_hid.mouse mystery

Post by DrMikeG »

I'm using the Circuit python adafruit_hid.mouse library on a pi pico.

This test should be moving the cursor +14 in X and +24 in Y (down and right), in 5 small steps.

Then it should make one large step of (-14,-24) - leaving the cursor where it started:
2023-02-18_22-37-29.gif
2023-02-18_22-37-29.gif (698.52 KiB) Viewed 90 times
Clearly the mouse doesn't end up back where it started.

I'm also not convinced the steps being made are the correct size.

If you look in the bottom left hand corner of good ol' paint - you can see the mouse position in the canvas.
excel.png
excel.png (9.25 KiB) Viewed 90 times
I've mapped out where the cursor should be and where it seems to be.

The interesting thing is that if I reverse the steps - I do end up where I started, so whatever is changing the numbers is doing it consistently and reversibly.

I've attached a minimal code example for the above - in case anyone can spot any simple errors.

Of course, it might be specific to some Windows mouse setting...

And thoughts appreciated.
Attachments
minimal.py
(1.49 KiB) Downloaded 2 times

User avatar
DrMikeG
 
Posts: 8
Joined: Fri Sep 18, 2015 4:25 pm

Re: Circuit python adafruit_hid.mouse mystery

Post by DrMikeG »

Bah, total rubber duck.

A quick google about Windows mouse acceleration suggests that's probably the culprit.

Is there an absolute way of returning the mouse to its starting point?

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: Circuit python adafruit_hid.mouse mystery

Post by neradoc »

Yep that's the reason. You can't know what the settings are on the host, so there is no way to know how many pixels the mouse really moves. To get back to the original point, you could try to move it slow enough that it doesn't trigger the acceleration, or try to reproduce the same movements back an forth (same number of steps, same number of pixels).

There is an Absolute Mouse descriptor that was contributed by a community member and I made into a library. There is no way to know where it starts though, so it can't do relative movements.
https://github.com/Neradoc/CircuitPython_Absolute_Mouse

User avatar
DrMikeG
 
Posts: 8
Joined: Fri Sep 18, 2015 4:25 pm

Re: Circuit python adafruit_hid.mouse mystery

Post by DrMikeG »

Thanks for the reply and confirmation @neradoc - much appreciated.

User avatar
xcg
 
Posts: 3
Joined: Sat Mar 18, 2023 1:42 am

Re: Circuit python adafruit_hid.mouse mystery

Post by xcg »

neradoc wrote: Sat Feb 18, 2023 7:26 pm Yep that's the reason. You can't know what the settings are on the host, so there is no way to know how many pixels the mouse really moves. To get back to the original point, you could try to move it slow enough that it doesn't trigger the acceleration, or try to reproduce the same movements back an forth (same number of steps, same number of pixels).

There is an Absolute Mouse descriptor that was contributed by a community member and I made into a library. There is no way to know where it starts though, so it can't do relative movements.
https://github.com/Neradoc/CircuitPython_Absolute_Mouse
hi, after using the source code you share, prompt exception:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 13, in <module>
  File "/lib/absolute_mouse/__init__.py", line 45, in __init__
  File "/lib/absolute_mouse/__init__.py", line 149, in _send_no_move
ValueError: report length should be 4

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: Circuit python adafruit_hid.mouse mystery

Post by neradoc »

Make sure that you follow the steps in the read me (install the boot.py file) and reset the board so that the new mouse device is seen.
Don't forget to eject the drive before resetting, to avoid potential drive corruption.

User avatar
xcg
 
Posts: 3
Joined: Sat Mar 18, 2023 1:42 am

Re: Circuit python adafruit_hid.mouse mystery

Post by xcg »

neradoc wrote: Sat Mar 18, 2023 2:07 am Make sure that you follow the steps in the read me (install the boot.py file) and reset the board so that the new mouse device is seen.
Don't forget to eject the drive before resetting, to avoid potential drive corruption.
As per the process, the code for boot.py:

Code: Select all

from absolute_mouse.descriptor import device

usb_hid.enable((usb_hid.Device.KEYBOARD, device,))
code.py:

Code: Select all

import usb_hid
from absolute_mouse import Mouse

# 初始化鼠标对象
mouse = Mouse(usb_hid.devices)

def transpose(x,y):
    return (
        (x * 32767) // 1920,
        (y * 32767) // 1080
    )
mouse.move(*transpose(*(960,540)))
I've copied the absolute_mouse folder into lib and plugged the device in. After Thonny runs, it still displays the above exception

User avatar
xcg
 
Posts: 3
Joined: Sat Mar 18, 2023 1:42 am

Re: Circuit python adafruit_hid.mouse mystery

Post by xcg »

neradoc wrote: Sat Mar 18, 2023 2:07 am Make sure that you follow the steps in the read me (install the boot.py file) and reset the board so that the new mouse device is seen.
Don't forget to eject the drive before resetting, to avoid potential drive corruption.
Thanks for your help, it has been successful, I found the error in boot_out.txt, I should need to import usb_hid in boot.py for the script to work properly

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: Circuit python adafruit_hid.mouse mystery

Post by neradoc »

Ah ! Nice find ! I'll fix that in the repo, thanks !

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”