mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
improved mac uefi keys handling
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
# include <avr/eeprom.h>
|
# include <avr/eeprom.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "tools.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#ifdef CMD_SPI
|
#ifdef CMD_SPI
|
||||||
# include "spi.h"
|
# include "spi.h"
|
||||||
@@ -337,6 +338,11 @@ int main() {
|
|||||||
aumProxyUsbVbus();
|
aumProxyUsbVbus();
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef HID_WITH_USB
|
||||||
|
if (_usb_kbd) {
|
||||||
|
_usb_kbd->periodic();
|
||||||
|
}
|
||||||
|
# endif
|
||||||
# ifdef HID_WITH_PS2
|
# ifdef HID_WITH_PS2
|
||||||
if (_ps2_kbd) {
|
if (_ps2_kbd) {
|
||||||
_ps2_kbd->periodic();
|
_ps2_kbd->periodic();
|
||||||
@@ -354,11 +360,7 @@ int main() {
|
|||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
} else if (index > 0) {
|
} else if (index > 0) {
|
||||||
unsigned long now = micros();
|
if (is_micros_timed_out(last, CMD_SERIAL_TIMEOUT)) {
|
||||||
if (
|
|
||||||
(now >= last && now - last > CMD_SERIAL_TIMEOUT)
|
|
||||||
|| (now < last && ((unsigned long)-1) - last + now > CMD_SERIAL_TIMEOUT)
|
|
||||||
) {
|
|
||||||
_sendResponse(PROTO::RESP::TIMEOUT_ERROR);
|
_sendResponse(PROTO::RESP::TIMEOUT_ERROR);
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
32
hid/src/tools.h
Normal file
32
hid/src/tools.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
# #
|
||||||
|
# KVMD - The main Pi-KVM daemon. #
|
||||||
|
# #
|
||||||
|
# Copyright (C) 2018-2021 Maxim Devaev <mdevaev@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This program is free software: you can redistribute it and/or modify #
|
||||||
|
# it under the terms of the GNU General Public License as published by #
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or #
|
||||||
|
# (at your option) any later version. #
|
||||||
|
# #
|
||||||
|
# This program is distributed in the hope that it will be useful, #
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
|
# GNU General Public License for more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the GNU General Public License #
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
bool is_micros_timed_out(unsigned long start_ts, unsigned long timeout) {
|
||||||
|
unsigned long now = micros();
|
||||||
|
return (
|
||||||
|
(now >= start_ts && now - start_ts > timeout)
|
||||||
|
|| (now < start_ts && ((unsigned long)-1) - start_ts + now > timeout)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <HID-Project.h>
|
#include <HID-Project.h>
|
||||||
|
|
||||||
|
#include "../tools.h"
|
||||||
#ifdef AUM
|
#ifdef AUM
|
||||||
# include "../aum.h"
|
# include "../aum.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -73,16 +74,27 @@ class UsbKeyboard {
|
|||||||
_kbd.begin();
|
_kbd.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void periodic() {
|
||||||
|
# ifdef HID_USB_CHECK_ENDPOINT
|
||||||
|
if (is_micros_timed_out(_last, 10000)) {
|
||||||
|
if (!_sent) {
|
||||||
|
_sendCurrent();
|
||||||
|
}
|
||||||
|
_last = micros();
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
_kbd.releaseAll();
|
_kbd.releaseAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendKey(uint8_t code, bool state) {
|
void sendKey(uint8_t code, bool state) {
|
||||||
CHECK_HID_EP;
|
|
||||||
KeyboardKeycode usb_code = keymapUsb(code);
|
KeyboardKeycode usb_code = keymapUsb(code);
|
||||||
if (usb_code != KEY_ERROR_UNDEFINED) {
|
if (usb_code != KEY_ERROR_UNDEFINED) {
|
||||||
if (state) _kbd.press(usb_code);
|
if (state ? _kbd.add(usb_code) : _kbd.remove(usb_code)) {
|
||||||
else _kbd.release(usb_code);
|
_sendCurrent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +111,20 @@ class UsbKeyboard {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BootKeyboard_ _kbd;
|
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 \
|
#define CLS_SEND_BUTTONS \
|
||||||
|
|||||||
Reference in New Issue
Block a user