From 3ac581eac92d31287580ea6da5357f3d6cd82db5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 25 Oct 2017 15:50:36 -0500 Subject: [PATCH] Neopixel changes for parity with 1.1.x --- .travis.yml | 2 +- Marlin/src/Marlin.cpp | 1 - Marlin/src/feature/leds/leds.cpp | 28 +++++++++++++++++----- Marlin/src/feature/leds/leds.h | 19 ++++++++------- Marlin/src/feature/leds/neopixel.cpp | 18 ++------------ Marlin/src/feature/leds/neopixel.h | 13 +++++++++- Marlin/src/gcode/feature/leds/M150.cpp | 10 +++++--- Marlin/src/gcode/temperature/M104_M109.cpp | 9 ++++++- Marlin/src/gcode/temperature/M140_M190.cpp | 9 ++++++- Marlin/src/inc/SanityCheck.h | 2 +- 10 files changed, 71 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index b9ef8e1e24..0812b8186d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,7 +61,7 @@ script: - opt_set TEMP_SENSOR_BED 1 - opt_enable PIDTEMPBED Z_SAFE_HOMING ARC_P_CIRCLES CNC_WORKSPACE_PLANES - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS - - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_RGBW_LED + - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM} # diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 75f10d0b83..658e2db42d 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -789,7 +789,6 @@ void setup() { #endif #if ENABLED(NEOPIXEL_LED) - SET_OUTPUT(NEOPIXEL_PIN); setup_neopixel(); #endif diff --git a/Marlin/src/feature/leds/leds.cpp b/Marlin/src/feature/leds/leds.cpp index 558e2ca8fe..b412bdc70c 100644 --- a/Marlin/src/feature/leds/leds.cpp +++ b/Marlin/src/feature/leds/leds.cpp @@ -31,15 +31,31 @@ #include "leds.h" void set_led_color( - const uint8_t r, const uint8_t g, const uint8_t b , const uint8_t w , const uint8_t p + const uint8_t r, const uint8_t g, const uint8_t b + #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED) + , const uint8_t w // = 0 + #if ENABLED(NEOPIXEL_LED) + , const uint8_t p // = NEOPIXEL_BRIGHTNESS + , const bool isSequence // = false + #endif + #endif ) { #if ENABLED(NEOPIXEL_LED) - if (w == 255 || (r == 255 && g == 255 && b == 255)) - neopixel_set_led_color(NEO_WHITE, p); - else - neopixel_set_led_color(r, g, b, w, p); - return; + + const uint32_t color = pixels.Color(r, g, b, w); + static uint16_t nextLed = 0; + + pixels.setBrightness(p); + if (!isSequence) + set_neopixel_color(color); + else { + pixels.setPixelColor(nextLed, color); + pixels.show(); + if (++nextLed >= pixels.numPixels()) nextLed = 0; + return; + } + #endif #if ENABLED(BLINKM) diff --git a/Marlin/src/feature/leds/leds.h b/Marlin/src/feature/leds/leds.h index b67e982a77..81c822666a 100644 --- a/Marlin/src/feature/leds/leds.h +++ b/Marlin/src/feature/leds/leds.h @@ -27,6 +27,8 @@ #ifndef __LEDS_H__ #define __LEDS_H__ +#include "../../inc/MarlinConfig.h" + #if ENABLED(NEOPIXEL_LED) #include #include "neopixel.h" @@ -40,14 +42,6 @@ #include "pca9632.h" #endif -#if ENABLED(NEOPIXEL_LED) - #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 - #define NEO_WHITE 255, 255, 255 - #else - #define NEO_WHITE 0, 0, 0, 255 - #endif -#endif - #if ENABLED(RGB_LED) || ENABLED(BLINKM) || ENABLED(PCA9632) #define LED_WHITE 255, 255, 255 #elif ENABLED(RGBW_LED) @@ -61,7 +55,14 @@ #endif void set_led_color( - const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w = 0, const uint8_t p = 255 + const uint8_t r, const uint8_t g, const uint8_t b + #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED) + , const uint8_t w = 0 + #if ENABLED(NEOPIXEL_LED) + , const uint8_t p = NEOPIXEL_BRIGHTNESS + , const bool isSequence = false + #endif + #endif ); #endif // __LEDS_H__ diff --git a/Marlin/src/feature/leds/neopixel.cpp b/Marlin/src/feature/leds/neopixel.cpp index d96e431c32..778170ba65 100644 --- a/Marlin/src/feature/leds/neopixel.cpp +++ b/Marlin/src/feature/leds/neopixel.cpp @@ -39,6 +39,7 @@ void set_neopixel_color(const uint32_t color) { } void setup_neopixel() { + SET_OUTPUT(NEOPIXEL_PIN); pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range pixels.begin(); pixels.show(); // initialize to all off @@ -52,22 +53,7 @@ void setup_neopixel() { set_neopixel_color(pixels.Color(0, 0, 255, 0)); // blue delay(2000); #endif - set_neopixel_color(pixels.Color(0, 0, 0, 255)); // white -} - -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) { - const uint32_t color = pixels.Color(r, g, b, w); - pixels.setBrightness(p); - #if !ENABLED(NEOPIXEL_IS_SEQUENTIAL) - set_neopixel_color(color); - return false; - #else - static uint16_t nextLed = 0; - pixels.setPixelColor(nextLed, color); - pixels.show(); - if (++nextLed >= pixels.numPixels()) nextLed = 0; - return true; - #endif + set_neopixel_color(pixels.Color(NEO_WHITE)); // white } #endif // NEOPIXEL_LED diff --git a/Marlin/src/feature/leds/neopixel.h b/Marlin/src/feature/leds/neopixel.h index 265b93d19d..2b937f1b87 100644 --- a/Marlin/src/feature/leds/neopixel.h +++ b/Marlin/src/feature/leds/neopixel.h @@ -27,11 +27,22 @@ #ifndef __NEOPIXEL_H__ #define __NEOPIXEL_H__ +#include "../../inc/MarlinConfig.h" + #include #include +#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) +#define NEOPIXEL_IS_RGBW !NEOPIXEL_IS_RGB + +#if NEOPIXEL_IS_RGB + #define NEO_WHITE 255, 255, 255 +#else + #define NEO_WHITE 0, 0, 0, 255 +#endif + void setup_neopixel(); -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); +void set_neopixel_color(const uint32_t color); extern Adafruit_NeoPixel pixels; diff --git a/Marlin/src/gcode/feature/leds/M150.cpp b/Marlin/src/gcode/feature/leds/M150.cpp index 91cdd65995..47c6e82ee1 100644 --- a/Marlin/src/gcode/feature/leds/M150.cpp +++ b/Marlin/src/gcode/feature/leds/M150.cpp @@ -49,9 +49,13 @@ void GcodeSuite::M150() { set_led_color( parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0, parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0, - parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0, - parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0, - parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : LED_BRIGHTNESS + parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0 + #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED) + , parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0 + #if ENABLED(NEOPIXEL_LED) + , parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : pixels.getBrightness() + #endif + #endif ); } diff --git a/Marlin/src/gcode/temperature/M104_M109.cpp b/Marlin/src/gcode/temperature/M104_M109.cpp index c99d49312a..afc7cda7a7 100644 --- a/Marlin/src/gcode/temperature/M104_M109.cpp +++ b/Marlin/src/gcode/temperature/M104_M109.cpp @@ -190,7 +190,14 @@ void GcodeSuite::M109() { const uint8_t blue = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 255, 0); if (blue != old_blue) { old_blue = blue; - set_led_color(255, 0, blue); + set_led_color(255, 0, blue + #if ENABLED(NEOPIXEL_LED) + , 0, pixels.getBrightness() + #if ENABLED(NEOPIXEL_IS_SEQUENTIAL) + , true + #endif + #endif + ); } } #endif diff --git a/Marlin/src/gcode/temperature/M140_M190.cpp b/Marlin/src/gcode/temperature/M140_M190.cpp index 3caec006e4..b72f3b7a9e 100644 --- a/Marlin/src/gcode/temperature/M140_M190.cpp +++ b/Marlin/src/gcode/temperature/M140_M190.cpp @@ -132,7 +132,14 @@ void GcodeSuite::M190() { const uint8_t red = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 0, 255); if (red != old_red) { old_red = red; - set_led_color(red, 0, 255); + set_led_color(red, 0, 255 + #if ENABLED(NEOPIXEL_LED) + , 0, pixels.getBrightness() + #if ENABLED(NEOPIXEL_IS_SEQUENTIAL) + , true + #endif + #endif + ); } } #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index b95099fe90..d83e8d3b61 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1162,7 +1162,7 @@ static_assert(1 >= 0 #if !(PIN_EXISTS(NEOPIXEL) && NEOPIXEL_PIXELS > 0) #error "NEOPIXEL_LED requires NEOPIXEL_PIN and NEOPIXEL_PIXELS." #endif -#elif ENABLED(PRINTER_EVENT_LEDS) && DISABLED(BLINKM) && DISABLED(PCA9632) && DISABLED(NEOPIXEL_LED) +#elif ENABLED(PRINTER_EVENT_LEDS) && DISABLED(BLINKM) && DISABLED(PCA9632) #error "PRINTER_EVENT_LEDS requires BLINKM, PCA9632, RGB_LED, RGBW_LED or NEOPIXEL_LED." #endif