Sfoglia il codice sorgente

♻️ LEDs refactor and extend (#21962)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
ellensp 3 anni fa
parent
commit
e60c38b622
Nessun account collegato all'indirizzo email del committer

+ 6
- 5
Marlin/Configuration.h Vedi File

@@ -2690,7 +2690,7 @@
2690 2690
 //#define NEOPIXEL_LED
2691 2691
 #if ENABLED(NEOPIXEL_LED)
2692 2692
   #define NEOPIXEL_TYPE   NEO_GRBW // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h)
2693
-  #define NEOPIXEL_PIN     4       // LED driving pin
2693
+  //#define NEOPIXEL_PIN     4     // LED driving pin
2694 2694
   //#define NEOPIXEL2_TYPE NEOPIXEL_TYPE
2695 2695
   //#define NEOPIXEL2_PIN    5
2696 2696
   #define NEOPIXEL_PIXELS 30       // Number of LEDs in the strip. (Longest strip when NEOPIXEL2_SEPARATE is disabled.)
@@ -2708,10 +2708,11 @@
2708 2708
     //#define NEOPIXEL2_INSERIES      // Default behavior is NeoPixel 2 in parallel
2709 2709
   #endif
2710 2710
 
2711
-  // Use a single NeoPixel LED for static (background) lighting
2712
-  //#define NEOPIXEL_BKGD_LED_INDEX  0               // Index of the LED to use
2713
-  //#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
2714
-  //#define NEOPIXEL_BKGD_ALWAYS_ON                  // Keep the backlight on when other NeoPixels are off
2711
+  // Use some of the NeoPixel LEDs for static (background) lighting
2712
+  //#define NEOPIXEL_BKGD_INDEX_FIRST  0              // Index of the first background LED
2713
+  //#define NEOPIXEL_BKGD_INDEX_LAST   5              // Index of the last background LED
2714
+  //#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 }  // R, G, B, W
2715
+  //#define NEOPIXEL_BKGD_ALWAYS_ON                   // Keep the backlight on when other NeoPixels are off
2715 2716
 #endif
2716 2717
 
2717 2718
 /**

+ 1
- 3
Marlin/src/feature/caselight.cpp Vedi File

@@ -65,9 +65,7 @@ void CaseLight::update(const bool sflag) {
65 65
   #endif
66 66
 
67 67
   #if CASE_LIGHT_IS_COLOR_LED
68
-
69
-    leds.set_color(MakeLEDColor(color.r, color.g, color.b, color.w, n10ct));
70
-
68
+    leds.set_color(LEDColor(color.r, color.g, color.b OPTARG(HAS_WHITE_LED, color.w), n10ct));
71 69
   #else // !CASE_LIGHT_IS_COLOR_LED
72 70
 
73 71
     #if CASELIGHT_USES_BRIGHTNESS

+ 27
- 24
Marlin/src/feature/leds/leds.cpp Vedi File

@@ -47,9 +47,10 @@
47 47
 #endif
48 48
 
49 49
 #if ENABLED(LED_COLOR_PRESETS)
50
-  const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
51
-    LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE,
52
-    LED_USER_PRESET_WHITE, LED_USER_PRESET_BRIGHTNESS
50
+  const LEDColor LEDLights::defaultLEDColor = LEDColor(
51
+    LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE
52
+    OPTARG(HAS_WHITE_LED, LED_USER_PRESET_WHITE)
53
+    OPTARG(NEOPIXEL_LED, LED_USER_PRESET_BRIGHTNESS)
53 54
   );
54 55
 #endif
55 56
 
@@ -75,34 +76,35 @@ void LEDLights::setup() {
75 76
 }
76 77
 
77 78
 void LEDLights::set_color(const LEDColor &incol
78
-  OPTARG(NEOPIXEL_LED, bool isSequence/*=false*/)
79
+  OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence/*=false*/)
79 80
 ) {
80 81
 
81 82
   #if ENABLED(NEOPIXEL_LED)
82 83
 
83 84
     const uint32_t neocolor = LEDColorWhite() == incol
84 85
                             ? neo.Color(NEO_WHITE)
85
-                            : neo.Color(incol.r, incol.g, incol.b, incol.w);
86
-    static uint16_t nextLed = 0;
87
-
88
-    #ifdef NEOPIXEL_BKGD_LED_INDEX
89
-      if (NEOPIXEL_BKGD_LED_INDEX == nextLed) {
90
-        neo.set_color_background();
91
-        if (++nextLed >= neo.pixels()) {
92
-          nextLed = 0;
93
-          return;
86
+                            : neo.Color(incol.r, incol.g, incol.b OPTARG(HAS_WHITE_LED, incol.w));
87
+
88
+    #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
89
+      static uint16_t nextLed = 0;
90
+      #ifdef NEOPIXEL_BKGD_INDEX_FIRST
91
+        while (WITHIN(nextLed, NEOPIXEL_BKGD_INDEX_FIRST, NEOPIXEL_BKGD_INDEX_LAST)) {
92
+          neo.reset_background_color();
93
+          if (++nextLed >= neo.pixels()) { nextLed = 0; return; }
94 94
         }
95
-      }
95
+      #endif
96 96
     #endif
97 97
 
98 98
     neo.set_brightness(incol.i);
99 99
 
100
-    if (isSequence) {
101
-      neo.set_pixel_color(nextLed, neocolor);
102
-      neo.show();
103
-      if (++nextLed >= neo.pixels()) nextLed = 0;
104
-      return;
105
-    }
100
+    #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
101
+      if (isSequence) {
102
+        neo.set_pixel_color(nextLed, neocolor);
103
+        neo.show();
104
+        if (++nextLed >= neo.pixels()) nextLed = 0;
105
+        return;
106
+      }
107
+    #endif
106 108
 
107 109
     neo.set_color(neocolor);
108 110
 
@@ -167,9 +169,10 @@ void LEDLights::set_color(const LEDColor &incol
167 169
 #if ENABLED(NEOPIXEL2_SEPARATE)
168 170
 
169 171
   #if ENABLED(NEO2_COLOR_PRESETS)
170
-    const LEDColor LEDLights2::defaultLEDColor = MakeLEDColor(
171
-      NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE,
172
-      NEO2_USER_PRESET_WHITE, NEO2_USER_PRESET_BRIGHTNESS
172
+    const LEDColor LEDLights2::defaultLEDColor = LEDColor(
173
+      LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE
174
+      OPTARG(HAS_WHITE_LED2, LED_USER_PRESET_WHITE)
175
+      OPTARG(NEOPIXEL_LED, LED_USER_PRESET_BRIGHTNESS)
173 176
     );
174 177
   #endif
175 178
 
@@ -188,7 +191,7 @@ void LEDLights::set_color(const LEDColor &incol
188 191
   void LEDLights2::set_color(const LEDColor &incol) {
189 192
     const uint32_t neocolor = LEDColorWhite() == incol
190 193
                             ? neo2.Color(NEO2_WHITE)
191
-                            : neo2.Color(incol.r, incol.g, incol.b, incol.w);
194
+                            : neo2.Color(incol.r, incol.g, incol.b OPTARG(HAS_WHITE_LED2, incol.w));
192 195
     neo2.set_brightness(incol.i);
193 196
     neo2.set_color(neocolor);
194 197
 

+ 19
- 12
Marlin/src/feature/leds/leds.h Vedi File

@@ -29,15 +29,17 @@
29 29
 
30 30
 #include <string.h>
31 31
 
32
-#if ENABLED(NEOPIXEL_LED)
33
-  #include "neopixel.h"
34
-#endif
35
-
36 32
 // A white component can be passed
37
-#if ANY(RGBW_LED, NEOPIXEL_LED, PCA9632_RGBW)
33
+#if EITHER(RGBW_LED, PCA9632_RGBW)
38 34
   #define HAS_WHITE_LED 1
39 35
 #endif
40 36
 
37
+#if ENABLED(NEOPIXEL_LED)
38
+  #define _NEOPIXEL_INCLUDE_
39
+  #include "neopixel.h"
40
+  #undef _NEOPIXEL_INCLUDE_
41
+#endif
42
+
41 43
 /**
42 44
  * LEDcolor type for use with leds.set_color
43 45
  */
@@ -84,9 +86,8 @@ typedef struct LEDColor {
84 86
 } LEDColor;
85 87
 
86 88
 /**
87
- * Color helpers and presets
89
+ * Color presets
88 90
  */
89
-#define MakeLEDColor(R,G,B,W,I)   LEDColor(R, G, B OPTARG(HAS_WHITE_LED, W) OPTARG(NEOPIXEL_LED, I))
90 91
 
91 92
 #define LEDColorOff()             LEDColor(  0,   0,   0)
92 93
 #define LEDColorRed()             LEDColor(255,   0,   0)
@@ -114,15 +115,15 @@ public:
114 115
   static void setup(); // init()
115 116
 
116 117
   static void set_color(const LEDColor &color
117
-    OPTARG(NEOPIXEL_LED, bool isSequence=false)
118
+    OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence=false)
118 119
   );
119 120
 
120 121
   static inline void set_color(uint8_t r, uint8_t g, uint8_t b
121 122
     OPTARG(HAS_WHITE_LED, uint8_t w=0)
122 123
     OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS)
123
-    OPTARG(NEOPIXEL_LED, bool isSequence=false)
124
+    OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence=false)
124 125
   ) {
125
-    set_color(MakeLEDColor(r, g, b, w, i) OPTARG(NEOPIXEL_LED, isSequence));
126
+    set_color(LEDColor(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, i)) OPTARG(NEOPIXEL_IS_SEQUENTIAL, isSequence));
126 127
   }
127 128
 
128 129
   static inline void set_off()   { set_color(LEDColorOff()); }
@@ -180,8 +181,14 @@ extern LEDLights leds;
180 181
 
181 182
     static void set_color(const LEDColor &color);
182 183
 
183
-    inline void set_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w=0, uint8_t i=NEOPIXEL2_BRIGHTNESS) {
184
-      set_color(MakeLEDColor(r, g, b, w, i));
184
+    static inline void set_color(uint8_t r, uint8_t g, uint8_t b
185
+      OPTARG(HAS_WHITE_LED, uint8_t w=0)
186
+      OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS)
187
+    ) {
188
+      set_color(LEDColor(r, g, b
189
+        OPTARG(HAS_WHITE_LED, w)
190
+        OPTARG(NEOPIXEL_LED, i)
191
+      ));
185 192
     }
186 193
 
187 194
     static inline void set_off()   { set_color(LEDColorOff()); }

+ 38
- 42
Marlin/src/feature/leds/neopixel.cpp Vedi File

@@ -28,7 +28,7 @@
28 28
 
29 29
 #if ENABLED(NEOPIXEL_LED)
30 30
 
31
-#include "neopixel.h"
31
+#include "leds.h"
32 32
 
33 33
 #if EITHER(NEOPIXEL_STARTUP_TEST, NEOPIXEL2_STARTUP_TEST)
34 34
   #include "../../core/utility.h"
@@ -37,17 +37,21 @@
37 37
 Marlin_NeoPixel neo;
38 38
 int8_t Marlin_NeoPixel::neoindex;
39 39
 
40
-Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
41
-  #if CONJOINED_NEOPIXEL
42
-    , Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800)
43
-  #endif
44
-;
40
+Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
41
+#if CONJOINED_NEOPIXEL
42
+  Adafruit_NeoPixel Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800);
43
+#endif
45 44
 
46
-#ifdef NEOPIXEL_BKGD_LED_INDEX
45
+#ifdef NEOPIXEL_BKGD_INDEX_FIRST
46
+
47
+  void Marlin_NeoPixel::set_background_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
48
+    for  (int background_led = NEOPIXEL_BKGD_INDEX_FIRST; background_led <= NEOPIXEL_BKGD_INDEX_LAST; background_led++)
49
+      set_pixel_color(background_led, adaneo1.Color(r, g, b, w));
50
+  }
47 51
 
48
-  void Marlin_NeoPixel::set_color_background() {
49
-    uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
50
-    set_pixel_color(NEOPIXEL_BKGD_LED_INDEX, adaneo1.Color(background_color[0], background_color[1], background_color[2], background_color[3]));
52
+  void Marlin_NeoPixel::reset_background_color() {
53
+    constexpr uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
54
+    set_background_color(background_color[0], background_color[1], background_color[2], background_color[3]);
51 55
   }
52 56
 
53 57
 #endif
@@ -59,9 +63,10 @@ void Marlin_NeoPixel::set_color(const uint32_t color) {
59 63
   }
60 64
   else {
61 65
     for (uint16_t i = 0; i < pixels(); ++i) {
62
-      #ifdef NEOPIXEL_BKGD_LED_INDEX
63
-        if (i == NEOPIXEL_BKGD_LED_INDEX && TERN(NEOPIXEL_BKGD_ALWAYS_ON, true, color != 0x000000)) {
64
-          set_color_background();
66
+      #ifdef NEOPIXEL_BKGD_INDEX_FIRST
67
+        if (i == NEOPIXEL_BKGD_INDEX_FIRST && TERN(NEOPIXEL_BKGD_ALWAYS_ON, true, color != 0x000000)) {
68
+          reset_background_color();
69
+          i += NEOPIXEL_BKGD_INDEX_LAST - (NEOPIXEL_BKGD_INDEX_FIRST);
65 70
           continue;
66 71
         }
67 72
       #endif
@@ -90,35 +95,22 @@ void Marlin_NeoPixel::init() {
90 95
     safe_delay(500);
91 96
     set_color_startup(adaneo1.Color(0, 0, 255, 0));  // blue
92 97
     safe_delay(500);
98
+    #if HAS_WHITE_LED
99
+      set_color_startup(adaneo1.Color(0, 0, 0, 255));  // white
100
+      safe_delay(500);
101
+    #endif
93 102
   #endif
94 103
 
95
-  #ifdef NEOPIXEL_BKGD_LED_INDEX
96
-    set_color_background();
97
-  #endif
98
-
99
-  #if ENABLED(LED_USER_PRESET_STARTUP)
100
-    set_color(adaneo1.Color(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE));
101
-  #else
102
-    set_color(adaneo1.Color(0, 0, 0, 0));
104
+  #ifdef NEOPIXEL_BKGD_INDEX_FIRST
105
+    reset_background_color();
103 106
   #endif
104
-}
105 107
 
106
-#if 0
107
-bool Marlin_NeoPixel::set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p) {
108
-  const uint32_t color = adaneo1.Color(r, g, b, w);
109
-  set_brightness(p);
110
-  #if DISABLED(NEOPIXEL_IS_SEQUENTIAL)
111
-    set_color(color);
112
-    return false;
113
-  #else
114
-    static uint16_t nextLed = 0;
115
-    set_pixel_color(nextLed, color);
116
-    show();
117
-    if (++nextLed >= pixels()) nextLed = 0;
118
-    return true;
119
-  #endif
108
+  set_color(adaneo1.Color
109
+    TERN(LED_USER_PRESET_STARTUP,
110
+      (LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE),
111
+      (0, 0, 0, 0))
112
+  );
120 113
 }
121
-#endif
122 114
 
123 115
 #if ENABLED(NEOPIXEL2_SEPARATE)
124 116
 
@@ -158,13 +150,17 @@ bool Marlin_NeoPixel::set_led_color(const uint8_t r, const uint8_t g, const uint
158 150
       safe_delay(500);
159 151
       set_color_startup(adaneo.Color(0, 0, 255, 0));  // blue
160 152
       safe_delay(500);
153
+      #if HAS_WHITE_LED2
154
+        set_color_startup(adaneo.Color(0, 0, 0, 255));  // white
155
+        safe_delay(500);
156
+      #endif
161 157
     #endif
162 158
 
163
-    #if ENABLED(NEO2_USER_PRESET_STARTUP)
164
-      set_color(adaneo.Color(NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE, NEO2_USER_PRESET_WHITE));
165
-    #else
166
-      set_color(adaneo.Color(0, 0, 0, 0));
167
-    #endif
159
+    set_color(adaneo.Color
160
+      TERN(NEO2_USER_PRESET_STARTUP,
161
+        (NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE, NEO2_USER_PRESET_WHITE),
162
+        (0, 0, 0, 0))
163
+    );
168 164
   }
169 165
 
170 166
 #endif // NEOPIXEL2_SEPARATE

+ 36
- 37
Marlin/src/feature/leds/neopixel.h Vedi File

@@ -25,6 +25,10 @@
25 25
  * NeoPixel support
26 26
  */
27 27
 
28
+#ifndef _NEOPIXEL_INCLUDE_
29
+  #error "Always include 'leds.h' and not 'neopixel.h' directly."
30
+#endif
31
+
28 32
 // ------------------------
29 33
 // Includes
30 34
 // ------------------------
@@ -38,24 +42,24 @@
38 42
 // Defines
39 43
 // ------------------------
40 44
 
41
-#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
42
-  #define MULTIPLE_NEOPIXEL_TYPES 1
43
-#endif
45
+#define _NEO_IS_RGB(N) (N == NEO_RGB || N == NEO_RBG || N == NEO_GRB || N == NEO_GBR || N == NEO_BRG || N == NEO_BGR)
44 46
 
45
-#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
46
-  #define CONJOINED_NEOPIXEL 1
47
+#if !_NEO_IS_RGB(NEOPIXEL_TYPE)
48
+  #define HAS_WHITE_LED 1
47 49
 #endif
48 50
 
49
-#if NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR
50
-  #define NEOPIXEL_IS_RGB 1
51
+#if HAS_WHITE_LED
52
+  #define NEO_WHITE 0, 0, 0, 255
51 53
 #else
52
-  #define NEOPIXEL_IS_RGBW 1
54
+  #define NEO_WHITE 255, 255, 255
53 55
 #endif
54 56
 
55
-#if NEOPIXEL_IS_RGB
56
-  #define NEO_WHITE 255, 255, 255, 0
57
-#else
58
-  #define NEO_WHITE 0, 0, 0, 255
57
+#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
58
+  #define MULTIPLE_NEOPIXEL_TYPES 1
59
+#endif
60
+
61
+#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
62
+  #define CONJOINED_NEOPIXEL 1
59 63
 #endif
60 64
 
61 65
 // ------------------------
@@ -64,11 +68,10 @@
64 68
 
65 69
 class Marlin_NeoPixel {
66 70
 private:
67
-  static Adafruit_NeoPixel adaneo1
68
-    #if CONJOINED_NEOPIXEL
69
-      , adaneo2
70
-    #endif
71
-  ;
71
+  static Adafruit_NeoPixel adaneo1;
72
+  #if CONJOINED_NEOPIXEL
73
+    static Adafruit_NeoPixel adaneo2;
74
+  #endif
72 75
 
73 76
 public:
74 77
   static int8_t neoindex;
@@ -78,8 +81,9 @@ public:
78 81
 
79 82
   static void set_color(const uint32_t c);
80 83
 
81
-  #ifdef NEOPIXEL_BKGD_LED_INDEX
82
-    static void set_color_background();
84
+  #ifdef NEOPIXEL_BKGD_INDEX_FIRST
85
+    static void set_background_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
86
+    static void reset_background_color();
83 87
   #endif
84 88
 
85 89
   static inline void begin() {
@@ -93,9 +97,7 @@ public:
93 97
       else adaneo1.setPixelColor(n, c);
94 98
     #else
95 99
       adaneo1.setPixelColor(n, c);
96
-      #if MULTIPLE_NEOPIXEL_TYPES
97
-        adaneo2.setPixelColor(n, c);
98
-      #endif
100
+      TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c));
99 101
     #endif
100 102
   }
101 103
 
@@ -120,15 +122,13 @@ public:
120 122
     TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT());
121 123
   }
122 124
 
123
-  #if 0
124
-    bool set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
125
-  #endif
126
-
127 125
   // Accessors
128
-  static inline uint16_t pixels() { TERN(NEOPIXEL2_INSERIES, return adaneo1.numPixels() * 2, return adaneo1.numPixels()); }
126
+  static inline uint16_t pixels() { return adaneo1.numPixels() * TERN1(NEOPIXEL2_INSERIES, 2); }
127
+
129 128
   static inline uint8_t brightness() { return adaneo1.getBrightness(); }
130
-  static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
131
-    return adaneo1.Color(r, g, b, w);
129
+
130
+  static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w)) {
131
+    return adaneo1.Color(r, g, b OPTARG(HAS_WHITE_LED, w));
132 132
   }
133 133
 };
134 134
 
@@ -137,15 +137,12 @@ extern Marlin_NeoPixel neo;
137 137
 // Neo pixel channel 2
138 138
 #if ENABLED(NEOPIXEL2_SEPARATE)
139 139
 
140
-  #if NEOPIXEL2_TYPE == NEO_RGB || NEOPIXEL2_TYPE == NEO_RBG || NEOPIXEL2_TYPE == NEO_GRB || NEOPIXEL2_TYPE == NEO_GBR || NEOPIXEL2_TYPE == NEO_BRG || NEOPIXEL2_TYPE == NEO_BGR
140
+  #if _NEO_IS_RGB(NEOPIXEL2_TYPE)
141 141
     #define NEOPIXEL2_IS_RGB 1
142
+    #define NEO2_WHITE 255, 255, 255
142 143
   #else
143 144
     #define NEOPIXEL2_IS_RGBW 1
144
-  #endif
145
-
146
-  #if NEOPIXEL2_IS_RGB
147
-    #define NEO2_WHITE 255, 255, 255, 0
148
-  #else
145
+    #define HAS_WHITE_LED2 1      // A white component can be passed for NEOPIXEL2
149 146
     #define NEO2_WHITE 0, 0, 0, 255
150 147
   #endif
151 148
 
@@ -172,11 +169,13 @@ extern Marlin_NeoPixel neo;
172 169
     // Accessors
173 170
     static inline uint16_t pixels() { return adaneo.numPixels();}
174 171
     static inline uint8_t brightness() { return adaneo.getBrightness(); }
175
-    static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
176
-      return adaneo.Color(r, g, b, w);
172
+    static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED2, uint8_t w)) {
173
+      return adaneo.Color(r, g, b OPTARG(HAS_WHITE_LED2, w));
177 174
     }
178 175
   };
179 176
 
180 177
   extern Marlin_NeoPixel2 neo2;
181 178
 
182 179
 #endif // NEOPIXEL2_SEPARATE
180
+
181
+#undef _NEO_IS_RGB

+ 3
- 5
Marlin/src/feature/leds/printer_event_leds.cpp Vedi File

@@ -45,12 +45,10 @@ PrinterEventLEDs printerEventLEDs;
45 45
     return (uint8_t)map(constrain(current, start, target), start, target, 0, 255);
46 46
   }
47 47
 
48
-  inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b) {
48
+  inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b OPTARG(HAS_WHITE_LED, const uint8_t w=0)) {
49 49
     leds.set_color(
50
-      MakeLEDColor(r, g, b, 0, neo.brightness())
51
-      #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
52
-        , true
53
-      #endif
50
+      LEDColor(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, neo.brightness()))
51
+      OPTARG(NEOPIXEL_IS_SEQUENTIAL, true)
54 52
     );
55 53
   }
56 54
 

+ 4
- 4
Marlin/src/gcode/feature/leds/M150.cpp Vedi File

@@ -66,12 +66,12 @@ void GcodeSuite::M150() {
66 66
     #endif
67 67
   #endif
68 68
 
69
-  const LEDColor color = MakeLEDColor(
69
+  const LEDColor color = LEDColor(
70 70
     parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
71 71
     parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
72
-    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
73
-    parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
74
-    parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness
72
+    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0
73
+    OPTARG(HAS_WHITE_LED, parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0)
74
+    OPTARG(NEOPIXEL_LED, parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness)
75 75
   );
76 76
 
77 77
   #if ENABLED(NEOPIXEL2_SEPARATE)

+ 7
- 0
Marlin/src/inc/Conditionals_LCD.h Vedi File

@@ -1321,3 +1321,10 @@
1321 1321
 #else
1322 1322
   #define COORDINATE_OKAY(N,L,H) true
1323 1323
 #endif
1324
+
1325
+/**
1326
+ * LED Backlight INDEX END
1327
+ */
1328
+#if defined(NEOPIXEL_BKGD_INDEX_FIRST) && !defined(NEOPIXEL_BKGD_INDEX_LAST)
1329
+  #define NEOPIXEL_BKGD_INDEX_LAST NEOPIXEL_BKGD_INDEX_FIRST
1330
+#endif

+ 2
- 0
Marlin/src/inc/SanityCheck.h Vedi File

@@ -562,6 +562,8 @@
562 562
   #error "CUSTOM_USER_MENUS has been replaced by CUSTOM_MENU_MAIN and CUSTOM_MENU_CONFIG."
563 563
 #elif defined(MKS_LCD12864)
564 564
   #error "MKS_LCD12864 is now MKS_LCD12864A or MKS_LCD12864B."
565
+#elif defined(NEOPIXEL_BKGD_LED_INDEX)
566
+  #error "NEOPIXEL_BKGD_LED_INDEX is now NEOPIXEL_BKGD_INDEX_FIRST."
565 567
 #endif
566 568
 
567 569
 /**

+ 2
- 2
Marlin/src/lcd/marlinui.cpp Vedi File

@@ -636,8 +636,8 @@ void MarlinUI::kill_screen(PGM_P lcd_error, PGM_P lcd_component) {
636 636
   // RED ALERT. RED ALERT.
637 637
   #ifdef LED_BACKLIGHT_TIMEOUT
638 638
     leds.set_color(LEDColorRed());
639
-    #ifdef NEOPIXEL_BKGD_LED_INDEX
640
-      neo.set_pixel_color(NEOPIXEL_BKGD_LED_INDEX, 255, 0, 0, 0);
639
+    #ifdef NEOPIXEL_BKGD_INDEX_FIRST
640
+      neo.set_background_color(255, 0, 0, 0);
641 641
       neo.show();
642 642
     #endif
643 643
   #endif

+ 7
- 5
Marlin/src/lcd/menu/menu_led.cpp Vedi File

@@ -84,18 +84,20 @@
84 84
     EDIT_ITEM(uint8, MSG_INTENSITY_R, &leds.color.r, 0, 255, leds.update, true);
85 85
     EDIT_ITEM(uint8, MSG_INTENSITY_G, &leds.color.g, 0, 255, leds.update, true);
86 86
     EDIT_ITEM(uint8, MSG_INTENSITY_B, &leds.color.b, 0, 255, leds.update, true);
87
-    #if EITHER(RGBW_LED, NEOPIXEL_LED)
87
+    #if HAS_WHITE_LED
88 88
       EDIT_ITEM(uint8, MSG_INTENSITY_W, &leds.color.w, 0, 255, leds.update, true);
89
-      #if ENABLED(NEOPIXEL_LED)
90
-        EDIT_ITEM(uint8, MSG_LED_BRIGHTNESS, &leds.color.i, 0, 255, leds.update, true);
91
-      #endif
89
+    #endif
90
+    #if ENABLED(NEOPIXEL_LED)
91
+      EDIT_ITEM(uint8, MSG_LED_BRIGHTNESS, &leds.color.i, 0, 255, leds.update, true);
92 92
     #endif
93 93
     #if ENABLED(NEOPIXEL2_SEPARATE)
94 94
       STATIC_ITEM_N(MSG_LED_CHANNEL_N, 2, SS_DEFAULT|SS_INVERT);
95 95
       EDIT_ITEM(uint8, MSG_INTENSITY_R, &leds2.color.r, 0, 255, leds2.update, true);
96 96
       EDIT_ITEM(uint8, MSG_INTENSITY_G, &leds2.color.g, 0, 255, leds2.update, true);
97 97
       EDIT_ITEM(uint8, MSG_INTENSITY_B, &leds2.color.b, 0, 255, leds2.update, true);
98
-      EDIT_ITEM(uint8, MSG_INTENSITY_W, &leds2.color.w, 0, 255, leds2.update, true);
98
+      #if HAS_WHITE_LED2
99
+        EDIT_ITEM(uint8, MSG_INTENSITY_W, &leds2.color.w, 0, 255, leds2.update, true);
100
+      #endif
99 101
       EDIT_ITEM(uint8, MSG_NEO2_BRIGHTNESS, &leds2.color.i, 0, 255, leds2.update, true);
100 102
     #endif
101 103
     END_MENU();

+ 1
- 1
buildroot/tests/DUE Vedi File

@@ -18,7 +18,7 @@ opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS \
18 18
            ASSISTED_TRAMMING ASSISTED_TRAMMING_WIZARD REPORT_TRAMMING_MM ASSISTED_TRAMMING_WAIT_POSITION \
19 19
            EEPROM_SETTINGS SDSUPPORT BINARY_FILE_TRANSFER \
20 20
            BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \
21
-           NEOPIXEL_LED CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_USE_RGB_LED CASE_LIGHT_MENU \
21
+           NEOPIXEL_LED NEOPIXEL_PIN CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_USE_RGB_LED CASE_LIGHT_MENU \
22 22
            NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE FILAMENT_RUNOUT_DISTANCE_MM FILAMENT_RUNOUT_SENSOR \
23 23
            AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \
24 24
            SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE CALIBRATION_GCODE \

+ 4
- 2
buildroot/tests/LPC1768 Vedi File

@@ -14,8 +14,10 @@ set -e
14 14
 #exec_test $1 $2 "Default Configuration" "$3"
15 15
 
16 16
 restore_configs
17
-opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EFB NEOPIXEL_PIN P1_16 SERIAL_PORT_3 3
18
-opt_enable VIKI2 SDSUPPORT SDCARD_READONLY SERIAL_PORT_2 NEOPIXEL_LED
17
+opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EFB  SERIAL_PORT_3 3 \
18
+        NEOPIXEL_TYPE NEO_GRB RGB_LED_R_PIN P2_12 RGB_LED_G_PIN P1_23 RGB_LED_B_PIN P1_22 RGB_LED_W_PIN P1_24
19
+opt_enable FYSETC_MINI_12864_2_1 SDSUPPORT SDCARD_READONLY SERIAL_PORT_2 RGBW_LED \
20
+           NEOPIXEL_LED NEOPIXEL_IS_SEQUENTIAL NEOPIXEL_STARTUP_TEST NEOPIXEL_BKGD_INDEX_FIRST NEOPIXEL_BKGD_INDEX_LAST NEOPIXEL_BKGD_COLOR NEOPIXEL_BKGD_ALWAYS_ON
19 21
 exec_test $1 $2 "ReARM EFB VIKI2, SDSUPPORT, 2 Serial ports (USB CDC + UART0), NeoPixel" "$3"
20 22
 
21 23
 #restore_configs

+ 1
- 1
buildroot/tests/rambo Vedi File

@@ -22,7 +22,7 @@ opt_enable USE_ZMAX_PLUG REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_P
22 22
            PREHEAT_BEFORE_PROBING PROBING_HEATERS_OFF PROBING_FANS_OFF PROBING_STEPPERS_OFF WAIT_FOR_BED_HEATER \
23 23
            EEPROM_SETTINGS SDSUPPORT SD_REPRINT_LAST_SELECTED_FILE BINARY_FILE_TRANSFER \
24 24
            BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \
25
-           NEOPIXEL_LED CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_MENU \
25
+           NEOPIXEL_LED NEOPIXEL_PIN CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_MENU \
26 26
            PID_PARAMS_PER_HOTEND PID_AUTOTUNE_MENU PID_EDIT_MENU LCD_SHOW_E_TOTAL \
27 27
            PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 LEVEL_BED_CORNERS LEVEL_CENTER_TOO \
28 28
            NOZZLE_PARK_FEATURE FILAMENT_RUNOUT_SENSOR FILAMENT_RUNOUT_DISTANCE_MM \

Loading…
Annulla
Salva