M150 I to set Neopixel by index (#18490)

This commit is contained in:
ellensp
2020-07-04 09:33:09 +12:00
committed by GitHub
parent bb89e33e24
commit 91dc74ff16
3 changed files with 29 additions and 10 deletions

View File

@ -35,6 +35,7 @@
#endif
Marlin_NeoPixel neo;
int8_t Marlin_NeoPixel::neoindex;
Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
#if MULTIPLE_NEOPIXEL_TYPES
@ -52,14 +53,20 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
#endif
void Marlin_NeoPixel::set_color(const uint32_t color) {
for (uint16_t i = 0; i < pixels(); ++i) {
#ifdef NEOPIXEL_BKGD_LED_INDEX
if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
set_color_background();
continue;
}
#endif
set_pixel_color(i, color);
if (get_neo_index() < 0) {
set_pixel_color(get_neo_index(), color);
set_neo_index(-1);
}
else {
for (uint16_t i = 0; i < pixels(); ++i) {
#ifdef NEOPIXEL_BKGD_LED_INDEX
if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
set_color_background();
continue;
}
#endif
set_pixel_color(i, color);
}
}
show();
}
@ -71,7 +78,8 @@ void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
}
void Marlin_NeoPixel::init() {
set_brightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
set_neo_index(-1); // -1 .. NEOPIXEL_PIXELS-1 range
set_brightness(NEOPIXEL_BRIGHTNESS); // 0 .. 255 range
begin();
show(); // initialize to all off

View File

@ -65,6 +65,7 @@ private:
, adaneo2
#endif
;
static int8_t neoindex;
public:
static void init();
@ -72,6 +73,9 @@ public:
static void set_color(const uint32_t c);
FORCE_INLINE static void set_neo_index(const int8_t neoIndex) { neoindex = neoIndex; }
FORCE_INLINE static int8_t get_neo_index() { return neoindex; }
#ifdef NEOPIXEL_BKGD_LED_INDEX
static void set_color_background();
#endif