summaryrefslogtreecommitdiff
path: root/hid/src/usb/hid.h
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-04-22 03:21:06 +0300
committerDevaev Maxim <[email protected]>2021-04-22 03:21:06 +0300
commit4279ae5bc3ffbd4f645195c38fe5a60a1d28ec01 (patch)
tree4b690b657adc3d942c86e051fceafa237ef618d5 /hid/src/usb/hid.h
parente6ecbb2a9ca6de372ba8cb627c79636832595805 (diff)
improved mac uefi keys handling
Diffstat (limited to 'hid/src/usb/hid.h')
-rw-r--r--hid/src/usb/hid.h32
1 files changed, 29 insertions, 3 deletions
diff --git a/hid/src/usb/hid.h b/hid/src/usb/hid.h
index c23f8715..92519329 100644
--- a/hid/src/usb/hid.h
+++ b/hid/src/usb/hid.h
@@ -25,6 +25,7 @@
#include <Arduino.h>
#include <HID-Project.h>
+#include "../tools.h"
#ifdef AUM
# include "../aum.h"
#endif
@@ -73,16 +74,27 @@ class UsbKeyboard {
_kbd.begin();
}
+ void periodic() {
+# ifdef HID_USB_CHECK_ENDPOINT
+ if (is_micros_timed_out(_last, 10000)) {
+ if (!_sent) {
+ _sendCurrent();
+ }
+ _last = micros();
+ }
+# endif
+ }
+
void clear() {
_kbd.releaseAll();
}
void sendKey(uint8_t code, bool state) {
- CHECK_HID_EP;
KeyboardKeycode usb_code = keymapUsb(code);
if (usb_code != KEY_ERROR_UNDEFINED) {
- if (state) _kbd.press(usb_code);
- else _kbd.release(usb_code);
+ if (state ? _kbd.add(usb_code) : _kbd.remove(usb_code)) {
+ _sendCurrent();
+ }
}
}
@@ -99,6 +111,20 @@ class UsbKeyboard {
private:
BootKeyboard_ _kbd;
+ bool _sent = true;
+ unsigned long _last = 0;
+
+ void _sendCurrent() {
+# ifdef HID_USB_CHECK_ENDPOINT
+ if (getOfflineAs(1)) {
+ _sent = false;
+ } else {
+# endif
+ _sent = (_kbd.send() >= 0);
+# ifdef HID_USB_CHECK_ENDPOINT
+ }
+# endif
+ }
};
#define CLS_SEND_BUTTONS \