Browse Source

Neopixel changes for parity with 1.1.x

Scott Lahteine 7 years ago
parent
commit
3ac581eac9

+ 1
- 1
.travis.yml View File

@@ -61,7 +61,7 @@ script:
61 61
   - opt_set TEMP_SENSOR_BED 1
62 62
   - opt_enable PIDTEMPBED Z_SAFE_HOMING ARC_P_CIRCLES CNC_WORKSPACE_PLANES
63 63
   - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS
64
-  - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_RGBW_LED
64
+  - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED
65 65
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
66 66
 
67 67
   #

+ 0
- 1
Marlin/src/Marlin.cpp View File

@@ -789,7 +789,6 @@ void setup() {
789 789
   #endif
790 790
 
791 791
   #if ENABLED(NEOPIXEL_LED)
792
-    SET_OUTPUT(NEOPIXEL_PIN);
793 792
     setup_neopixel();
794 793
   #endif
795 794
 

+ 22
- 6
Marlin/src/feature/leds/leds.cpp View File

@@ -31,15 +31,31 @@
31 31
 #include "leds.h"
32 32
 
33 33
 void set_led_color(
34
-  const uint8_t r, const uint8_t g, const uint8_t b , const uint8_t w , const uint8_t p
34
+  const uint8_t r, const uint8_t g, const uint8_t b
35
+    #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
36
+      , const uint8_t w // = 0
37
+      #if ENABLED(NEOPIXEL_LED)
38
+        , const uint8_t p // = NEOPIXEL_BRIGHTNESS
39
+        , const bool isSequence // = false
40
+      #endif
41
+    #endif
35 42
 ) {
36 43
 
37 44
   #if ENABLED(NEOPIXEL_LED)
38
-    if (w == 255 || (r == 255 && g == 255 && b == 255))
39
-      neopixel_set_led_color(NEO_WHITE, p);
40
-    else
41
-      neopixel_set_led_color(r, g, b, w, p);
42
-    return;
45
+
46
+    const uint32_t color = pixels.Color(r, g, b, w);
47
+    static uint16_t nextLed = 0;
48
+
49
+    pixels.setBrightness(p);
50
+    if (!isSequence)
51
+      set_neopixel_color(color);
52
+    else {
53
+      pixels.setPixelColor(nextLed, color);
54
+      pixels.show();
55
+      if (++nextLed >= pixels.numPixels()) nextLed = 0;
56
+      return;
57
+    }
58
+
43 59
   #endif
44 60
 
45 61
   #if ENABLED(BLINKM)

+ 10
- 9
Marlin/src/feature/leds/leds.h View File

@@ -27,6 +27,8 @@
27 27
 #ifndef __LEDS_H__
28 28
 #define __LEDS_H__
29 29
 
30
+#include "../../inc/MarlinConfig.h"
31
+
30 32
 #if ENABLED(NEOPIXEL_LED)
31 33
   #include <Adafruit_NeoPixel.h>
32 34
   #include "neopixel.h"
@@ -40,14 +42,6 @@
40 42
   #include "pca9632.h"
41 43
 #endif
42 44
 
43
-#if ENABLED(NEOPIXEL_LED) 
44
-  #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
45
-    #define NEO_WHITE 255, 255, 255
46
-  #else
47
-    #define NEO_WHITE 0, 0, 0, 255
48
-  #endif
49
-#endif
50
-
51 45
 #if ENABLED(RGB_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
52 46
   #define LED_WHITE 255, 255, 255
53 47
 #elif ENABLED(RGBW_LED)
@@ -61,7 +55,14 @@
61 55
 #endif
62 56
 
63 57
 void set_led_color(
64
-  const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w = 0, const uint8_t p = 255
58
+  const uint8_t r, const uint8_t g, const uint8_t b
59
+    #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
60
+      , const uint8_t w = 0
61
+      #if ENABLED(NEOPIXEL_LED)
62
+        , const uint8_t p = NEOPIXEL_BRIGHTNESS
63
+        , const bool isSequence = false
64
+      #endif
65
+    #endif
65 66
 );
66 67
 
67 68
 #endif // __LEDS_H__

+ 2
- 16
Marlin/src/feature/leds/neopixel.cpp View File

@@ -39,6 +39,7 @@ void set_neopixel_color(const uint32_t color) {
39 39
 }
40 40
 
41 41
 void setup_neopixel() {
42
+  SET_OUTPUT(NEOPIXEL_PIN);
42 43
   pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
43 44
   pixels.begin();
44 45
   pixels.show(); // initialize to all off
@@ -52,22 +53,7 @@ void setup_neopixel() {
52 53
     set_neopixel_color(pixels.Color(0, 0, 255, 0));  // blue
53 54
     delay(2000);
54 55
   #endif
55
-  set_neopixel_color(pixels.Color(0, 0, 0, 255));    // white
56
-}
57
-
58
-bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p) {
59
-  const uint32_t color = pixels.Color(r, g, b, w);
60
-  pixels.setBrightness(p);
61
-  #if !ENABLED(NEOPIXEL_IS_SEQUENTIAL)
62
-    set_neopixel_color(color);
63
-    return false;
64
-  #else
65
-    static uint16_t nextLed = 0;
66
-    pixels.setPixelColor(nextLed, color);
67
-    pixels.show();
68
-    if (++nextLed >= pixels.numPixels()) nextLed = 0;
69
-    return true;
70
-  #endif
56
+  set_neopixel_color(pixels.Color(NEO_WHITE));       // white
71 57
 }
72 58
 
73 59
 #endif // NEOPIXEL_LED

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

@@ -27,11 +27,22 @@
27 27
 #ifndef __NEOPIXEL_H__
28 28
 #define __NEOPIXEL_H__
29 29
 
30
+#include "../../inc/MarlinConfig.h"
31
+
30 32
 #include <Adafruit_NeoPixel.h>
31 33
 #include <stdint.h>
32 34
 
35
+#define NEOPIXEL_IS_RGB  (NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR)
36
+#define NEOPIXEL_IS_RGBW !NEOPIXEL_IS_RGB
37
+
38
+#if NEOPIXEL_IS_RGB
39
+  #define NEO_WHITE 255, 255, 255
40
+#else
41
+  #define NEO_WHITE 0, 0, 0, 255
42
+#endif
43
+
33 44
 void setup_neopixel();
34
-bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p);
45
+void set_neopixel_color(const uint32_t color);
35 46
 
36 47
 extern Adafruit_NeoPixel pixels;
37 48
 

+ 7
- 3
Marlin/src/gcode/feature/leds/M150.cpp View File

@@ -49,9 +49,13 @@ void GcodeSuite::M150() {
49 49
   set_led_color(
50 50
     parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
51 51
     parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
52
-    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
53
-    parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
54
-    parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : LED_BRIGHTNESS
52
+    parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0
53
+    #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
54
+      , parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0
55
+      #if ENABLED(NEOPIXEL_LED)
56
+        , parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : pixels.getBrightness()
57
+      #endif
58
+    #endif
55 59
   );
56 60
 }
57 61
 

+ 8
- 1
Marlin/src/gcode/temperature/M104_M109.cpp View File

@@ -190,7 +190,14 @@ void GcodeSuite::M109() {
190 190
         const uint8_t blue = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 255, 0);
191 191
         if (blue != old_blue) {
192 192
           old_blue = blue;
193
-          set_led_color(255, 0, blue);
193
+          set_led_color(255, 0, blue
194
+            #if ENABLED(NEOPIXEL_LED)
195
+              , 0, pixels.getBrightness()
196
+              #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
197
+                , true
198
+              #endif
199
+            #endif
200
+          );
194 201
         }
195 202
       }
196 203
     #endif

+ 8
- 1
Marlin/src/gcode/temperature/M140_M190.cpp View File

@@ -132,7 +132,14 @@ void GcodeSuite::M190() {
132 132
         const uint8_t red = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 0, 255);
133 133
         if (red != old_red) {
134 134
           old_red = red;
135
-          set_led_color(red, 0, 255);
135
+          set_led_color(red, 0, 255
136
+            #if ENABLED(NEOPIXEL_LED)
137
+              , 0, pixels.getBrightness()
138
+              #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
139
+                , true
140
+              #endif
141
+            #endif
142
+          );
136 143
         }
137 144
       }
138 145
     #endif

+ 1
- 1
Marlin/src/inc/SanityCheck.h View File

@@ -1162,7 +1162,7 @@ static_assert(1 >= 0
1162 1162
   #if !(PIN_EXISTS(NEOPIXEL) && NEOPIXEL_PIXELS > 0)
1163 1163
     #error "NEOPIXEL_LED requires NEOPIXEL_PIN and NEOPIXEL_PIXELS."
1164 1164
   #endif
1165
-#elif ENABLED(PRINTER_EVENT_LEDS) && DISABLED(BLINKM) && DISABLED(PCA9632) && DISABLED(NEOPIXEL_LED)
1165
+#elif ENABLED(PRINTER_EVENT_LEDS) && DISABLED(BLINKM) && DISABLED(PCA9632)
1166 1166
   #error "PRINTER_EVENT_LEDS requires BLINKM, PCA9632, RGB_LED, RGBW_LED or NEOPIXEL_LED."
1167 1167
 #endif
1168 1168
 

Loading…
Cancel
Save