Skip to content

Commit 5e1c015

Browse files
authored
Merge pull request #60 from Legion2/dev
Version 0.7.0
2 parents 2749402 + b0b6165 commit 5e1c015

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+991
-691
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These are supported funding model platforms
22

3-
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3+
github: Legion2
44
patreon: # Replace with a single Patreon username
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
sketch: [LightingNodePRO, SingleStripLightingNodePRO, CommanderPRO, DeviceIDTool]
9+
sketch: [LightingNodePRO, SingleStripLightingNodePRO, CommanderPRO, DeviceIDTool, RepeatAndScale, TransformLLFansFormatToStrip]
1010
board: ["arduino:avr:leonardo", "arduino:avr:micro", "SparkFun:avr:promicro:cpu=16MHzatmega32U4"]
1111
steps:
1212
- uses: actions/checkout@master

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [Supported LED chipsets](https://github.com/FastLED/FastLED/wiki/Overview#chipsets).
1212
* Persistent settings for use without a USB connection.
1313
* Use multiple devices at the same time.
14+
* Repeat or scale LED channels to arbitrary size.
1415

1516
![Overview](docs/Overview.png)
1617

@@ -20,9 +21,6 @@
2021
- [Install the library](#install-the-library)
2122
- [Create a Lighting Node PRO](#create-a-lighting-node-pro)
2223
- [Use the library](#use-the-library)
23-
- [How it works](#how-it-works)
24-
- [Use multiple Devices](#use-multiple-devices)
25-
- [Debugging](#debugging)
2624

2725
## Requirements
2826
The library is compatible with all boards using the MCU ATmega32U4.
@@ -43,11 +41,11 @@ Additionally, the [FastLED](http://fastled.io/) library must be installed.
4341

4442
## Create a Lighting Node PRO
4543
Open the example "LightingNodePRO", you can find it in the Visual Micro Explorer or the [examples directory](examples).
46-
The library [FastLED](http://fastled.io/) is used to control the LEDs, for more information on [how to wiring the leds](https://github.com/FastLED/FastLED/wiki/Wiring-leds) and [how to set up the LEDs in the code](https://github.com/FastLED/FastLED/wiki/Basic-usage#setting-up-the-leds) see the links.
47-
After you did the wiring or at least know which pin is the data pin, you can set this pin in the example sketch and upload it to the Arduino.
44+
The library [FastLED](http://fastled.io/) is used to control the LEDs. For more information on [how to wire the leds](https://github.com/FastLED/FastLED/wiki/Wiring-leds) and [how to set up the LEDs in the code](https://github.com/FastLED/FastLED/wiki/Basic-usage#setting-up-the-leds) see the links.
45+
After you have done the wiring or at least know which pin is the data pin, you can set this pin in the example sketch and upload it to the Arduino.
4846
In Visual Studio use the "Release" [configuration](https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/debugger/how-to-set-debug-and-release-configurations.md#change-the-build-configuration).
4947

50-
To verify the library works as expected open the Windows settings -> devices -> connected devices. Somewhere in the list of devices, there should be a device called "Lighting Node PRO". (If not, please open an [Issue](https://github.com/Legion2/CorsairLightingProtocol/issues))
48+
To verify that the library works as expected, open the Windows settings -> devices -> connected devices. Somewhere in the list of devices, there should be a device called "Lighting Node PRO". (If not, please open an [Issue](https://github.com/Legion2/CorsairLightingProtocol/issues))
5149
Open [iCUE](https://www.corsair.com/icue) there should also be the "Lighting Node PRO".
5250

5351
![iCUE RGB Strip example](docs/iCUE.jpg)
@@ -58,11 +56,18 @@ So if you have 20 LEDs, set the amount to 2.
5856
Now you can create lighting effects in the "Lighting Channel #" tabs.
5957

6058
The example "SingleStripLightingNodePRO" only requires one LED strip connected to the Arduino.
61-
Because the "SingleStripLightingNodePRO" concatenate the two channels a total of 120 LEDs can be controlled on a single LED Strip.
59+
Because the "SingleStripLightingNodePRO" concatenate the two channels, a total of 120 LEDs can be controlled on a single LED Strip.
6260

6361
## Use the library
6462
If you want to use this library in your own sketch don't forget to use Visual Studio as IDE and include the [board.txt](examples/LightingNodePRO/board.txt) in the root directory of your sketch.
6563

64+
# Misc
65+
66+
- [How it works](#how-it-works)
67+
- [Use multiple Devices](#use-multiple-devices)
68+
- [Repeat or scale LED channel](#repeat-or-scale-led-channel)
69+
- [Debugging](#debugging)
70+
6671
## How it works
6772
This library uses the USB HID interface of the Arduino Micro or Leonardo.
6873
In the board.txt the unique VID and PID of a "Lighting Node PRO" are defined.
@@ -83,8 +88,26 @@ Upload the DeviceIDTool sketch and then open the Serial monitor with baudrate 11
8388
The tool displays the current DeviceID, you can type in a new DeviceID that is saved on the Arduino.
8489
After that, you can upload another sketch.
8590

91+
## Repeat or scale LED channel
92+
You can repeat or scale LED channel controlled by iCUE onto physical LED strips.
93+
This is very useful if you have very long LED strips that are longer than 60/96 LEDs.
94+
This is the maximum number iCUE supports.
95+
96+
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.
97+
The functions must be included from `FastLEDControllerUtils.h`.
98+
See the [RepeatAndScale](examples/RepeatAndScale/RepeatAndScale.ino) example for the complete code.
99+
Both functions take the FastLEDController pointer and the channel index as arguments.
100+
Additionally, the `repeat` function takes as an argument how often the LED channel should be repeated.
101+
For example, if you want to duplicate the channel you must pass `2` as argument.
102+
The `scale` function takes as third argument the length of the physical LED strip to which it scales the channel using integer scaling.
103+
For example you have 144 physical LEDs on you strip and 60 on the LED channel.
104+
Then the third argument of the `scale` function is `144`.
105+
106+
For both functions it's **important**, that the CRGB arrays have at least the length of the physical LED strip.
107+
This means if your LED channel from iCUE has 50 LEDs and you use the `repeat` function to control 100 physical LEDs you MUST declare the CRGB array at least with a length of 100.
108+
86109
## Debugging
87-
For debugging don't use the integrated debugger of Visual Studio, it will most likely break the USB communication.
110+
For debugging don't use the integrated debugger of Visual Studio, as it will most likely break the USB communication.
88111
Use the `DEBUG` macro and the Serial Monitor.
89112
With the `-DDEBUG` flag you can enable debugging in the whole project.
90113
Add this flag in the board.txt file to the `build.extra_flags`.
@@ -100,3 +123,7 @@ This is a DO IT YOURSELF project, use at your own risk!
100123
- [HoodLoader2](https://github.com/NicoHood/HoodLoader2)
101124
- [Arduino HID Project](https://github.com/NicoHood/HID)
102125
- [Protocol Information](https://github.com/audiohacked/OpenCorsairLink/issues/70)
126+
127+
## Related projects
128+
- [CorsairArduinoController](https://github.com/TylerSeiford/CorsairArduinoController)
129+
- [OpenCorsairLighting](https://github.com/McHauge/OpenCorsairLighting)

examples/CommanderPRO/CommanderPRO.ino

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "SimpleFanController.h"
1717
#include "ThermistorTemperatureController.h"
1818
#include <CorsairLightingProtocol.h>
19-
#include <CorsairLightingProtocolHID.h>
20-
#include <FastLEDController.h>
2119
#include <FastLED.h>
2220

2321
#define DATA_PIN_CHANNEL_1 2
@@ -32,14 +30,13 @@
3230
#define PWM_FAN_PIN_3 9
3331
#define PWM_FAN_PIN_4 10
3432

35-
#define CHANNEL_LED_COUNT 60
36-
37-
const uint8_t firmware_version[FIRMWARE_VERSION_SIZE] PROGMEM = { 0x00, 0x09, 0xD4 };
33+
#define CHANNEL_LED_COUNT 96
3834

35+
CorsairLightingFirmware firmware = corsairCommanderPROFirmware();
3936
ThermistorTemperatureController temperatureController;
40-
FastLEDController<CHANNEL_LED_COUNT> ledController(&temperatureController, true);
37+
FastLEDController ledController(&temperatureController, true);
4138
SimpleFanController fanController(&temperatureController, FAN_UPDATE_RATE, EEPROM_ADDRESS + ledController.getEEPROMSize());
42-
CorsairLightingProtocol cLP(&ledController, &temperatureController, &fanController, firmware_version);
39+
CorsairLightingProtocolController cLP(&ledController, &temperatureController, &fanController, &firmware);
4340
CorsairLightingProtocolHID cHID(&cLP);
4441

4542
CRGB ledsChannel1[CHANNEL_LED_COUNT];
@@ -51,11 +48,11 @@ PWMFan fan3(PWM_FAN_PIN_3, 0, 2000);
5148
PWMFan fan4(PWM_FAN_PIN_4, 0, 2000);
5249

5350
void setup() {
54-
disableBuildInLEDs();
51+
CLP::disableBuildInLEDs();
5552
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledsChannel1, CHANNEL_LED_COUNT);
5653
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledsChannel2, CHANNEL_LED_COUNT);
57-
ledController.addLeds(0, ledsChannel1);
58-
ledController.addLeds(1, ledsChannel2);
54+
ledController.addLEDs(0, ledsChannel1, CHANNEL_LED_COUNT);
55+
ledController.addLEDs(1, ledsChannel2, CHANNEL_LED_COUNT);
5956
temperatureController.addSensor(0, TEMP_SENSOR_PIN_1);
6057
temperatureController.addSensor(1, TEMP_SENSOR_PIN_2);
6158
fanController.addFan(0, &fan1);

examples/CommanderPRO/PWMFan.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#ifndef _PWMFan_h
17-
#define _PWMFan_h
16+
#pragma once
1817

1918
#include "Arduino.h"
2019

@@ -31,5 +30,3 @@ class PWMFan {
3130
const uint16_t minRPM;
3231
const uint16_t maxRPM;
3332
};
34-
35-
#endif

examples/CommanderPRO/SimpleFanController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool SimpleFanController::updateFans()
5151
}
5252

5353
for (uint8_t i = 0; i < FAN_NUM; i++) {
54-
if (fans[i] == NULL) {
54+
if (fans[i] == nullptr) {
5555
continue;
5656
}
5757
if (fanData[i].mode == FAN_CONTROL_MODE_FIXED_RPM || fanData[i].mode == FAN_CONTROL_MODE_FIXED_POWER) {
@@ -105,7 +105,7 @@ void SimpleFanController::setFanSpeed(uint8_t fan, uint16_t speed)
105105
{
106106
fanData[fan].speed = speed;
107107
fanData[fan].mode = FAN_CONTROL_MODE_FIXED_RPM;
108-
fanData[fan].power = fans[fan] != NULL ? fans[fan]->calculatePowerFromSpeed(speed) : 0;
108+
fanData[fan].power = fans[fan] != nullptr ? fans[fan]->calculatePowerFromSpeed(speed) : 0;
109109
trigger_save = true;
110110
}
111111

@@ -118,7 +118,7 @@ void SimpleFanController::setFanPower(uint8_t fan, uint8_t percentage)
118118
{
119119
fanData[fan].power = percentage;
120120
fanData[fan].mode = FAN_CONTROL_MODE_FIXED_POWER;
121-
fanData[fan].speed = fans[fan] != NULL ? fans[fan]->calculateSpeedFromPower(percentage) : 0;
121+
fanData[fan].speed = fans[fan] != nullptr ? fans[fan]->calculateSpeedFromPower(percentage) : 0;
122122
trigger_save = true;
123123
}
124124

examples/CommanderPRO/SimpleFanController.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#ifndef _SimpleFanController_h
17-
#define _SimpleFanController_h
16+
#pragma once
1817

1918
#include "Arduino.h"
2019
#include "FanController.h"
@@ -57,7 +56,7 @@ class SimpleFanController : public FanController {
5756
bool save();
5857

5958
TemperatureController* const temperatureController;
60-
PWMFan* fans[FAN_NUM] = { NULL };
59+
PWMFan* fans[FAN_NUM] = { nullptr };
6160
bool force3PinMode = false;
6261
FanData fanData[FAN_NUM];
6362
uint16_t externalTemp[FAN_NUM];
@@ -66,6 +65,3 @@ class SimpleFanController : public FanController {
6665
bool trigger_save = false;
6766
long lastUpdate = 0;
6867
};
69-
70-
#endif
71-

examples/CommanderPRO/ThermistorTemperatureController.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#ifndef _ThermistorTemperatureController_h
17-
#define _ThermistorTemperatureController_h
16+
#pragma once
1817

1918
#include "TemperatureController.h"
2019
/*
@@ -35,6 +34,3 @@ class ThermistorTemperatureController : public TemperatureController {
3534

3635
uint8_t sensorPins[TEMPERATURE_NUM] = { 0 };
3736
};
38-
39-
#endif
40-

examples/DebugSketch/DebugSketch.ino

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include <CorsairLightingNodePRO.h>
16+
#include <CorsairLightingProtocol.h>
1717
#include <FastLED.h>
18+
#include <EEPROM.h>
1819

19-
#define CHANNEL_LED_COUNT 60
20+
#define CHANNEL_LED_COUNT 96
2021

2122
#define DATA_PIN_CHANNEL_1 2
2223
#define DATA_PIN_CHANNEL_2 3
2324

24-
FastLEDController<CHANNEL_LED_COUNT> ledController(true);
25-
CorsairLightingProtocol cLP(&ledController, firmware_version);
25+
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
26+
FastLEDController ledController(true);
27+
CorsairLightingProtocolController cLP(&ledController, &firmware);
2628
CorsairLightingProtocolHID cLPS(&cLP);
2729

2830
CRGB ledsChannel1[CHANNEL_LED_COUNT];
@@ -36,8 +38,8 @@ void setup() {
3638
Serial.setTimeout(100);
3739
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledsChannel1, CHANNEL_LED_COUNT);
3840
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledsChannel2, CHANNEL_LED_COUNT);
39-
ledController.addLeds(0, ledsChannel1);
40-
ledController.addLeds(1, ledsChannel2);
41+
ledController.addLEDs(0, ledsChannel1, CHANNEL_LED_COUNT);
42+
ledController.addLEDs(1, ledsChannel2, CHANNEL_LED_COUNT);
4143
}
4244

4345
void loop() {
@@ -60,7 +62,7 @@ void processCommand(String& cmd) {
6062
if (cmd == F("print DeviceID")) {
6163
byte DeviceId[4];
6264
EEPROM.get(EEPROM_ADDRESS_DEVICE_ID, DeviceId);
63-
printDeviceID(DeviceId);
65+
CLP::printDeviceID(DeviceId);
6466
Serial.println();
6567
}
6668
#ifdef VERBOSE

examples/DeviceIDTool/DeviceIDTool.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void setup() {
3535
; // wait for serial port to connect. Needed for native USB
3636
}
3737
Serial.print(F("Current DeviceID: "));
38-
printDeviceID(deviceID);
38+
CLP::printDeviceID(deviceID);
3939
Serial.println();
4040
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 Blocks with 2 digits separated by white space."));
4141
Serial.println();
@@ -53,12 +53,12 @@ void loop() {
5353
else {
5454
uint8_t newDeviceID[4];
5555

56-
newDeviceID[0] = strtol(&inputString[0], NULL, 16);
57-
newDeviceID[1] = strtol(&inputString[3], NULL, 16);
58-
newDeviceID[2] = strtol(&inputString[6], NULL, 16);
59-
newDeviceID[3] = strtol(&inputString[9], NULL, 16);
56+
newDeviceID[0] = strtol(&inputString[0], nullptr, 16);
57+
newDeviceID[1] = strtol(&inputString[3], nullptr, 16);
58+
newDeviceID[2] = strtol(&inputString[6], nullptr, 16);
59+
newDeviceID[3] = strtol(&inputString[9], nullptr, 16);
6060
Serial.println(F("Set DeviceID to: "));
61-
printDeviceID(newDeviceID);
61+
CLP::printDeviceID(newDeviceID);
6262
Serial.println();
6363
if (isNullID(newDeviceID)) {
6464
Serial.println(F("This is a special DeviceID, it will generate a new random DeviceID next time iCUE controls the device!"));

examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#ifndef _CLPUSBSerialBridge_h
17-
#define _CLPUSBSerialBridge_h
16+
#pragma once
1817

1918
#include "Arduino.h"
2019
#include <CorsairLightingProtocolConstants.h>
@@ -39,5 +38,3 @@ class CLPUSBSerialBridge {
3938
void sendError();
4039
void sendResponse();
4140
};
42-
43-
#endif

examples/HoodLoader2UnoMegaController/HoodLoader2UnoMegaController.ino

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414
limitations under the License.
1515
*/
1616
#include <CorsairLightingProtocol.h>
17-
#include <CorsairLightingProtocolSerial.h>
18-
#include <CorsairLightingNodePRO.h>
19-
#include <FastLEDController.h>
2017
#include <FastLED.h>
2118

22-
#define CHANNEL_LED_COUNT 60
19+
#define CHANNEL_LED_COUNT 96
2320

2421
#define DATA_PIN_CHANNEL_1 2
2522
#define DATA_PIN_CHANNEL_2 3
2623

27-
FastLEDController<CHANNEL_LED_COUNT> ledController(true);
28-
CorsairLightingProtocol cLP(&ledController, firmware_version);
24+
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
25+
FastLEDController ledController(true);
26+
CorsairLightingProtocolController cLP(&ledController, &firmware);
2927
CorsairLightingProtocolSerial cLPS(&cLP);
3028

3129
CRGB ledsChannel1[CHANNEL_LED_COUNT];
@@ -39,8 +37,8 @@ void setup() {
3937
cLPS.setup();
4038
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledsChannel1, CHANNEL_LED_COUNT);
4139
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledsChannel2, CHANNEL_LED_COUNT);
42-
ledController.addLeds(0, ledsChannel1);
43-
ledController.addLeds(1, ledsChannel2);
40+
ledController.addLEDs(0, ledsChannel1, CHANNEL_LED_COUNT);
41+
ledController.addLEDs(1, ledsChannel2, CHANNEL_LED_COUNT);
4442
}
4543

4644
void loop() {

examples/LightingNodePRO/LightingNodePRO.ino

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
#define DATA_PIN_CHANNEL_1 2
2020
#define DATA_PIN_CHANNEL_2 3
2121

22-
CRGB ledsChannel1[CHANNEL_LED_COUNT];
23-
CRGB ledsChannel2[CHANNEL_LED_COUNT];
24-
25-
CorsairLightingNodePRO cLNP(ledsChannel1, ledsChannel2);
22+
CorsairLightingNodePRO cLNP;
2623

2724
void setup() {
28-
disableBuildInLEDs();
29-
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledsChannel1, CHANNEL_LED_COUNT);
30-
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledsChannel2, CHANNEL_LED_COUNT);
25+
CLP::disableBuildInLEDs();
26+
auto ledController = cLNP.getFastLEDController();
27+
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledController->getLEDs(0), ledController->getLEDCount(0));
28+
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledController->getLEDs(1), ledController->getLEDCount(1));
3129
}
3230

3331
void loop() {

0 commit comments

Comments
 (0)