@@ -21,9 +21,7 @@ void fastled_fadeToBlackBy(CRGB* leds, uint16_t num_leds, uint8_t fadeBy) { fade
2121void fastled_fill_solid (struct CRGB * targetArray, int numToFill, const CRGB& color) { fill_solid (targetArray, numToFill, color); }
2222void fastled_fill_rainbow (struct CRGB * targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue) { fill_rainbow (targetArray, numToFill, initialhue, deltahue); }
2323
24- VirtualLayer::VirtualLayer () {
25- EXT_LOGV (ML_TAG, " constructor" );
26- }
24+ VirtualLayer::VirtualLayer () { EXT_LOGV (ML_TAG, " constructor" ); }
2725
2826VirtualLayer::~VirtualLayer () {
2927 EXT_LOGV (ML_TAG, " destructor" );
@@ -138,12 +136,19 @@ void VirtualLayer::setLight(const uint16_t indexV, const uint8_t* channels, uint
138136 }
139137 case m_oneLight: {
140138 uint16_t indexP = mappingTable[indexV].indexP ;
139+ if (layerP->lights .header .lightPreset == 13 ) { // RGB2040 has empty channels: Skip the 20..39 range, so adjust group mapping
140+ indexP = (indexP / 20 * 40 + indexP % 20 );
141+ }
141142 memcpy (&layerP->lights .channels [indexP * layerP->lights .header .channelsPerLight + offset], channels, length);
143+
142144 break ;
143145 }
144146 case m_moreLights:
145147 if (mappingTable[indexV].indexes < mappingTableIndexes.size ())
146148 for (uint16_t indexP : mappingTableIndexes[mappingTable[indexV].indexes ]) {
149+ if (layerP->lights .header .lightPreset == 13 ) { // RGB2040 has empty channels: Skip the 20..39 range, so adjust group mapping
150+ indexP = (indexP / 20 * 40 + indexP % 20 );
151+ }
147152 memcpy (&layerP->lights .channels [indexP * layerP->lights .header .channelsPerLight + offset], channels, length);
148153 }
149154 else
@@ -161,7 +166,11 @@ T VirtualLayer::getLight(const uint16_t indexV, uint8_t offset) const {
161166 if (indexV < mappingTableSize) {
162167 switch (mappingTable[indexV].mapType ) {
163168 case m_oneLight: {
164- T* result = (T*)&layerP->lights .channels [mappingTable[indexV].indexP * layerP->lights .header .channelsPerLight + offset];
169+ uint16_t indexP = mappingTable[indexV].indexP ;
170+ if (layerP->lights .header .lightPreset == 13 ) { // RGB2040 has empty channels: Skip the 20..39 range, so adjust group mapping
171+ indexP = (indexP / 20 * 40 + indexP % 20 );
172+ }
173+ T* result = (T*)&layerP->lights .channels [indexP * layerP->lights .header .channelsPerLight + offset];
165174 return *result; // return the color as CRGB
166175 break ;
167176 }
@@ -208,7 +217,7 @@ void VirtualLayer::fadeToBlackMin() {
208217 // }
209218 // } else
210219 if (layerP->lights .header .channelsPerLight == 3 && layerP->layers .size () == 1 ) { // CRGB lights
211- fastled_fadeToBlackBy ((CRGB*)layerP->lights .channels , layerP->lights .header .nrOfLights , fadeBy);
220+ fastled_fadeToBlackBy ((CRGB*)layerP->lights .channels , layerP->lights .header .nrOfChannels , fadeBy);
212221 } else { // multichannel lights
213222 for (uint16_t index = 0 ; index < nrOfLights; index++) {
214223 CRGB color = getRGB (index); // direct access to the channels
@@ -250,7 +259,7 @@ void VirtualLayer::fill_solid(const CRGB& color) {
250259 // }
251260 // } else
252261 if (layerP->lights .header .channelsPerLight == 3 && layerP->layers .size () == 1 ) { // faster, else manual
253- fastled_fill_solid ((CRGB*)layerP->lights .channels , layerP->lights .header .nrOfLights , color);
262+ fastled_fill_solid ((CRGB*)layerP->lights .channels , layerP->lights .header .nrOfChannels , color);
254263 } else {
255264 for (uint16_t index = 0 ; index < nrOfLights; index++) setRGB (index, color);
256265 }
@@ -270,7 +279,7 @@ void VirtualLayer::fill_rainbow(const uint8_t initialhue, const uint8_t deltahue
270279 // }
271280 // } else
272281 if (layerP->lights .header .channelsPerLight == 3 && layerP->layers .size () == 1 ) { // faster, else manual
273- fastled_fill_rainbow ((CRGB*)layerP->lights .channels , layerP->lights .header .nrOfLights , initialhue, deltahue);
282+ fastled_fill_rainbow ((CRGB*)layerP->lights .channels , layerP->lights .header .nrOfChannels , initialhue, deltahue); // RGB2040 has empty channels
274283 } else {
275284 CHSV hsv;
276285 hsv.hue = initialhue;
0 commit comments