summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomaszduda23 <[email protected]>2022-07-11 08:01:57 +0900
committerGitHub <[email protected]>2022-07-11 02:01:57 +0300
commit1afd96cdb932ccb1df0f0ed7e6662080f2618a26 (patch)
treef747158fd5b2a1fd9f26568302d9ffb8a4dddb30
parent67547636cfae08121154179266bd1c42f59a72cb (diff)
add factory for avr (#98)
-rw-r--r--hid/lib/drivers-avr/factory.cpp61
-rw-r--r--hid/lib/drivers-avr/ps2/hid.h (renamed from hid/src/ps2/hid.h)0
-rw-r--r--hid/lib/drivers-avr/ps2/keymap.h (renamed from hid/src/ps2/keymap.h)0
-rw-r--r--hid/lib/drivers-avr/ps2/keymap.h.mako (renamed from hid/src/ps2/keymap.h.mako)0
-rw-r--r--hid/lib/drivers-avr/spi.cpp (renamed from hid/src/spi.cpp)0
-rw-r--r--hid/lib/drivers-avr/spi.h (renamed from hid/src/spi.h)0
-rw-r--r--hid/lib/drivers-avr/usb/hid.h (renamed from hid/src/usb/hid.h)4
-rw-r--r--hid/lib/drivers-avr/usb/keymap.h (renamed from hid/src/usb/keymap.h)0
-rw-r--r--hid/lib/drivers-avr/usb/keymap.h.mako (renamed from hid/src/usb/keymap.h.mako)0
-rw-r--r--hid/lib/drivers/aum.h (renamed from hid/src/aum.h)0
-rw-r--r--hid/lib/drivers/factory.h33
-rw-r--r--hid/lib/drivers/tools.cpp (renamed from hid/src/tools.h)4
-rw-r--r--hid/lib/drivers/tools.h26
-rw-r--r--hid/platformio.ini2
-rw-r--r--hid/src/main.cpp25
15 files changed, 134 insertions, 21 deletions
diff --git a/hid/lib/drivers-avr/factory.cpp b/hid/lib/drivers-avr/factory.cpp
new file mode 100644
index 00000000..d58e6c96
--- /dev/null
+++ b/hid/lib/drivers-avr/factory.cpp
@@ -0,0 +1,61 @@
+/*****************************************************************************
+# #
+# KVMD - The main PiKVM daemon. #
+# #
+# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> #
+# #
+# 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);
+ }
+ }
+
+}
diff --git a/hid/src/ps2/hid.h b/hid/lib/drivers-avr/ps2/hid.h
index 809f9d2d..809f9d2d 100644
--- a/hid/src/ps2/hid.h
+++ b/hid/lib/drivers-avr/ps2/hid.h
diff --git a/hid/src/ps2/keymap.h b/hid/lib/drivers-avr/ps2/keymap.h
index a2b6f8fd..a2b6f8fd 100644
--- a/hid/src/ps2/keymap.h
+++ b/hid/lib/drivers-avr/ps2/keymap.h
diff --git a/hid/src/ps2/keymap.h.mako b/hid/lib/drivers-avr/ps2/keymap.h.mako
index bc4ecb47..bc4ecb47 100644
--- a/hid/src/ps2/keymap.h.mako
+++ b/hid/lib/drivers-avr/ps2/keymap.h.mako
diff --git a/hid/src/spi.cpp b/hid/lib/drivers-avr/spi.cpp
index e2b56928..e2b56928 100644
--- a/hid/src/spi.cpp
+++ b/hid/lib/drivers-avr/spi.cpp
diff --git a/hid/src/spi.h b/hid/lib/drivers-avr/spi.h
index fc9337e5..fc9337e5 100644
--- a/hid/src/spi.h
+++ b/hid/lib/drivers-avr/spi.h
diff --git a/hid/src/usb/hid.h b/hid/lib/drivers-avr/usb/hid.h
index ca923352..0bc5cb2d 100644
--- a/hid/src/usb/hid.h
+++ b/hid/lib/drivers-avr/usb/hid.h
@@ -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"
diff --git a/hid/src/usb/keymap.h b/hid/lib/drivers-avr/usb/keymap.h
index 224a181c..224a181c 100644
--- a/hid/src/usb/keymap.h
+++ b/hid/lib/drivers-avr/usb/keymap.h
diff --git a/hid/src/usb/keymap.h.mako b/hid/lib/drivers-avr/usb/keymap.h.mako
index fe295bea..fe295bea 100644
--- a/hid/src/usb/keymap.h.mako
+++ b/hid/lib/drivers-avr/usb/keymap.h.mako
diff --git a/hid/src/aum.h b/hid/lib/drivers/aum.h
index 42b379aa..42b379aa 100644
--- a/hid/src/aum.h
+++ b/hid/lib/drivers/aum.h
diff --git a/hid/lib/drivers/factory.h b/hid/lib/drivers/factory.h
new file mode 100644
index 00000000..c787347a
--- /dev/null
+++ b/hid/lib/drivers/factory.h
@@ -0,0 +1,33 @@
+/*****************************************************************************
+# #
+# KVMD - The main PiKVM daemon. #
+# #
+# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> #
+# #
+# 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);
+ };
+}
diff --git a/hid/src/tools.h b/hid/lib/drivers/tools.cpp
index 0a798596..7f0e29ca 100644
--- a/hid/src/tools.h
+++ b/hid/lib/drivers/tools.cpp
@@ -19,9 +19,7 @@
# #
*****************************************************************************/
-
-#pragma once
-
+#include <Arduino.h>
bool is_micros_timed_out(unsigned long start_ts, unsigned long timeout) {
unsigned long now = micros();
diff --git a/hid/lib/drivers/tools.h b/hid/lib/drivers/tools.h
new file mode 100644
index 00000000..0f11c7c3
--- /dev/null
+++ b/hid/lib/drivers/tools.h
@@ -0,0 +1,26 @@
+/*****************************************************************************
+# #
+# KVMD - The main PiKVM daemon. #
+# #
+# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> #
+# #
+# 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);
diff --git a/hid/platformio.ini b/hid/platformio.ini
index aa9202dd..8484ef50 100644
--- a/hid/platformio.ini
+++ b/hid/platformio.ini
@@ -10,6 +10,8 @@ lib_deps =
git+https://github.com/NicoHood/HID#2.8.2
git+https://github.com/Harvie/ps2dev#v0.0.3
+ drivers-avr
extra_scripts =
pre:avrdude.py
post:patch.py
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
index 732cbde2..fe030a3a 100644
--- a/hid/src/main.cpp
+++ b/hid/src/main.cpp
@@ -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);