|
|
@ -25,6 +25,10 @@ |
|
|
|
* NeoPixel support |
|
|
|
*/ |
|
|
|
|
|
|
|
#ifndef _NEOPIXEL_INCLUDE_ |
|
|
|
#error "Always include 'leds.h' and not 'neopixel.h' directly." |
|
|
|
#endif |
|
|
|
|
|
|
|
// ------------------------
|
|
|
|
// Includes
|
|
|
|
// ------------------------
|
|
|
@ -38,24 +42,24 @@ |
|
|
|
// Defines
|
|
|
|
// ------------------------
|
|
|
|
|
|
|
|
#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE) |
|
|
|
#define MULTIPLE_NEOPIXEL_TYPES 1 |
|
|
|
#endif |
|
|
|
#define _NEO_IS_RGB(N) (N == NEO_RGB || N == NEO_RBG || N == NEO_GRB || N == NEO_GBR || N == NEO_BRG || N == NEO_BGR) |
|
|
|
|
|
|
|
#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES) |
|
|
|
#define CONJOINED_NEOPIXEL 1 |
|
|
|
#if !_NEO_IS_RGB(NEOPIXEL_TYPE) |
|
|
|
#define HAS_WHITE_LED 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 |
|
|
|
#if HAS_WHITE_LED |
|
|
|
#define NEO_WHITE 0, 0, 0, 255 |
|
|
|
#else |
|
|
|
#define NEOPIXEL_IS_RGBW 1 |
|
|
|
#define NEO_WHITE 255, 255, 255 |
|
|
|
#endif |
|
|
|
|
|
|
|
#if NEOPIXEL_IS_RGB |
|
|
|
#define NEO_WHITE 255, 255, 255, 0 |
|
|
|
#else |
|
|
|
#define NEO_WHITE 0, 0, 0, 255 |
|
|
|
#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 |
|
|
|
|
|
|
|
// ------------------------
|
|
|
@ -64,11 +68,10 @@ |
|
|
|
|
|
|
|
class Marlin_NeoPixel { |
|
|
|
private: |
|
|
|
static Adafruit_NeoPixel adaneo1 |
|
|
|
static Adafruit_NeoPixel adaneo1; |
|
|
|
#if CONJOINED_NEOPIXEL |
|
|
|
, adaneo2 |
|
|
|
static Adafruit_NeoPixel adaneo2; |
|
|
|
#endif |
|
|
|
; |
|
|
|
|
|
|
|
public: |
|
|
|
static int8_t neoindex; |
|
|
@ -78,8 +81,9 @@ public: |
|
|
|
|
|
|
|
static void set_color(const uint32_t c); |
|
|
|
|
|
|
|
#ifdef NEOPIXEL_BKGD_LED_INDEX |
|
|
|
static void set_color_background(); |
|
|
|
#ifdef NEOPIXEL_BKGD_INDEX_FIRST |
|
|
|
static void set_background_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w); |
|
|
|
static void reset_background_color(); |
|
|
|
#endif |
|
|
|
|
|
|
|
static inline void begin() { |
|
|
@ -93,9 +97,7 @@ public: |
|
|
|
else adaneo1.setPixelColor(n, c); |
|
|
|
#else |
|
|
|
adaneo1.setPixelColor(n, c); |
|
|
|
#if MULTIPLE_NEOPIXEL_TYPES |
|
|
|
adaneo2.setPixelColor(n, c); |
|
|
|
#endif |
|
|
|
TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c)); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
@ -120,15 +122,13 @@ public: |
|
|
|
TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT()); |
|
|
|
} |
|
|
|
|
|
|
|
#if 0 |
|
|
|
bool set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p); |
|
|
|
#endif |
|
|
|
|
|
|
|
// Accessors
|
|
|
|
static inline uint16_t pixels() { TERN(NEOPIXEL2_INSERIES, return adaneo1.numPixels() * 2, return adaneo1.numPixels()); } |
|
|
|
static inline uint16_t pixels() { return adaneo1.numPixels() * TERN1(NEOPIXEL2_INSERIES, 2); } |
|
|
|
|
|
|
|
static inline uint8_t brightness() { return adaneo1.getBrightness(); } |
|
|
|
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { |
|
|
|
return adaneo1.Color(r, g, b, w); |
|
|
|
|
|
|
|
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w)) { |
|
|
|
return adaneo1.Color(r, g, b OPTARG(HAS_WHITE_LED, w)); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
@ -137,15 +137,12 @@ 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 |
|
|
|
#if _NEO_IS_RGB(NEOPIXEL2_TYPE) |
|
|
|
#define NEOPIXEL2_IS_RGB 1 |
|
|
|
#define NEO2_WHITE 255, 255, 255 |
|
|
|
#else |
|
|
|
#define NEOPIXEL2_IS_RGBW 1 |
|
|
|
#endif |
|
|
|
|
|
|
|
#if NEOPIXEL2_IS_RGB |
|
|
|
#define NEO2_WHITE 255, 255, 255, 0 |
|
|
|
#else |
|
|
|
#define HAS_WHITE_LED2 1 // A white component can be passed for NEOPIXEL2
|
|
|
|
#define NEO2_WHITE 0, 0, 0, 255 |
|
|
|
#endif |
|
|
|
|
|
|
@ -172,11 +169,13 @@ extern Marlin_NeoPixel neo; |
|
|
|
// 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); |
|
|
|
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED2, uint8_t w)) { |
|
|
|
return adaneo.Color(r, g, b OPTARG(HAS_WHITE_LED2, w)); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
extern Marlin_NeoPixel2 neo2; |
|
|
|
|
|
|
|
#endif // NEOPIXEL2_SEPARATE
|
|
|
|
|
|
|
|
#undef _NEO_IS_RGB |
|
|
|