From b07cae73144223af024b60abe26bee5656e879e9 Mon Sep 17 00:00:00 2001 From: tobozo Date: Tue, 22 Feb 2022 16:45:34 +0100 Subject: [PATCH 01/11] Absolute mouse support --- libraries/USB/src/USBHIDMouse.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libraries/USB/src/USBHIDMouse.h b/libraries/USB/src/USBHIDMouse.h index 17adf17b471..2bccd580c14 100644 --- a/libraries/USB/src/USBHIDMouse.h +++ b/libraries/USB/src/USBHIDMouse.h @@ -30,6 +30,8 @@ #define MOUSE_FORWARD 0x10 #define MOUSE_ALL 0x1F +// Relative Mouse + class USBHIDMouse: public USBHIDDevice { private: USBHID hid; @@ -51,4 +53,27 @@ class USBHIDMouse: public USBHIDDevice { uint16_t _onGetDescriptor(uint8_t* buffer); }; + +// Absolute Mouse + +typedef struct TU_ATTR_PACKED +{ + uint8_t buttons = 0; + int16_t x = 0; + int16_t y = 0; +} abs_mouse_report_t; + + +class USBHIDAbsMouse: public USBHIDDevice +{ +private: + USBHID hid; +public: + USBHIDAbsMouse(void); + void begin(void); + uint16_t _onGetDescriptor(uint8_t* buffer); + bool sendReport(abs_mouse_report_t * value); + void end(); +}; + #endif From 841f40de511f14b0591ea5931166467a4e585bb3 Mon Sep 17 00:00:00 2001 From: tobozo Date: Tue, 22 Feb 2022 16:47:20 +0100 Subject: [PATCH 02/11] Absolute mouse support --- libraries/USB/src/USBHIDMouse.cpp | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/libraries/USB/src/USBHIDMouse.cpp b/libraries/USB/src/USBHIDMouse.cpp index 30b802a4607..4c00493f63a 100644 --- a/libraries/USB/src/USBHIDMouse.cpp +++ b/libraries/USB/src/USBHIDMouse.cpp @@ -89,4 +89,72 @@ bool USBHIDMouse::isPressed(uint8_t b){ } +// Absolute Mouse + +// We use a custom HID mouse report descriptor with absolute positioning +// where coordinates are expressed as an unsigned value between 0 and 32767 +static const uint8_t abs_mouse_report_descriptor[] = { + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x09, 0x01, // USAGE (Pointer) + 0xA1, 0x00, // COLLECTION (Physical) + 0x85, HID_REPORT_ID_MOUSE, // REPORT_ID (1) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (1) + 0x29, 0x03, // USAGE_MAXIMUM (3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x05, // REPORT_SIZE (5) + 0x81, 0x03, // INPUT (Const,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x16, 0x00, 0x00, // LOGICAL_MINIMUM(0) + 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM(32767) + 0x75, 0x10, // REPORT_SIZE (16) + 0x95, 0x02, // REPORT_COUNT (2) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0xC0, // END_COLLECTION + 0xC0, // END COLLECTION +}; + + + +USBHIDAbsMouse::USBHIDAbsMouse(): hid() { + static bool initialized = false; + if(!initialized){ + initialized = true; + hid.addDevice(this, sizeof(abs_mouse_report_descriptor)); + } +} + +void USBHIDAbsMouse::begin(void) +{ + hid.begin(); +} + +uint16_t USBHIDAbsMouse::_onGetDescriptor(uint8_t* buffer) +{ + memcpy(buffer, abs_mouse_report_descriptor, sizeof(abs_mouse_report_descriptor)); + return sizeof(abs_mouse_report_descriptor); +} + +bool USBHIDAbsMouse::sendReport(abs_mouse_report_t * report) +{ + return hid.SendReport( HID_REPORT_ID_MOUSE, report, sizeof(abs_mouse_report_t) ); +} + +void USBHIDAbsMouse::end() +{ + hid.end(); +} + + + + #endif /* CONFIG_TINYUSB_HID_ENABLED */ From 0c699ebda11992c9abcd2f6d11d876eec4414961 Mon Sep 17 00:00:00 2001 From: tobozo Date: Tue, 22 Feb 2022 17:13:29 +0100 Subject: [PATCH 03/11] ping gh-actions --- libraries/USB/src/USBHIDMouse.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/USB/src/USBHIDMouse.h b/libraries/USB/src/USBHIDMouse.h index 2bccd580c14..49810233de6 100644 --- a/libraries/USB/src/USBHIDMouse.h +++ b/libraries/USB/src/USBHIDMouse.h @@ -56,6 +56,7 @@ class USBHIDMouse: public USBHIDDevice { // Absolute Mouse + typedef struct TU_ATTR_PACKED { uint8_t buttons = 0; From 35a0054b6241006f70dcd92a6b4cf81b3cb33f7f Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 14:14:47 +0100 Subject: [PATCH 04/11] Update USBHIDMouse.h --- libraries/USB/src/USBHIDMouse.h | 76 ++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/libraries/USB/src/USBHIDMouse.h b/libraries/USB/src/USBHIDMouse.h index 49810233de6..067a555a5c9 100644 --- a/libraries/USB/src/USBHIDMouse.h +++ b/libraries/USB/src/USBHIDMouse.h @@ -30,51 +30,67 @@ #define MOUSE_FORWARD 0x10 #define MOUSE_ALL 0x1F -// Relative Mouse -class USBHIDMouse: public USBHIDDevice { -private: - USBHID hid; - uint8_t _buttons; - void buttons(uint8_t b); - bool write(int8_t x, int8_t y, int8_t vertical, int8_t horizontal); +enum MousePositioning_t +{ + HID_MOUSE_RELATIVE, + HID_MOUSE_ABSOLUTE +}; + +struct HIDMouseType_t +{ + MousePositioning_t positioning; + const uint8_t* report_descriptor; + size_t descriptor_size; + size_t report_size; +}; + +extern HIDMouseType_t HIDMouseRel; +extern HIDMouseType_t HIDMouseAbs; + + +class USBHIDMouseBase: public USBHIDDevice { public: - USBHIDMouse(void); + USBHIDMouseBase(HIDMouseType_t *type); void begin(void); void end(void); - - void click(uint8_t b = MOUSE_LEFT); - void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0); void press(uint8_t b = MOUSE_LEFT); // press LEFT by default void release(uint8_t b = MOUSE_LEFT); // release LEFT by default bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default - + template bool sendReport(T report) { return hid.SendReport( HID_REPORT_ID_MOUSE, &report, _type->report_size ); }; // internal use uint16_t _onGetDescriptor(uint8_t* buffer); + void buttons(uint8_t b); +protected: + USBHID hid; + uint8_t _buttons; + HIDMouseType_t *_type; }; -// Absolute Mouse - - -typedef struct TU_ATTR_PACKED -{ - uint8_t buttons = 0; - int16_t x = 0; - int16_t y = 0; -} abs_mouse_report_t; +class USBHIDRelativeMouse: public USBHIDMouseBase { +public: + USBHIDRelativeMouse(void): USBHIDMouseBase(&HIDMouseRel) { } + void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0); + void click(uint8_t b = MOUSE_LEFT); + void buttons(uint8_t b); +}; -class USBHIDAbsMouse: public USBHIDDevice -{ -private: - USBHID hid; +class USBHIDAbsoluteMouse: public USBHIDMouseBase { public: - USBHIDAbsMouse(void); - void begin(void); - uint16_t _onGetDescriptor(uint8_t* buffer); - bool sendReport(abs_mouse_report_t * value); - void end(); + USBHIDAbsoluteMouse(void): USBHIDMouseBase(&HIDMouseAbs) { } + void move(int16_t x, int16_t y, int8_t wheel = 0, int8_t pan = 0); + void click(uint8_t b = MOUSE_LEFT); + void buttons(uint8_t b); +private: + int16_t _lastx = 0; + int16_t _lasty = 0; }; + +// don't break examples and old sketches +#define USBHIDMouse USBHIDRelativeMouse; + + #endif From 5ed84d5b929298e8b1fa4da5038b436ffb1db37b Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 14:15:08 +0100 Subject: [PATCH 05/11] Update USBHIDMouse.cpp --- libraries/USB/src/USBHIDMouse.cpp | 161 ++++++++++++++---------------- 1 file changed, 77 insertions(+), 84 deletions(-) diff --git a/libraries/USB/src/USBHIDMouse.cpp b/libraries/USB/src/USBHIDMouse.cpp index 4c00493f63a..c0911ffe682 100644 --- a/libraries/USB/src/USBHIDMouse.cpp +++ b/libraries/USB/src/USBHIDMouse.cpp @@ -24,64 +24,46 @@ #include "USBHIDMouse.h" -static const uint8_t report_descriptor[] = { - TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) -}; -USBHIDMouse::USBHIDMouse(): hid(), _buttons(0){ - static bool initialized = false; + + +USBHIDMouseBase::USBHIDMouseBase(HIDMouseType_t *type) : hid(), _buttons(0), _type(type) +{ + static bool initialized = false; if(!initialized){ initialized = true; - hid.addDevice(this, sizeof(report_descriptor)); + hid.addDevice(this, _type->descriptor_size); } -} +}; -uint16_t USBHIDMouse::_onGetDescriptor(uint8_t* dst){ - memcpy(dst, report_descriptor, sizeof(report_descriptor)); - return sizeof(report_descriptor); +uint16_t USBHIDMouseBase::_onGetDescriptor(uint8_t* dst) +{ + memcpy(dst, _type->report_descriptor, _type->descriptor_size); + return _type->descriptor_size; } -void USBHIDMouse::begin(){ +void USBHIDMouseBase::begin() +{ hid.begin(); } -void USBHIDMouse::end(){ -} - -void USBHIDMouse::move(int8_t x, int8_t y, int8_t wheel, int8_t pan){ - hid_mouse_report_t report = { - .buttons = _buttons, - .x = x, - .y = y, - .wheel = wheel, - .pan = pan - }; - hid.SendReport(HID_REPORT_ID_MOUSE, &report, sizeof(report)); -} - -void USBHIDMouse::click(uint8_t b){ - _buttons = b; - move(0,0); - _buttons = 0; - move(0,0); +void USBHIDMouseBase::end() +{ } -void USBHIDMouse::buttons(uint8_t b){ - if (b != _buttons){ - _buttons = b; - move(0,0); - } -} -void USBHIDMouse::press(uint8_t b){ +void USBHIDMouseBase::press(uint8_t b) +{ buttons(_buttons | b); } -void USBHIDMouse::release(uint8_t b){ +void USBHIDMouseBase::release(uint8_t b) +{ buttons(_buttons & ~b); } -bool USBHIDMouse::isPressed(uint8_t b){ +bool USBHIDMouseBase::isPressed(uint8_t b) +{ if ((b & _buttons) > 0) { return true; } @@ -89,72 +71,83 @@ bool USBHIDMouse::isPressed(uint8_t b){ } -// Absolute Mouse -// We use a custom HID mouse report descriptor with absolute positioning -// where coordinates are expressed as an unsigned value between 0 and 32767 static const uint8_t abs_mouse_report_descriptor[] = { - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x01, // USAGE (Pointer) - 0xA1, 0x00, // COLLECTION (Physical) - 0x85, HID_REPORT_ID_MOUSE, // REPORT_ID (1) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (1) - 0x29, 0x03, // USAGE_MAXIMUM (3) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x05, // REPORT_SIZE (5) - 0x81, 0x03, // INPUT (Const,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x16, 0x00, 0x00, // LOGICAL_MINIMUM(0) - 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM(32767) - 0x75, 0x10, // REPORT_SIZE (16) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0xC0, // END_COLLECTION - 0xC0, // END COLLECTION + TUD_HID_REPORT_DESC_ABSMOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) }; +HIDMouseType_t HIDMouseAbs = { HID_MOUSE_ABSOLUTE, abs_mouse_report_descriptor, sizeof(abs_mouse_report_descriptor), sizeof(abs_mouse_report_t) }; -USBHIDAbsMouse::USBHIDAbsMouse(): hid() { - static bool initialized = false; - if(!initialized){ - initialized = true; - hid.addDevice(this, sizeof(abs_mouse_report_descriptor)); - } +void USBHIDAbsoluteMouse::move(int16_t x, int16_t y, int8_t wheel, int8_t pan) +{ + abs_mouse_report_t report; + report.buttons = _buttons; + report.x = _lastx = x; + report.y = _lasty = y; + report.wheel = wheel; + report.pan = pan; + sendReport(report); } -void USBHIDAbsMouse::begin(void) + +void USBHIDAbsoluteMouse::click(uint8_t b) { - hid.begin(); + _buttons = b; + move(_lastx,_lasty); + _buttons = 0; + move(_lastx,_lasty); +} + +void USBHIDAbsoluteMouse::buttons(uint8_t b) +{ + if (b != _buttons){ + _buttons = b; + move(_lastx,_lasty); + } } -uint16_t USBHIDAbsMouse::_onGetDescriptor(uint8_t* buffer) + + +static const uint8_t rel_mouse_report_descriptor[] = { + TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) +}; + +HIDMouseType_t HIDMouseRel = { HID_MOUSE_RELATIVE, rel_mouse_report_descriptor, sizeof(rel_mouse_report_descriptor), sizeof(hid_mouse_report_t) }; + + + +void USBHIDRelativeMouse::move(int8_t x, int8_t y, int8_t wheel, int8_t pan) { - memcpy(buffer, abs_mouse_report_descriptor, sizeof(abs_mouse_report_descriptor)); - return sizeof(abs_mouse_report_descriptor); + hid_mouse_report_t report = { + .buttons = _buttons, + .x = x, + .y = y, + .wheel = wheel, + .pan = pan + }; + sendReport(report); } -bool USBHIDAbsMouse::sendReport(abs_mouse_report_t * report) + +void USBHIDRelativeMouse::click(uint8_t b) { - return hid.SendReport( HID_REPORT_ID_MOUSE, report, sizeof(abs_mouse_report_t) ); + _buttons = b; + move(0,0); + _buttons = 0; + move(0,0); } -void USBHIDAbsMouse::end() +void USBHIDRelativeMouse::buttons(uint8_t b) { - hid.end(); + if (b != _buttons){ + _buttons = b; + move(0,0); + } } + #endif /* CONFIG_TINYUSB_HID_ENABLED */ From a49b3b00b3d9018e7080fb735aadba1c263f5b5f Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 14:16:46 +0100 Subject: [PATCH 06/11] Update hid.h --- .../arduino_tinyusb/tinyusb/src/class/hid/hid.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h b/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h index 9265a2ede76..400cf22f678 100644 --- a/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h +++ b/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h @@ -300,6 +300,17 @@ typedef struct TU_ATTR_PACKED int8_t pan; // using AC Pan } hid_mouse_report_t; +// Absolute Mouse data struct is a copy of the Standard (relative) Mouse Report +// with int16_t instead of int8_t for X and Y coordinates. +typedef struct TU_ATTR_PACKED +{ + uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */ + int16_t x; /**< Current x position of the mouse. */ + int16_t y; /**< Current y position of the mouse. */ + int8_t wheel; /**< Current delta wheel movement on the mouse. */ + int8_t pan; // using AC Pan +} abs_mouse_report_t; + /// Standard Mouse Buttons Bitmap typedef enum { From ef4da227dad909e2f5cbf275fc30ba0e486210cf Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 14:17:28 +0100 Subject: [PATCH 07/11] Update hid_device.h --- .../tinyusb/src/class/hid/hid_device.h | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid_device.h b/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid_device.h index 078b67349dc..547a78f4f4a 100644 --- a/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid_device.h +++ b/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid_device.h @@ -266,6 +266,55 @@ static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y HID_COLLECTION_END , \ HID_COLLECTION_END \ +// Absolute Mouse Report Descriptor Template +#define TUD_HID_REPORT_DESC_ABSMOUSE(...) \ + HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ + HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\ + HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ + /* Report ID if any */\ + __VA_ARGS__ \ + HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\ + HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\ + HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\ + HID_USAGE_MIN ( 1 ) ,\ + HID_USAGE_MAX ( 5 ) ,\ + HID_LOGICAL_MIN ( 0 ) ,\ + HID_LOGICAL_MAX ( 1 ) ,\ + /* Left, Right, Middle, Backward, Forward buttons */ \ + HID_REPORT_COUNT( 5 ) ,\ + HID_REPORT_SIZE ( 1 ) ,\ + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ + /* 3 bit padding */ \ + HID_REPORT_COUNT( 1 ) ,\ + HID_REPORT_SIZE ( 3 ) ,\ + HID_INPUT ( HID_CONSTANT ) ,\ + HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ + /* X, Y absolute position [0, 32767] */ \ + HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\ + HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\ + HID_LOGICAL_MIN ( 0x00 ) ,\ + HID_LOGICAL_MAX_N( 0x7FFF, 2 ) ,\ + HID_REPORT_SIZE ( 16 ) ,\ + HID_REPORT_COUNT ( 2 ) ,\ + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ + /* Vertical wheel scroll [-127, 127] */ \ + HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ) ,\ + HID_LOGICAL_MIN ( 0x81 ) ,\ + HID_LOGICAL_MAX ( 0x7f ) ,\ + HID_REPORT_COUNT( 1 ) ,\ + HID_REPORT_SIZE ( 8 ) ,\ + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\ + HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ), \ + /* Horizontal wheel scroll [-127, 127] */ \ + HID_USAGE_N ( HID_USAGE_CONSUMER_AC_PAN, 2 ), \ + HID_LOGICAL_MIN ( 0x81 ), \ + HID_LOGICAL_MAX ( 0x7f ), \ + HID_REPORT_COUNT( 1 ), \ + HID_REPORT_SIZE ( 8 ), \ + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), \ + HID_COLLECTION_END , \ + HID_COLLECTION_END \ + // Consumer Control Report Descriptor Template #define TUD_HID_REPORT_DESC_CONSUMER(...) \ HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\ From 76a38273a64a3d13a24191c5d19e096fb05d38b9 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 14:25:43 +0100 Subject: [PATCH 08/11] Update USBHIDMouse.h --- libraries/USB/src/USBHIDMouse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/USB/src/USBHIDMouse.h b/libraries/USB/src/USBHIDMouse.h index 067a555a5c9..dfe59a917d6 100644 --- a/libraries/USB/src/USBHIDMouse.h +++ b/libraries/USB/src/USBHIDMouse.h @@ -90,7 +90,7 @@ class USBHIDAbsoluteMouse: public USBHIDMouseBase { // don't break examples and old sketches -#define USBHIDMouse USBHIDRelativeMouse; +typedef USBHIDRelativeMouse USBHIDMouse; #endif From 70517ccbd14c32d241f2526d020a0b9f2623a960 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 17:21:04 +0100 Subject: [PATCH 09/11] Update USBHIDMouse.h --- libraries/USB/src/USBHIDMouse.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/USB/src/USBHIDMouse.h b/libraries/USB/src/USBHIDMouse.h index dfe59a917d6..b62d4473851 100644 --- a/libraries/USB/src/USBHIDMouse.h +++ b/libraries/USB/src/USBHIDMouse.h @@ -60,7 +60,7 @@ class USBHIDMouseBase: public USBHIDDevice { template bool sendReport(T report) { return hid.SendReport( HID_REPORT_ID_MOUSE, &report, _type->report_size ); }; // internal use uint16_t _onGetDescriptor(uint8_t* buffer); - void buttons(uint8_t b); + virtual void buttons(uint8_t b); protected: USBHID hid; uint8_t _buttons; @@ -73,7 +73,7 @@ class USBHIDRelativeMouse: public USBHIDMouseBase { USBHIDRelativeMouse(void): USBHIDMouseBase(&HIDMouseRel) { } void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0); void click(uint8_t b = MOUSE_LEFT); - void buttons(uint8_t b); + void buttons(uint8_t b) override; }; @@ -82,7 +82,7 @@ class USBHIDAbsoluteMouse: public USBHIDMouseBase { USBHIDAbsoluteMouse(void): USBHIDMouseBase(&HIDMouseAbs) { } void move(int16_t x, int16_t y, int8_t wheel = 0, int8_t pan = 0); void click(uint8_t b = MOUSE_LEFT); - void buttons(uint8_t b); + void buttons(uint8_t b) override; private: int16_t _lastx = 0; int16_t _lasty = 0; From 15d8ea37fc2e77975db6baa5ccd68a1f8b5e24ce Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 17:21:25 +0100 Subject: [PATCH 10/11] Update USBHIDMouse.cpp --- libraries/USB/src/USBHIDMouse.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libraries/USB/src/USBHIDMouse.cpp b/libraries/USB/src/USBHIDMouse.cpp index c0911ffe682..635004804ce 100644 --- a/libraries/USB/src/USBHIDMouse.cpp +++ b/libraries/USB/src/USBHIDMouse.cpp @@ -29,7 +29,7 @@ USBHIDMouseBase::USBHIDMouseBase(HIDMouseType_t *type) : hid(), _buttons(0), _type(type) { - static bool initialized = false; + static bool initialized = false; if(!initialized){ initialized = true; hid.addDevice(this, _type->descriptor_size); @@ -42,6 +42,15 @@ uint16_t USBHIDMouseBase::_onGetDescriptor(uint8_t* dst) return _type->descriptor_size; } + +void USBHIDMouseBase::buttons(uint8_t b) +{ + if (b != _buttons){ + _buttons = b; + } +} + + void USBHIDMouseBase::begin() { hid.begin(); @@ -54,12 +63,12 @@ void USBHIDMouseBase::end() void USBHIDMouseBase::press(uint8_t b) { - buttons(_buttons | b); + this->buttons(_buttons | b); } void USBHIDMouseBase::release(uint8_t b) { - buttons(_buttons & ~b); + this->buttons(_buttons & ~b); } bool USBHIDMouseBase::isPressed(uint8_t b) @@ -76,12 +85,12 @@ static const uint8_t abs_mouse_report_descriptor[] = { TUD_HID_REPORT_DESC_ABSMOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) }; -HIDMouseType_t HIDMouseAbs = { HID_MOUSE_ABSOLUTE, abs_mouse_report_descriptor, sizeof(abs_mouse_report_descriptor), sizeof(abs_mouse_report_t) }; +HIDMouseType_t HIDMouseAbs = { HID_MOUSE_ABSOLUTE, abs_mouse_report_descriptor, sizeof(abs_mouse_report_descriptor), sizeof(hid_abs_mouse_report_t) }; void USBHIDAbsoluteMouse::move(int16_t x, int16_t y, int8_t wheel, int8_t pan) { - abs_mouse_report_t report; + hid_abs_mouse_report_t report; report.buttons = _buttons; report.x = _lastx = x; report.y = _lasty = y; From ac94db64e8aa71cf9c4c4bb4a79d5aa78e5e053d Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 2 Mar 2022 17:22:41 +0100 Subject: [PATCH 11/11] Update hid.h --- .../esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h b/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h index 400cf22f678..95e065fef8e 100644 --- a/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h +++ b/tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/hid/hid.h @@ -309,7 +309,7 @@ typedef struct TU_ATTR_PACKED int16_t y; /**< Current y position of the mouse. */ int8_t wheel; /**< Current delta wheel movement on the mouse. */ int8_t pan; // using AC Pan -} abs_mouse_report_t; +} hid_abs_mouse_report_t; /// Standard Mouse Buttons Bitmap typedef enum