-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Legion2/dev
Version 0.5.0
- Loading branch information
Showing
26 changed files
with
1,249 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright 2019 Leon Kiefer | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "CLPUSBSerialBridge.h" | ||
#include <RawHID.h> | ||
#include <CorsairLightingProtocolConstants.h> | ||
|
||
void resetIOMCU() { | ||
digitalWrite(RESET_PIN, LOW); | ||
delay(10); | ||
digitalWrite(RESET_PIN, HIGH); | ||
#ifdef DEBUG | ||
Serial.println(F("R")); | ||
#endif // DEBUG | ||
} | ||
|
||
void CLPUSBSerialBridge::begin() | ||
{ | ||
Serial1.begin(SERIAL_BAUD); | ||
RawHID.begin(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); | ||
} | ||
|
||
bool waitForSynchronization() { | ||
while (Serial1.available()) { | ||
Serial1.read(); | ||
} | ||
Serial1.setTimeout(SERIAL_SYNCHRONIZATION_TIMEOUT); | ||
byte value; | ||
size_t read = Serial1.readBytes(&value, 1); | ||
return read == 1 && value == 42; | ||
} | ||
|
||
void CLPUSBSerialBridge::sendError() { | ||
memset(rawHIDAndSerialBuffer, 0, sizeof(rawHIDAndSerialBuffer)); | ||
rawHIDAndSerialBuffer[0] = PROTOCOL_RESPONSE_ERROR; | ||
sendResponse(); | ||
} | ||
|
||
void CLPUSBSerialBridge::sendResponse() { | ||
RawHID.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); | ||
// free the shared buffer to receive new data | ||
RawHID.enable(); | ||
} | ||
|
||
void CLPUSBSerialBridge::handleHID() | ||
{ | ||
if (RawHID.available()) { | ||
if (!waitForSynchronization()) { | ||
sendError(); | ||
return; | ||
} | ||
|
||
Serial1.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); | ||
Serial1.setTimeout(SERIAL_RESPONSE_TIMEOUT); | ||
size_t read = Serial1.readBytes(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer)); | ||
if (read != sizeof(rawHIDAndSerialBuffer)) { | ||
#ifdef DEBUG | ||
Serial.print(F("T")); | ||
Serial.println(read); | ||
Serial.println(rawHIDAndSerialBuffer[0], HEX); | ||
#endif // DEBUG | ||
sendError(); | ||
return; | ||
} | ||
sendResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2019 Leon Kiefer | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
#ifndef _CLPUSBSerialBridge_h | ||
#define _CLPUSBSerialBridge_h | ||
|
||
#include "Arduino.h" | ||
#include <CorsairLightingProtocolConstants.h> | ||
|
||
#if (COMMAND_SIZE == RESPONSE_SIZE) | ||
#define RAWHID_AND_SERIAL_BUFFER_SIZE COMMAND_SIZE | ||
#endif | ||
|
||
#define SERIAL_SYNCHRONIZATION_TIMEOUT 20 | ||
#define SERIAL_RESPONSE_TIMEOUT 10 | ||
#define SERIAL_BAUD 1000000 | ||
|
||
#define RESET_PIN IO_MCU_RESET_PIN | ||
|
||
class CLPUSBSerialBridge { | ||
public: | ||
virtual void begin(); | ||
virtual void handleHID(); | ||
private: | ||
byte rawHIDAndSerialBuffer[RAWHID_AND_SERIAL_BUFFER_SIZE]; | ||
|
||
void sendError(); | ||
void sendResponse(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2019 Leon Kiefer | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
#include "CLPUSBSerialBridge.h" | ||
|
||
CLPUSBSerialBridge usbToSerialBridge; | ||
|
||
void setup() { | ||
#ifdef DEBUG | ||
Serial.begin(1000000); | ||
#endif // DEBUG | ||
usbToSerialBridge.begin(); | ||
} | ||
|
||
void loop() { | ||
usbToSerialBridge.handleHID(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# CorsairLightingProtocol build property overrides | ||
# | ||
|
||
############################################################## | ||
|
||
build.vid=0x1b1c | ||
build.pid=0x0c0b | ||
build.usb_product="Lighting Node PRO" | ||
build.usb_manufacturer="Corsair" | ||
|
||
#build.extra_flags={build.usb_flags} '-DSERIAL_NUMBER="FB66DF55421900F5"' |
51 changes: 51 additions & 0 deletions
51
examples/HoodLoader2UnoMegaController/HoodLoader2UnoMegaController.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2019 Leon Kiefer | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
#include <CorsairLightingProtocol.h> | ||
#include <CorsairLightingProtocolSerial.h> | ||
#include <CorsairLightingNodePRO.h> | ||
#include <FastLEDController.h> | ||
#include <FastLED.h> | ||
|
||
#define CHANNEL_LED_COUNT 60 | ||
|
||
#define DATA_PIN_CHANNEL_1 2 | ||
#define DATA_PIN_CHANNEL_2 3 | ||
|
||
FastLEDController<CHANNEL_LED_COUNT> ledController(true); | ||
CorsairLightingProtocol cLP(&ledController, firmware_version); | ||
CorsairLightingProtocolSerial cLPS(&cLP); | ||
|
||
CRGB ledsChannel1[CHANNEL_LED_COUNT]; | ||
CRGB ledsChannel2[CHANNEL_LED_COUNT]; | ||
|
||
void setup() { | ||
/* | ||
YOU MUST NOT USE Serial! | ||
Serial is used by CorsairLightingProtocolSerial! | ||
*/ | ||
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledsChannel1, CHANNEL_LED_COUNT); | ||
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledsChannel2, CHANNEL_LED_COUNT); | ||
ledController.addLeds(0, ledsChannel1); | ||
ledController.addLeds(1, ledsChannel2); | ||
} | ||
|
||
void loop() { | ||
cLPS.update(); | ||
|
||
if (ledController.updateLEDs()) { | ||
FastLED.show(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# CorsairLightingProtocol build property overrides | ||
# | ||
|
||
############################################################## | ||
|
||
build.extra_flags=-DSERIAL_RX_BUFFER_SIZE=128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.