diff options
author | Maxim Devaev <[email protected]> | 2022-07-09 23:00:13 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-07-09 23:00:13 +0300 |
commit | ad6a387941012e5c54b1f6e977e4bc5425f9be5d (patch) | |
tree | b45b8e95fcac482cf29b85da72eac21f215761e0 | |
parent | 38fae01cc01a0e984f52c004ade79256d8c90e17 (diff) |
refactoring
-rw-r--r-- | hid/lib/drivers/driver.h | 3 | ||||
-rw-r--r-- | hid/lib/drivers/keyboard.h | 11 | ||||
-rw-r--r-- | hid/lib/drivers/mouse.h | 4 | ||||
-rw-r--r-- | hid/src/main.cpp | 39 | ||||
-rw-r--r-- | hid/src/usb/hid.h | 3 |
5 files changed, 38 insertions, 22 deletions
diff --git a/hid/lib/drivers/driver.h b/hid/lib/drivers/driver.h index ea209c2e..e720f7ac 100644 --- a/hid/lib/drivers/driver.h +++ b/hid/lib/drivers/driver.h @@ -19,12 +19,13 @@ # # *****************************************************************************/ + #pragma once #include <stdint.h> -namespace DRIVERS { +namespace DRIVERS { enum type { DUMMY = 0, USB_MOUSE_ABSOLUTE, diff --git a/hid/lib/drivers/keyboard.h b/hid/lib/drivers/keyboard.h index 39517f68..2e902818 100644 --- a/hid/lib/drivers/keyboard.h +++ b/hid/lib/drivers/keyboard.h @@ -19,20 +19,21 @@ # # *****************************************************************************/ + #pragma once #include <stdint.h> + #include "driver.h" -namespace DRIVERS { +namespace DRIVERS { typedef struct { bool caps; bool scroll; bool num; } KeyboardLedsState; - struct Keyboard : public Driver { using Driver::Driver; @@ -55,10 +56,12 @@ namespace DRIVERS { /** * False if online or unknown. Otherwise true. */ - virtual bool isOffline() { return false; } + virtual bool isOffline() { + return false; + } virtual KeyboardLedsState getLeds() { - KeyboardLedsState result = {}; + KeyboardLedsState result = {0}; return result; } diff --git a/hid/lib/drivers/mouse.h b/hid/lib/drivers/mouse.h index 3ec29ee9..e9092bc5 100644 --- a/hid/lib/drivers/mouse.h +++ b/hid/lib/drivers/mouse.h @@ -19,13 +19,15 @@ # # *****************************************************************************/ + #pragma once #include <stdint.h> + #include "driver.h" -namespace DRIVERS { +namespace DRIVERS { class Mouse : public Driver { using Driver::Driver; }; diff --git a/hid/src/main.cpp b/hid/src/main.cpp index 168cdc17..cfefb965 100644 --- a/hid/src/main.cpp +++ b/hid/src/main.cpp @@ -113,12 +113,18 @@ 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(); break; + case PROTO::OUTPUTS1::KEYBOARD::USB: + _kbd = new UsbKeyboard(); + break; # endif # ifdef HID_WITH_PS2 - case PROTO::OUTPUTS1::KEYBOARD::PS2: _kbd = new Ps2Keyboard(); break; + case PROTO::OUTPUTS1::KEYBOARD::PS2: + _kbd = new Ps2Keyboard(); + break; # endif - default: _kbd = new DRIVERS::Keyboard(DRIVERS::DUMMY); break; + default: + _kbd = new DRIVERS::Keyboard(DRIVERS::DUMMY); + break; } uint8_t mouse = outputs & PROTO::OUTPUTS1::MOUSE::MASK; @@ -130,7 +136,9 @@ static void _initOutputs() { case PROTO::OUTPUTS1::MOUSE::USB_WIN98: _usb_mouse_abs = new UsbMouseAbsolute(DRIVERS::USB_MOUSE_ABSOLUTE_WIN98); break; - case PROTO::OUTPUTS1::MOUSE::USB_REL: _usb_mouse_rel = new UsbMouseRelative(); break; + case PROTO::OUTPUTS1::MOUSE::USB_REL: + _usb_mouse_rel = new UsbMouseRelative(); + break; # endif } @@ -146,7 +154,9 @@ static void _initOutputs() { # endif _usb_mouse_abs->begin(); break; - case PROTO::OUTPUTS1::MOUSE::USB_REL: _usb_mouse_rel->begin(); break; + case PROTO::OUTPUTS1::MOUSE::USB_REL: + _usb_mouse_rel->begin(); + break; # endif } } @@ -274,24 +284,23 @@ static void _sendResponse(uint8_t code) { } response[2] = PROTO::OUTPUTS1::DYNAMIC; # endif - if (DRIVERS::DUMMY != _kbd->getType()) { + if (_kbd->getType() != DRIVERS::DUMMY) { response[1] |= (_kbd->isOffline() ? PROTO::PONG::KEYBOARD_OFFLINE : 0); 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); - switch (_kbd->getType()) - { - case DRIVERS::USB_KEYBOARD: - response[2] |= PROTO::OUTPUTS1::KEYBOARD::USB; - break; - case DRIVERS::PS2_KEYBOARD: - response[2] |= PROTO::OUTPUTS1::KEYBOARD::PS2; - break; + switch (_kbd->getType()) { + case DRIVERS::USB_KEYBOARD: + response[2] |= PROTO::OUTPUTS1::KEYBOARD::USB; + break; + case DRIVERS::PS2_KEYBOARD: + response[2] |= PROTO::OUTPUTS1::KEYBOARD::PS2; + break; } } if (_usb_mouse_abs) { - response[1] |= _usb_mouse_abs->isOffline() ? PROTO::PONG::MOUSE_OFFLINE : 0; + response[1] |= (_usb_mouse_abs->isOffline() ? PROTO::PONG::MOUSE_OFFLINE : 0); if (_usb_mouse_abs->getType() == DRIVERS::USB_MOUSE_ABSOLUTE_WIN98) { response[2] |= PROTO::OUTPUTS1::MOUSE::USB_WIN98; } else { diff --git a/hid/src/usb/hid.h b/hid/src/usb/hid.h index a3641565..e63aa8be 100644 --- a/hid/src/usb/hid.h +++ b/hid/src/usb/hid.h @@ -69,6 +69,7 @@ using namespace DRIVERS; #endif + class UsbKeyboard : public DRIVERS::Keyboard { public: UsbKeyboard() : DRIVERS::Keyboard(DRIVERS::USB_KEYBOARD) {} @@ -110,7 +111,7 @@ class UsbKeyboard : public DRIVERS::Keyboard { KeyboardLedsState getLeds() override { uint8_t leds = _kbd.getLeds(); KeyboardLedsState result = { - .caps = leds & LED_CAPS_LOCK, + .caps = leds & LED_CAPS_LOCK, .scroll = leds & LED_SCROLL_LOCK, .num = leds & LED_NUM_LOCK, }; |