Skip to content

Commit 5d9594c

Browse files
authored
Merge pull request #123 from Legion2/timeout
Added timeout to SoftwarePlayback
2 parents 5e483d0 + 01b114b commit 5d9594c

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

src/FastLEDController.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ int FastLEDController::animation_step_count(int duration, int steps) {
8787
bool FastLEDController::updateLEDs() {
8888
lastUpdate = currentUpdate;
8989
currentUpdate = millis();
90+
if (currentUpdate - lastCommand > LED_CONTROLLER_TIMEOUT) {
91+
timeoutAction();
92+
}
9093

9194
bool anyUpdate = false;
9295

@@ -436,3 +439,10 @@ void FastLEDController::setLEDColorValues(uint8_t channel, uint8_t color, uint8_
436439
void FastLEDController::clearLEDColorValues(uint8_t channel) {
437440
memset(channelData[channel].valuesBuffer[0], 0, channelData[channel].ledCount);
438441
}
442+
443+
void FastLEDController::timeoutAction() {
444+
for (int channelId = 0; channelId < CHANNEL_NUM; channelId++) {
445+
triggerSave |= setLEDMode(channelId, ChannelMode::HardwarePlayback);
446+
}
447+
saveIfNeeded();
448+
}

src/FastLEDController.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#define EEPROM_ADDRESS 4
2626
#endif
2727

28+
#ifndef LED_CONTROLLER_TIMEOUT
29+
#define LED_CONTROLLER_TIMEOUT 30000
30+
#endif
31+
2832
/**
2933
* The default LEDController. This controller uses the FastLED library to implement the Hardware Lighting effects. Also
3034
* all RGB values of the LEDs are stored into CRGB arrays which can be used by the FastLED library to show them on the
@@ -154,4 +158,8 @@ class FastLEDController : public LEDController {
154158
virtual void setLEDColorValues(uint8_t channel, uint8_t color, uint8_t offset, const uint8_t* values,
155159
size_t len) override;
156160
virtual void clearLEDColorValues(uint8_t channel) override;
161+
/**
162+
* This function is called when a timeout occurs.
163+
*/
164+
virtual void timeoutAction();
157165
};

src/LEDController.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
#include "TemperatureController.h"
1919

2020
void LEDController::handleLEDControl(const Command& command, const CorsairLightingProtocolResponse* response) {
21+
lastCommand = millis();
2122
auto& data = command.data;
2223
if (command.command == WRITE_LED_TRIGGER) {
2324
triggerLEDUpdate();
24-
if (triggerSave) {
25-
triggerSave = false;
26-
save();
27-
}
25+
saveIfNeeded();
2826
} else {
2927
if (data[0] >= CHANNEL_NUM) {
3028
response->sendError();
@@ -232,4 +230,11 @@ bool LEDController::setLEDPortType(uint8_t channel, PortType ledPortType) {
232230
return true;
233231
}
234232
return false;
235-
}
233+
}
234+
235+
bool LEDController::saveIfNeeded() {
236+
if (triggerSave) {
237+
triggerSave = false;
238+
save();
239+
}
240+
}

src/LEDController.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ class LEDController : public ILEDController {
195195
* Indicates that the configuration of the channels has been changed and should be saved.
196196
*/
197197
bool triggerSave = false;
198+
/**
199+
* Stores the time at which the last command was received by the LEDController.
200+
*/
201+
long lastCommand = 0;
198202

199203
/**
200204
* Trigger update of the LEDs
@@ -246,4 +250,8 @@ class LEDController : public ILEDController {
246250
virtual bool clearLEDGroups(uint8_t channel);
247251
virtual bool save() = 0;
248252
virtual bool load() = 0;
253+
/**
254+
* Save if triggerSave is true and then reset triggerSave.
255+
*/
256+
bool saveIfNeeded();
249257
};

0 commit comments

Comments
 (0)