Merge pull request #8094 from thinkyhead/bf2_neopixel_led_parity

[2.0.x] Bring NEOPIXEL_LED into parity with 1.1.x
2.0.x
Scott Lahteine 7 years ago committed by GitHub
commit c45514f811

@ -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}
#

@ -792,7 +792,6 @@ void setup() {
#endif
#if ENABLED(NEOPIXEL_LED)
SET_OUTPUT(NEOPIXEL_PIN);
setup_neopixel();
#endif

@ -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);
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)

@ -27,6 +27,8 @@
#ifndef __LEDS_H__
#define __LEDS_H__
#include "../../inc/MarlinConfig.h"
#if ENABLED(NEOPIXEL_LED)
#include <Adafruit_NeoPixel.h>
#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__

@ -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

@ -27,11 +27,22 @@
#ifndef __NEOPIXEL_H__
#define __NEOPIXEL_H__
#include "../../inc/MarlinConfig.h"
#include <Adafruit_NeoPixel.h>
#include <stdint.h>
#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;

@ -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
);
}

@ -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

@ -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

@ -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

Loading…
Cancel
Save