Independent Neopixel option (#19115)
This commit is contained in:
@ -44,11 +44,8 @@
|
||||
|
||||
#if ENABLED(LED_COLOR_PRESETS)
|
||||
const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
|
||||
LED_USER_PRESET_RED,
|
||||
LED_USER_PRESET_GREEN,
|
||||
LED_USER_PRESET_BLUE,
|
||||
LED_USER_PRESET_WHITE,
|
||||
LED_USER_PRESET_BRIGHTNESS
|
||||
LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE,
|
||||
LED_USER_PRESET_WHITE, LED_USER_PRESET_BRIGHTNESS
|
||||
);
|
||||
#endif
|
||||
|
||||
@ -117,12 +114,13 @@ void LEDLights::set_color(const LEDColor &incol
|
||||
|
||||
// This variant uses 3-4 separate pins for the RGB(W) components.
|
||||
// If the pins can do PWM then their intensity will be set.
|
||||
#define UPDATE_RGBW(C,c) do { if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
#define UPDATE_RGBW(C,c) do { \
|
||||
if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \
|
||||
else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
|
||||
UPDATE_RGBW(R,r);
|
||||
UPDATE_RGBW(G,g);
|
||||
UPDATE_RGBW(B,b);
|
||||
else \
|
||||
WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); \
|
||||
}while(0)
|
||||
UPDATE_RGBW(R,r); UPDATE_RGBW(G,g); UPDATE_RGBW(B,b);
|
||||
#if ENABLED(RGBW_LED)
|
||||
UPDATE_RGBW(W,w);
|
||||
#endif
|
||||
@ -158,4 +156,35 @@ void LEDLights::set_color(const LEDColor &incol
|
||||
|
||||
#endif
|
||||
|
||||
#endif // HAS_COLOR_LEDS
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
#if ENABLED(NEO2_COLOR_PRESETS)
|
||||
const LEDColor LEDLights2::defaultLEDColor = MakeLEDColor(
|
||||
NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE,
|
||||
NEO2_USER_PRESET_WHITE, NEO2_USER_PRESET_BRIGHTNESS
|
||||
);
|
||||
#endif
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
LEDColor LEDLights2::color;
|
||||
bool LEDLights2::lights_on;
|
||||
#endif
|
||||
|
||||
LEDLights2 leds2;
|
||||
|
||||
void LEDLights2::setup() {
|
||||
neo2.init();
|
||||
TERN_(NEO2_USER_PRESET_STARTUP, set_default());
|
||||
}
|
||||
|
||||
void LEDLights2::set_color(const LEDColor &incol) {
|
||||
const uint32_t neocolor = LEDColorWhite() == incol
|
||||
? neo2.Color(NEO2_WHITE)
|
||||
: neo2.Color(incol.r, incol.g, incol.b, incol.w);
|
||||
neo2.set_brightness(incol.i);
|
||||
neo2.set_color(neocolor);
|
||||
}
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
||||
#endif // HAS_COLOR_LEDS
|
||||
|
@ -155,11 +155,9 @@ public:
|
||||
static inline void set_color(uint8_t r, uint8_t g, uint8_t b
|
||||
#if HAS_WHITE_LED
|
||||
, uint8_t w=0
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, uint8_t i=NEOPIXEL_BRIGHTNESS
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
, uint8_t i=NEOPIXEL_BRIGHTNESS
|
||||
, bool isSequence=false
|
||||
#endif
|
||||
) {
|
||||
@ -212,3 +210,44 @@ public:
|
||||
};
|
||||
|
||||
extern LEDLights leds;
|
||||
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
class LEDLights2 {
|
||||
public:
|
||||
LEDLights2() {}
|
||||
|
||||
static void setup(); // init()
|
||||
|
||||
static void set_color(const LEDColor &color);
|
||||
|
||||
inline void set_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w=0, uint8_t i=NEOPIXEL2_BRIGHTNESS) {
|
||||
set_color(MakeLEDColor(r, g, b, w, i));
|
||||
}
|
||||
|
||||
static inline void set_off() { set_color(LEDColorOff()); }
|
||||
static inline void set_green() { set_color(LEDColorGreen()); }
|
||||
static inline void set_white() { set_color(LEDColorWhite()); }
|
||||
|
||||
#if ENABLED(NEO2_COLOR_PRESETS)
|
||||
static const LEDColor defaultLEDColor;
|
||||
static inline void set_default() { set_color(defaultLEDColor); }
|
||||
static inline void set_red() { set_color(LEDColorRed()); }
|
||||
static inline void set_orange() { set_color(LEDColorOrange()); }
|
||||
static inline void set_yellow() { set_color(LEDColorYellow()); }
|
||||
static inline void set_blue() { set_color(LEDColorBlue()); }
|
||||
static inline void set_indigo() { set_color(LEDColorIndigo()); }
|
||||
static inline void set_violet() { set_color(LEDColorViolet()); }
|
||||
#endif
|
||||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
static LEDColor color; // last non-off color
|
||||
static bool lights_on; // the last set color was "on"
|
||||
static void toggle(); // swap "off" with color
|
||||
static inline void update() { set_color(color); }
|
||||
#endif
|
||||
};
|
||||
|
||||
extern LEDLights2 leds2;
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "neopixel.h"
|
||||
|
||||
#if ENABLED(NEOPIXEL_STARTUP_TEST)
|
||||
#if EITHER(NEOPIXEL_STARTUP_TEST, NEOPIXEL2_STARTUP_TEST)
|
||||
#include "../../core/utility.h"
|
||||
#endif
|
||||
|
||||
@ -38,7 +38,7 @@ Marlin_NeoPixel neo;
|
||||
int8_t Marlin_NeoPixel::neoindex;
|
||||
|
||||
Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
|
||||
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
|
||||
#if CONJOINED_NEOPIXEL
|
||||
, Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800)
|
||||
#endif
|
||||
;
|
||||
@ -120,4 +120,53 @@ bool Marlin_NeoPixel::set_led_color(const uint8_t r, const uint8_t g, const uint
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
Marlin_NeoPixel2 neo2;
|
||||
|
||||
int8_t Marlin_NeoPixel2::neoindex;
|
||||
Adafruit_NeoPixel Marlin_NeoPixel2::adaneo(NEOPIXEL2_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE);
|
||||
|
||||
void Marlin_NeoPixel2::set_color(const uint32_t color) {
|
||||
if (neoindex >= 0) {
|
||||
set_pixel_color(neoindex, color);
|
||||
neoindex = -1;
|
||||
}
|
||||
else {
|
||||
for (uint16_t i = 0; i < pixels(); ++i)
|
||||
set_pixel_color(i, color);
|
||||
}
|
||||
show();
|
||||
}
|
||||
|
||||
void Marlin_NeoPixel2::set_color_startup(const uint32_t color) {
|
||||
for (uint16_t i = 0; i < pixels(); ++i)
|
||||
set_pixel_color(i, color);
|
||||
show();
|
||||
}
|
||||
|
||||
void Marlin_NeoPixel2::init() {
|
||||
neoindex = -1; // -1 .. NEOPIXEL2_PIXELS-1 range
|
||||
set_brightness(NEOPIXEL2_BRIGHTNESS); // 0 .. 255 range
|
||||
begin();
|
||||
show(); // initialize to all off
|
||||
|
||||
#if ENABLED(NEOPIXEL2_STARTUP_TEST)
|
||||
set_color_startup(adaneo.Color(255, 0, 0, 0)); // red
|
||||
safe_delay(500);
|
||||
set_color_startup(adaneo.Color(0, 255, 0, 0)); // green
|
||||
safe_delay(500);
|
||||
set_color_startup(adaneo.Color(0, 0, 255, 0)); // blue
|
||||
safe_delay(500);
|
||||
#endif
|
||||
|
||||
#if ENABLED(NEO2_USER_PRESET_STARTUP)
|
||||
set_color(adaneo.Color(NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE, NEO2_USER_PRESET_WHITE));
|
||||
#else
|
||||
set_color(adaneo.Color(0, 0, 0, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
||||
#endif // NEOPIXEL_LED
|
||||
|
@ -38,10 +38,14 @@
|
||||
// Defines
|
||||
// ------------------------
|
||||
|
||||
#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE
|
||||
#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
|
||||
#define MULTIPLE_NEOPIXEL_TYPES 1
|
||||
#endif
|
||||
|
||||
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
|
||||
#define CONJOINED_NEOPIXEL 1
|
||||
#endif
|
||||
|
||||
#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 NEOPIXEL_IS_RGB 1
|
||||
#else
|
||||
@ -61,7 +65,7 @@
|
||||
class Marlin_NeoPixel {
|
||||
private:
|
||||
static Adafruit_NeoPixel adaneo1
|
||||
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
|
||||
#if CONJOINED_NEOPIXEL
|
||||
, adaneo2
|
||||
#endif
|
||||
;
|
||||
@ -80,11 +84,7 @@ public:
|
||||
|
||||
static inline void begin() {
|
||||
adaneo1.begin();
|
||||
#if ENABLED(NEOPIXEL2_INSERIES)
|
||||
adaneo2.begin();
|
||||
#else
|
||||
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.begin());
|
||||
#endif
|
||||
TERN_(CONJOINED_NEOPIXEL, adaneo2.begin());
|
||||
}
|
||||
|
||||
static inline void set_pixel_color(const uint16_t n, const uint32_t c) {
|
||||
@ -93,23 +93,21 @@ public:
|
||||
else adaneo1.setPixelColor(n, c);
|
||||
#else
|
||||
adaneo1.setPixelColor(n, c);
|
||||
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c));
|
||||
#if MULTIPLE_NEOPIXEL_TYPES
|
||||
adaneo2.setPixelColor(n, c);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void set_brightness(const uint8_t b) {
|
||||
adaneo1.setBrightness(b);
|
||||
#if ENABLED(NEOPIXEL2_INSERIES)
|
||||
adaneo2.setBrightness(b);
|
||||
#else
|
||||
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setBrightness(b));
|
||||
#endif
|
||||
TERN_(CONJOINED_NEOPIXEL, adaneo2.setBrightness(b));
|
||||
}
|
||||
|
||||
static inline void show() {
|
||||
adaneo1.show();
|
||||
#if PIN_EXISTS(NEOPIXEL2)
|
||||
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
|
||||
#if CONJOINED_NEOPIXEL
|
||||
adaneo2.show();
|
||||
#else
|
||||
adaneo1.setPin(NEOPIXEL2_PIN);
|
||||
@ -132,3 +130,47 @@ public:
|
||||
};
|
||||
|
||||
extern Marlin_NeoPixel neo;
|
||||
|
||||
// Neo pixel channel 2
|
||||
#if ENABLED(NEOPIXEL2_SEPARATE)
|
||||
|
||||
#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
|
||||
#define NEOPIXEL2_IS_RGB 1
|
||||
#else
|
||||
#define NEOPIXEL2_IS_RGBW 1
|
||||
#endif
|
||||
|
||||
#if NEOPIXEL2_IS_RGB
|
||||
#define NEO2_WHITE 255, 255, 255, 0
|
||||
#else
|
||||
#define NEO2_WHITE 0, 0, 0, 255
|
||||
#endif
|
||||
|
||||
class Marlin_NeoPixel2 {
|
||||
private:
|
||||
static Adafruit_NeoPixel adaneo;
|
||||
|
||||
public:
|
||||
static int8_t neoindex;
|
||||
|
||||
static void init();
|
||||
static void set_color_startup(const uint32_t c);
|
||||
|
||||
static void set_color(const uint32_t c);
|
||||
|
||||
static inline void begin() { adaneo.begin(); }
|
||||
static inline void set_pixel_color(const uint16_t n, const uint32_t c) { adaneo.setPixelColor(n, c); }
|
||||
static inline void set_brightness(const uint8_t b) { adaneo.setBrightness(b); }
|
||||
static inline void show() { adaneo.show(); }
|
||||
|
||||
// Accessors
|
||||
static inline uint16_t pixels() { return adaneo.numPixels();}
|
||||
static inline uint8_t brightness() { return adaneo.getBrightness(); }
|
||||
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
return adaneo.Color(r, g, b, w);
|
||||
}
|
||||
};
|
||||
|
||||
extern Marlin_NeoPixel2 neo2;
|
||||
|
||||
#endif // NEOPIXEL2_SEPARATE
|
||||
|
Reference in New Issue
Block a user