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

Use CorsairLightingProtocol namespace and naming convention #191

Closed
wants to merge 4 commits into from
Closed
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
12 changes: 11 additions & 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 Expand Up @@ -32,3 +32,13 @@ Public methods must be documented with JavaDoc style comments.
When introducing new methods you should think about if the method should be part of the public API or only used internally.
Always use descriptive names for variables, only use acronyms if they are well known and frequently used.
The coding style is defined using ClangFormat and automatically checked when you submit a Pull Request.

### Naming

Everything should be defined in the `CorsairLightingProtocol` namespace.
Use camel case for names.
Type names start with an upper case letter and variable, parameter and property names start with a lower case letter.

Free function names should be unambiguous without the namespace.
So, don't use names such as `reset` or `init`.
Instead use `resetSomething` or `initSomethingElse`.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ After that, you can upload another sketch.
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, which 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 `repeat` or the `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 @@ -149,12 +149,12 @@ This means if your LED channel from iCUE has 50 LEDs and you use the `repeat` fu
## Increase the Brightness of the LEDs
When using LS100 or LT100 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/AmbientBacklight/AmbientBacklight.ino).
Add the `fixIcueBrightness` function to the `onUpdateHook` in the setup function as shown in the [example](examples/AmbientBacklight/AmbientBacklight.ino).
If there are multiple functions called in `onUpdateHook`, `fixIcueBrightness` should be the first.
Only use this function with LS100 and LT100 devices!
```C++
ledController.onUpdateHook(0, []() {
CLP::fixIcueBrightness(&ledController, 0);
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 @@ -52,6 +53,6 @@ void loop() {

if (ledController.updateLEDs()) {
FastLED.show();
CLP::printFps(5000);
printFps(5000);
}
}
5 changes: 3 additions & 2 deletions examples/AmbientBacklight/AmbientBacklight.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;

// Hint: The channels are swapped in iCUE, so the first channel in iCUE is here channel 2
#define DATA_PIN_CHANNEL_1 2 // For the monitor backlight
Expand All @@ -35,9 +36,9 @@ void setup() {
ledController.addLEDs(1, ledsChannel2, 105);
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);
// gamma correction with gamma value 2.0. Use napplyGamma_video for other gamma values.
CLP::gammaCorrection(&ledController, 0);
gammaCorrection(&ledController, 0);
// napplyGamma_video(ledsChannel1, 84, 2.2);
});
}
Expand Down
3 changes: 2 additions & 1 deletion examples/CommanderPRO/CommanderPRO.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;

#include "SimpleFanController.h"
#include "ThermistorTemperatureController.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ PWMFan fan3(PWM_FAN_PIN_3, 0, 2000);
PWMFan fan4(PWM_FAN_PIN_4, 0, 2000);

void setup() {
CLP::disableBuildInLEDs();
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
5 changes: 3 additions & 2 deletions examples/DebugSketch/DebugSketch.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 CHANNEL_LED_COUNT 96

Expand Down Expand Up @@ -48,7 +49,7 @@ void loop() {
if (ledController.updateLEDs()) {
if (printUpdate) Serial.println(F("updateLEDs"));
FastLED.show();
CLP::printFps(5000);
printFps(5000);
}

if (Serial.available()) {
Expand All @@ -62,7 +63,7 @@ void processCommand(String& cmd) {
if (cmd == F("print DeviceID")) {
byte deviceId[4];
firmware.getDeviceID(deviceId);
CLP::printDeviceID(deviceId);
printDeviceID(deviceId);
Serial.println();
}
#ifdef VERBOSE
Expand Down
11 changes: 6 additions & 5 deletions examples/DeviceIDTool/DeviceIDTool.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//
#include <CLPUtils.h>
#include <EEPROM.h>
using namespace CorsairLightingProtocol;

#define EEPROM_ADDRESS_DEVICE_ID 0

Expand All @@ -31,7 +32,7 @@ void setup() {
; // wait for serial port to connect. Needed for native USB
}
Serial.print(F("Current DeviceID: "));
CLP::printDeviceID(deviceID);
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 +55,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);
printDeviceID(newDeviceID);
Serial.println();
if (CLP::isNullID(newDeviceID)) {
if (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 (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
1 change: 1 addition & 0 deletions examples/HoodLoader2CLPBridge/HoodLoader2CLPBridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
*/
#include "CLPUSBSerialBridge.h"
using namespace CorsairLightingProtocol;

CLPUSBSerialBridge usbToSerialBridge;

Expand Down
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;

// Hint: The Arduino Uno does not have as much memory as the Arduino Mega, it may be that problems occur when a higher
// value is set here.
Expand Down
1 change: 1 addition & 0 deletions examples/LS100/LS100.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;

// Hint: The channels of the LS100 are swapped in iCUE, so the first channel in iCUE is here channel 2
#define DATA_PIN_CHANNEL_1 2
Expand Down
1 change: 1 addition & 0 deletions examples/LT100/LT100.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

Expand Down
1 change: 1 addition & 0 deletions examples/LightingNodeCORE/LightingNodeCORE.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

Expand Down
1 change: 1 addition & 0 deletions examples/LightingNodePRO/LightingNodePRO.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 Down
1 change: 1 addition & 0 deletions examples/MultipleFans/MultipleFans.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 NUMBER_OF_LEDS_PER_FAN 8

Expand Down
1 change: 1 addition & 0 deletions examples/NonAddressable/NonAddressable.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;

// The Arduino pin where the physical LEDs are connected.
// Must be PWM pins
Expand Down
5 changes: 3 additions & 2 deletions examples/RepeatAndScale/RepeatAndScale.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,10 +34,10 @@ void setup() {
ledController.addLEDs(0, ledsChannel1, 50);
ledController.addLEDs(1, ledsChannel2, 60);
ledController.onUpdateHook(0, []() {
CLP::repeat(&ledController, 0, 2);
repeat(&ledController, 0, 2);
});
ledController.onUpdateHook(1, []() {
CLP::scale(&ledController, 1, 144);
scale(&ledController, 1, 144);
});
}

Expand Down
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;

// The number of LEDs per channel.
#define CHANNEL_LED_COUNT 50
Expand All @@ -39,7 +40,7 @@ void setup() {
#ifdef DEBUG
Serial.begin(115200);
#endif
CLP::disableBuildInLEDs();
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 @@ -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,7 +34,7 @@ void setup() {
ledController.addLEDs(0, ledsChannel1, 96);
ledController.addLEDs(1, ledsChannel2, 60);
ledController.onUpdateHook(0, []() {
CLP::transformLLFanToStrip(&ledController, 0);
transformLLFanToStrip(&ledController, 0);
});
}

Expand Down
Loading