Skip to content

Commit

Permalink
Reactive LED fixes (#1116)
Browse files Browse the repository at this point in the history
Fixed issue with reactive LEDs not using all configurable LEDs.
Added 2 extra LED slots bringing the count to 10.
  • Loading branch information
mikepparks authored Aug 14, 2024
1 parent 362e23e commit 90a875c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion headers/addons/reactiveleds.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif

#ifndef REACTIVE_LED_COUNT
#define REACTIVE_LED_COUNT 8
#define REACTIVE_LED_COUNT 10
#endif

#ifndef REACTIVE_LED_DELAY
Expand Down
2 changes: 1 addition & 1 deletion proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ message ReactiveLEDInfo
message ReactiveLEDOptions
{
optional bool enabled = 1;
repeated ReactiveLEDInfo leds = 2 [(nanopb).max_count = 8];
repeated ReactiveLEDInfo leds = 2 [(nanopb).max_count = 10];
}

message AddonOptions
Expand Down
6 changes: 3 additions & 3 deletions src/addons/reactiveleds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
bool ReactiveLEDAddon::available() {
bool pinsEnabled = false;
const ReactiveLEDOptions& options = Storage::getInstance().getAddonOptions().reactiveLEDOptions;
for (uint8_t led = 0; led < sizeof(REACTIVE_LED_COUNT); led++) {
for (uint8_t led = 0; led < REACTIVE_LED_COUNT; led++) {
if (isValidPin(options.leds[led].pin)) {
pinsEnabled = true;
break;
Expand All @@ -20,7 +20,7 @@ bool ReactiveLEDAddon::available() {
void ReactiveLEDAddon::setup() {
const ReactiveLEDOptions& options = Storage::getInstance().getAddonOptions().reactiveLEDOptions;

for (uint8_t led = 0; led < sizeof(REACTIVE_LED_COUNT); led++) {
for (uint8_t led = 0; led < REACTIVE_LED_COUNT; led++) {
ReactiveLEDInfo ledInfo = options.leds[led];

ledPins[led].pinNumber = ledInfo.pin;
Expand Down Expand Up @@ -48,7 +48,7 @@ void ReactiveLEDAddon::process() {

uint32_t currUpdate = to_ms_since_boot(get_absolute_time());

for (uint8_t led = 0; led < sizeof(REACTIVE_LED_COUNT); led++) {
for (uint8_t led = 0; led < REACTIVE_LED_COUNT; led++) {
if (isValidPin(ledPins[led].pinNumber) && ledPins[led].action != GpioAction::NONE) {
ledPins[led].currUpdate = currUpdate;
switch (ledPins[led].action) {
Expand Down
6 changes: 3 additions & 3 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ std::string getReactiveLEDs()
DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN);
ReactiveLEDInfo* ledInfo = Storage::getInstance().getAddonOptions().reactiveLEDOptions.leds;

for (uint16_t led = 0; led < 8; led++) {
for (uint16_t led = 0; led < 10; led++) {
writeDoc(doc, "leds", led, "pin", ledInfo[led].pin);
writeDoc(doc, "leds", led, "action", ledInfo[led].action);
writeDoc(doc, "leds", led, "modeDown", ledInfo[led].modeDown);
Expand All @@ -1364,13 +1364,13 @@ std::string setReactiveLEDs()

ReactiveLEDInfo* ledInfo = Storage::getInstance().getAddonOptions().reactiveLEDOptions.leds;

for (uint16_t led = 0; led < 8; led++) {
for (uint16_t led = 0; led < 10; led++) {
ledInfo[led].pin = doc["leds"][led]["pin"];
ledInfo[led].action = doc["leds"][led]["action"];
ledInfo[led].modeDown = doc["leds"][led]["modeDown"];
ledInfo[led].modeUp = doc["leds"][led]["modeUp"];
}
Storage::getInstance().getAddonOptions().reactiveLEDOptions.leds_count = 8;
Storage::getInstance().getAddonOptions().reactiveLEDOptions.leds_count = 10;

Storage::getInstance().save();

Expand Down
2 changes: 2 additions & 0 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ app.get('/api/getReactiveLEDs', (req, res) => {
{ pin: -1, action: -10, modeDown: 1, modeUp: 0 },
{ pin: -1, action: -10, modeDown: 1, modeUp: 0 },
{ pin: -1, action: -10, modeDown: 1, modeUp: 0 },
{ pin: -1, action: -10, modeDown: 1, modeUp: 0 },
{ pin: -1, action: -10, modeDown: 1, modeUp: 0 },
],
});
});
Expand Down

0 comments on commit 90a875c

Please sign in to comment.