| @@ -1,6 +1,8 @@ | |||||
| static const char *TAG = "leds"; | static const char *TAG = "leds"; | ||||
| #include <esp_log.h> | #include <esp_log.h> | ||||
| #include <cstring> | |||||
| #include "leds.hpp" | #include "leds.hpp" | ||||
| #include "utils.hpp" | #include "utils.hpp" | ||||
| @@ -18,6 +20,7 @@ void LEDStrip::update_state() { | |||||
| } | } | ||||
| void LEDStrip::setLength(int _length) { | void LEDStrip::setLength(int _length) { | ||||
| clear(); | |||||
| length_changing(_length); | length_changing(_length); | ||||
| delete[] pixels; | delete[] pixels; | ||||
| length = _length; | length = _length; | ||||
| @@ -29,6 +32,11 @@ void LEDStrip::step() { | |||||
| if (pattern) pattern->step(pixels, length, state); | if (pattern) pattern->step(pixels, length, state); | ||||
| } | } | ||||
| void LEDStrip::clear() { | |||||
| memset(pixels, 0, length * sizeof(*pixels)); | |||||
| show(); | |||||
| } | |||||
| static std::string termcolor(Color c) { | static std::string termcolor(Color c) { | ||||
| return "\x1b[48;2;" + | return "\x1b[48;2;" + | ||||
| std::to_string((int)c.r) + ";" + | std::to_string((int)c.r) + ";" + | ||||
| @@ -34,6 +34,7 @@ public: | |||||
| ~LEDStrip() { if (state) delete state; } | ~LEDStrip() { if (state) delete state; } | ||||
| void step(); | void step(); | ||||
| void clear(); | |||||
| virtual void show() = 0; | virtual void show() = 0; | ||||
| virtual void length_changing(int) {}; | virtual void length_changing(int) {}; | ||||
| @@ -129,7 +129,11 @@ extern "C" void app_main(void) { | |||||
| cJSON_Delete(json); | 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) { | while (true) { | ||||
| // Trash the old preset in case we can't find the set effect | // 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"); | if (!pattern) ESP_LOGW(TAG, "No LED pattern set"); | ||||
| ESP_LOGI(TAG, "Waiting for new config"); | ESP_LOGI(TAG, "Waiting for new config"); | ||||
| LEDs->clear(); | |||||
| device.wait(); | device.wait(); | ||||
| } else { | } else { | ||||
| ESP_LOGI(TAG, "Starting animation"); | ESP_LOGI(TAG, "Starting animation"); | ||||
| int period_us = 1000000 / 30; | |||||
| int period_us = 1000000 / frequency; | |||||
| int64_t target_us = time_us(); | int64_t target_us = time_us(); | ||||
| int64_t profile_start = target_us; | int64_t profile_start = target_us; | ||||
| #ifdef PROFILE_PERF | #ifdef PROFILE_PERF | ||||