summaryrefslogtreecommitdiff
path: root/hid/src/main.cpp
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-11-15 23:16:46 +0300
committerDevaev Maxim <[email protected]>2020-11-15 23:16:46 +0300
commitf5250bb0e90b005128bd5025604cc41d3c3f7392 (patch)
tree75fc6b4d1e89c0dcb0727fa7e16d961d0f8c2fd8 /hid/src/main.cpp
parentd99771b2cd0110c9a5fcf9279184451c51a2d120 (diff)
display endpoints state
Diffstat (limited to 'hid/src/main.cpp')
-rw-r--r--hid/src/main.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
index 1bcd2162..f87c719f 100644
--- a/hid/src/main.cpp
+++ b/hid/src/main.cpp
@@ -59,19 +59,30 @@
// -----------------------------------------------------------------------------
-uint8_t cmdResetHid(const uint8_t *buffer) { // 0 bytes
+uint8_t cmdPong(const uint8_t *_=NULL) { // 0 bytes
+ return (
+ ((uint8_t)PROTO_RESP_PONG_PREFIX)
+ | hid_kbd.getLedsAs(PROTO_RESP_PONG_CAPS, PROTO_RESP_PONG_SCROLL, PROTO_RESP_PONG_NUM)
+ | (hid_kbd.isOnline() ? 0 : PROTO_RESP_PONG_KEYBOARD_OFFLINE)
+# ifdef HID_USB_MOUSE
+ | (hid_mouse.isOnline() ? 0 : PROTO_RESP_PONG_MOUSE_OFFLINE)
+# endif
+ );
+}
+
+uint8_t cmdResetHid(const uint8_t *_) { // 0 bytes
# ifdef HID_USB_KBD
hid_kbd.reset();
# endif
# ifdef HID_USB_MOUSE
hid_mouse.reset();
# endif
- return PROTO_RESP_OK;
+ return cmdPong();
}
uint8_t cmdKeyEvent(const uint8_t *buffer) { // 2 bytes
hid_kbd.sendKey(buffer[0], buffer[1]);
- return PROTO_RESP_OK;
+ return cmdPong();
}
uint8_t cmdMouseButtonEvent(const uint8_t *buffer) { // 2 bytes
@@ -91,7 +102,7 @@ uint8_t cmdMouseButtonEvent(const uint8_t *buffer) { // 2 bytes
);
# undef MOUSE_PAIR
# endif
- return PROTO_RESP_OK;
+ return cmdPong();
}
uint8_t cmdMouseMoveEvent(const uint8_t *buffer) { // 4 bytes
@@ -106,22 +117,14 @@ uint8_t cmdMouseMoveEvent(const uint8_t *buffer) { // 4 bytes
hid_mouse.sendMove(x, y);
# endif
- return PROTO_RESP_OK;
+ return cmdPong();
}
uint8_t cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
# ifdef HID_USB_MOUSE
hid_mouse.sendWheel(buffer[1]); // Y only, X is not supported
# endif
- return PROTO_RESP_OK;
-}
-
-uint8_t cmdPongLeds(const uint8_t *buffer) { // 0 bytes
- return ((uint8_t) PROTO_RESP_PONG_PREFIX) | hid_kbd.getLedsAs(
- PROTO_RESP_PONG_CAPS,
- PROTO_RESP_PONG_SCROLL,
- PROTO_RESP_PONG_NUM
- );
+ return cmdPong();
}
uint8_t handleCmdBuffer(const uint8_t *buffer) { // 8 bytes
@@ -136,7 +139,7 @@ uint8_t handleCmdBuffer(const uint8_t *buffer) { // 8 bytes
case PROTO_CMD_MOUSE_BUTTON_EVENT: HANDLE(cmdMouseButtonEvent);
case PROTO_CMD_MOUSE_MOVE_EVENT: HANDLE(cmdMouseMoveEvent);
case PROTO_CMD_MOUSE_WHEEL_EVENT: HANDLE(cmdMouseWheelEvent);
- case PROTO_CMD_PING: HANDLE(cmdPongLeds);
+ case PROTO_CMD_PING: HANDLE(cmdPong);
case PROTO_CMD_REPEAT: return 0;
default: return PROTO_RESP_INVALID_ERROR;
}