Heerkog / MicroPythonBLEHID

Human Interface Device (HID) over Bluetooth Low Energy (BLE) GATT library for MicroPython.
GNU General Public License v3.0
238 stars 32 forks source link

Pimoroni tracball PIM-447 + ESP32 - how to move cursor on screen? #4

Closed c0dexter closed 2 years ago

c0dexter commented 2 years ago

Hi, At first I would like to say thank you for your effort in creating library and examples :) Sorry that I bother you, my question is probably dumb, but I'm a noob in programming on micro controllers. I found your library and example of code snippets - generaly it's working, but I can see only logs when I move the trackball, but cursor on screen is not moving. I reviewed hid_services.py lib and I cannot see there any method for moving cursor. What I suppose to do, to move cursor in real?

My current code: https://pastebin.com/GTNPsnEg

Thank you in advance for the response

Heerkog commented 2 years ago

What logs do you see?

c0dexter commented 2 years ago

Hi, have a few more problems, but at first I will show you my logs when I pair device with Android smartphone - Huawei P20 Pro (Android 10, EMUI 10):

Server created

no secrets available

BLE on

Registering services

Writing service characteristics

Writing device information service characteristics

Writing battery service characteristics

Writing hid service characteristics

Advertiser created:  Trackball  with services:  [UUID(0x1812)]

Server started

Started advertising

Started advertising

Started advertising

Central connected:  0                                    // Here I was able to establish connection for a while

Notify with report:  (0, 4, 6, 0)                        // Here I started using trackbal, gathering logs about trackball position

Notify with report:  (0, 4, 5, 0)

Notify with report:  (0, 4, 4, 0)

Notify with report:  (1, 4, 4, 0)

Notify with report:  (0, 4, 4, 0)

Connection update                                        // Connection has been refreshed, but I don't know why

Notify with report:  (1, 4, 4, 0)

Notify with report:  (0, 4, 4, 0)

Notify with report:  (1, 4, 4, 0)                        // I clicked trackbal, then I was able to see that deveice started advertising again

Started advertising                                        // Started advertisng after I clicked trackball button

Notify with report:  (0, 4, 4, 0)

Notify with report:  (1, 4, 4, 0)

Notify with report:  (0, 4, 4, 0)

Notify with report:  (1, 4, 4, 0)

Notify with report:  (0, -9, 2, 0)

Central disconnected:  0                               // I've lost connection

Started advertising                                        // Trackball clicked, advertising has been started, but I coudn't establish connection again

Started advertising                                     //  Trackball clicked

Started advertising                                     // Trackball clicked

Issues:

  1. When I try to pair Android device (above logs) - I'm able to do this only for a few seconds - I mean that I have connection only for a few seconds, then ESP32 send me "Central disconnected: 0". In mentioned a few seconds when I have connection, I'm able to use trackball and gather logs about movement info, for example: Notify with report: (1, 4, 4, 0) Smartphone indicated the ESP device as mouse, but in real I cant see a cursor.
  2. When I try to find ESP Mouse device on Windows 10, I can't see it. System isn't display this device
  3. I also tried to pair with laptop with Linux Mint, but I was able to do this one day only, now, I can't pair devices, maybe it's a linux system bug. When I was paired, I coudn't move a cursor on screen when I used a trackball.

Questions:

  1. How can I improve paring process and establishing a stable connection as a mouse device?
  2. How can I move a cursror when I have a conncection? Are there any methods like mouse.moveToLeft/Right/Up/Down(value_here)?

EDIT: I was able to establish connection with Windows 11, but when I stopped using trackball for a while, then HID device has been disconnected in a very short time. Logs below:

MicroPython v1.15 on 2021-06-04; ESP32 module with ESP32
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
Server created
no secrets available
BLE on
Registering services
Writing service characteristics
Writing device information service characteristics
Writing battery service characteristics
Writing hid service characteristics
Advertiser created:  Trackball  with services:  [UUID(0x1812)]
Server started
Started advertising
Central connected:  0
MTU exchanged:  23
Connection update
Notify with report:  (0, 0, -2, 0)
Notify with report:  (0, 0, -3, 0)
Notify with report:  (0, 0, -4, 0)
Notify with report:  (0, 0, -6, 0)
Notify with report:  (0, -1, -6, 0)
Notify with report:  (0, -1, -8, 0)
Notify with report:  (0, -2, -10, 0)
Notify with report:  (0, -2, -12, 0)
Notify with report:  (0, -2, -14, 0)
Notify with report:  (0, 0, -15, 0)
Notify with report:  (0, 2, -15, 0)
Notify with report:  (0, 4, -15, 0)
Notify with report:  (0, 6, -15, 0)
Notify with report:  (0, 6, -13, 0)
Notify with report:  (0, 8, -13, 0)
Notify with report:  (0, 8, -11, 0)
Notify with report:  (0, 8, -10, 0)
Notify with report:  (0, 8, -9, 0)
Notify with report:  (0, 8, -7, 0)
Notify with report:  (0, 8, -8, 0)
Notify with report:  (0, 6, -8, 0)
Notify with report:  (0, 6, -10, 0)
Notify with report:  (0, 6, -12, 0)
Notify with report:  (0, 6, -13, 0)
Notify with report:  (0, 6, -14, 0)
Notify with report:  (0, 5, -16, 0)
Notify with report:  (0, 4, -16, 0)
Notify with report:  (0, 4, -18, 0)
Notify with report:  (0, 2, -18, 0)
Notify with report:  (0, 0, -18, 0)
Notify with report:  (0, 0, -16, 0)
Notify with report:  (0, 0, -15, 0)
Notify with report:  (0, 0, -14, 0)
Notify with report:  (0, 0, -12, 0)
Notify with report:  (0, 0, -10, 0)
Notify with report:  (0, 2, -10, 0)
Notify with report:  (0, 2, -11, 0)
Notify with report:  (0, 2, -12, 0)
Notify with report:  (0, 3, -12, 0)
Notify with report:  (0, 4, -12, 0)
Notify with report:  (0, 5, -12, 0)
Notify with report:  (0, 4, -12, 0)
Notify with report:  (0, 3, -12, 0)
Notify with report:  (0, 3, -14, 0)
Notify with report:  (0, 2, -14, 0)
Notify with report:  (0, 1, -14, 0)
Notify with report:  (0, 0, -12, 0)
Notify with report:  (0, -1, -12, 0)
Notify with report:  (0, -2, -10, 0)
Notify with report:  (0, -3, -10, 0)
Notify with report:  (0, -4, -10, 0)
Notify with report:  (0, -5, -9, 0)
Notify with report:  (0, -5, -8, 0)
Notify with report:  (0, -7, -8, 0)
Notify with report:  (0, -6, -8, 0)
Notify with report:  (0, -6, -7, 0)
Notify with report:  (0, -5, -7, 0)
Notify with report:  (0, -4, -7, 0)
Notify with report:  (0, -4, -9, 0)
Notify with report:  (0, -4, -11, 0)
Notify with report:  (0, -4, -13, 0)
Notify with report:  (0, -2, -13, 0)
Notify with report:  (0, -2, -15, 0)
Notify with report:  (1, -2, -15, 0)
Notify with report:  (0, -2, -15, 0)
Notify with report:  (1, -2, -15, 0)
Notify with report:  (0, -2, -14, 0)
Notify with report:  (0, -4, -12, 0)
Notify with report:  (0, -5, -12, 0)
Central disconnected:  0
Started advertising

Thank you in advance for reply

Heerkog commented 2 years ago

Ha! You're using my tinypico_trackball personal project! As this is a personal project, it behalves different than you'd expect. It actually uses the trackball as a joystick that doesn't self center. As a result, your cursor flies to a corner and stays there because you're not manually centering it. You really should have started from the mouse example, not a personal project.

I can explain the issues, but the simple solution is probably to change

            self.axes = (self.clamp(self.axes[0] + left - right), self.clamp(self.axes[1] + up - down))

to

            self.axes = (right - left, down - up)

If that doesn't work, please try starting from the mouse example. You can adapt that easily to use the trackball.py file.

Finally, when you power cycle your board or restart the services, always remove the paired device before connecting again.