From de973eadb99cd56075835960fcd0a2a48f43f3a6 Mon Sep 17 00:00:00 2001 From: Leon Kiefer Date: Wed, 1 Jul 2020 00:41:17 +0200 Subject: [PATCH] added support for LT100 Smart Lighting Towers --- .github/workflows/push.yml | 2 ++ examples/LT100/LT100.ino | 39 ++++++++++++++++++++++++++ src/CorsairLightingFirmware.cpp | 4 +++ src/CorsairLightingFirmware.h | 2 ++ src/CorsairLightingProtocolConstants.h | 2 ++ src/FastLEDController.cpp | 2 ++ src/FastLEDController.h | 1 + src/LEDController.cpp | 16 +++++++++++ src/LEDController.h | 16 +++++++++++ 9 files changed, 84 insertions(+) create mode 100644 examples/LT100/LT100.ino diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 1e9075f5..aefdef2a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -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 diff --git a/examples/LT100/LT100.ino b/examples/LT100/LT100.ino new file mode 100644 index 00000000..bcb04981 --- /dev/null +++ b/examples/LT100/LT100.ino @@ -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 +#include + +#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(ledsChannel1, 108); + ledController.addLEDs(0, ledsChannel1, 108); +} + +void loop() { + cHID.update(); + + if (ledController.updateLEDs()) { + FastLED.show(); + } +} diff --git a/src/CorsairLightingFirmware.cpp b/src/CorsairLightingFirmware.cpp index f7e5f060..ea9c4f53 100644 --- a/src/CorsairLightingFirmware.cpp +++ b/src/CorsairLightingFirmware.cpp @@ -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); } @@ -84,3 +86,5 @@ CorsairLightingFirmware corsairLS100Firmware() { CorsairLightingFirmware corsairCommanderPROFirmware() { return CorsairLightingFirmware(corsairCommanderPROFirmwareVersion); } + +CorsairLightingFirmware corsairLT100Firmware() { return CorsairLightingFirmware(corsairLT100FirmwareVersion); } diff --git a/src/CorsairLightingFirmware.h b/src/CorsairLightingFirmware.h index 84de7e4d..ac2e2a2b 100644 --- a/src/CorsairLightingFirmware.h +++ b/src/CorsairLightingFirmware.h @@ -52,3 +52,5 @@ CorsairLightingFirmware corsairLightingNodeCOREFirmware(); CorsairLightingFirmware corsairLS100Firmware(); CorsairLightingFirmware corsairCommanderPROFirmware(); + +CorsairLightingFirmware corsairLT100Firmware(); diff --git a/src/CorsairLightingProtocolConstants.h b/src/CorsairLightingProtocolConstants.h index 11f34475..ef50fb7b 100644 --- a/src/CorsairLightingProtocolConstants.h +++ b/src/CorsairLightingProtocolConstants.h @@ -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 diff --git a/src/FastLEDController.cpp b/src/FastLEDController.cpp index 8a5a2c9d..a7620e6d 100644 --- a/src/FastLEDController.cpp +++ b/src/FastLEDController.cpp @@ -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); diff --git a/src/FastLEDController.h b/src/FastLEDController.h index f08b23e8..a520f45b 100644 --- a/src/FastLEDController.h +++ b/src/FastLEDController.h @@ -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. */ diff --git a/src/LEDController.cpp b/src/LEDController.cpp index 0859cd4f..c0423329 100644 --- a/src/LEDController.cpp +++ b/src/LEDController.cpp @@ -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: ")); @@ -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; diff --git a/src/LEDController.h b/src/LEDController.h index ac02fd64..ddef3f87 100644 --- a/src/LEDController.h +++ b/src/LEDController.h @@ -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; /**