Skip to content

Commit

Permalink
Merge pull request #31 from Legion2/dev
Browse files Browse the repository at this point in the history
Version 0.5.0
  • Loading branch information
Legion2 authored Jul 12, 2019
2 parents c4f1d83 + db90cbc commit 6615ffd
Show file tree
Hide file tree
Showing 26 changed files with 1,249 additions and 702 deletions.
37 changes: 35 additions & 2 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
workflow "Test" {
on = "push"
resolves = ["Build examples"]
resolves = [
"Build LightingNodePRO",
"Build CommanderPRO",
"Build SingleStripLightingNodePRO",
"Build HoodLoader2UnoMegaController",
]
}

action "Install FastLED" {
Expand All @@ -11,10 +16,38 @@ action "Install FastLED" {
}
}

action "Build examples" {
action "Build LightingNodePRO" {
uses = "Legion2/arduino-builder-action@master"
needs = ["Install FastLED"]
env = {
BOARD_NAME = "arduino:avr:leonardo"
SKETCH_PATH = "./examples/LightingNodePRO/LightingNodePRO.ino"
}
}

action "Build CommanderPRO" {
uses = "Legion2/arduino-builder-action@master"
needs = ["Install FastLED"]
env = {
BOARD_NAME = "arduino:avr:leonardo"
SKETCH_PATH = "./examples/CommanderPRO/CommanderPRO.ino"
}
}

action "Build SingleStripLightingNodePRO" {
uses = "Legion2/arduino-builder-action@master"
needs = ["Install FastLED"]
env = {
BOARD_NAME = "arduino:avr:micro"
SKETCH_PATH = "./examples/SingleStripLightingNodePRO/SingleStripLightingNodePRO.ino"
}
}

action "Build HoodLoader2UnoMegaController" {
uses = "Legion2/arduino-builder-action@master"
needs = ["Install FastLED"]
env = {
BOARD_NAME = "arduino:avr:uno"
SKETCH_PATH = "./examples/HoodLoader2UnoMegaController/HoodLoader2UnoMegaController.ino"
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
## Requirements
The library is compatible with all boards using the MCU ATmega32U4.
This includes **Arduino Leonardo**, **SparkFun Pro Micro** and **Arduino Micro**.
It is **not** compatible with Arduino Uno, Arduino Mega and Arduino Nano.
It also supports the Arduino Uno and Arduino Mega, **but** this requires the [HoodLoader2](https://github.com/NicoHood/HoodLoader2) bootloader, see [this wiki](https://github.com/Legion2/CorsairLightingProtocol/wiki/How-to-use-on-Arduino-Uno-and-Arduino-Mega) for more details.
It is **not** compatible with Arduino Nano.
In the rest of the documentation "Arduino" is used as synonym for all supported boards regardless of the manufacturer.

In the rest of the documentation the board with the ATmega32U4 is called "Arduino" regardless of the manufacturer.

As an IDE Visual Studio with the extension [Visual Micro](https://marketplace.visualstudio.com/items?itemName=VisualMicro.ArduinoIDEforVisualStudio) is recommended.
As an IDE [Visual Studio](https://visualstudio.microsoft.com/downloads/) with the extension [Visual Micro](https://marketplace.visualstudio.com/items?itemName=VisualMicro.ArduinoIDEforVisualStudio) is recommended.
Visual Micro provides the required functionality for free, but sometimes ask you to buy the full version.
Using the Arduino IDE is difficult, but you can find a tutorial in the [wiki](https://github.com/Legion2/CorsairLightingProtocol/wiki/How-to-use-Arduino-IDE).

Expand Down
15 changes: 5 additions & 10 deletions examples/CommanderPRO/CommanderPRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include "SimpleFanController.h"
#include "ThermistorTemperatureController.h"
#include <CorsairLightingProtocol.h>
#include <LEDController.h>
#include <CorsairLightingProtocolHID.h>
#include <FastLEDController.h>
#include <FastLED.h>

#define DATA_PIN_CHANNEL_1 2
Expand All @@ -35,10 +36,11 @@

const uint8_t firmware_version[FIRMWARE_VERSION_SIZE] PROGMEM = { 0x00, 0x08, 0x00 };

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

CRGB ledsChannel1[CHANNEL_LED_COUNT];
CRGB ledsChannel2[CHANNEL_LED_COUNT];
Expand All @@ -48,8 +50,6 @@ PWMFan fan2(PWM_FAN_PIN_2, 0, 2000);
PWMFan fan3(PWM_FAN_PIN_3, 0, 2000);
PWMFan fan4(PWM_FAN_PIN_4, 0, 2000);

Command command;

void setup() {
disableBuildInLEDs();
FastLED.addLeds<NEOPIXEL, DATA_PIN_CHANNEL_1>(ledsChannel1, CHANNEL_LED_COUNT);
Expand All @@ -62,15 +62,10 @@ void setup() {
fanController.addFan(1, &fan2);
fanController.addFan(2, &fan3);
fanController.addFan(3, &fan4);
cLP.begin();
}

void loop() {
if (cLP.available())
{
cLP.getCommand(command);
cLP.handleCommand(command);
}
cHID.update();

if (ledController.updateLEDs()) {
FastLED.show();
Expand Down
80 changes: 80 additions & 0 deletions examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp
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();
}
}
43 changes: 43 additions & 0 deletions examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.h
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
29 changes: 29 additions & 0 deletions examples/HoodLoader2CLPBridge/HoodLoader2CLPBridge.ino
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();
}
11 changes: 11 additions & 0 deletions examples/HoodLoader2CLPBridge/board.txt
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"'
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();
}
}
6 changes: 6 additions & 0 deletions examples/HoodLoader2UnoMegaController/board.txt
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
1 change: 0 additions & 1 deletion examples/LightingNodePRO/LightingNodePRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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);
cLNP.begin();
}

void loop() {
Expand Down
17 changes: 4 additions & 13 deletions examples/SingleStripLightingNodePRO/SingleStripLightingNodePRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
*/
#include <CorsairLightingNodePRO.h>
#include <CorsairLightingProtocolHID.h>
#include <FastLED.h>

// The number of LEDs per channel, there are two channels.
Expand All @@ -32,15 +33,13 @@
// If enabled, the Hardware Lighting configured in iCUE works without a USB connection and even after a restart of the Arduino.
#define USE_EEPROM true

LEDController<CHANNEL_LED_COUNT> ledController(USE_EEPROM);
FastLEDController<CHANNEL_LED_COUNT> ledController(USE_EEPROM);
CorsairLightingProtocol cLP(&ledController, firmware_version);
CorsairLightingProtocolHID cHID(&cLP);

// This array conatins all RGB values for all LEDs of the both channels.
CRGB leds[NUM_LEDS];

// This variable stores the current command which was received.
Command command;

void setup() {
#ifdef DEBUG
Serial.begin(115200);
Expand All @@ -49,20 +48,12 @@ void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
ledController.addLeds(0, leds);
ledController.addLeds(1, &(leds[CHANNEL_LED_COUNT]));
cLP.begin();
}

void loop() {
if (cLP.available())
{
cLP.getCommand(command);
cLP.handleCommand(command);
}
cHID.update();

if (ledController.updateLEDs()) {
FastLED.show();
}
else {
delay(3);
}
}
Loading

0 comments on commit 6615ffd

Please sign in to comment.