|
- static const char *TAG = "screen_leds";
- #include <esp_log.h>
-
- #include "screen_leds.hpp"
-
-
- static inline void fill(uint16_t *buffer, uint16_t value, int w, int h, int p = -1) {
- if (p <= 0) p = w;
- uint16_t *line = buffer;
- while (--h >= 0) {
- uint16_t *pixel = line;
- for (int _w = w; _w > 0; --_w) {
- *pixel = value;
- ++pixel;
- }
- line += p;
- }
- }
-
- static inline void box(uint16_t *buffer, uint16_t value, int x, int y, int w, int h, int p = -1) {
- if (p <= 0) p = w;
- fill(buffer + x + (y * p), value, w, h, p);
- }
-
- static inline uint16_t rgb16(int r, int g, int b) {
- return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((uint8_t)b >> 3);
- }
-
- static inline uint16_t color_to_565(Color c) {
- return rgb16(c.r, c.g, c.b);
- }
-
- ScreenLEDs::ScreenLEDs(int length) : LEDStrip(length), display(135, 240) {}
-
- void ScreenLEDs::length_changing(int length) {
- fill(display.get_buffer(), COLOR_BLACK, display.get_width(), display.get_height());
- }
-
- void ScreenLEDs::show() {
- const int width = display.get_width();
- const int height = display.get_height();
- const int pitch = display.get_pitch();
- auto buffer = display.get_buffer();
-
- const size_t size = ((width + height) * 2) / (length + 4);
-
- int lx = 0, ly = 0;
- int dx = 0, dy = size;
- for (size_t l = 0; l < length; ++l) {
- if (ly + dy > height) {
- ly -= dy;
- dx = size;
- dy = 0;
- lx += dx;
- } else if (ly < 0) {
- ly -= dy;
- dx = -size;
- dy = 0;
- lx += dx;
- } else if (lx + dx > width) {
- lx -= dx;
- dx = 0;
- dy = -size;
- ly += dy;
- } else if (lx < 0) {
- lx -= dx;
- dx = 0;
- dy = size;
- ly += dy;
- }
-
- box(buffer, color_to_565(pixels[l]), lx, ly, size, size, pitch);
-
- lx += dx;
- ly += dy;
- }
-
- display.refresh();
- }
|