Skip to content

Commit 530a334

Browse files
authored
Merge pull request #98 from Legion2/code-refactoring
improve compatibility with other platforms
2 parents bc4e766 + 0589142 commit 530a334

8 files changed

+20
-15
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ sentence=Allows iCUE to control RGB LEDs.
66
paragraph=The library mimics a Lighting Node PRO and can be controlled as such in iCUE.
77
category=Device Control
88
url=https://github.com/Legion2/CorsairLightingProtocol
9-
architectures=*
9+
architectures=avr
1010
includes=CorsairLightingProtocol.h
1111
depends=FastLED

src/CorsairLightingProtocolResponse.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
#include "CorsairLightingProtocolConstants.h"
1818

1919
void CorsairLightingProtocolResponse::send(const uint8_t* data, size_t size) const {
20-
uint8_t response[RESPONSE_SIZE];
21-
memset(response, 0x00, sizeof(response));
20+
uint8_t response[RESPONSE_SIZE] = { 0x00 };
2221
if (size + 1 > sizeof(response)) {
2322
return;
2423
}
@@ -28,18 +27,17 @@ void CorsairLightingProtocolResponse::send(const uint8_t* data, size_t size) con
2827
}
2928

3029
void CorsairLightingProtocolResponse::sendError() const {
31-
uint8_t response[RESPONSE_SIZE];
32-
memset(response, 0x00, sizeof(response));
30+
uint8_t response[RESPONSE_SIZE] = { 0x00 };
3331
response[0] = PROTOCOL_RESPONSE_ERROR;
3432
sendX(response, sizeof(response));
3533
}
3634

3735
void CorsairLightingProtocolResponse::send_P(const uint8_t* data, size_t size) const {
38-
uint8_t response[RESPONSE_SIZE];
39-
memset(response, 0x00, sizeof(response));
36+
uint8_t response[RESPONSE_SIZE] = { 0x00 };
4037
if (size + 1 > sizeof(response)) {
4138
return;
4239
}
40+
response[0] = PROTOCOL_RESPONSE_OK;
4341
memcpy_P(response + 1, data, size);
4442
sendX(response, sizeof(response));
4543
}

src/FanController.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void FanController::handleFanControl(const Command& command, const CorsairLighti
4545
break;
4646
case FanDetectionType::Disconnected:
4747
mask[i] = FanMask::Disconnected;
48+
break;
4849
}
4950
}
5051
response->send(reinterpret_cast<byte*>(mask), sizeof(mask));

src/FastLEDController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,5 +467,5 @@ void FastLEDController::setLEDColorValues(uint8_t channel, uint8_t color, uint8_
467467

468468
void FastLEDController::clearLEDColorValues(uint8_t channel)
469469
{
470-
memset(channelData[channel].valuesBuffer[0], 0, sizeof(channelData[channel].ledCount));
470+
memset(channelData[channel].valuesBuffer[0], 0, channelData[channel].ledCount);
471471
}

src/FastLEDControllerUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void CLP::scale(FastLEDController* controller, uint8_t channelIndex, int scaleTo
3737
auto leds = controller->getLEDs(channelIndex);
3838
const float scaleFactor = (float)controller->getLEDCount(channelIndex) / scaleToSize;
3939
for (int ledIndex = scaleToSize - 1; ledIndex >= 0; ledIndex--) {
40-
leds[ledIndex] = leds[round(ledIndex * scaleFactor)];
40+
leds[ledIndex] = leds[lround(ledIndex * scaleFactor)];
4141
}
4242
}
4343

@@ -66,7 +66,7 @@ void CLP::scaleSegments(FastLEDController* controller, uint8_t channelIndex, con
6666
ledStripIndexAfterScaling -= segments[i].scaleToSize;
6767
ledStripIndexBeforeScaling -= segments[i].segmentLength;
6868
for (int ledIndex = segments[i].scaleToSize - 1; ledIndex >= 0; ledIndex--) {
69-
leds[ledStripIndexAfterScaling + ledIndex] = leds[ledStripIndexBeforeScaling + round(ledIndex * scaleFactor)];
69+
leds[ledStripIndexAfterScaling + ledIndex] = leds[ledStripIndexBeforeScaling + lround(ledIndex * scaleFactor)];
7070
}
7171
}
7272
}

src/LEDController.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ void LEDController::handleLEDControl(const Command& command, const CorsairLighti
5656
Serial.println(F("WriteLedRgbValue"));
5757
#endif
5858
// TODO
59+
response->sendError();
60+
return;
5961
break;
6062
}
6163
case WRITE_LED_COLOR_VALUES:
6264
{
6365
const uint8_t offset = data[1];
64-
const uint8_t inputLength = data[2];
66+
const size_t inputLength = min((size_t)data[2], sizeof(data) - 4);
6567
const uint8_t color = data[3];
6668
if (color >= 3) {
6769
response->sendError();

src/RawHID.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ THE SOFTWARE.
2424
#pragma once
2525

2626
#include <Arduino.h>
27+
28+
#if defined(ARDUINO_ARCH_AVR)
29+
2730
#include "HID.h"
2831
#if defined(USBCON)
2932

@@ -164,3 +167,4 @@ class RawHID_ : public PluggableUSBModule, public Stream
164167
};
165168
extern RawHID_ RawHID;
166169
#endif
170+
#endif

src/TemperatureController.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ void TemperatureController::handleTemperatureControl(const Command& command, con
3737
return;
3838
}
3939
uint16_t temp = getTemperatureValue(tempSensor);
40-
uint8_t tempdata[] = { toBigEndian(temp) };
41-
response->send(tempdata, sizeof(tempdata));
40+
uint8_t tempData[] = { toBigEndian(temp) };
41+
response->send(tempData, sizeof(tempData));
4242
break;
4343
}
4444
case READ_VOLTAGE_VALUE:
@@ -69,8 +69,8 @@ void TemperatureController::handleTemperatureControl(const Command& command, con
6969
}
7070
}
7171

72-
uint8_t voltagedata[] = { toBigEndian(voltage) };
73-
response->send(voltagedata, sizeof(voltagedata));
72+
uint8_t voltageData[] = { toBigEndian(voltage) };
73+
response->send(voltageData, sizeof(voltageData));
7474
break;
7575
}
7676
default:

0 commit comments

Comments
 (0)