Skip to content

Commit 6187d2e

Browse files
authored
Merge pull request #155 from Legion2/dev
Version 0.14.0
2 parents 7070558 + ca95a0d commit 6187d2e

19 files changed

+115
-16
lines changed

.github/workflows/push.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ jobs:
2828
RepeatAndScale.ino,
2929
TransformLLFansFormatToStrip.ino,
3030
LS100.ino,
31+
LT100.ino,
3132
LightingNodeCORE.ino,
3233
NonAddressable.ino,
34+
AdditionalFeatures.ino,
3335
AmbientBacklight.ino,
3436
MultipleFans.ino,
3537
DebugSketch.ino

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# Corsair Lighting Protocol [![arduino-library-badge](https://www.ardu-badge.com/badge/Corsair%20Lighting%20Protocol.svg?)](https://www.ardu-badge.com/Corsair%20Lighting%20Protocol) [![Test Status](https://github.com/Legion2/CorsairLightingProtocol/workflows/Test/badge.svg)](https://github.com/Legion2/CorsairLightingProtocol/actions?query=workflow%3ATest+branch%3Adev+event%3Apush)
1+
# Corsair Lighting Protocol [![arduino-library-badge](https://www.ardu-badge.com/badge/Corsair%20Lighting%20Protocol.svg?)](https://www.ardu-badge.com/Corsair%20Lighting%20Protocol) [![Test Status](https://github.com/Legion2/CorsairLightingProtocol/workflows/Test/badge.svg)](https://github.com/Legion2/CorsairLightingProtocol/actions?query=workflow%3ATest+branch%3Adev+event%3Apush) [![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/Legion2/CorsairLightingProtocol.svg)](https://isitmaintained.com/project/Legion2/CorsairLightingProtocol "Average time to resolve an issue")
2+
3+
<a href="https://www.corsair.com/icue"><img src="extra/images/iCUEDarkBadge.png" alt="iCUE" height="80" /></a>
4+
<a href="https://rgbsync.com/"><img src="extra/images/RGBSyncDarkBadge.png" alt="RGBSync" height="80" /></a>
5+
<a href="https://gitlab.com/CalcProgrammer1/OpenRGB"><img src="extra/images/OpenRGBBadge.png" alt="OpenRGB" height="80" /></a>
26

37
**This library can be used to integrate custom/unofficial RGB strips with iCUE.**
8+
_This is not an official corsair project._
49

510
## Features
611
* Add support of Corsair DIY device protocol to Arduino.
@@ -34,7 +39,7 @@ This project provides example sketches for easy use with Arduino IDE.
3439
The library is compatible with all boards using the MCU ATmega32U4.
3540
This includes **Arduino Leonardo**, **SparkFun Pro Micro**, and **Arduino Micro**.
3641
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.
37-
It is **not** compatible with Arduino Nano.
42+
It is **not** compatible with ATmega328 (Arduino Nano), STM8S103F3, teensy, ESP8266 and ESP32 see [list of architecture/platform](https://github.com/Legion2/CorsairLightingProtocol/issues?q=is%3Aissue+label%3Aarchitecture%2Fplatform) for a detailed description why they are not supported.
3843
In the rest of the documentation "Arduino" is used as a synonym for all supported boards regardless of the manufacturer.
3944

4045
When you have problems with a board not listed here, please open an [Issue](https://github.com/Legion2/CorsairLightingProtocol/issues).

examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool waitForSynchronization() {
4848
}
4949

5050
void CLPUSBSerialBridge::sendError() {
51-
memset(rawHIDAndSerialBuffer, 0, sizeof(rawHIDAndSerialBuffer));
51+
memset(rawHIDAndSerialBuffer, 0, RESPONSE_SIZE_16U2);
5252
rawHIDAndSerialBuffer[0] = PROTOCOL_RESPONSE_ERROR;
5353
sendResponse();
5454
}
@@ -58,7 +58,7 @@ void CLPUSBSerialBridge::sendResponse() {
5858
Serial.print(F("R"));
5959
Serial.println(rawHIDAndSerialBuffer[0], HEX);
6060
#endif // DEBUG
61-
CLP::RawHID.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
61+
CLP::RawHID.write(rawHIDAndSerialBuffer, RESPONSE_SIZE_16U2);
6262
// free the shared buffer to receive new data
6363
CLP::RawHID.enable();
6464
}
@@ -68,6 +68,7 @@ void CLPUSBSerialBridge::handleHID() {
6868
#ifdef DEBUG
6969
Serial.print(F("C"));
7070
Serial.println(rawHIDAndSerialBuffer[0], HEX);
71+
long time = micros();
7172
#endif // DEBUG
7273
if (!waitForSynchronization()) {
7374
#ifdef DEBUG
@@ -77,10 +78,10 @@ void CLPUSBSerialBridge::handleHID() {
7778
return;
7879
}
7980

80-
Serial1.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
81+
Serial1.write(rawHIDAndSerialBuffer, COMMAND_SIZE);
8182
Serial1.setTimeout(SERIAL_RESPONSE_TIMEOUT);
82-
size_t read = Serial1.readBytes(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
83-
if (read != sizeof(rawHIDAndSerialBuffer)) {
83+
size_t read = Serial1.readBytes(rawHIDAndSerialBuffer, RESPONSE_SIZE);
84+
if (read != RESPONSE_SIZE) {
8485
#ifdef DEBUG
8586
Serial.print(F("T"));
8687
Serial.println(read);
@@ -90,5 +91,11 @@ void CLPUSBSerialBridge::handleHID() {
9091
return;
9192
}
9293
sendResponse();
94+
95+
#ifdef DEBUG
96+
long duration = micros() - time;
97+
Serial.print(F("D"));
98+
Serial.println(duration);
99+
#endif // DEBUG
93100
}
94101
}

examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
#include "Arduino.h"
2121

22-
#if (COMMAND_SIZE == RESPONSE_SIZE)
22+
#if (COMMAND_SIZE >= RESPONSE_SIZE)
2323
#define RAWHID_AND_SERIAL_BUFFER_SIZE COMMAND_SIZE
2424
#endif
2525

26+
// Workaround for 16 byte responses don't work on 16U2 see https://github.com/Legion2/CorsairLightingProtocol/pull/152
27+
#define RESPONSE_SIZE_16U2 64
28+
2629
#define SERIAL_SYNCHRONIZATION_TIMEOUT 20
2730
#define SERIAL_RESPONSE_TIMEOUT 10
2831
#define SERIAL_BAUD 1000000

examples/LT100/LT100.ino

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2020 Leon Kiefer
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
#include <CorsairLightingProtocol.h>
17+
#include <FastLED.h>
18+
19+
#define DATA_PIN_CHANNEL_1 2
20+
21+
CRGB ledsChannel1[108];
22+
23+
CorsairLightingFirmware firmware = corsairLT100Firmware();
24+
FastLEDController ledController(true);
25+
CorsairLightingProtocolController cLP(&ledController, &firmware);
26+
CorsairLightingProtocolHID cHID(&cLP);
27+
28+
void setup() {
29+
FastLED.addLeds<WS2812B, DATA_PIN_CHANNEL_1, GRB>(ledsChannel1, 108);
30+
ledController.addLEDs(0, ledsChannel1, 108);
31+
}
32+
33+
void loop() {
34+
cHID.update();
35+
36+
if (ledController.updateLEDs()) {
37+
FastLED.show();
38+
}
39+
}

extra/doxygen.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = "Corsair Lighting Protocol"
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = 0.13.0
41+
PROJECT_NUMBER = 0.14.0
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

extra/images/OpenRGBBadge.png

23.1 KB
Loading

extra/images/RGBSyncDarkBadge.png

40.5 KB
Loading

extra/images/iCUEDarkBadge.png

26 KB
Loading

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Corsair Lighting Protocol
2-
version=0.13.0
2+
version=0.14.0
33
author=Leon Kiefer
44
maintainer=Leon Kiefer
55
sentence=Control LED strips via USB from a PC.

src/CorsairLightingFirmware.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const uint8_t corsairLightingNodePROFirmwareVersion[FIRMWARE_VERSION_SIZE] PROGM
2323

2424
const uint8_t corsairCommanderPROFirmwareVersion[FIRMWARE_VERSION_SIZE] PROGMEM = {0x00, 0x09, 0xD4};
2525

26+
const uint8_t corsairLT100FirmwareVersion[FIRMWARE_VERSION_SIZE] PROGMEM = {0x01, 0x01, 0x38};
27+
2628
CorsairLightingFirmware::CorsairLightingFirmware(const uint8_t* firmwareVersion) : firmwareVersion(firmwareVersion) {
2729
EEPROM.get(EEPROM_ADDRESS_DEVICE_ID, deviceId);
2830
}
@@ -84,3 +86,5 @@ CorsairLightingFirmware corsairLS100Firmware() {
8486
CorsairLightingFirmware corsairCommanderPROFirmware() {
8587
return CorsairLightingFirmware(corsairCommanderPROFirmwareVersion);
8688
}
89+
90+
CorsairLightingFirmware corsairLT100Firmware() { return CorsairLightingFirmware(corsairLT100FirmwareVersion); }

src/CorsairLightingFirmware.h

+2
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ CorsairLightingFirmware corsairLightingNodeCOREFirmware();
5252
CorsairLightingFirmware corsairLS100Firmware();
5353

5454
CorsairLightingFirmware corsairCommanderPROFirmware();
55+
56+
CorsairLightingFirmware corsairLT100Firmware();

src/CorsairLightingProtocolConstants.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "Arduino.h"
1919

2020
#define COMMAND_SIZE 64
21-
#define RESPONSE_SIZE 64
21+
#define RESPONSE_SIZE 16
2222

2323
#define READ_STATUS 0x01
2424
#define READ_FIRMWARE_VERSION 0x02
@@ -55,6 +55,8 @@
5555
#define WRITE_LED_BRIGHTNESS 0x39
5656
#define WRITE_LED_COUNT 0x3A
5757
#define WRITE_LED_PORT_TYPE 0x3B
58+
#define WRITE_LED_START_AUTODETECTION 0x3C
59+
#define READ_LED_AUTODETECTION_RESULTS 0x3D
5860

5961
#define PROTOCOL_RESPONSE_OK 0x00
6062
#define PROTOCOL_RESPONSE_ERROR 0x01

src/CorsairLightingProtocolHID.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
#if defined(SUPPORT_RAW_HID)
1919

20-
#if (RAWHID_TX_SIZE != RESPONSE_SIZE)
21-
#error "USB endpoint must be the same size as the protocol response"
22-
#endif
23-
2420
#if defined(DEBUG) && defined(VERBOSE)
2521
bool printCommand = PRINT_COMMAND;
2622
bool printResponse = PRINT_RESPONSE;

src/FastLEDController.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ void FastLEDController::clearLEDColorValues(uint8_t channel) {
503503
}
504504
}
505505

506+
uint8_t FastLEDController::getLEDAutodetectionResult(uint8_t channel) { return channelData[channel].ledCount; }
507+
506508
void FastLEDController::timeoutAction() {
507509
for (int channelId = 0; channelId < CHANNEL_NUM; channelId++) {
508510
triggerSave |= setLEDMode(channelId, ChannelMode::HardwarePlayback);

src/FastLEDController.h

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class FastLEDController : public LEDController {
177177
virtual void setLEDColorValues(uint8_t channel, uint8_t color, uint8_t offset, const uint8_t* values,
178178
size_t len) override;
179179
virtual void clearLEDColorValues(uint8_t channel) override;
180+
virtual uint8_t getLEDAutodetectionResult(uint8_t channel) override;
180181
/**
181182
* This function is called when a timeout occurs.
182183
*/

src/LEDController.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ void LEDController::handleLEDControl(const Command& command, const CorsairLighti
149149
triggerSave |= setLEDPortType(channel, portType);
150150
break;
151151
}
152+
case WRITE_LED_START_AUTODETECTION: {
153+
startLEDAutodetection(channel);
154+
break;
155+
}
156+
case READ_LED_AUTODETECTION_RESULTS: {
157+
const uint8_t result = getLEDAutodetectionResult(channel);
158+
uint8_t buffer[] = {result};
159+
response->send(buffer, sizeof(buffer));
160+
// don't send default response
161+
return;
162+
break;
163+
}
152164
default: {
153165
#ifdef DEBUG
154166
Serial.print(F("unkown command: "));
@@ -232,6 +244,10 @@ bool LEDController::setLEDPortType(uint8_t channel, PortType ledPortType) {
232244
return false;
233245
}
234246

247+
void LEDController::startLEDAutodetection(uint8_t channel) {
248+
// Nothing to do here
249+
}
250+
235251
bool LEDController::saveIfNeeded() {
236252
if (triggerSave) {
237253
triggerSave = false;

src/LEDController.h

+16
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ class LEDController : public ILEDController {
264264
*/
265265
virtual void clearLEDColorValues(uint8_t channel) = 0;
266266
virtual bool clearLEDGroups(uint8_t channel);
267+
/**
268+
* Start the potentially long running process to detect the current number of LEDs connected to given channel.
269+
*
270+
* @param channel the channel index
271+
* @see getLEDAutodetectionResult()
272+
*/
273+
virtual void startLEDAutodetection(uint8_t channel);
274+
/**
275+
* Get the result of the LED number autodetection on the given channel.
276+
* Potential values for LT100: 27, 54, 81, 108
277+
*
278+
* @param channel the channel index
279+
* @return the number of LEDs currently connected to the channel
280+
* @see startLEDAutodetection()
281+
*/
282+
virtual uint8_t getLEDAutodetectionResult(uint8_t channel) = 0;
267283
virtual bool save() = 0;
268284
virtual bool load() = 0;
269285
/**

src/RawHID.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ THE SOFTWARE.
4242
#undef RAWHID_USAGE
4343
#define RAWHID_USAGE 0x0C00 // recommended: 0x0100 to 0xFFFF
4444

45+
#if defined(__AVR_ATmega16U2__)
4546
#define RAWHID_TX_SIZE 64
47+
#else
48+
#define RAWHID_TX_SIZE 16
49+
#endif
4650
#define RAWHID_RX_SIZE 64
4751

4852
#endif
@@ -51,7 +55,7 @@ THE SOFTWARE.
5155

5256
#define EPTYPE_DESCRIPTOR_SIZE uint8_t
5357
// HID Functional Characteristics HID1.11 Page 10 4.4 Interfaces
54-
// Interrupt Out Endpoint is optional, contoll endpoint is used by default
58+
// Interrupt Out Endpoint is optional, control endpoint is used by default
5559
#define ENDPOINT_COUNT 1
5660
namespace CLP {
5761
class RawHID_ : public PluggableUSBModule, public Stream {

0 commit comments

Comments
 (0)