static const char *TAG = "leds"; #include #include #include "gamma.hpp" #include "leds.hpp" #include "utils.hpp" LEDStrip::LEDStrip(int _length) : length(_length), brightness(255), pattern(NULL), pixels(new Color[_length]), colors(new Color[_length]), state(NULL) {} void LEDStrip::update_state() { if (state) delete state; if (pattern) state = pattern->start(length); else state = NULL; } void LEDStrip::setLength(int _length) { clear(); length_changing(_length); delete[] pixels; delete[] colors; length = _length; pixels = new Color[_length]; colors = new Color[_length]; update_state(); } void LEDStrip::step() { if (pattern) pattern->step(colors, length, state); Gamma::correct(pixels, colors, length, brightness); } 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) + ";" + std::to_string((int)c.g) + ";" + std::to_string((int)c.b) + "m"; } void TerminalLEDs::show() { std::string line; for (int i = 0; i < length; i++) { line += termcolor(pixels[i]) + " "; } line += "\x1b[0m"; ESP_LOGI(TAG, "%s", line.c_str()); }