Skip to content

Commit 07e5a00

Browse files
committed
cache hid mouse button
1 parent 8d9fa65 commit 07e5a00

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Adafruit_USBD_HID.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ Adafruit_USBD_HID::Adafruit_USBD_HID(void)
3838
{
3939
_interval_ms = 10;
4040
_protocol = HID_PROTOCOL_NONE;
41+
42+
_mouse_button = 0;
43+
4144
_desc_report = NULL;
4245
_desc_report_len = 0;
46+
47+
_get_report_cb = NULL;
48+
_set_report_cb = NULL;
4349
}
4450

4551
void Adafruit_USBD_HID::setPollInterval(uint8_t interval_ms)
@@ -110,31 +116,35 @@ bool Adafruit_USBD_HID::keyboardPress(uint8_t report_id, char ch)
110116

111117
if ( _ascii2keycode[ch][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
112118
keycode[0] = _ascii2keycode[ch][1];
113-
tud_hid_keyboard_report(report_id, modifier, keycode);
119+
120+
return tud_hid_keyboard_report(report_id, modifier, keycode);
114121
}
115122

116123
bool Adafruit_USBD_HID::keyboardRelease(uint8_t report_id)
117124
{
118-
return tud_hid_keyboard_key_release(report_id);
125+
return tud_hid_keyboard_report(report_id, 0, NULL);
119126
}
120127

121128
//--------------------------------------------------------------------+
122129
// Mouse
123130
//--------------------------------------------------------------------+
124131

125-
bool Adafruit_USBD_HID::mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan)
132+
bool Adafruit_USBD_HID::mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
126133
{
127-
return tud_hid_mouse_report(report_id, buttons, x, y, scroll, pan);
134+
// cache mouse button for other API such as move, scroll
135+
_mouse_button = buttons;
136+
137+
return tud_hid_mouse_report(report_id, buttons, x, y, vertical, horizontal);
128138
}
129139

130140
bool Adafruit_USBD_HID::mouseMove(uint8_t report_id, int8_t x, int8_t y)
131141
{
132-
return tud_hid_mouse_move(report_id, x, y);
142+
return tud_hid_mouse_report(report_id, _mouse_button, x, y, 0, 0);
133143
}
134144

135145
bool Adafruit_USBD_HID::mouseScroll(uint8_t report_id, int8_t scroll, int8_t pan)
136146
{
137-
return tud_hid_mouse_scroll(report_id, scroll, pan);
147+
return tud_hid_mouse_report(report_id, _mouse_button, 0, 0, scroll, pan);
138148
}
139149

140150
bool Adafruit_USBD_HID::mouseButtonPress(uint8_t report_id, uint8_t buttons)

src/Adafruit_USBD_HID.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Adafruit_USBD_HID : Adafruit_USBD_Interface
5151
bool keyboardRelease(uint8_t report_id);
5252

5353
//------------- Mouse API -------------//
54-
bool mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan);
54+
bool mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
5555
bool mouseMove(uint8_t report_id, int8_t x, int8_t y);
5656
bool mouseScroll(uint8_t report_id, int8_t scroll, int8_t pan);
5757
bool mouseButtonPress(uint8_t report_id, uint8_t buttons);
@@ -63,6 +63,7 @@ class Adafruit_USBD_HID : Adafruit_USBD_Interface
6363
private:
6464
uint8_t _interval_ms;
6565
uint8_t _protocol;
66+
uint8_t _mouse_button;
6667

6768
uint16_t _desc_report_len;
6869
uint8_t const* _desc_report;

0 commit comments

Comments
 (0)