Skip to content

Commit

Permalink
🐛 Fix dual Neopixels (MarlinFirmware#22174)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSaffer authored and ptoal committed Dec 16, 2021
1 parent 1c5e190 commit 7b580fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion Marlin/src/feature/leds/neopixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class Marlin_NeoPixel {
#if CONJOINED_NEOPIXEL
adaneo2.show();
#else
IF_DISABLED(NEOPIXEL2_SEPARATE, adaneo1.setPin(NEOPIXEL2_PIN));
adaneo1.show();
adaneo1.setPin(NEOPIXEL_PIN);
#endif
Expand Down
19 changes: 13 additions & 6 deletions Marlin/src/gcode/feature/leds/M150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@
* M150 I1 R ; Set NEOPIXEL index 1 to red
* M150 S1 I1 R ; Set SEPARATE index 1 to red
*/

void GcodeSuite::M150() {
#if ENABLED(NEOPIXEL_LED)
const uint8_t index = parser.intval('I', -1);
const int8_t index = parser.intval('I', -1);
#if ENABLED(NEOPIXEL2_SEPARATE)
const uint8_t unit = parser.intval('S'),
brightness = unit ? neo2.brightness() : neo.brightness();
*(unit ? &neo2.neoindex : &neo.neoindex) = index;
int8_t brightness, unit = parser.intval('S', -1);
switch (unit) {
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
const uint8_t brightness = neo.brightness();
neo.neoindex = index;
Expand All @@ -75,10 +77,15 @@ void GcodeSuite::M150() {
);

#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

// If 'S' is not specified use both
leds.set_color(color);
TERN_(NEOPIXEL2_SEPARATE, leds2.set_color(color));
}

#endif // HAS_COLOR_LEDS

0 comments on commit 7b580fc

Please sign in to comment.