🐛 Fix dual Neopixels (#22174)

This commit is contained in:
Grumpy 2021-06-22 08:12:39 +12:00 committed by Scott Lahteine
parent 25e7e2fce0
commit 8050813d32
2 changed files with 13 additions and 7 deletions

View File

@ -114,7 +114,6 @@ public:
#if CONJOINED_NEOPIXEL #if CONJOINED_NEOPIXEL
adaneo2.show(); adaneo2.show();
#else #else
IF_DISABLED(NEOPIXEL2_SEPARATE, adaneo1.setPin(NEOPIXEL2_PIN));
adaneo1.show(); adaneo1.show();
adaneo1.setPin(NEOPIXEL_PIN); adaneo1.setPin(NEOPIXEL_PIN);
#endif #endif

View File

@ -52,14 +52,16 @@
* M150 I1 R ; Set NEOPIXEL index 1 to red * M150 I1 R ; Set NEOPIXEL index 1 to red
* M150 S1 I1 R ; Set SEPARATE index 1 to red * M150 S1 I1 R ; Set SEPARATE index 1 to red
*/ */
void GcodeSuite::M150() { void GcodeSuite::M150() {
#if ENABLED(NEOPIXEL_LED) #if ENABLED(NEOPIXEL_LED)
const uint8_t index = parser.intval('I', -1); const int8_t index = parser.intval('I', -1);
#if ENABLED(NEOPIXEL2_SEPARATE) #if ENABLED(NEOPIXEL2_SEPARATE)
const uint8_t unit = parser.intval('S'), int8_t brightness, unit = parser.intval('S', -1);
brightness = unit ? neo2.brightness() : neo.brightness(); switch (unit) {
*(unit ? &neo2.neoindex : &neo.neoindex) = index; case -1: neo2.neoindex = index; // fall-thru
case 0: neo.neoindex = index; brightness = neo.brightness(); break;
case 1: neo2.neoindex = index; brightness = neo2.brightness(); break;
}
#else #else
const uint8_t brightness = neo.brightness(); const uint8_t brightness = neo.brightness();
neo.neoindex = index; neo.neoindex = index;
@ -75,10 +77,15 @@ void GcodeSuite::M150() {
); );
#if ENABLED(NEOPIXEL2_SEPARATE) #if ENABLED(NEOPIXEL2_SEPARATE)
if (unit == 1) { leds2.set_color(color); return; } switch (unit) {
case 0: leds.set_color(color); return;
case 1: leds2.set_color(color); return;
}
#endif #endif
// If 'S' is not specified use both
leds.set_color(color); leds.set_color(color);
TERN_(NEOPIXEL2_SEPARATE, leds2.set_color(color));
} }
#endif // HAS_COLOR_LEDS #endif // HAS_COLOR_LEDS