Skip to content

Commit

Permalink
renamed CLP namespace to CorsairLightingProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Legion2 committed Aug 10, 2020
1 parent 832afd4 commit 445f465
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

You can contribute in many different ways, for example report a bug or come up with an idea for improvement.
If you are good at programming you could also provide a fix for bugs or Pull Requests with improvements.
If you want to help others using CLP you are welcome to extend the [Wiki on GitHub](https://github.com/Legion2/CorsairLightingProtocol/wiki).
If you want to help others using CorsairLightingProtocol (CLP) you are welcome to extend the [Wiki on GitHub](https://github.com/Legion2/CorsairLightingProtocol/wiki).

## Finding information

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ You can repeat or scale LED channel controlled by iCUE onto physical LED strips.
This is very useful if you have very long LED strips that are longer than 60/96/135 LEDs.
This is the maximum number iCUE supports.

To repeat or scale a LED channel you must apply the `CLP::repeat` or the `CLP:scale` function in the update hook of the FastLEDController.
To repeat or scale a LED channel you must apply the `CorsairLightingProtocol::repeat` or the `CorsairLightingProtocol::scale` function in the update hook of the FastLEDController.
See the [RepeatAndScale](examples/RepeatAndScale/RepeatAndScale.ino) example for the complete code.
Both functions take the FastLEDController pointer and the channel index as arguments.
Additionally, the `repeat` function takes as an argument how often the LED channel should be repeated.
Expand All @@ -148,11 +148,11 @@ This means if your LED channel from iCUE has 50 LEDs and you use the `repeat` fu
## Increase the Brightness of the LEDs
By default iCUE only uses 50% of the LEDs brightness even if you set the brightness to max in the iCUE Device Settings.
But there are good news, we can increase the brightness with the Arduino so we can use the full brightness of our LEDs.
Add the `CLP::fixIcueBrightness` function to the `onUpdateHook` in the setup function as shown in the [example](examples/AdditionalFeatures/AdditionalFeatures.ino).
Add the `CorsairLightingProtocol::fixIcueBrightness` function to the `onUpdateHook` in the setup function as shown in the [example](examples/AdditionalFeatures/AdditionalFeatures.ino).
If there are multiple functions called in `onUpdateHook`, `fixIcueBrightness` should be the first.
```C++
ledController.onUpdateHook(0, []() {
CLP::fixIcueBrightness(&ledController, 0);
CorsairLightingProtocol::fixIcueBrightness(&ledController, 0);
});
```

Expand Down
9 changes: 5 additions & 4 deletions examples/AdditionalFeatures/AdditionalFeatures.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#include <CorsairLightingProtocol.h>
#include <FastLED.h>
using namespace CorsairLightingProtocol;

#define DATA_PIN_CHANNEL_1 2
#define DATA_PIN_CHANNEL_2 3
Expand All @@ -33,11 +34,11 @@ CorsairLightingProtocolHID cHID(&cLP, mySerialNumber);

void setup() {
// Disable the build in RX and TX LEDs of the Arduino
CLP::disableBuildInLEDs();
disableBuildInLEDs();
// enable reset on DeviceId (FF FF FF FF)
if (CLP::shouldReset(&firmware)) {
if (shouldReset(&firmware)) {
// reset DeviceId and generate new one
CLP::reset(&firmware);
reset(&firmware);
// reset the LEDController Settings
ledController.reset();
}
Expand All @@ -49,7 +50,7 @@ void setup() {
// modify the RGB values before they are shown on the LED strip
ledController.onUpdateHook(0, []() {
// increase the brightness of channel 1 when using iCUE, because iCUE only set brightness to max 50%
CLP::fixIcueBrightness(&ledController, 0);
fixIcueBrightness(&ledController, 0);
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/AmbientBacklight/AmbientBacklight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup() {
ledController.addLEDs(1, ledsChannel2, 105);
ledController.onUpdateHook(0, []() {
// gamma correction with gamma value 2.0. Use napplyGamma_video for other gamma values.
CLP::gammaCorrection(&ledController, 0);
CorsairLightingProtocol::gammaCorrection(&ledController, 0);
// napplyGamma_video(ledsChannel1, 84, 2.2);
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/CommanderPRO/CommanderPRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PWMFan fan3(PWM_FAN_PIN_3, 0, 2000);
PWMFan fan4(PWM_FAN_PIN_4, 0, 2000);

void setup() {
CLP::disableBuildInLEDs();
CorsairLightingProtocol::disableBuildInLEDs();
FastLED.addLeds<WS2812B, DATA_PIN_CHANNEL_1, GRB>(ledsChannel1, CHANNEL_LED_COUNT);
FastLED.addLeds<WS2812B, DATA_PIN_CHANNEL_2, GRB>(ledsChannel2, CHANNEL_LED_COUNT);
ledController.addLEDs(0, ledsChannel1, CHANNEL_LED_COUNT);
Expand Down
2 changes: 1 addition & 1 deletion examples/DebugSketch/DebugSketch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void processCommand(String& cmd) {
if (cmd == F("print DeviceID")) {
byte deviceId[4];
firmware.getDeviceID(deviceId);
CLP::printDeviceID(deviceId);
CorsairLightingProtocol::printDeviceID(deviceId);
Serial.println();
}
#ifdef VERBOSE
Expand Down
10 changes: 5 additions & 5 deletions examples/DeviceIDTool/DeviceIDTool.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void setup() {
; // wait for serial port to connect. Needed for native USB
}
Serial.print(F("Current DeviceID: "));
CLP::printDeviceID(deviceID);
CorsairLightingProtocol::printDeviceID(deviceID);
Serial.println();
Serial.println(
F("Set a new DeviceID by typing it in the Serial Monitor. The new DeviceID must be in same format as above. 4 "
Expand All @@ -54,19 +54,19 @@ void loop() {
newDeviceID[2] = strtol(&inputString[6], nullptr, 16);
newDeviceID[3] = strtol(&inputString[9], nullptr, 16);
Serial.println(F("Set DeviceID to: "));
CLP::printDeviceID(newDeviceID);
CorsairLightingProtocol::printDeviceID(newDeviceID);
Serial.println();
if (CLP::isNullID(newDeviceID)) {
if (CorsairLightingProtocol::isNullID(newDeviceID)) {
Serial.println(
F("This is a special DeviceID, it will generate a new random DeviceID next time iCUE controls the "
"device!"));
}
if (CLP::isResetID(newDeviceID)) {
if (CorsairLightingProtocol::isResetID(newDeviceID)) {
Serial.println(
F("This is a special DeviceID, it will reset the device and then generate a new DeviceID!"));
}
Serial.println();
EEPROM.put(EEPROM_ADDRESS_DEVICE_ID, newDeviceID);
}
}
}
}
10 changes: 5 additions & 5 deletions examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ void resetIOMCU() {
}

CLPUSBSerialBridge::CLPUSBSerialBridge(const char* serialNumber) {
CLP::RawHID.setSerialNumber(serialNumber);
CorsairLightingProtocol::RawHID.setSerialNumber(serialNumber);
}

void CLPUSBSerialBridge::begin() {
Serial1.begin(SERIAL_BAUD);
CLP::RawHID.begin(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
CorsairLightingProtocol::RawHID.begin(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
}

bool waitForSynchronization() {
Expand All @@ -58,13 +58,13 @@ void CLPUSBSerialBridge::sendResponse() {
Serial.print(F("R"));
Serial.println(rawHIDAndSerialBuffer[0], HEX);
#endif // DEBUG
CLP::RawHID.write(rawHIDAndSerialBuffer, RESPONSE_SIZE_16U2);
CorsairLightingProtocol::RawHID.write(rawHIDAndSerialBuffer, RESPONSE_SIZE_16U2);
// free the shared buffer to receive new data
CLP::RawHID.enable();
CorsairLightingProtocol::RawHID.enable();
}

void CLPUSBSerialBridge::handleHID() {
if (CLP::RawHID.available()) {
if (CorsairLightingProtocol::RawHID.available()) {
#ifdef DEBUG
Serial.print(F("C"));
Serial.println(rawHIDAndSerialBuffer[0], HEX);
Expand Down
4 changes: 2 additions & 2 deletions examples/RepeatAndScale/RepeatAndScale.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ void setup() {
ledController.addLEDs(0, ledsChannel1, 50);
ledController.addLEDs(1, ledsChannel2, 60);
ledController.onUpdateHook(0, []() {
CLP::repeat(&ledController, 0, 2);
CorsairLightingProtocol::repeat(&ledController, 0, 2);
});
ledController.onUpdateHook(1, []() {
CLP::scale(&ledController, 1, 144);
CorsairLightingProtocol::scale(&ledController, 1, 144);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void setup() {
#ifdef DEBUG
Serial.begin(115200);
#endif
CLP::disableBuildInLEDs();
CorsairLightingProtocol::disableBuildInLEDs();
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
ledController.addLEDs(0, leds, CHANNEL_LED_COUNT);
ledController.addLEDs(1, &(leds[CHANNEL_LED_COUNT]), CHANNEL_LED_COUNT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void setup() {
ledController.addLEDs(0, ledsChannel1, 96);
ledController.addLEDs(1, ledsChannel2, 60);
ledController.onUpdateHook(0, []() {
CLP::transformLLFanToStrip(&ledController, 0);
CorsairLightingProtocol::transformLLFanToStrip(&ledController, 0);
});
}

Expand Down
42 changes: 21 additions & 21 deletions examples/UnitTests/UnitTests.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ testF(FastLEDControllerTest, simpleScaleUp) {
ledController.addLEDs(0, leds, 10);

fill_solid(leds, 10, CRGB::White);
CLP::scale(&ledController, 0, 20);
CorsairLightingProtocol::scale(&ledController, 0, 20);

for (int i = 0; i < 10; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -59,7 +59,7 @@ testF(FastLEDControllerTest, simpleScaleDown) {
ledController.addLEDs(0, leds, 20);

fill_solid(leds, 10, CRGB::White);
CLP::scale(&ledController, 0, 10);
CorsairLightingProtocol::scale(&ledController, 0, 10);

for (int i = 0; i < 5; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -76,7 +76,7 @@ testF(FastLEDControllerTest, simpleScaleIdentity) {
ledController.addLEDs(0, leds, 10);

fill_solid(leds, 10, CRGB::White);
CLP::scale(&ledController, 0, 10);
CorsairLightingProtocol::scale(&ledController, 0, 10);

for (int i = 0; i < 10; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -94,8 +94,8 @@ testF(FastLEDControllerTest, LT100) {

leds[0] = CRGB::White;
fill_solid(leds + 1, 26, CRGB::Blue);
CLP::SegmentScaling segments[2] = {{1, 4}, {26, 26}};
CLP::scaleSegments(&ledController, 0, segments, 2);
CorsairLightingProtocol::SegmentScaling segments[2] = {{1, 4}, {26, 26}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 2);

for (int i = 0; i < 4; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -112,8 +112,8 @@ testF(FastLEDControllerTest, singleSegmentScaleUp) {
ledController.addLEDs(0, leds, 20);

fill_solid(leds, 10, CRGB::White);
CLP::SegmentScaling segments[] = {{10, 20}};
CLP::scaleSegments(&ledController, 0, segments, 1);
CorsairLightingProtocol::SegmentScaling segments[] = {{10, 20}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 1);

for (int i = 0; i < 20; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -127,8 +127,8 @@ testF(FastLEDControllerTest, multiScaleUp) {
ledController.addLEDs(0, leds, 10);

fill_solid(leds + 5, 5, CRGB::White);
CLP::SegmentScaling segments[] = {{5, 10}, {5, 20}};
CLP::scaleSegments(&ledController, 0, segments, 2);
CorsairLightingProtocol::SegmentScaling segments[] = {{5, 10}, {5, 20}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 2);

for (int i = 0; i < 10; i++) {
assertCRGB(leds[i], CRGB::Black);
Expand All @@ -145,8 +145,8 @@ testF(FastLEDControllerTest, multiScaleDown) {
ledController.addLEDs(0, leds, 30);

fill_solid(leds + 10, 20, CRGB::White);
CLP::SegmentScaling segments[] = {{10, 5}, {20, 5}};
CLP::scaleSegments(&ledController, 0, segments, 2);
CorsairLightingProtocol::SegmentScaling segments[] = {{10, 5}, {20, 5}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 2);

for (int i = 0; i < 5; i++) {
assertCRGB(leds[i], CRGB::Black);
Expand All @@ -163,8 +163,8 @@ testF(FastLEDControllerTest, singleSegmentScaleDown) {
ledController.addLEDs(0, leds, 20);

fill_solid(leds, 10, CRGB::White);
CLP::SegmentScaling segments[] = {{20, 10}};
CLP::scaleSegments(&ledController, 0, segments, 1);
CorsairLightingProtocol::SegmentScaling segments[] = {{20, 10}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 1);

for (int i = 0; i < 5; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -181,8 +181,8 @@ testF(FastLEDControllerTest, SegmentScaleOverlap) {
ledController.addLEDs(0, leds, 15);

fill_solid(leds, 5, CRGB::White);
CLP::SegmentScaling segments[] = {{5, 10}, {10, 5}};
CLP::scaleSegments(&ledController, 0, segments, 2);
CorsairLightingProtocol::SegmentScaling segments[] = {{5, 10}, {10, 5}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 2);

for (int i = 0; i < 10; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -199,8 +199,8 @@ testF(FastLEDControllerTest, SegmentScaleOverlapInverted) {
ledController.addLEDs(0, leds, 15);

fill_solid(leds, 10, CRGB::White);
CLP::SegmentScaling segments[] = {{10, 5}, {5, 10}};
CLP::scaleSegments(&ledController, 0, segments, 2);
CorsairLightingProtocol::SegmentScaling segments[] = {{10, 5}, {5, 10}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 2);

for (int i = 0; i < 5; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -219,8 +219,8 @@ testF(FastLEDControllerTest, SegmentScaleMix) {
fill_solid(leds, 5, CRGB::White);
fill_solid(leds + 5, 20, CRGB::Red);
fill_solid(leds + 25, 5, CRGB::Blue);
CLP::SegmentScaling segments[] = {{5, 10}, {20, 5}, {5, 10}};
CLP::scaleSegments(&ledController, 0, segments, 3);
CorsairLightingProtocol::SegmentScaling segments[] = {{5, 10}, {20, 5}, {5, 10}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 3);

for (int i = 0; i < 10; i++) {
assertCRGB(leds[i], CRGB::White);
Expand All @@ -242,8 +242,8 @@ testF(FastLEDControllerTest, SegmentScaleMixInverted) {
fill_solid(leds, 10, CRGB::White);
fill_solid(leds + 10, 5, CRGB::Red);
fill_solid(leds + 15, 10, CRGB::Blue);
CLP::SegmentScaling segments[] = {{10, 5}, {5, 20}, {10, 5}};
CLP::scaleSegments(&ledController, 0, segments, 3);
CorsairLightingProtocol::SegmentScaling segments[] = {{10, 5}, {5, 20}, {10, 5}};
CorsairLightingProtocol::scaleSegments(&ledController, 0, segments, 3);

for (int i = 0; i < 5; i++) {
assertCRGB(leds[i], CRGB::White);
Expand Down
6 changes: 3 additions & 3 deletions src/CLPAdditionalFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

#include "CLPUtils.h"

bool CLP::shouldReset(const CorsairLightingFirmware* firmware) {
bool CorsairLightingProtocol::shouldReset(const CorsairLightingFirmware* firmware) {
byte deviceId[4];
firmware->getDeviceID(deviceId);
return CLP::isResetID(deviceId);
return CorsairLightingProtocol::isResetID(deviceId);
}

void CLP::reset(CorsairLightingFirmware* firmware) {
void CorsairLightingProtocol::reset(CorsairLightingFirmware* firmware) {
byte deviceId[4] = {0x00};
firmware->setDeviceID(deviceId);
}
4 changes: 2 additions & 2 deletions src/CLPAdditionalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "Arduino.h"
#include "CorsairLightingFirmware.h"

namespace CLP {
namespace CorsairLightingProtocol {
/**
* Check if the device should be reseted. The check is based on the DeviceID from the firmware.
*
Expand All @@ -33,4 +33,4 @@ bool shouldReset(const CorsairLightingFirmware* firmware);
* @param firmware reset this firmware
*/
void reset(CorsairLightingFirmware* firmware);
} // namespace CLP
} // namespace CorsairLightingProtocol
12 changes: 7 additions & 5 deletions src/CLPUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
#include "CLPUtils.h"

uint16_t CLP::fromBigEndian(const byte& byte1, const byte& byte2) {
uint16_t CorsairLightingProtocol::fromBigEndian(const byte& byte1, const byte& byte2) {
uint16_t t = byte1;
t = t << 8;
t |= byte2;
return t;
}

void CLP::disableBuildInLEDs() {
void CorsairLightingProtocol::disableBuildInLEDs() {
#ifndef DEBUG
#ifdef LED_BUILTIN_RX
pinMode(LED_BUILTIN_RX, INPUT);
Expand All @@ -33,13 +33,15 @@ void CLP::disableBuildInLEDs() {
#endif
}

bool CLP::isNullID(const uint8_t* deviceId) { return !(deviceId[0] | deviceId[1] | deviceId[2] | deviceId[3]); }
bool CorsairLightingProtocol::isNullID(const uint8_t* deviceId) {
return !(deviceId[0] | deviceId[1] | deviceId[2] | deviceId[3]);
}

bool CLP::isResetID(const uint8_t* deviceId) {
bool CorsairLightingProtocol::isResetID(const uint8_t* deviceId) {
return deviceId[0] == 0xFF && deviceId[1] == 0xFF && deviceId[2] == 0xFF && deviceId[3] == 0xFF;
}

void CLP::printDeviceID(const uint8_t* deviceId) {
void CorsairLightingProtocol::printDeviceID(const uint8_t* deviceId) {
char tmp[16];
for (size_t i = 0; i < 4; i++) {
sprintf(tmp, "%.2X", deviceId[i]);
Expand Down
4 changes: 2 additions & 2 deletions src/CLPUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#define toBigEndian(a) highByte(a), lowByte(a)

namespace CLP {
namespace CorsairLightingProtocol {
uint16_t fromBigEndian(const byte& byte1, const byte& byte2);

/**
Expand Down Expand Up @@ -61,4 +61,4 @@ void disableBuildInLEDs();
* @param deviceId the device id to print
*/
void printDeviceID(const uint8_t* deviceId);
} // namespace CLP
} // namespace CorsairLightingProtocol
Loading

0 comments on commit 445f465

Please sign in to comment.