diff options
Diffstat (limited to 'hid/src/usb/hid.h')
-rw-r--r-- | hid/src/usb/hid.h | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/hid/src/usb/hid.h b/hid/src/usb/hid.h index 0fedc3ee..48e99d28 100644 --- a/hid/src/usb/hid.h +++ b/hid/src/usb/hid.h @@ -30,18 +30,16 @@ // ----------------------------------------------------------------------------- -class UsbHid { +class UsbHidKeyboard { public: - UsbHid() {} + UsbHidKeyboard() {} void begin() { BootKeyboard.begin(); - SingleAbsoluteMouse.begin(); } - void reset() { + INLINE void reset() { BootKeyboard.releaseAll(); - SingleAbsoluteMouse.releaseAll(); } INLINE void sendKey(uint8_t code, bool state) { @@ -52,14 +50,37 @@ class UsbHid { } } + INLINE uint8_t getLedsAs(uint8_t caps, uint8_t scroll, uint8_t num) { + uint8_t leds = BootKeyboard.getLeds(); + uint8_t result = 0; + + if (leds & LED_CAPS_LOCK) result |= caps; + if (leds & LED_SCROLL_LOCK) result |= scroll; + if (leds & LED_NUM_LOCK) result |= num; + return result; + } +}; + +class UsbHidMouse { + public: + UsbHidMouse() {} + + void begin() { + SingleAbsoluteMouse.begin(); + } + + INLINE void reset() { + SingleAbsoluteMouse.releaseAll(); + } + INLINE void sendMouseButtons( bool left_select, bool left_state, bool right_select, bool right_state, bool middle_select, bool middle_state ) { - if (left_select) sendMouseButton(MOUSE_LEFT, left_state); - if (right_select) sendMouseButton(MOUSE_RIGHT, right_state); - if (middle_select) sendMouseButton(MOUSE_MIDDLE, middle_state); + if (left_select) _sendMouseButton(MOUSE_LEFT, left_state); + if (right_select) _sendMouseButton(MOUSE_RIGHT, right_state); + if (middle_select) _sendMouseButton(MOUSE_MIDDLE, middle_state); } INLINE void sendMouseMove(int x, int y) { @@ -71,18 +92,8 @@ class UsbHid { SingleAbsoluteMouse.move(0, 0, delta_y); } - INLINE uint8_t getLedsAs(uint8_t caps, uint8_t scroll, uint8_t num) { - uint8_t leds = BootKeyboard.getLeds(); - uint8_t result = 0; - - if (leds & LED_CAPS_LOCK) result |= caps; - if (leds & LED_SCROLL_LOCK) result |= scroll; - if (leds & LED_NUM_LOCK) result |= num; - return result; - } - private: - INLINE void sendMouseButton(uint8_t button, bool state) { + INLINE void _sendMouseButton(uint8_t button, bool state) { if (state) SingleAbsoluteMouse.press(button); else SingleAbsoluteMouse.release(button); } |