Skip to content

Commit 9415667

Browse files
authored
Update USBHIDMouse.h
1 parent 6d9ebea commit 9415667

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

libraries/USB/src/USBHIDMouse.h

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,68 @@
3434
#define MOUSE_FORWARD 0x10
3535
#define MOUSE_ALL 0x1F
3636

37-
class USBHIDMouse: public USBHIDDevice {
38-
private:
39-
USBHID hid;
40-
uint8_t _buttons;
41-
void buttons(uint8_t b);
42-
bool write(int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
37+
#include "./tusb_hid_mouse.h"
38+
39+
enum MousePositioning_t
40+
{
41+
HID_MOUSE_RELATIVE,
42+
HID_MOUSE_ABSOLUTE
43+
};
44+
45+
struct HIDMouseType_t
46+
{
47+
MousePositioning_t positioning;
48+
const uint8_t* report_descriptor;
49+
size_t descriptor_size;
50+
size_t report_size;
51+
};
52+
53+
extern HIDMouseType_t HIDMouseRel;
54+
extern HIDMouseType_t HIDMouseAbs;
55+
56+
57+
class USBHIDMouseBase: public USBHIDDevice {
4358
public:
44-
USBHIDMouse(void);
59+
USBHIDMouseBase(HIDMouseType_t *type);
4560
void begin(void);
4661
void end(void);
47-
48-
void click(uint8_t b = MOUSE_LEFT);
49-
void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0);
5062
void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
5163
void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
5264
bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
53-
65+
template <typename T> bool sendReport(T report) { return hid.SendReport( HID_REPORT_ID_MOUSE, &report, _type->report_size ); };
5466
// internal use
5567
uint16_t _onGetDescriptor(uint8_t* buffer);
68+
virtual void buttons(uint8_t b);
69+
protected:
70+
USBHID hid;
71+
uint8_t _buttons;
72+
HIDMouseType_t *_type;
73+
};
74+
75+
76+
class USBHIDRelativeMouse: public USBHIDMouseBase {
77+
public:
78+
USBHIDRelativeMouse(void): USBHIDMouseBase(&HIDMouseRel) { }
79+
void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0);
80+
void click(uint8_t b = MOUSE_LEFT);
81+
void buttons(uint8_t b) override;
82+
};
83+
84+
85+
class USBHIDAbsoluteMouse: public USBHIDMouseBase {
86+
public:
87+
USBHIDAbsoluteMouse(void): USBHIDMouseBase(&HIDMouseAbs) { }
88+
void move(int16_t x, int16_t y, int8_t wheel = 0, int8_t pan = 0);
89+
void click(uint8_t b = MOUSE_LEFT);
90+
void buttons(uint8_t b) override;
91+
private:
92+
int16_t _lastx = 0;
93+
int16_t _lasty = 0;
5694
};
5795

96+
97+
// don't break examples and old sketches
98+
typedef USBHIDRelativeMouse USBHIDMouse;
99+
58100
#endif /* CONFIG_TINYUSB_HID_ENABLED */
59101
#endif /* SOC_USB_OTG_SUPPORTED */

0 commit comments

Comments
 (0)