chegewara / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
9 stars 4 forks source link

Bluetooth Mouse with Arduino IDE #13

Open T-vK opened 4 years ago

T-vK commented 4 years ago

I just stumbled across this issue: https://github.com/nkolban/esp32-snippets/issues/230

It is the only source on the Internet I could find where people have gotten Bluetooth Keyboards/Mice to work on the ESP32 with the Arduino IDE.

I open this issue on your fork (@chegewara) because the original esp32-snippets repository has been archived and thus I can't add a comment to the linked issue.

I have a question about a piece of code that you provided: right here

I tried it with a Linux device and with an Android device. On both devices the code was moving the mouse pointer up/down instead of scrolling the mouse wheel up/down.

For example:

          Serial.println("mouse Scroll DOWN");
          //<button>, <x>, <y>, <wheel>

          uint8_t msg[] = {  0x00, 0x00, -0x01};

          inputMouse->setValue(msg,3);
          inputMouse->notify();
          delay(10);

This causes my mouse to move UP.

I was wondering if you could help me out getting this to work (scroll instead of mouse move) and maybe even help me understand how inputMouse->setValue(...) works in general. I couldn't make any sense of how the table or the reportMapMouse variable in that code translate to { 0x00, 0x00, -0x01} in the end.

My poor guess from looking at the table

//     Byte | D7      D6      D5      D4      D3      D2      D1      D0
//    ------+---------------------------------------------------------------------
//      0   |  0       0       0    Forward  Back    Middle  Right   Left (Buttons)
//      1   |                             X
//      2   |                             Y
//      3   |                       Vertical Wheel
//      4   |                    Horizontal (Tilt) Wheel

is that the byte column refers to the bytes in the array. So { 0x00, 0x00, -0x01} would mean the first byte indicates the button (0x00 probably meaning no button?), the second byte refers to the X-axis (0x00 meaning don't move on the a-axis) and the last byte refers to the y-axis (-0x01 meaning "move up by 1 unit on the y-axis"). If that logic was correct that I would have guessed that { 0x00, 0x00, 0x00, 0x09} would scroll the wheel down by 9 units and not move the mouse and not press a button. But unfortunately it doesn't do anything at all and I still have no clue what the 3 in setValue(msg,3); could mean.

chegewara commented 4 years ago

Here you have values for X and Y:

LOGICAL_MINIMUM(1),  0x81,
LOGICAL_MAXIMUM(1),  0x7f,

It is 2 compliment value where 0x7f is highest right and down value.

BTW looks like Kolban's repository is no longer archived.