Browse Source

M150 I to set Neopixel by index (#18490)

ellensp 5 years ago
parent
commit
91dc74ff16
No account linked to committer's email address

+ 17
- 9
Marlin/src/feature/leds/neopixel.cpp View File

@@ -35,6 +35,7 @@
35 35
 #endif
36 36
 
37 37
 Marlin_NeoPixel neo;
38
+int8_t Marlin_NeoPixel::neoindex;
38 39
 
39 40
 Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
40 41
   #if MULTIPLE_NEOPIXEL_TYPES
@@ -52,14 +53,20 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
52 53
 #endif
53 54
 
54 55
 void Marlin_NeoPixel::set_color(const uint32_t color) {
55
-  for (uint16_t i = 0; i < pixels(); ++i) {
56
-    #ifdef NEOPIXEL_BKGD_LED_INDEX
57
-      if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
58
-        set_color_background();
59
-        continue;
60
-      }
61
-    #endif
62
-    set_pixel_color(i, color);
56
+  if (get_neo_index() < 0) { 
57
+    set_pixel_color(get_neo_index(), color);
58
+    set_neo_index(-1);
59
+  }
60
+  else { 
61
+    for (uint16_t i = 0; i < pixels(); ++i) {
62
+      #ifdef NEOPIXEL_BKGD_LED_INDEX
63
+        if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
64
+          set_color_background();
65
+          continue;
66
+        }
67
+      #endif
68
+      set_pixel_color(i, color);
69
+    }
63 70
   }
64 71
   show();
65 72
 }
@@ -71,7 +78,8 @@ void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
71 78
 }
72 79
 
73 80
 void Marlin_NeoPixel::init() {
74
-  set_brightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
81
+  set_neo_index(-1);                   // -1 .. NEOPIXEL_PIXELS-1 range
82
+  set_brightness(NEOPIXEL_BRIGHTNESS); //  0 .. 255 range
75 83
   begin();
76 84
   show();  // initialize to all off
77 85
 

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

@@ -65,6 +65,7 @@ private:
65 65
       , adaneo2
66 66
     #endif
67 67
   ;
68
+  static int8_t neoindex;
68 69
 
69 70
 public:
70 71
   static void init();
@@ -72,6 +73,9 @@ public:
72 73
 
73 74
   static void set_color(const uint32_t c);
74 75
 
76
+  FORCE_INLINE static void set_neo_index(const int8_t neoIndex) { neoindex = neoIndex; }
77
+  FORCE_INLINE static int8_t get_neo_index() { return neoindex; }
78
+
75 79
   #ifdef NEOPIXEL_BKGD_LED_INDEX
76 80
     static void set_color_background();
77 81
   #endif

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

@@ -34,6 +34,9 @@
34 34
  * Always sets all 3 or 4 components. If a component is left out, set to 0.
35 35
  *                                    If brightness is left out, no value changed
36 36
  *
37
+ * With NEOPIXEL_LED:
38
+ *  I<index>  Set the Neopixel index to affect. Default: All
39
+ *
37 40
  * Examples:
38 41
  *
39 42
  *   M150 R255       ; Turn LED red
@@ -43,8 +46,12 @@
43 46
  *   M150 W          ; Turn LED white using a white LED
44 47
  *   M150 P127       ; Set LED 50% brightness
45 48
  *   M150 P          ; Set LED full brightness
46
- */
49
+ *   M150 I1 R       ; Set NEOPIXEL index 1 to red
50
+ */  
47 51
 void GcodeSuite::M150() {
52
+  #if ENABLED(NEOPIXEL_LED)
53
+    neo.set_neo_index(parser.intval('I', -1));
54
+  #endif
48 55
   leds.set_color(MakeLEDColor(
49 56
     parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
50 57
     parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,

Loading…
Cancel
Save