diff options
author | Devaev Maxim <[email protected]> | 2020-11-15 23:16:46 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-11-15 23:16:46 +0300 |
commit | f5250bb0e90b005128bd5025604cc41d3c3f7392 (patch) | |
tree | 75fc6b4d1e89c0dcb0727fa7e16d961d0f8c2fd8 /hid/src/usb/hid.h | |
parent | d99771b2cd0110c9a5fcf9279184451c51a2d120 (diff) |
display endpoints state
Diffstat (limited to 'hid/src/usb/hid.h')
-rw-r--r-- | hid/src/usb/hid.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/hid/src/usb/hid.h b/hid/src/usb/hid.h index f0016931..d48d0fc2 100644 --- a/hid/src/usb/hid.h +++ b/hid/src/usb/hid.h @@ -40,9 +40,9 @@ static bool _checkEndpoint(uint8_t ep) { SREG = intr_state; return rw_allowed; } -# define CHECK_HID_EP(_hid) { if (!_checkEndpoint(_hid.getPluggedEndpoint())) return; } +# define CHECK_HID_EP { if (!isOnline()) return; } #else -# define CHECK_HID_EP(_hid) +# define CHECK_HID_EP #endif class UsbHidKeyboard { @@ -53,12 +53,20 @@ class UsbHidKeyboard { BootKeyboard.begin(); } + bool isOnline() { +# ifdef CHECK_ENDPOINT + return _checkEndpoint(BootKeyboard.getPluggedEndpoint()); +# else + return true; +# endif + } + void reset() { BootKeyboard.releaseAll(); } void sendKey(uint8_t code, bool state) { - CHECK_HID_EP(BootKeyboard); + CHECK_HID_EP; KeyboardKeycode usb_code = keymapUsb(code); if (usb_code != KEY_ERROR_UNDEFINED) { if (state) BootKeyboard.press(usb_code); @@ -85,6 +93,14 @@ class UsbHidMouse { SingleAbsoluteMouse.begin(); } + bool isOnline() { +# ifdef CHECK_ENDPOINT + return _checkEndpoint(SingleAbsoluteMouse.getPluggedEndpoint()); +# else + return true; +# endif + } + void reset() { SingleAbsoluteMouse.releaseAll(); } @@ -104,19 +120,19 @@ class UsbHidMouse { } void sendMove(int x, int y) { - CHECK_HID_EP(SingleAbsoluteMouse); + CHECK_HID_EP; SingleAbsoluteMouse.moveTo(x, y); } void sendWheel(int delta_y) { - CHECK_HID_EP(SingleAbsoluteMouse); + CHECK_HID_EP; // delta_x is not supported by hid-project now SingleAbsoluteMouse.move(0, 0, delta_y); } private: void _sendButton(uint8_t button, bool state) { - CHECK_HID_EP(SingleAbsoluteMouse); + CHECK_HID_EP; if (state) SingleAbsoluteMouse.press(button); else SingleAbsoluteMouse.release(button); } |