8#include "../shared/color.h"
9#include "../shared/framebuffer.h"
10#include "../shared/settings.h"
11#include "./LedRopeTCL.h"
12#include "../shared/led_layout_array.h"
27Button buttonAllWhite(
"All white");
31 const int length = cols.length;
33 for (
int i = 0; i < length; ++i) {
38 for (
int i = 0; i < length; ++i) {
39 int n = cols.array[i];
40 int stagger = i % 2 ? 4 : 0;
41 for (
int j = 0; j < n; ++j) {
43 screen_map.set(curr_idx++, xy);
54void LedRopeTCL::PreDrawSetup() {
55 if (!lazy_initialized_) {
57 lazy_initialized_ =
true;
62void LedRopeTCL::RawBeginDraw() {
68void LedRopeTCL::RawDrawPixel(
const Color3i& c) {
69 RawDrawPixel(c.r_, c.g_, c.b_);
73void LedRopeTCL::RawDrawPixel(
byte r,
byte g,
byte b) {
74 if (led_buffer_.size() >= mScreenMap.getLength()) {
77 if (buttonAllWhite.isPressed()) {
83 led_buffer_.push_back(
CRGB(r, g, b));
87void LedRopeTCL::RawDrawPixels(
const Color3i& c,
int n) {
88 for (
int i = 0; i < n; ++i) {
94void LedRopeTCL::set_draw_offset(
int val) {
95 draw_offset_ = constrain(val, 0, frame_buffer_.length());
100void LedRopeTCL::RawCommitDraw() {
101 if (!controller_added_) {
102 controller_added_ =
true;
103 CRGB* leds = led_buffer_.data();
104 size_t n_leds = led_buffer_.size();
111LedRopeTCL::LedRopeTCL(
int n_pixels)
112 : draw_offset_(0), lazy_initialized_(false), frame_buffer_(n_pixels) {
113 mScreenMap = init_screenmap();
114 led_buffer_.reserve(mScreenMap.getLength());
118LedRopeTCL::~LedRopeTCL() {
122void LedRopeTCL::Draw() {
125 const Color3i* begin = GetIterator(0);
126 const Color3i* middle = GetIterator(draw_offset_);
127 const Color3i* end = GetIterator(length() - 1);
129 for (
const Color3i* it = middle; it != end; ++it) {
132 for (
const Color3i* it = begin; it != middle; ++it) {
139void LedRopeTCL::DrawSequentialRepeat(
int repeat) {
142 const Color3i* begin = GetIterator(0);
143 const Color3i* middle = GetIterator(draw_offset_);
144 const Color3i* end = GetIterator(length());
145 for (
const Color3i* it = middle; it != end; ++it) {
146 for (
int i = 0; i < repeat; ++i) {
147 RawDrawPixel(it->r_, it->g_, it->b_);
150 for (
const Color3i* it = begin; it != middle; ++it) {
151 for (
int i = 0; i < repeat; ++i) {
152 RawDrawPixel(it->r_, it->g_, it->b_);
159void LedRopeTCL::DrawRepeat(
const int* value_array,
int array_length) {
164 const int len = min(array_length, frame_buffer_.length());
166 for (
int i = 0; i < len; ++i) {
167 const Color3i* cur_color = GetIterator(i);
168 const int repeat_count = value_array[i];
170 for (
int k = 0; k < repeat_count; ++k) {
171 RawDrawPixel(cur_color->r_, cur_color->g_, cur_color->b_);
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
@ APA102
APA102 LED chipset.
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Implements a simple red square effect for 2D LED grids.
Representation of an RGB pixel (Red, Green, Blue)