Browse Source

🐛 Fix dual Neopixels (#22174)

Grumpy 4 years ago
parent
commit
59f01b417a
No account linked to committer's email address
2 changed files with 13 additions and 7 deletions
  1. 0
    1
      Marlin/src/feature/leds/neopixel.h
  2. 13
    6
      Marlin/src/gcode/feature/leds/M150.cpp

+ 0
- 1
Marlin/src/feature/leds/neopixel.h View File

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

+ 13
- 6
Marlin/src/gcode/feature/leds/M150.cpp View File

@@ -52,14 +52,16 @@
52 52
  *   M150 I1 R       ; Set NEOPIXEL index 1 to red
53 53
  *   M150 S1 I1 R    ; Set SEPARATE index 1 to red
54 54
  */
55
-
56 55
 void GcodeSuite::M150() {
57 56
   #if ENABLED(NEOPIXEL_LED)
58
-    const uint8_t index = parser.intval('I', -1);
57
+    const int8_t index = parser.intval('I', -1);
59 58
     #if ENABLED(NEOPIXEL2_SEPARATE)
60
-      const uint8_t unit = parser.intval('S'),
61
-                    brightness = unit ? neo2.brightness() : neo.brightness();
62
-      *(unit ? &neo2.neoindex : &neo.neoindex) = index;
59
+      int8_t brightness, unit = parser.intval('S', -1);
60
+      switch (unit) {
61
+        case -1: neo2.neoindex = index; // fall-thru
62
+        case  0:  neo.neoindex = index; brightness =  neo.brightness(); break;
63
+        case  1: neo2.neoindex = index; brightness = neo2.brightness(); break;
64
+      }
63 65
     #else
64 66
       const uint8_t brightness = neo.brightness();
65 67
       neo.neoindex = index;
@@ -75,10 +77,15 @@ void GcodeSuite::M150() {
75 77
   );
76 78
 
77 79
   #if ENABLED(NEOPIXEL2_SEPARATE)
78
-    if (unit == 1) { leds2.set_color(color); return; }
80
+    switch (unit) {
81
+      case 0: leds.set_color(color); return;
82
+      case 1: leds2.set_color(color); return;
83
+    }
79 84
   #endif
80 85
 
86
+  // If 'S' is not specified use both
81 87
   leds.set_color(color);
88
+  TERN_(NEOPIXEL2_SEPARATE, leds2.set_color(color));
82 89
 }
83 90
 
84 91
 #endif // HAS_COLOR_LEDS

Loading…
Cancel
Save