From fc711f8dd925f06a4f56faa98818afdba5d73620 Mon Sep 17 00:00:00 2001 From: Leon Kiefer Date: Mon, 20 Jan 2020 22:03:48 +0100 Subject: [PATCH] added CLP namespace to the RawHID class --- .../HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp | 10 +++++----- src/CorsairLightingProtocolHID.cpp | 12 ++++++------ src/RawHID.cpp | 17 +++++++++-------- src/RawHID.h | 8 +++----- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp b/examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp index c37385ca..6c40c417 100644 --- a/examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp +++ b/examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp @@ -29,13 +29,13 @@ void resetIOMCU() { CLPUSBSerialBridge::CLPUSBSerialBridge(const char* serialNumber) { - RawHID.setSerialNumber(serialNumber); + CLP::RawHID.setSerialNumber(serialNumber); } void CLPUSBSerialBridge::begin() { Serial1.begin(SERIAL_BAUD); - RawHID.begin(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); + CLP::RawHID.begin(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); } bool waitForSynchronization() { @@ -59,14 +59,14 @@ void CLPUSBSerialBridge::sendResponse() { Serial.print(F("R")); Serial.println(rawHIDAndSerialBuffer[0], HEX); #endif // DEBUG - RawHID.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); + CLP::RawHID.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); // free the shared buffer to receive new data - RawHID.enable(); + CLP::RawHID.enable(); } void CLPUSBSerialBridge::handleHID() { - if (RawHID.available()) { + if (CLP::RawHID.available()) { #ifdef DEBUG Serial.print(F("C")); Serial.println(rawHIDAndSerialBuffer[0], HEX); diff --git a/src/CorsairLightingProtocolHID.cpp b/src/CorsairLightingProtocolHID.cpp index 3e356567..ee2969ca 100644 --- a/src/CorsairLightingProtocolHID.cpp +++ b/src/CorsairLightingProtocolHID.cpp @@ -28,12 +28,12 @@ bool printResponse = PRINT_RESPONSE; CorsairLightingProtocolHID::CorsairLightingProtocolHID(CorsairLightingProtocolController* controller) : controller(controller) { - RawHID.begin(rawhidData, sizeof(rawhidData)); + CLP::RawHID.begin(rawhidData, sizeof(rawhidData)); } CorsairLightingProtocolHID::CorsairLightingProtocolHID(CorsairLightingProtocolController* controller, const char* serialNumber) : CorsairLightingProtocolHID(controller) { - RawHID.setSerialNumber(serialNumber); + CLP::RawHID.setSerialNumber(serialNumber); } void CorsairLightingProtocolHID::update() @@ -48,15 +48,15 @@ void CorsairLightingProtocolHID::update() bool CorsairLightingProtocolHID::available() const { - return RawHID.available() > 0; + return CLP::RawHID.available() > 0; } void CorsairLightingProtocolHID::getCommand(Command& command) { - auto bytesAvailable = RawHID.available(); + auto bytesAvailable = CLP::RawHID.available(); if (bytesAvailable) { - RawHID.readBytes(command.raw, sizeof(command.raw)); + CLP::RawHID.readBytes(command.raw, sizeof(command.raw)); #if defined(DEBUG) && defined(VERBOSE) if (printCommand) { Serial.print(F("Received Command: ")); @@ -76,7 +76,7 @@ void CorsairLightingProtocolHID::sendX(const uint8_t* data, const size_t x) cons Serial.println(data[0], HEX); } #endif - RawHID.write(data, x); + CLP::RawHID.write(data, x); } #endif diff --git a/src/RawHID.cpp b/src/RawHID.cpp index 8e60668a..270e36ae 100644 --- a/src/RawHID.cpp +++ b/src/RawHID.cpp @@ -55,32 +55,32 @@ static const uint8_t _hidReportDescriptorRawHID[] PROGMEM = { const char defaultSerialNumber[] PROGMEM = SERIAL_NUMBER; -RawHID_::RawHID_(void) : PluggableUSBModule(ENDPOINT_COUNT, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1), dataLength(0), dataAvailable(0), data(nullptr), serialNumber(defaultSerialNumber), featureReport(nullptr), featureLength(0) +CLP::RawHID_::RawHID_(void) : PluggableUSBModule(ENDPOINT_COUNT, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1), dataLength(0), dataAvailable(0), data(nullptr), serialNumber(defaultSerialNumber), featureReport(nullptr), featureLength(0) { setTimeout(10); epType[0] = EP_TYPE_INTERRUPT_IN; PluggableUSB().plug(this); } -void RawHID_::setSerialNumber(const char* argSerialNumber) +void CLP::RawHID_::setSerialNumber(const char* argSerialNumber) { serialNumber = argSerialNumber; } -int RawHID_::getInterface(uint8_t* interfaceCount) +int CLP::RawHID_::getInterface(uint8_t* interfaceCount) { // Maybe as optional device FastRawHID with different USAGE PAGE *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { D_INTERFACE(pluggedInterface, ENDPOINT_COUNT, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_HIDREPORT(sizeof(_hidReportDescriptorRawHID)), - D_ENDPOINT(USB_ENDPOINT_IN(HID_ENDPOINT_IN), USB_ENDPOINT_TYPE_INTERRUPT, RAWHID_TX_SIZE, HID_ENDPOINT_INTERVAL_RAWHID) + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, RAWHID_TX_SIZE, HID_ENDPOINT_INTERVAL_RAWHID) }; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int RawHID_::getDescriptor(USBSetup& setup) +int CLP::RawHID_::getDescriptor(USBSetup& setup) { // Check if this is a HID Class Descriptor request if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; } @@ -96,7 +96,7 @@ int RawHID_::getDescriptor(USBSetup& setup) return USB_SendControl(TRANSFER_PGM, _hidReportDescriptorRawHID, sizeof(_hidReportDescriptorRawHID)); } -bool RawHID_::setup(USBSetup& setup) +bool CLP::RawHID_::setup(USBSetup& setup) { if (pluggedInterface != setup.wIndex) { return false; @@ -161,12 +161,13 @@ bool RawHID_::setup(USBSetup& setup) return false; } -uint8_t RawHID_::getShortName(char *name) +uint8_t CLP::RawHID_::getShortName(char *name) { name[0] = '\0'; strncat_P(name, serialNumber, ISERIAL_MAX_LEN - 1); return strlen(name); } - +namespace CLP { RawHID_ RawHID; +} #endif diff --git a/src/RawHID.h b/src/RawHID.h index 3368bce7..65004b96 100644 --- a/src/RawHID.h +++ b/src/RawHID.h @@ -53,10 +53,7 @@ THE SOFTWARE. // HID Functional Characteristics HID1.11 Page 10 4.4 Interfaces // Interrupt Out Endpoint is optional, contoll endpoint is used by default #define ENDPOINT_COUNT 1 - -#define HID_ENDPOINT_IN pluggedEndpoint -#define HID_TX HID_ENDPOINT_IN - +namespace CLP { class RawHID_ : public PluggableUSBModule, public Stream { public: @@ -150,7 +147,7 @@ class RawHID_ : public PluggableUSBModule, public Stream } virtual size_t write(const uint8_t *buffer, size_t size){ - return USB_Send(HID_TX | TRANSFER_RELEASE, buffer, size); + return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, buffer, size); } protected: @@ -174,4 +171,5 @@ class RawHID_ : public PluggableUSBModule, public Stream int featureLength; }; extern RawHID_ RawHID; +} #endif