Skip to content

Commit

Permalink
Remove LED limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Pereira committed Aug 6, 2023
1 parent ee5aaef commit fb97002
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ static bool test_running = false;

char connection_state[64] = "";

static uint8_t leds_on = 0;

typedef struct {
uint8_t strip;
uint16_t led[128];
Expand All @@ -57,26 +55,18 @@ void control_LEDs(void *led_arg) {
led_ctrl led;
memcpy(&led, led_arg, sizeof(led_ctrl));

if (led.n_leds + leds_on > 128) {
vTaskDelete(NULL);
return;
}

for (uint8_t i = 0; i < led.n_leds; i++) {
led_strips[led.strip][led.led[i]] = CRGB(led.r, led.g, led.b);
leds_on++;
}
FastLED.show();

vTaskDelay((led.timeout * 1000) / portTICK_PERIOD_MS);

for (uint8_t i = 0; i < led.n_leds; i++) {
led_strips[led.strip][led.led[i]] = CRGB(0, 0, 0);
leds_on--;
}
FastLED.show();

log_d("Turned strip %u led %u off", led.strip, led.led);

vTaskDelete(NULL);
}

Expand All @@ -96,7 +86,7 @@ void LED_init_sequence(uint16_t group_size = 3) {
led_strips[i][j - group_size] = CRGB(0, 0, 0);
}
}
FastLED.show();
FastLED.show();
log_d("Lighting up LED # %d", j);
}
test_running = false;
Expand All @@ -114,36 +104,36 @@ void mqtt_receive(char *topic, byte *payload, unsigned int length) {
if (strcmp(token, "multiple") == 0) {

DynamicJsonDocument doc(2048);
if (deserializeJson(doc, (char *)payload)) {
log_e("Received invalid JSON");
return;
}
log_d("Deserialized JSON successfully");
log_d("Doc has size: %d", doc.size());
if (deserializeJson(doc, (char *)payload)) {
log_e("Received invalid JSON");
return;
}
log_d("Deserialized JSON successfully");
log_d("Doc has size: %d", doc.size());

uint16_t timeout;
uint16_t timeout;
if (doc.containsKey("timeout")) {
timeout = doc["timeout"];
} else {
timeout = 5;
}
} else {
timeout = 5;
}

log_d("Received command to control %d LEDs", doc["leds"].size());
log_d("Received command to control %d LEDs", doc["leds"].size());

led_ctrl led_c;
led_c.strip = doc["strip"];
led_ctrl led_c;
led_c.strip = doc["strip"];
uint16_t nleds = doc["to"].as<uint16_t>() - doc["from"].as<uint16_t>() + 1;
nleds = nleds > 128 ? 128 : nleds;
for (uint8_t i = 0; i < nleds; i++) {
led_c.led[i] = doc["from"].as<uint16_t>() + i;
}
}
led_c.n_leds = nleds;
led_c.r = doc["color"]["r"];
led_c.g = doc["color"]["g"];
led_c.b = doc["color"]["b"];
led_c.timeout = timeout;
led_c.r = doc["color"]["r"];
led_c.g = doc["color"]["g"];
led_c.b = doc["color"]["b"];
led_c.timeout = timeout;

xTaskCreate(control_LEDs, "control_LEDs", 4096, &led_c, 1, NULL);
xTaskCreate(control_LEDs, "control_LEDs", 4096, &led_c, 1, NULL);
} else if (strcmp(token, "test") == 0) {
LED_init_sequence();
} else {
Expand Down Expand Up @@ -229,7 +219,7 @@ void setup() {
FastLED.addLeds<WS2812, LED_STRIP_5_PIN, GRB>(led_strips[4], NUM_LEDS);
FastLED.addLeds<WS2812, LED_STRIP_6_PIN, GRB>(led_strips[5], NUM_LEDS);

for (uint8_t i = 0; i < NUM_STRIPS; i++) {
for (uint8_t i = 0; i < NUM_STRIPS; i++) {
for (uint16_t j = 0; j < NUM_LEDS; j++) {
led_strips[i][j] = CRGB(0, 0, 0);
}
Expand Down Expand Up @@ -263,8 +253,8 @@ void setup() {
Ethernet.localIP().toString().c_str());
} else {
delay(5000);
ESP.restart();
}
ESP.restart();
}
log_i("%s", connection_state);
if (strcmp(Ethernet.localIP().toString().c_str(), "0.0.0.0") == 0) {
delay(5000);
Expand Down

0 comments on commit fb97002

Please sign in to comment.