|
34 | 34 | #define MOUSE_FORWARD 0x10
|
35 | 35 | #define MOUSE_ALL 0x1F
|
36 | 36 |
|
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 { |
43 | 58 | public:
|
44 |
| - USBHIDMouse(void); |
| 59 | + USBHIDMouseBase(HIDMouseType_t *type); |
45 | 60 | void begin(void);
|
46 | 61 | 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); |
50 | 62 | void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
|
51 | 63 | void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
|
52 | 64 | 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 ); }; |
54 | 66 | // internal use
|
55 | 67 | 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; |
56 | 94 | };
|
57 | 95 |
|
| 96 | + |
| 97 | +// don't break examples and old sketches |
| 98 | +typedef USBHIDRelativeMouse USBHIDMouse; |
| 99 | + |
58 | 100 | #endif /* CONFIG_TINYUSB_HID_ENABLED */
|
59 | 101 | #endif /* SOC_USB_OTG_SUPPORTED */
|
0 commit comments