From 94f93d88e83072a4a7790f3e7177f46b5a47897b Mon Sep 17 00:00:00 2001 From: jrhoffa Date: Fri, 4 Nov 2022 19:25:21 -0700 Subject: [PATCH] Actually turn off LEDs when state set to off --- main/leds.cpp | 8 ++++++++ main/leds.hpp | 1 + main/main.cpp | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/main/leds.cpp b/main/leds.cpp index bf67917..6ede02e 100644 --- a/main/leds.cpp +++ b/main/leds.cpp @@ -1,6 +1,8 @@ static const char *TAG = "leds"; #include +#include + #include "leds.hpp" #include "utils.hpp" @@ -18,6 +20,7 @@ void LEDStrip::update_state() { } void LEDStrip::setLength(int _length) { + clear(); length_changing(_length); delete[] pixels; length = _length; @@ -29,6 +32,11 @@ void LEDStrip::step() { if (pattern) pattern->step(pixels, length, state); } +void LEDStrip::clear() { + memset(pixels, 0, length * sizeof(*pixels)); + show(); +} + static std::string termcolor(Color c) { return "\x1b[48;2;" + std::to_string((int)c.r) + ";" + diff --git a/main/leds.hpp b/main/leds.hpp index 3a23040..2770ac9 100644 --- a/main/leds.hpp +++ b/main/leds.hpp @@ -34,6 +34,7 @@ public: ~LEDStrip() { if (state) delete state; } void step(); + void clear(); virtual void show() = 0; virtual void length_changing(int) {}; diff --git a/main/main.cpp b/main/main.cpp index 3e3b243..1795378 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -129,7 +129,11 @@ extern "C" void app_main(void) { cJSON_Delete(json); } - LEDStrip *LEDs = new SPI_LEDs(39); //new TerminalLEDs(); + // TerminalLEDs() + // ScreenLEDs() + // SPI_LEDs(39); + LEDStrip *LEDs = new SPI_LEDs(39); + int frequency = 60; while (true) { // Trash the old preset in case we can't find the set effect @@ -172,12 +176,13 @@ extern "C" void app_main(void) { if (!pattern) ESP_LOGW(TAG, "No LED pattern set"); ESP_LOGI(TAG, "Waiting for new config"); + LEDs->clear(); device.wait(); } else { ESP_LOGI(TAG, "Starting animation"); - int period_us = 1000000 / 30; + int period_us = 1000000 / frequency; int64_t target_us = time_us(); int64_t profile_start = target_us; #ifdef PROFILE_PERF