Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added CLP namespace to the RawHID class #103

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/CorsairLightingProtocolHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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: "));
Expand All @@ -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
17 changes: 9 additions & 8 deletions src/RawHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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;
Expand Down Expand Up @@ -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
8 changes: 3 additions & 5 deletions src/RawHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -174,4 +171,5 @@ class RawHID_ : public PluggableUSBModule, public Stream
int featureLength;
};
extern RawHID_ RawHID;
}
#endif