From 2c4a274cb3b50d8eb9b836a15726812ba73f3266 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 15 Dec 2020 19:38:38 +0100 Subject: [PATCH] driver/KeyboardioHID: make cpplint happy Signed-off-by: Gergely Nagy --- .../HID/BootKeyboard/BootKeyboard.cpp | 13 +++---- .../driver/hid/keyboardio/HID/HID.cpp | 6 +-- .../driver/hid/keyboardio/HID/HID.h | 2 +- .../keyboardio/HID/MultiReport/Keyboard.cpp | 37 ++++++++----------- .../hid/keyboardio/HID/MultiReport/Keyboard.h | 2 +- .../HID/MultiReport/SystemControl.cpp | 2 +- .../HID/SingleReport/SingleAbsoluteMouse.cpp | 4 +- .../HID/SingleReport/SingleAbsoluteMouse.h | 2 +- 8 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/BootKeyboard/BootKeyboard.cpp b/src/kaleidoscope/driver/hid/keyboardio/HID/BootKeyboard/BootKeyboard.cpp index 4acc5891..a68914af 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/BootKeyboard/BootKeyboard.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/BootKeyboard/BootKeyboard.cpp @@ -137,11 +137,11 @@ bool BootKeyboard_::setup(USBSetup& setup) { if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { if (request == HID_GET_REPORT) { - // TODO: HID_GetReport(); + // TODO(anyone): HID_GetReport(); return true; } if (request == HID_GET_PROTOCOL) { - // TODO improve + // TODO(anyone) improve #ifdef __AVR__ UEDATX = protocol; #endif @@ -151,7 +151,7 @@ bool BootKeyboard_::setup(USBSetup& setup) { return true; } if (request == HID_GET_IDLE) { - // TODO improve + // TODO(anyone) improve #ifdef __AVR__ UEDATX = idle; #endif @@ -187,14 +187,13 @@ bool BootKeyboard_::setup(USBSetup& setup) { USB_RecvControl(&leds, length); return true; } - } - - // Input (set HID report) - else if (setup.wValueH == HID_REPORT_TYPE_INPUT) { + } else { // Input (set HID report) + if (setup.wValueH == HID_REPORT_TYPE_INPUT) { if (length == sizeof(_keyReport)) { USB_RecvControl(&_keyReport, length); return true; } + } } } } diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/HID.cpp b/src/kaleidoscope/driver/hid/keyboardio/HID/HID.cpp index f1a10644..6d5e2932 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/HID.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/HID.cpp @@ -132,15 +132,15 @@ bool HID_::setup(USBSetup& setup) { if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { if (request == HID_GET_REPORT) { - // TODO: HID_GetReport(); + // TODO(anyone): HID_GetReport(); return true; } if (request == HID_GET_PROTOCOL) { - // TODO: Send8(protocol); + // TODO(anyone): Send8(protocol); return true; } if (request == HID_GET_IDLE) { - // TODO: Send8(idle); + // TODO(anyone): Send8(idle); } } diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/HID.h b/src/kaleidoscope/driver/hid/keyboardio/HID/HID.h index a566f93f..b21419ac 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/HID.h +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/HID.h @@ -94,7 +94,7 @@ class HID_ : public PluggableUSBModule { void AppendDescriptor(HIDSubDescriptor* node); uint8_t getLEDs(void) { return setReportData.leds; - }; + } protected: // Implementation of the PluggableUSBModule diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.cpp b/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.cpp index 1f4c7e19..cb288d90 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.cpp @@ -124,25 +124,22 @@ int Keyboard_::sendReport(void) { lastKeyReport.modifiers = keyReport.modifiers; int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &lastKeyReport, sizeof(lastKeyReport)); lastKeyReport.modifiers = last_mods; - } - - // If modifiers are being turned off, then we send the new report with the previous modifiers. - // We need to do this, at least on Linux 4.17 + Wayland. - // Jesse has observed that sending Shift + 3 key up events in the same report - // will sometimes result in a spurious '3' rather than '#', especially when the keys - // had been held for a while - else if (( (lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers) - && (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) { + } else { + // If modifiers are being turned off, then we send the new report with the previous modifiers. + // We need to do this, at least on Linux 4.17 + Wayland. + // Jesse has observed that sending Shift + 3 key up events in the same report + // will sometimes result in a spurious '3' rather than '#', especially when the keys + // had been held for a while + + if (( (lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers) + && (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) { uint8_t mods = keyReport.modifiers; keyReport.modifiers = lastKeyReport.modifiers; int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &keyReport, sizeof(lastKeyReport)); keyReport.modifiers = mods; + } } - - - - int returnCode = sendReportUnchecked(); if (returnCode > 0) memcpy(lastKeyReport.allkeys, keyReport.allkeys, sizeof(keyReport)); @@ -218,14 +215,13 @@ size_t Keyboard_::press(uint8_t k) { uint8_t bit = 1 << (uint8_t(k) % 8); keyReport.keys[k / 8] |= bit; return 1; - } - - // It's a modifier key - else if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) { + } else { // It's a modifier key + if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) { // Convert key into bitfield (0 - 7) k = k - HID_KEYBOARD_FIRST_MODIFIER; keyReport.modifiers |= (1 << k); return 1; + } } // No empty/pressed key was found @@ -238,14 +234,13 @@ size_t Keyboard_::release(uint8_t k) { uint8_t bit = 1 << (k % 8); keyReport.keys[k / 8] &= ~bit; return 1; - } - - // It's a modifier key - else if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) { + } else { // It's a modifier key + if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) { // Convert key into bitfield (0 - 7) k = k - HID_KEYBOARD_FIRST_MODIFIER; keyReport.modifiers &= ~(1 << k); return 1; + } } // No empty/pressed key was found diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.h b/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.h index ecfb6e3a..5bfec52d 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.h +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/Keyboard.h @@ -64,7 +64,7 @@ class Keyboard_ { uint8_t getLEDs() { return HID().getLEDs(); - }; + } HID_KeyboardReport_Data_t keyReport; HID_KeyboardReport_Data_t lastKeyReport; diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/SystemControl.cpp b/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/SystemControl.cpp index 338a6190..b717d71c 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/SystemControl.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/MultiReport/SystemControl.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. #include "../DescriptorPrimitives.h" static const uint8_t _hidMultiReportDescriptorSystem[] PROGMEM = { - //TODO limit to system keys only? + //TODO(anyone): limit to system keys only? /* System Control (Power Down, Sleep, Wakeup, ...) */ D_USAGE_PAGE, D_PAGE_GENERIC_DESKTOP, /* USAGE_PAGE (Generic Desktop) */ D_USAGE, 0x80, /* USAGE (System Control) */ diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.cpp b/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.cpp index b4795d8b..b5a31e95 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.cpp +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.cpp @@ -84,11 +84,11 @@ bool SingleAbsoluteMouse_::setup(USBSetup& setup) { if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) { if (request == HID_GET_REPORT) { - // TODO: HID_GetReport(); + // TODO(anyone): HID_GetReport(); return true; } if (request == HID_GET_PROTOCOL) { - // TODO: Send8(protocol); + // TODO(anyone): Send8(protocol); return true; } } diff --git a/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.h b/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.h index 924d1538..cc1fc6cf 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.h +++ b/src/kaleidoscope/driver/hid/keyboardio/HID/SingleReport/SingleAbsoluteMouse.h @@ -48,6 +48,6 @@ class SingleAbsoluteMouse_ : public PluggableUSBModule, public AbsoluteMouseAPI uint8_t protocol; uint8_t idle; - virtual inline void sendReport(void* data, int length) override; + inline void sendReport(void* data, int length) override; }; extern SingleAbsoluteMouse_ SingleAbsoluteMouse;