Skip to content

Commit

Permalink
Merge pull request #60 from Legion2/dev
Browse files Browse the repository at this point in the history
Version 0.7.0
  • Loading branch information
Legion2 authored Nov 14, 2019
2 parents 2749402 + b0b6165 commit 5e1c015
Show file tree
Hide file tree
Showing 49 changed files with 991 additions and 691 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: Legion2
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
sketch: [LightingNodePRO, SingleStripLightingNodePRO, CommanderPRO, DeviceIDTool]
sketch: [LightingNodePRO, SingleStripLightingNodePRO, CommanderPRO, DeviceIDTool, RepeatAndScale, TransformLLFansFormatToStrip]
board: ["arduino:avr:leonardo", "arduino:avr:micro", "SparkFun:avr:promicro:cpu=16MHzatmega32U4"]
steps:
- uses: actions/checkout@master
Expand Down
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [Supported LED chipsets](https://github.com/FastLED/FastLED/wiki/Overview#chipsets).
* Persistent settings for use without a USB connection.
* Use multiple devices at the same time.
* Repeat or scale LED channels to arbitrary size.

![Overview](docs/Overview.png)

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

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

## Create a Lighting Node PRO
Open the example "LightingNodePRO", you can find it in the Visual Micro Explorer or the [examples directory](examples).
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.
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.
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.
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.
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).

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))
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))
Open [iCUE](https://www.corsair.com/icue) there should also be the "Lighting Node PRO".

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

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

## Use the library
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.

# Misc

- [How it works](#how-it-works)
- [Use multiple Devices](#use-multiple-devices)
- [Repeat or scale LED channel](#repeat-or-scale-led-channel)
- [Debugging](#debugging)

## How it works
This library uses the USB HID interface of the Arduino Micro or Leonardo.
In the board.txt the unique VID and PID of a "Lighting Node PRO" are defined.
Expand All @@ -83,8 +88,26 @@ Upload the DeviceIDTool sketch and then open the Serial monitor with baudrate 11
The tool displays the current DeviceID, you can type in a new DeviceID that is saved on the Arduino.
After that, you can upload another sketch.

## Repeat or scale LED channel
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 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.
The functions must be included from `FastLEDControllerUtils.h`.
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.
For example, if you want to duplicate the channel you must pass `2` as argument.
The `scale` function takes as third argument the length of the physical LED strip to which it scales the channel using integer scaling.
For example you have 144 physical LEDs on you strip and 60 on the LED channel.
Then the third argument of the `scale` function is `144`.

For both functions it's **important**, that the CRGB arrays have at least the length of the physical LED strip.
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.

## Debugging
For debugging don't use the integrated debugger of Visual Studio, it will most likely break the USB communication.
For debugging don't use the integrated debugger of Visual Studio, as it will most likely break the USB communication.
Use the `DEBUG` macro and the Serial Monitor.
With the `-DDEBUG` flag you can enable debugging in the whole project.
Add this flag in the board.txt file to the `build.extra_flags`.
Expand All @@ -100,3 +123,7 @@ This is a DO IT YOURSELF project, use at your own risk!
- [HoodLoader2](https://github.com/NicoHood/HoodLoader2)
- [Arduino HID Project](https://github.com/NicoHood/HID)
- [Protocol Information](https://github.com/audiohacked/OpenCorsairLink/issues/70)

## Related projects
- [CorsairArduinoController](https://github.com/TylerSeiford/CorsairArduinoController)
- [OpenCorsairLighting](https://github.com/McHauge/OpenCorsairLighting)
17 changes: 7 additions & 10 deletions examples/CommanderPRO/CommanderPRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include "SimpleFanController.h"
#include "ThermistorTemperatureController.h"
#include <CorsairLightingProtocol.h>
#include <CorsairLightingProtocolHID.h>
#include <FastLEDController.h>
#include <FastLED.h>

#define DATA_PIN_CHANNEL_1 2
Expand All @@ -32,14 +30,13 @@
#define PWM_FAN_PIN_3 9
#define PWM_FAN_PIN_4 10

#define CHANNEL_LED_COUNT 60

const uint8_t firmware_version[FIRMWARE_VERSION_SIZE] PROGMEM = { 0x00, 0x09, 0xD4 };
#define CHANNEL_LED_COUNT 96

CorsairLightingFirmware firmware = corsairCommanderPROFirmware();
ThermistorTemperatureController temperatureController;
FastLEDController<CHANNEL_LED_COUNT> ledController(&temperatureController, true);
FastLEDController ledController(&temperatureController, true);
SimpleFanController fanController(&temperatureController, FAN_UPDATE_RATE, EEPROM_ADDRESS + ledController.getEEPROMSize());
CorsairLightingProtocol cLP(&ledController, &temperatureController, &fanController, firmware_version);
CorsairLightingProtocolController cLP(&ledController, &temperatureController, &fanController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

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

void setup() {
disableBuildInLEDs();
CLP::disableBuildInLEDs();
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);
ledController.addLEDs(0, ledsChannel1, CHANNEL_LED_COUNT);
ledController.addLEDs(1, ledsChannel2, CHANNEL_LED_COUNT);
temperatureController.addSensor(0, TEMP_SENSOR_PIN_1);
temperatureController.addSensor(1, TEMP_SENSOR_PIN_2);
fanController.addFan(0, &fan1);
Expand Down
5 changes: 1 addition & 4 deletions examples/CommanderPRO/PWMFan.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _PWMFan_h
#define _PWMFan_h
#pragma once

#include "Arduino.h"

Expand All @@ -31,5 +30,3 @@ class PWMFan {
const uint16_t minRPM;
const uint16_t maxRPM;
};

#endif
6 changes: 3 additions & 3 deletions examples/CommanderPRO/SimpleFanController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool SimpleFanController::updateFans()
}

for (uint8_t i = 0; i < FAN_NUM; i++) {
if (fans[i] == NULL) {
if (fans[i] == nullptr) {
continue;
}
if (fanData[i].mode == FAN_CONTROL_MODE_FIXED_RPM || fanData[i].mode == FAN_CONTROL_MODE_FIXED_POWER) {
Expand Down Expand Up @@ -105,7 +105,7 @@ void SimpleFanController::setFanSpeed(uint8_t fan, uint16_t speed)
{
fanData[fan].speed = speed;
fanData[fan].mode = FAN_CONTROL_MODE_FIXED_RPM;
fanData[fan].power = fans[fan] != NULL ? fans[fan]->calculatePowerFromSpeed(speed) : 0;
fanData[fan].power = fans[fan] != nullptr ? fans[fan]->calculatePowerFromSpeed(speed) : 0;
trigger_save = true;
}

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

Expand Down
8 changes: 2 additions & 6 deletions examples/CommanderPRO/SimpleFanController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _SimpleFanController_h
#define _SimpleFanController_h
#pragma once

#include "Arduino.h"
#include "FanController.h"
Expand Down Expand Up @@ -57,7 +56,7 @@ class SimpleFanController : public FanController {
bool save();

TemperatureController* const temperatureController;
PWMFan* fans[FAN_NUM] = { NULL };
PWMFan* fans[FAN_NUM] = { nullptr };
bool force3PinMode = false;
FanData fanData[FAN_NUM];
uint16_t externalTemp[FAN_NUM];
Expand All @@ -66,6 +65,3 @@ class SimpleFanController : public FanController {
bool trigger_save = false;
long lastUpdate = 0;
};

#endif

6 changes: 1 addition & 5 deletions examples/CommanderPRO/ThermistorTemperatureController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _ThermistorTemperatureController_h
#define _ThermistorTemperatureController_h
#pragma once

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

uint8_t sensorPins[TEMPERATURE_NUM] = { 0 };
};

#endif

16 changes: 9 additions & 7 deletions examples/DebugSketch/DebugSketch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <CorsairLightingNodePRO.h>
#include <CorsairLightingProtocol.h>
#include <FastLED.h>
#include <EEPROM.h>

#define CHANNEL_LED_COUNT 60
#define CHANNEL_LED_COUNT 96

#define DATA_PIN_CHANNEL_1 2
#define DATA_PIN_CHANNEL_2 3

FastLEDController<CHANNEL_LED_COUNT> ledController(true);
CorsairLightingProtocol cLP(&ledController, firmware_version);
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
FastLEDController ledController(true);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cLPS(&cLP);

CRGB ledsChannel1[CHANNEL_LED_COUNT];
Expand All @@ -36,8 +38,8 @@ void setup() {
Serial.setTimeout(100);
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);
ledController.addLEDs(0, ledsChannel1, CHANNEL_LED_COUNT);
ledController.addLEDs(1, ledsChannel2, CHANNEL_LED_COUNT);
}

void loop() {
Expand All @@ -60,7 +62,7 @@ void processCommand(String& cmd) {
if (cmd == F("print DeviceID")) {
byte DeviceId[4];
EEPROM.get(EEPROM_ADDRESS_DEVICE_ID, DeviceId);
printDeviceID(DeviceId);
CLP::printDeviceID(DeviceId);
Serial.println();
}
#ifdef VERBOSE
Expand Down
12 changes: 6 additions & 6 deletions examples/DeviceIDTool/DeviceIDTool.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup() {
; // wait for serial port to connect. Needed for native USB
}
Serial.print(F("Current DeviceID: "));
printDeviceID(deviceID);
CLP::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 Blocks with 2 digits separated by white space."));
Serial.println();
Expand All @@ -53,12 +53,12 @@ void loop() {
else {
uint8_t newDeviceID[4];

newDeviceID[0] = strtol(&inputString[0], NULL, 16);
newDeviceID[1] = strtol(&inputString[3], NULL, 16);
newDeviceID[2] = strtol(&inputString[6], NULL, 16);
newDeviceID[3] = strtol(&inputString[9], NULL, 16);
newDeviceID[0] = strtol(&inputString[0], nullptr, 16);
newDeviceID[1] = strtol(&inputString[3], nullptr, 16);
newDeviceID[2] = strtol(&inputString[6], nullptr, 16);
newDeviceID[3] = strtol(&inputString[9], nullptr, 16);
Serial.println(F("Set DeviceID to: "));
printDeviceID(newDeviceID);
CLP::printDeviceID(newDeviceID);
Serial.println();
if (isNullID(newDeviceID)) {
Serial.println(F("This is a special DeviceID, it will generate a new random DeviceID next time iCUE controls the device!"));
Expand Down
5 changes: 1 addition & 4 deletions examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _CLPUSBSerialBridge_h
#define _CLPUSBSerialBridge_h
#pragma once

#include "Arduino.h"
#include <CorsairLightingProtocolConstants.h>
Expand All @@ -39,5 +38,3 @@ class CLPUSBSerialBridge {
void sendError();
void sendResponse();
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
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 CHANNEL_LED_COUNT 96

#define DATA_PIN_CHANNEL_1 2
#define DATA_PIN_CHANNEL_2 3

FastLEDController<CHANNEL_LED_COUNT> ledController(true);
CorsairLightingProtocol cLP(&ledController, firmware_version);
CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
FastLEDController ledController(true);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolSerial cLPS(&cLP);

CRGB ledsChannel1[CHANNEL_LED_COUNT];
Expand All @@ -39,8 +37,8 @@ void setup() {
cLPS.setup();
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);
ledController.addLEDs(0, ledsChannel1, CHANNEL_LED_COUNT);
ledController.addLEDs(1, ledsChannel2, CHANNEL_LED_COUNT);
}

void loop() {
Expand Down
12 changes: 5 additions & 7 deletions examples/LightingNodePRO/LightingNodePRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
#define DATA_PIN_CHANNEL_1 2
#define DATA_PIN_CHANNEL_2 3

CRGB ledsChannel1[CHANNEL_LED_COUNT];
CRGB ledsChannel2[CHANNEL_LED_COUNT];

CorsairLightingNodePRO cLNP(ledsChannel1, ledsChannel2);
CorsairLightingNodePRO cLNP;

void setup() {
disableBuildInLEDs();
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledsChannel1, CHANNEL_LED_COUNT);
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledsChannel2, CHANNEL_LED_COUNT);
CLP::disableBuildInLEDs();
auto ledController = cLNP.getFastLEDController();
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledController->getLEDs(0), ledController->getLEDCount(0));
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_2>(ledController->getLEDs(1), ledController->getLEDCount(1));
}

void loop() {
Expand Down
Loading

0 comments on commit 5e1c015

Please sign in to comment.