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
       #if CONJOINED_NEOPIXEL
114
       #if CONJOINED_NEOPIXEL
115
         adaneo2.show();
115
         adaneo2.show();
116
       #else
116
       #else
117
-        IF_DISABLED(NEOPIXEL2_SEPARATE, adaneo1.setPin(NEOPIXEL2_PIN));
118
         adaneo1.show();
117
         adaneo1.show();
119
         adaneo1.setPin(NEOPIXEL_PIN);
118
         adaneo1.setPin(NEOPIXEL_PIN);
120
       #endif
119
       #endif

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

52
  *   M150 I1 R       ; Set NEOPIXEL index 1 to red
52
  *   M150 I1 R       ; Set NEOPIXEL index 1 to red
53
  *   M150 S1 I1 R    ; Set SEPARATE index 1 to red
53
  *   M150 S1 I1 R    ; Set SEPARATE index 1 to red
54
  */
54
  */
55
-
56
 void GcodeSuite::M150() {
55
 void GcodeSuite::M150() {
57
   #if ENABLED(NEOPIXEL_LED)
56
   #if ENABLED(NEOPIXEL_LED)
58
-    const uint8_t index = parser.intval('I', -1);
57
+    const int8_t index = parser.intval('I', -1);
59
     #if ENABLED(NEOPIXEL2_SEPARATE)
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
     #else
65
     #else
64
       const uint8_t brightness = neo.brightness();
66
       const uint8_t brightness = neo.brightness();
65
       neo.neoindex = index;
67
       neo.neoindex = index;
75
   );
77
   );
76
 
78
 
77
   #if ENABLED(NEOPIXEL2_SEPARATE)
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
   #endif
84
   #endif
80
 
85
 
86
+  // If 'S' is not specified use both
81
   leds.set_color(color);
87
   leds.set_color(color);
88
+  TERN_(NEOPIXEL2_SEPARATE, leds2.set_color(color));
82
 }
89
 }
83
 
90
 
84
 #endif // HAS_COLOR_LEDS
91
 #endif // HAS_COLOR_LEDS

Loading…
Cancel
Save