|
- static const char *TAG = "leds";
- #include <esp_log.h>
-
- #include "leds.hpp"
- #include "utils.hpp"
-
-
- LEDStrip::LEDStrip(int _length) :
- length(_length), pattern(NULL),
- pixels(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) {
- length_changing(_length);
- delete[] pixels;
- length = _length;
- pixels = new Color[_length];
- update_state();
- }
-
- void LEDStrip::step() {
- if (pattern) pattern->step(pixels, length, state);
- }
-
- 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());
- }
|