Skip to content

Commit

Permalink
Merge pull request #154 from Legion2/lt100
Browse files Browse the repository at this point in the history
added support for LT100 Smart Lighting Towers
  • Loading branch information
Legion2 authored Jun 30, 2020
2 parents 6e64953 + de973ea commit c59f81a
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 0 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
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();
}
}
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();
2 changes: 2 additions & 0 deletions src/CorsairLightingProtocolConstants.h
Original file line number Diff line number Diff line change
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
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

0 comments on commit c59f81a

Please sign in to comment.