M150 I to set Neopixel by index (#18490)
This commit is contained in:
parent
bb89e33e24
commit
91dc74ff16
3 changed files with 29 additions and 10 deletions
|
@ -35,6 +35,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Marlin_NeoPixel neo;
|
Marlin_NeoPixel neo;
|
||||||
|
int8_t Marlin_NeoPixel::neoindex;
|
||||||
|
|
||||||
Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
|
Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
|
||||||
#if MULTIPLE_NEOPIXEL_TYPES
|
#if MULTIPLE_NEOPIXEL_TYPES
|
||||||
|
@ -52,14 +53,20 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Marlin_NeoPixel::set_color(const uint32_t color) {
|
void Marlin_NeoPixel::set_color(const uint32_t color) {
|
||||||
for (uint16_t i = 0; i < pixels(); ++i) {
|
if (get_neo_index() < 0) {
|
||||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
set_pixel_color(get_neo_index(), color);
|
||||||
if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
|
set_neo_index(-1);
|
||||||
set_color_background();
|
}
|
||||||
continue;
|
else {
|
||||||
}
|
for (uint16_t i = 0; i < pixels(); ++i) {
|
||||||
#endif
|
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||||
set_pixel_color(i, color);
|
if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
|
||||||
|
set_color_background();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
set_pixel_color(i, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
@ -71,7 +78,8 @@ void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marlin_NeoPixel::init() {
|
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();
|
begin();
|
||||||
show(); // initialize to all off
|
show(); // initialize to all off
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ private:
|
||||||
, adaneo2
|
, adaneo2
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
static int8_t neoindex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void init();
|
static void init();
|
||||||
|
@ -72,6 +73,9 @@ public:
|
||||||
|
|
||||||
static void set_color(const uint32_t c);
|
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
|
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||||
static void set_color_background();
|
static void set_color_background();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
* Always sets all 3 or 4 components. If a component is left out, set to 0.
|
* Always sets all 3 or 4 components. If a component is left out, set to 0.
|
||||||
* If brightness is left out, no value changed
|
* If brightness is left out, no value changed
|
||||||
*
|
*
|
||||||
|
* With NEOPIXEL_LED:
|
||||||
|
* I<index> Set the Neopixel index to affect. Default: All
|
||||||
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
* M150 R255 ; Turn LED red
|
* M150 R255 ; Turn LED red
|
||||||
|
@ -43,8 +46,12 @@
|
||||||
* M150 W ; Turn LED white using a white LED
|
* M150 W ; Turn LED white using a white LED
|
||||||
* M150 P127 ; Set LED 50% brightness
|
* M150 P127 ; Set LED 50% brightness
|
||||||
* M150 P ; Set LED full brightness
|
* M150 P ; Set LED full brightness
|
||||||
|
* M150 I1 R ; Set NEOPIXEL index 1 to red
|
||||||
*/
|
*/
|
||||||
void GcodeSuite::M150() {
|
void GcodeSuite::M150() {
|
||||||
|
#if ENABLED(NEOPIXEL_LED)
|
||||||
|
neo.set_neo_index(parser.intval('I', -1));
|
||||||
|
#endif
|
||||||
leds.set_color(MakeLEDColor(
|
leds.set_color(MakeLEDColor(
|
||||||
parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
|
parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
|
||||||
parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
|
parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0,
|
||||||
|
|
Reference in a new issue