Skip to content

Commit

Permalink
Merge pull request #155 from Legion2/dev
Browse files Browse the repository at this point in the history
Version 0.14.0
  • Loading branch information
Legion2 authored Jun 30, 2020
2 parents 7070558 + ca95a0d commit 6187d2e
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ jobs:
RepeatAndScale.ino,
TransformLLFansFormatToStrip.ino,
LS100.ino,
LT100.ino,
LightingNodeCORE.ino,
NonAddressable.ino,
AdditionalFeatures.ino,
AmbientBacklight.ino,
MultipleFans.ino,
DebugSketch.ino
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# 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)
# 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")

<a href="https://www.corsair.com/icue"><img src="extra/images/iCUEDarkBadge.png" alt="iCUE" height="80" /></a>
<a href="https://rgbsync.com/"><img src="extra/images/RGBSyncDarkBadge.png" alt="RGBSync" height="80" /></a>
<a href="https://gitlab.com/CalcProgrammer1/OpenRGB"><img src="extra/images/OpenRGBBadge.png" alt="OpenRGB" height="80" /></a>

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

## Features
* Add support of Corsair DIY device protocol to Arduino.
Expand Down Expand Up @@ -34,7 +39,7 @@ This project provides example sketches for easy use with Arduino IDE.
The library is compatible with all boards using the MCU ATmega32U4.
This includes **Arduino Leonardo**, **SparkFun Pro Micro**, and **Arduino Micro**.
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.
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.
In the rest of the documentation "Arduino" is used as a synonym for all supported boards regardless of the manufacturer.

When you have problems with a board not listed here, please open an [Issue](/~https://github.com/Legion2/CorsairLightingProtocol/issues).
Expand Down
17 changes: 12 additions & 5 deletions examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool waitForSynchronization() {
}

void CLPUSBSerialBridge::sendError() {
memset(rawHIDAndSerialBuffer, 0, sizeof(rawHIDAndSerialBuffer));
memset(rawHIDAndSerialBuffer, 0, RESPONSE_SIZE_16U2);
rawHIDAndSerialBuffer[0] = PROTOCOL_RESPONSE_ERROR;
sendResponse();
}
Expand All @@ -58,7 +58,7 @@ void CLPUSBSerialBridge::sendResponse() {
Serial.print(F("R"));
Serial.println(rawHIDAndSerialBuffer[0], HEX);
#endif // DEBUG
CLP::RawHID.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
CLP::RawHID.write(rawHIDAndSerialBuffer, RESPONSE_SIZE_16U2);
// free the shared buffer to receive new data
CLP::RawHID.enable();
}
Expand All @@ -68,6 +68,7 @@ void CLPUSBSerialBridge::handleHID() {
#ifdef DEBUG
Serial.print(F("C"));
Serial.println(rawHIDAndSerialBuffer[0], HEX);
long time = micros();
#endif // DEBUG
if (!waitForSynchronization()) {
#ifdef DEBUG
Expand All @@ -77,10 +78,10 @@ void CLPUSBSerialBridge::handleHID() {
return;
}

Serial1.write(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
Serial1.write(rawHIDAndSerialBuffer, COMMAND_SIZE);
Serial1.setTimeout(SERIAL_RESPONSE_TIMEOUT);
size_t read = Serial1.readBytes(rawHIDAndSerialBuffer, sizeof(rawHIDAndSerialBuffer));
if (read != sizeof(rawHIDAndSerialBuffer)) {
size_t read = Serial1.readBytes(rawHIDAndSerialBuffer, RESPONSE_SIZE);
if (read != RESPONSE_SIZE) {
#ifdef DEBUG
Serial.print(F("T"));
Serial.println(read);
Expand All @@ -90,5 +91,11 @@ void CLPUSBSerialBridge::handleHID() {
return;
}
sendResponse();

#ifdef DEBUG
long duration = micros() - time;
Serial.print(F("D"));
Serial.println(duration);
#endif // DEBUG
}
}
5 changes: 4 additions & 1 deletion examples/HoodLoader2CLPBridge/CLPUSBSerialBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

#include "Arduino.h"

#if (COMMAND_SIZE == RESPONSE_SIZE)
#if (COMMAND_SIZE >= RESPONSE_SIZE)
#define RAWHID_AND_SERIAL_BUFFER_SIZE COMMAND_SIZE
#endif

// Workaround for 16 byte responses don't work on 16U2 see /~https://github.com/Legion2/CorsairLightingProtocol/pull/152
#define RESPONSE_SIZE_16U2 64

#define SERIAL_SYNCHRONIZATION_TIMEOUT 20
#define SERIAL_RESPONSE_TIMEOUT 10
#define SERIAL_BAUD 1000000
Expand Down
39 changes: 39 additions & 0 deletions examples/LT100/LT100.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2020 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 <FastLED.h>

#define DATA_PIN_CHANNEL_1 2

CRGB ledsChannel1[108];

CorsairLightingFirmware firmware = corsairLT100Firmware();
FastLEDController ledController(true);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

void setup() {
FastLED.addLeds<WS2812B, DATA_PIN_CHANNEL_1, GRB>(ledsChannel1, 108);
ledController.addLEDs(0, ledsChannel1, 108);
}

void loop() {
cHID.update();

if (ledController.updateLEDs()) {
FastLED.show();
}
}
2 changes: 1 addition & 1 deletion extra/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Corsair Lighting Protocol"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.13.0
PROJECT_NUMBER = 0.14.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
Binary file added extra/images/OpenRGBBadge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extra/images/RGBSyncDarkBadge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extra/images/iCUEDarkBadge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Corsair Lighting Protocol
version=0.13.0
version=0.14.0
author=Leon Kiefer
maintainer=Leon Kiefer
sentence=Control LED strips via USB from a PC.
Expand Down
4 changes: 4 additions & 0 deletions src/CorsairLightingFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const uint8_t corsairLightingNodePROFirmwareVersion[FIRMWARE_VERSION_SIZE] PROGM

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

const uint8_t corsairLT100FirmwareVersion[FIRMWARE_VERSION_SIZE] PROGMEM = {0x01, 0x01, 0x38};

CorsairLightingFirmware::CorsairLightingFirmware(const uint8_t* firmwareVersion) : firmwareVersion(firmwareVersion) {
EEPROM.get(EEPROM_ADDRESS_DEVICE_ID, deviceId);
}
Expand Down Expand Up @@ -84,3 +86,5 @@ CorsairLightingFirmware corsairLS100Firmware() {
CorsairLightingFirmware corsairCommanderPROFirmware() {
return CorsairLightingFirmware(corsairCommanderPROFirmwareVersion);
}

CorsairLightingFirmware corsairLT100Firmware() { return CorsairLightingFirmware(corsairLT100FirmwareVersion); }
2 changes: 2 additions & 0 deletions src/CorsairLightingFirmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ CorsairLightingFirmware corsairLightingNodeCOREFirmware();
CorsairLightingFirmware corsairLS100Firmware();

CorsairLightingFirmware corsairCommanderPROFirmware();

CorsairLightingFirmware corsairLT100Firmware();
4 changes: 3 additions & 1 deletion src/CorsairLightingProtocolConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "Arduino.h"

#define COMMAND_SIZE 64
#define RESPONSE_SIZE 64
#define RESPONSE_SIZE 16

#define READ_STATUS 0x01
#define READ_FIRMWARE_VERSION 0x02
Expand Down Expand Up @@ -55,6 +55,8 @@
#define WRITE_LED_BRIGHTNESS 0x39
#define WRITE_LED_COUNT 0x3A
#define WRITE_LED_PORT_TYPE 0x3B
#define WRITE_LED_START_AUTODETECTION 0x3C
#define READ_LED_AUTODETECTION_RESULTS 0x3D

#define PROTOCOL_RESPONSE_OK 0x00
#define PROTOCOL_RESPONSE_ERROR 0x01
Expand Down
4 changes: 0 additions & 4 deletions src/CorsairLightingProtocolHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

#if defined(SUPPORT_RAW_HID)

#if (RAWHID_TX_SIZE != RESPONSE_SIZE)
#error "USB endpoint must be the same size as the protocol response"
#endif

#if defined(DEBUG) && defined(VERBOSE)
bool printCommand = PRINT_COMMAND;
bool printResponse = PRINT_RESPONSE;
Expand Down
2 changes: 2 additions & 0 deletions src/FastLEDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ void FastLEDController::clearLEDColorValues(uint8_t channel) {
}
}

uint8_t FastLEDController::getLEDAutodetectionResult(uint8_t channel) { return channelData[channel].ledCount; }

void FastLEDController::timeoutAction() {
for (int channelId = 0; channelId < CHANNEL_NUM; channelId++) {
triggerSave |= setLEDMode(channelId, ChannelMode::HardwarePlayback);
Expand Down
1 change: 1 addition & 0 deletions src/FastLEDController.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class FastLEDController : public LEDController {
virtual void setLEDColorValues(uint8_t channel, uint8_t color, uint8_t offset, const uint8_t* values,
size_t len) override;
virtual void clearLEDColorValues(uint8_t channel) override;
virtual uint8_t getLEDAutodetectionResult(uint8_t channel) override;
/**
* This function is called when a timeout occurs.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/LEDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ void LEDController::handleLEDControl(const Command& command, const CorsairLighti
triggerSave |= setLEDPortType(channel, portType);
break;
}
case WRITE_LED_START_AUTODETECTION: {
startLEDAutodetection(channel);
break;
}
case READ_LED_AUTODETECTION_RESULTS: {
const uint8_t result = getLEDAutodetectionResult(channel);
uint8_t buffer[] = {result};
response->send(buffer, sizeof(buffer));
// don't send default response
return;
break;
}
default: {
#ifdef DEBUG
Serial.print(F("unkown command: "));
Expand Down Expand Up @@ -232,6 +244,10 @@ bool LEDController::setLEDPortType(uint8_t channel, PortType ledPortType) {
return false;
}

void LEDController::startLEDAutodetection(uint8_t channel) {
// Nothing to do here
}

bool LEDController::saveIfNeeded() {
if (triggerSave) {
triggerSave = false;
Expand Down
16 changes: 16 additions & 0 deletions src/LEDController.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,22 @@ class LEDController : public ILEDController {
*/
virtual void clearLEDColorValues(uint8_t channel) = 0;
virtual bool clearLEDGroups(uint8_t channel);
/**
* Start the potentially long running process to detect the current number of LEDs connected to given channel.
*
* @param channel the channel index
* @see getLEDAutodetectionResult()
*/
virtual void startLEDAutodetection(uint8_t channel);
/**
* Get the result of the LED number autodetection on the given channel.
* Potential values for LT100: 27, 54, 81, 108
*
* @param channel the channel index
* @return the number of LEDs currently connected to the channel
* @see startLEDAutodetection()
*/
virtual uint8_t getLEDAutodetectionResult(uint8_t channel) = 0;
virtual bool save() = 0;
virtual bool load() = 0;
/**
Expand Down
6 changes: 5 additions & 1 deletion src/RawHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ THE SOFTWARE.
#undef RAWHID_USAGE
#define RAWHID_USAGE 0x0C00 // recommended: 0x0100 to 0xFFFF

#if defined(__AVR_ATmega16U2__)
#define RAWHID_TX_SIZE 64
#else
#define RAWHID_TX_SIZE 16
#endif
#define RAWHID_RX_SIZE 64

#endif
Expand All @@ -51,7 +55,7 @@ THE SOFTWARE.

#define EPTYPE_DESCRIPTOR_SIZE uint8_t
// HID Functional Characteristics HID1.11 Page 10 4.4 Interfaces
// Interrupt Out Endpoint is optional, contoll endpoint is used by default
// Interrupt Out Endpoint is optional, control endpoint is used by default
#define ENDPOINT_COUNT 1
namespace CLP {
class RawHID_ : public PluggableUSBModule, public Stream {
Expand Down

0 comments on commit 6187d2e

Please sign in to comment.