M150 K – Keep unspecified components (#24315)

This commit is contained in:
qwertymodo 2022-08-05 22:07:30 -07:00 committed by Scott Lahteine
parent e06340abd1
commit 7196f13125
2 changed files with 21 additions and 8 deletions

View File

@ -131,6 +131,13 @@ public:
// Accessors // Accessors
static uint16_t pixels() { return adaneo1.numPixels() * TERN1(NEOPIXEL2_INSERIES, 2); } static uint16_t pixels() { return adaneo1.numPixels() * TERN1(NEOPIXEL2_INSERIES, 2); }
static uint32_t pixel_color(const uint16_t n) {
#if ENABLED(NEOPIXEL2_INSERIES)
if (n >= NEOPIXEL_PIXELS) return adaneo2.getPixelColor(n - (NEOPIXEL_PIXELS));
#endif
return adaneo1.getPixelColor(n);
}
static uint8_t brightness() { return adaneo1.getBrightness(); } static uint8_t brightness() { return adaneo1.getBrightness(); }
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w)) { static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w)) {
@ -174,6 +181,7 @@ extern Marlin_NeoPixel neo;
// Accessors // Accessors
static uint16_t pixels() { return adaneo.numPixels();} static uint16_t pixels() { return adaneo.numPixels();}
static uint32_t pixel_color(const uint16_t n) { return adaneo.getPixelColor(n); }
static uint8_t brightness() { return adaneo.getBrightness(); } static uint8_t brightness() { return adaneo.getBrightness(); }
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED2, uint8_t w)) { static 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)); return adaneo.Color(r, g, b OPTARG(HAS_WHITE_LED2, w));

View File

@ -31,11 +31,13 @@
* M150: Set Status LED Color - Use R-U-B-W for R-G-B-W * M150: Set Status LED Color - Use R-U-B-W for R-G-B-W
* and Brightness - Use P (for NEOPIXEL only) * and Brightness - Use P (for NEOPIXEL only)
* *
* Always sets all 3 or 4 components. If a component is left out, set to 0. * Always sets all 3 or 4 components unless the K flag is specified.
* If brightness is left out, no value changed * If a component is left out, set to 0.
* If brightness is left out, no value changed.
* *
* With NEOPIXEL_LED: * With NEOPIXEL_LED:
* I<index> Set the NeoPixel index to affect. Default: All * I<index> Set the NeoPixel index to affect. Default: All
* K Keep all unspecified values unchanged instead of setting to 0.
* *
* With NEOPIXEL2_SEPARATE: * With NEOPIXEL2_SEPARATE:
* S<index> The NeoPixel strip to set. Default: All. * S<index> The NeoPixel strip to set. Default: All.
@ -51,16 +53,19 @@
* M150 P ; Set LED full brightness * M150 P ; Set LED full brightness
* M150 I1 R ; Set NEOPIXEL index 1 to red * M150 I1 R ; Set NEOPIXEL index 1 to red
* M150 S1 I1 R ; Set SEPARATE index 1 to red * M150 S1 I1 R ; Set SEPARATE index 1 to red
* M150 K R127 ; Set LED red to 50% without changing blue or green
*/ */
void GcodeSuite::M150() { void GcodeSuite::M150() {
int32_t old_color = 0;
#if ENABLED(NEOPIXEL_LED) #if ENABLED(NEOPIXEL_LED)
const pixel_index_t index = parser.intval('I', -1); const pixel_index_t index = parser.intval('I', -1);
#if ENABLED(NEOPIXEL2_SEPARATE) #if ENABLED(NEOPIXEL2_SEPARATE)
int8_t brightness = neo.brightness(), unit = parser.intval('S', -1); int8_t brightness = neo.brightness(), unit = parser.intval('S', -1);
switch (unit) { switch (unit) {
case -1: neo2.neoindex = index; // fall-thru case -1: neo2.neoindex = index; // fall-thru
case 0: neo.neoindex = index; break; case 0: neo.neoindex = index; old_color = parser.seen('K') ? neo.pixel_color(index >= 0 ? index : 0) : 0; break;
case 1: neo2.neoindex = index; brightness = neo2.brightness(); break; case 1: neo2.neoindex = index; brightness = neo2.brightness(); old_color = parser.seen('K') ? neo2.pixel_color(index >= 0 ? index : 0) : 0; break;
} }
#else #else
const uint8_t brightness = neo.brightness(); const uint8_t brightness = neo.brightness();
@ -69,10 +74,10 @@ void GcodeSuite::M150() {
#endif #endif
const LEDColor color = LEDColor( const LEDColor color = LEDColor(
parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : 0, parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 16) & 0xFF,
parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : 0, parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 8) & 0xFF,
parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : 0 parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : old_color & 0xFF
OPTARG(HAS_WHITE_LED, parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : 0) OPTARG(HAS_WHITE_LED, parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 24) & 0xFF)
OPTARG(NEOPIXEL_LED, parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness) OPTARG(NEOPIXEL_LED, parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness)
); );