mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
add factory for avr (#98)
This commit is contained in:
61
hid/lib/drivers-avr/factory.cpp
Normal file
61
hid/lib/drivers-avr/factory.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*****************************************************************************
|
||||
# #
|
||||
# KVMD - The main PiKVM daemon. #
|
||||
# #
|
||||
# Copyright (C) 2018-2022 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/>. #
|
||||
# #
|
||||
*****************************************************************************/
|
||||
|
||||
#include "usb/hid.h"
|
||||
#include "ps2/hid.h"
|
||||
#include "factory.h"
|
||||
|
||||
namespace DRIVERS
|
||||
{
|
||||
|
||||
Keyboard *Factory::makeKeyboard(type _type) {
|
||||
switch (_type) {
|
||||
|
||||
# ifdef HID_WITH_USB
|
||||
case USB_KEYBOARD:
|
||||
return new UsbKeyboard();
|
||||
# endif
|
||||
|
||||
# ifdef HID_WITH_PS2
|
||||
case PS2_KEYBOARD:
|
||||
return new Ps2Keyboard();
|
||||
# endif
|
||||
default:
|
||||
return new Keyboard(DUMMY);
|
||||
}
|
||||
}
|
||||
|
||||
Mouse *Factory::makeMouse(type _type) {
|
||||
switch(_type)
|
||||
{
|
||||
# ifdef HID_WITH_USB
|
||||
case USB_MOUSE_ABSOLUTE:
|
||||
case USB_MOUSE_ABSOLUTE_WIN98:
|
||||
return new UsbMouseAbsolute(_type);
|
||||
case USB_MOUSE_RELATIVE:
|
||||
return new UsbMouseRelative();
|
||||
# endif
|
||||
default:
|
||||
return new Mouse(DRIVERS::DUMMY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
#include "keyboard.h"
|
||||
#include "mouse.h"
|
||||
#include "../tools.h"
|
||||
#include "tools.h"
|
||||
#ifdef AUM
|
||||
# include "../aum.h"
|
||||
# include "aum.h"
|
||||
#endif
|
||||
#include "keymap.h"
|
||||
|
||||
33
hid/lib/drivers/factory.h
Normal file
33
hid/lib/drivers/factory.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*****************************************************************************
|
||||
# #
|
||||
# KVMD - The main PiKVM daemon. #
|
||||
# #
|
||||
# Copyright (C) 2018-2022 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
|
||||
|
||||
#include "keyboard.h"
|
||||
#include "mouse.h"
|
||||
|
||||
namespace DRIVERS {
|
||||
|
||||
struct Factory {
|
||||
static Keyboard *makeKeyboard(type _type);
|
||||
static Mouse *makeMouse(type _type);
|
||||
};
|
||||
}
|
||||
30
hid/lib/drivers/tools.cpp
Normal file
30
hid/lib/drivers/tools.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*****************************************************************************
|
||||
# #
|
||||
# KVMD - The main PiKVM daemon. #
|
||||
# #
|
||||
# Copyright (C) 2018-2022 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/>. #
|
||||
# #
|
||||
*****************************************************************************/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
@@ -23,10 +23,4 @@
|
||||
#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)
|
||||
);
|
||||
}
|
||||
bool is_micros_timed_out(unsigned long start_ts, unsigned long timeout);
|
||||
@@ -10,6 +10,8 @@ lib_deps =
|
||||
git+https://github.com/NicoHood/HID#2.8.2
|
||||
git+https://github.com/Harvie/ps2dev#v0.0.3
|
||||
digitalWriteFast@1.0.0
|
||||
HID@1.0
|
||||
drivers-avr
|
||||
extra_scripts =
|
||||
pre:avrdude.py
|
||||
post:patch.py
|
||||
|
||||
@@ -44,9 +44,8 @@
|
||||
#ifdef AUM
|
||||
# include "aum.h"
|
||||
#endif
|
||||
#include "usb/hid.h"
|
||||
#include "ps2/hid.h"
|
||||
|
||||
#include "factory.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
static DRIVERS::Keyboard *_kbd = nullptr;
|
||||
@@ -110,36 +109,30 @@ static void _initOutputs() {
|
||||
|
||||
uint8_t kbd = outputs & PROTO::OUTPUTS1::KEYBOARD::MASK;
|
||||
switch (kbd) {
|
||||
# ifdef HID_WITH_USB
|
||||
case PROTO::OUTPUTS1::KEYBOARD::USB:
|
||||
_kbd = new UsbKeyboard();
|
||||
_kbd = DRIVERS::Factory::makeKeyboard(DRIVERS::USB_KEYBOARD);
|
||||
break;
|
||||
# endif
|
||||
# ifdef HID_WITH_PS2
|
||||
case PROTO::OUTPUTS1::KEYBOARD::PS2:
|
||||
_kbd = new Ps2Keyboard();
|
||||
_kbd = DRIVERS::Factory::makeKeyboard(DRIVERS::PS2_KEYBOARD);
|
||||
break;
|
||||
# endif
|
||||
default:
|
||||
_kbd = new DRIVERS::Keyboard(DRIVERS::DUMMY);
|
||||
_kbd = DRIVERS::Factory::makeKeyboard(DRIVERS::DUMMY);
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t mouse = outputs & PROTO::OUTPUTS1::MOUSE::MASK;
|
||||
switch (mouse) {
|
||||
# ifdef HID_WITH_USB
|
||||
case PROTO::OUTPUTS1::MOUSE::USB_ABS:
|
||||
_mouse = new UsbMouseAbsolute(DRIVERS::USB_MOUSE_ABSOLUTE);
|
||||
_mouse = DRIVERS::Factory::makeMouse(DRIVERS::USB_MOUSE_ABSOLUTE);
|
||||
break;
|
||||
case PROTO::OUTPUTS1::MOUSE::USB_WIN98:
|
||||
_mouse = new UsbMouseAbsolute(DRIVERS::USB_MOUSE_ABSOLUTE_WIN98);
|
||||
_mouse = DRIVERS::Factory::makeMouse(DRIVERS::USB_MOUSE_ABSOLUTE_WIN98);
|
||||
break;
|
||||
case PROTO::OUTPUTS1::MOUSE::USB_REL:
|
||||
_mouse = new UsbMouseRelative();
|
||||
_mouse = DRIVERS::Factory::makeMouse(DRIVERS::USB_MOUSE_RELATIVE);
|
||||
break;
|
||||
# endif
|
||||
default:
|
||||
_mouse = new DRIVERS::Mouse(DRIVERS::DUMMY);
|
||||
_mouse = DRIVERS::Factory::makeMouse(DRIVERS::DUMMY);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -255,7 +248,7 @@ static void _sendResponse(uint8_t code) {
|
||||
# endif
|
||||
if (_kbd->getType() != DRIVERS::DUMMY) {
|
||||
response[1] |= (_kbd->isOffline() ? PROTO::PONG::KEYBOARD_OFFLINE : 0);
|
||||
KeyboardLedsState leds = _kbd->getLeds();
|
||||
DRIVERS::KeyboardLedsState leds = _kbd->getLeds();
|
||||
response[1] |= (leds.caps ? PROTO::PONG::CAPS : 0);
|
||||
response[1] |= (leds.num ? PROTO::PONG::NUM : 0);
|
||||
response[1] |= (leds.scroll ? PROTO::PONG::SCROLL : 0);
|
||||
|
||||
Reference in New Issue
Block a user