Browse Source

✨ M150 K – Keep unspecified components (#24315)

qwertymodo 1 year ago
parent
commit
5a2cc41f9c
2 changed files with 21 additions and 8 deletions
  1. 8
    0
      Marlin/src/feature/leds/neopixel.h
  2. 13
    8
      Marlin/src/gcode/feature/leds/M150.cpp

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

@@ -131,6 +131,13 @@ public:
131 131
   // Accessors
132 132
   static uint16_t pixels() { return adaneo1.numPixels() * TERN1(NEOPIXEL2_INSERIES, 2); }
133 133
 
134
+  static uint32_t pixel_color(const uint16_t n) {
135
+    #if ENABLED(NEOPIXEL2_INSERIES)
136
+      if (n >= NEOPIXEL_PIXELS) return adaneo2.getPixelColor(n - (NEOPIXEL_PIXELS));
137
+    #endif
138
+    return adaneo1.getPixelColor(n);
139
+  }
140
+
134 141
   static uint8_t brightness() { return adaneo1.getBrightness(); }
135 142
 
136 143
   static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w)) {
@@ -174,6 +181,7 @@ extern Marlin_NeoPixel neo;
174 181
 
175 182
     // Accessors
176 183
     static uint16_t pixels() { return adaneo.numPixels();}
184
+    static uint32_t pixel_color(const uint16_t n) { return adaneo.getPixelColor(n); }
177 185
     static uint8_t brightness() { return adaneo.getBrightness(); }
178 186
     static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED2, uint8_t w)) {
179 187
       return adaneo.Color(r, g, b OPTARG(HAS_WHITE_LED2, w));

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

@@ -31,11 +31,13 @@
31 31
  * M150: Set Status LED Color - Use R-U-B-W for R-G-B-W
32 32
  *       and Brightness       - Use P (for NEOPIXEL only)
33 33
  *
34
- * Always sets all 3 or 4 components. If a component is left out, set to 0.
35
- *                                    If brightness is left out, no value changed
34
+ * Always sets all 3 or 4 components unless the K flag is specified.
35
+ *                              If a component is left out, set to 0.
36
+ *                              If brightness is left out, no value changed.
36 37
  *
37 38
  * With NEOPIXEL_LED:
38 39
  *  I<index>  Set the NeoPixel index to affect. Default: All
40
+ *  K         Keep all unspecified values unchanged instead of setting to 0.
39 41
  *
40 42
  * With NEOPIXEL2_SEPARATE:
41 43
  *  S<index>  The NeoPixel strip to set. Default: All.
@@ -51,16 +53,19 @@
51 53
  *   M150 P          ; Set LED full brightness
52 54
  *   M150 I1 R       ; Set NEOPIXEL index 1 to red
53 55
  *   M150 S1 I1 R    ; Set SEPARATE index 1 to red
56
+ *   M150 K R127     ; Set LED red to 50% without changing blue or green
54 57
  */
55 58
 void GcodeSuite::M150() {
59
+  int32_t old_color = 0;
60
+
56 61
   #if ENABLED(NEOPIXEL_LED)
57 62
     const pixel_index_t index = parser.intval('I', -1);
58 63
     #if ENABLED(NEOPIXEL2_SEPARATE)
59 64
       int8_t brightness = neo.brightness(), unit = parser.intval('S', -1);
60 65
       switch (unit) {
61 66
         case -1: neo2.neoindex = index; // fall-thru
62
-        case  0:  neo.neoindex = index; break;
63
-        case  1: neo2.neoindex = index; brightness = neo2.brightness(); break;
67
+        case  0:  neo.neoindex = index; old_color = parser.seen('K') ? neo.pixel_color(index >= 0 ? index : 0) : 0; break;
68
+        case  1: neo2.neoindex = index; brightness = neo2.brightness(); old_color = parser.seen('K') ? neo2.pixel_color(index >= 0 ? index : 0) : 0; break;
64 69
       }
65 70
     #else
66 71
       const uint8_t brightness = neo.brightness();
@@ -69,10 +74,10 @@ void GcodeSuite::M150() {
69 74
   #endif
70 75
 
71 76
   const LEDColor color = LEDColor(
72
-    parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
73
-    parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
74
-    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0
75
-    OPTARG(HAS_WHITE_LED, parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0)
77
+    parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 16) & 0xFF,
78
+    parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >>  8) & 0xFF,
79
+    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : old_color & 0xFF
80
+    OPTARG(HAS_WHITE_LED, parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 24) & 0xFF)
76 81
     OPTARG(NEOPIXEL_LED, parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness)
77 82
   );
78 83
 

Loading…
Cancel
Save