🩹 Distinct types for LEDs 1/2 (#27959)

This commit is contained in:
ellensp 2025-08-14 05:04:16 +12:00 committed by GitHub
parent beb3a0fc4b
commit 02fe1ff95e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 224 additions and 155 deletions

View file

@ -40,7 +40,7 @@ bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
#if CASE_LIGHT_IS_COLOR_LED
constexpr uint8_t init_case_light[] = CASE_LIGHT_DEFAULT_COLOR;
LEDColor CaseLight::color = { init_case_light[0], init_case_light[1], init_case_light[2] OPTARG(HAS_WHITE_LED, init_case_light[3]) };
LED1Color_t CaseLight::color = { init_case_light[0], init_case_light[1], init_case_light[2] OPTARG(HAS_WHITE_LED, init_case_light[3]) };
#endif
void CaseLight::update(const bool sflag) {
@ -67,13 +67,13 @@ void CaseLight::update(const bool sflag) {
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
if (on)
// Use current color of (NeoPixel) leds and new brightness level
leds.set_color(LEDColor(leds.color.r, leds.color.g, leds.color.b OPTARG(HAS_WHITE_LED, leds.color.w) OPTARG(NEOPIXEL_LED, n10ct)));
leds.set_color(LED1Color_t(leds.color.r, leds.color.g, leds.color.b OPTARG(HAS_WHITE_LED, leds.color.w) OPTARG(NEOPIXEL_LED, n10ct)));
else
// Switch off leds
leds.set_off();
#else
// Use CaseLight color (CASE_LIGHT_DEFAULT_COLOR) and new brightness level
leds.set_color(LEDColor(color.r, color.g, color.b OPTARG(HAS_WHITE_LED, color.w) OPTARG(NEOPIXEL_LED, n10ct)));
leds.set_color(LED1Color_t(color.r, color.g, color.b OPTARG(HAS_WHITE_LED, color.w) OPTARG(NEOPIXEL_LED, n10ct)));
#endif
#else // !CASE_LIGHT_IS_COLOR_LED

View file

@ -24,7 +24,7 @@
#include "../inc/MarlinConfig.h"
#if CASE_LIGHT_IS_COLOR_LED
#include "leds/leds.h" // for LEDColor
#include "leds/leds.h" // for LED1Color_t
#endif
class CaseLight {
@ -50,7 +50,7 @@ public:
#if ENABLED(CASE_LIGHT_IS_COLOR_LED)
private:
static LEDColor color;
static LED1Color_t color;
#endif
};

View file

@ -32,7 +32,7 @@
#include "leds.h"
#include <Wire.h>
void blinkm_set_led_color(const LEDColor &color) {
void blinkm_set_led_color(const LED1Color_t &color) {
Wire.begin();
Wire.beginTransmission(I2C_ADDRESS(0x09));
Wire.write('o'); //to disable ongoing script, only needs to be used once

View file

@ -25,7 +25,6 @@
* blinkm.h - Control a BlinkM over i2c
*/
struct LEDColor;
typedef LEDColor LEDColor;
struct LED1Color_t;
void blinkm_set_led_color(const LEDColor &color);
void blinkm_set_led_color(const LED1Color_t &color);

View file

@ -35,15 +35,15 @@
#endif
#if ENABLED(LED_COLOR_PRESETS)
const LEDColor LEDLights::defaultLEDColor = LEDColor(
const LED1Color_t LEDLights::defaultLEDColor {
LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE
OPTARG(HAS_WHITE_LED, LED_USER_PRESET_WHITE)
OPTARG(NEOPIXEL_LED, LED_USER_PRESET_BRIGHTNESS)
);
};
#endif
#if ANY(LED_CONTROL_MENU, PRINTER_EVENT_LEDS, CASE_LIGHT_IS_COLOR_LED)
LEDColor LEDLights::color;
LED1Color_t LEDLights::color;
bool LEDLights::lights_on;
#endif
@ -101,7 +101,7 @@ void LEDLights::setup() {
constexpr int8_t led_pin_count = TERN(HAS_WHITE_LED, 4, 3);
// Startup animation
LEDColor curColor = LEDColorOff();
LED1Color_t curColor = LEDColorOff();
PCA9632_set_led_color(curColor); // blackout
delay(200);
@ -156,15 +156,15 @@ void LEDLights::setup() {
TERN_(LED_USER_PRESET_STARTUP, set_default());
}
void LEDLights::set_color(const LEDColor &incol
void LEDLights::set_color(const LED1Color_t &incol
OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence/*=false*/)
) {
#if ENABLED(NEOPIXEL_LED)
const uint32_t neocolor = LEDColorWhite() == incol
? neo.Color(NEO_WHITE)
: neo.Color(incol.r, incol.g, incol.b OPTARG(HAS_WHITE_LED, incol.w));
? neo.White()
: neo.Color(incol.r, incol.g, incol.b OPTARG(HAS_WHITE_NEOPIXEL_1, incol.w));
#if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
static uint16_t nextLed = 0;
@ -258,7 +258,7 @@ void LEDLights::set_color(const LEDColor &incol
#if ENABLED(NEOPIXEL2_SEPARATE)
#if ENABLED(NEO2_COLOR_PRESETS)
const LEDColor LEDLights2::defaultLEDColor = LEDColor(
const LED2Color_t LEDLights2::defaultLEDColor2 = LED2Color_t(
NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE
OPTARG(HAS_WHITE_LED2, NEO2_USER_PRESET_WHITE)
OPTARG(NEOPIXEL_LED, NEO2_USER_PRESET_BRIGHTNESS)
@ -266,7 +266,7 @@ void LEDLights::set_color(const LEDColor &incol
#endif
#if ENABLED(LED_CONTROL_MENU)
LEDColor LEDLights2::color;
LED2Color_t LEDLights2::color;
bool LEDLights2::lights_on;
#endif
@ -277,10 +277,10 @@ void LEDLights::set_color(const LEDColor &incol
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 OPTARG(HAS_WHITE_LED2, incol.w));
void LEDLights2::set_color(const LED2Color_t &incol) {
const uint32_t neocolor = LEDColorWhite2() == incol
? neo2.White()
: neo2.Color(incol.r, incol.g, incol.b OPTARG(HAS_WHITE_NEOPIXEL_2, incol.w));
neo2.set_brightness(incol.i);
neo2.set_color(neocolor);

View file

@ -29,11 +29,6 @@
#include <string.h>
// A white component can be passed
#if ANY(RGBW_LED, PCA9632_RGBW)
#define HAS_WHITE_LED 1
#endif
#if ENABLED(NEOPIXEL_LED)
#define _NEOPIXEL_INCLUDE_
#include "neopixel.h"
@ -52,75 +47,142 @@
#include "pca9632.h"
#endif
#if ANY(RGBW_LED, PCA9632_RGBW, HAS_WHITE_NEOPIXEL_1)
#define HAS_WHITE_LED 1
#endif
#if HAS_WHITE_NEOPIXEL_2
#define HAS_WHITE_LED2 1
#endif
/**
* LEDcolor type for use with leds.set_color
*/
typedef struct LEDColor {
uint8_t r, g, b
OPTARG(HAS_WHITE_LED, w)
OPTARG(NEOPIXEL_LED, i)
;
struct LED1Color_t {
// Basic RGB color components
uint8_t r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, i);
// Default constructor - white color
LED1Color_t() : r(255), g(255), b(255) OPTARG(HAS_WHITE_LED, w(255)) OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS)){}
LEDColor() : r(255), g(255), b(255)
OPTARG(HAS_WHITE_LED, w(255))
OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS))
{}
// Copy constructor
LED1Color_t(const LED1Color_t&) = default;
LEDColor(const LEDColor&) = default;
LEDColor(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w=0) OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS))
// Constructor with individual components
LED1Color_t(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED, uint8_t w=0) OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS))
: r(r), g(g), b(b) OPTARG(HAS_WHITE_LED, w(w)) OPTARG(NEOPIXEL_LED, i(i)) {}
LEDColor(const uint8_t (&rgbw)[4]) : r(rgbw[0]), g(rgbw[1]), b(rgbw[2])
OPTARG(HAS_WHITE_LED, w(rgbw[3]))
OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS))
{}
// Constructor from array
LED1Color_t(const uint8_t (&rgbw)[4]) : r(rgbw[0]), g(rgbw[1]), b(rgbw[2])
OPTARG(HAS_WHITE_LED, w(rgbw[3])) OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS)){}
LEDColor& operator=(const uint8_t (&rgbw)[4]) {
// Array assignment operator
LED1Color_t& operator=(const uint8_t (&rgbw)[4]) {
r = rgbw[0]; g = rgbw[1]; b = rgbw[2];
TERN_(HAS_WHITE_LED, w = rgbw[3]);
return *this;
}
bool operator==(const LEDColor &right) {
if (this == &right) return true;
return 0 == memcmp(this, &right, sizeof(LEDColor));
// Comparison operators
bool operator==(const LED1Color_t &right) {
return (this == &right) || (0 == memcmp(this, &right, sizeof(LED1Color_t)));
}
bool operator!=(const LEDColor &right) { return !operator==(right); }
bool operator!=(const LED1Color_t &right) {
return !operator==(right);
}
// Check if LED is effectively off
bool is_off() const {
return 3 > r + g + b + TERN0(HAS_WHITE_LED, w);
}
} LEDColor;
};
struct LED2Color_t {
// Basic RGB color components
uint8_t r, g, b OPTARG(HAS_WHITE_LED2, w) OPTARG(NEOPIXEL_LED, i);
// Default constructor - white color
LED2Color_t() : r(255), g(255), b(255) OPTARG(HAS_WHITE_LED2, w(255)) OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS)){}
// Copy constructor
LED2Color_t(const LED2Color_t&) = default;
// Constructor with individual components
LED2Color_t(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_LED2, uint8_t w=0) OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS))
: r(r), g(g), b(b) OPTARG(HAS_WHITE_LED2, w(w)) OPTARG(NEOPIXEL_LED, i(i)) {}
// Constructor from array
LED2Color_t(const uint8_t (&rgbw)[4]) : r(rgbw[0]), g(rgbw[1]), b(rgbw[2])
OPTARG(HAS_WHITE_LED2, w(rgbw[3])) OPTARG(NEOPIXEL_LED, i(NEOPIXEL_BRIGHTNESS)){}
// Array assignment operator
LED2Color_t& operator=(const uint8_t (&rgbw)[4]) {
r = rgbw[0]; g = rgbw[1]; b = rgbw[2];
TERN_(HAS_WHITE_LED2, w = rgbw[3]);
return *this;
}
// Comparison operators
bool operator==(const LED2Color_t &right) {
return (this == &right) || (0 == memcmp(this, &right, sizeof(LED1Color_t)));
}
bool operator!=(const LED2Color_t &right) {
return !operator==(right);
}
// Check if LED is effectively off
bool is_off() const {
return 3 > r + g + b + TERN0(HAS_WHITE_LED2, w);
}
};
/**
* Color presets
*/
#define LEDColorOff() LEDColor( 0, 0, 0)
#define LEDColorRed() LEDColor(255, 0, 0)
#define LEDColorOff() LED1Color_t( 0, 0, 0)
#define LEDColorRed() LED1Color_t(255, 0, 0)
#if ENABLED(LED_COLORS_REDUCE_GREEN)
#define LEDColorOrange() LEDColor(255, 25, 0)
#define LEDColorYellow() LEDColor(255, 75, 0)
#define LEDColorOrange() LED1Color_t(255, 25, 0)
#define LEDColorYellow() LED1Color_t(255, 75, 0)
#else
#define LEDColorOrange() LEDColor(255, 80, 0)
#define LEDColorYellow() LEDColor(255, 255, 0)
#define LEDColorOrange() LED1Color_t(255, 80, 0)
#define LEDColorYellow() LED1Color_t(255, 255, 0)
#endif
#define LEDColorGreen() LEDColor( 0, 255, 0)
#define LEDColorBlue() LEDColor( 0, 0, 255)
#define LEDColorIndigo() LEDColor( 0, 255, 255)
#define LEDColorViolet() LEDColor(255, 0, 255)
#define LEDColorGreen() LED1Color_t( 0, 255, 0)
#define LEDColorBlue() LED1Color_t( 0, 0, 255)
#define LEDColorIndigo() LED1Color_t( 0, 255, 255)
#define LEDColorViolet() LED1Color_t(255, 0, 255)
#if HAS_WHITE_LED && DISABLED(RGB_LED)
#define LEDColorWhite() LEDColor( 0, 0, 0, 255)
#define LEDColorWhite() LED1Color_t( 0, 0, 0, 255)
#else
#define LEDColorWhite() LEDColor(255, 255, 255)
#define LEDColorWhite() LED1Color_t(255, 255, 255)
#endif
#define LEDColorOff2() LED2Color_t( 0, 0, 0)
#define LEDColorRed2() LED2Color_t(255, 0, 0)
#if ENABLED(LED_COLORS_REDUCE_GREEN)
#define LEDColorOrange2() LED2Color_t(255, 25, 0)
#define LEDColorYellow2() LED2Color_t(255, 75, 0)
#else
#define LEDColorOrange2() LED2Color_t(255, 80, 0)
#define LEDColorYellow2() LED2Color_t(255, 255, 0)
#endif
#define LEDColorGreen2() LED2Color_t( 0, 255, 0)
#define LEDColorBlue2() LED2Color_t( 0, 0, 255)
#define LEDColorIndigo2() LED2Color_t( 0, 255, 255)
#define LEDColorViolet2() LED2Color_t(255, 0, 255)
#if HAS_WHITE_LED2 && DISABLED(RGB_LED)
#define LEDColorWhite2() LED2Color_t( 0, 0, 0, 255)
#else
#define LEDColorWhite2() LED2Color_t(255, 255, 255)
#endif
class LEDLights {
public:
#if ANY(LED_CONTROL_MENU, PRINTER_EVENT_LEDS, CASE_LIGHT_IS_COLOR_LED)
static LEDColor color; // last non-off color
static LED1Color_t color; // last non-off color
static bool lights_on; // the last set color was "on"
#else
static constexpr bool lights_on = true;
@ -130,7 +192,7 @@ public:
static void setup(); // init()
static void set_color(const LEDColor &color
static void set_color(const LED1Color_t &color
OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence=false)
);
@ -139,7 +201,7 @@ public:
OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS)
OPTARG(NEOPIXEL_IS_SEQUENTIAL, bool isSequence=false)
) {
set_color(LEDColor(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, i)) OPTARG(NEOPIXEL_IS_SEQUENTIAL, isSequence));
set_color(LED1Color_t(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, i)) OPTARG(NEOPIXEL_IS_SEQUENTIAL, isSequence));
}
static void set_off() { set_color(LEDColorOff()); }
@ -147,7 +209,7 @@ public:
static void set_white() { set_color(LEDColorWhite()); }
#if ENABLED(LED_COLOR_PRESETS)
static const LEDColor defaultLEDColor;
static const LED1Color_t defaultLEDColor;
static void set_default() { set_color(defaultLEDColor); }
static void set_red() { set_color(LEDColorRed()); }
static void set_orange() { set_color(LEDColorOrange()); }
@ -158,7 +220,7 @@ public:
#endif
#if ENABLED(PRINTER_EVENT_LEDS)
static LEDColor get_color() { return lights_on ? color : LEDColorOff(); }
static LED1Color_t get_color() { return lights_on ? color : LEDColorOff(); }
#endif
#if ENABLED(LED_CONTROL_MENU)
@ -190,35 +252,35 @@ extern LEDLights leds;
static void setup(); // init()
static void set_color(const LEDColor &color);
static void set_color(const LED2Color_t &color);
static void set_color(uint8_t r, uint8_t g, uint8_t b
OPTARG(HAS_WHITE_LED, uint8_t w=0)
OPTARG(HAS_WHITE_LED2, uint8_t w=0)
OPTARG(NEOPIXEL_LED, uint8_t i=NEOPIXEL_BRIGHTNESS)
) {
set_color(LEDColor(r, g, b
OPTARG(HAS_WHITE_LED, w)
set_color(LED2Color_t(r, g, b
OPTARG(HAS_WHITE_LED2, w)
OPTARG(NEOPIXEL_LED, i)
));
}
static void set_off() { set_color(LEDColorOff()); }
static void set_green() { set_color(LEDColorGreen()); }
static void set_white() { set_color(LEDColorWhite()); }
static void set_off() { set_color(LEDColorOff2()); }
static void set_green() { set_color(LEDColorGreen2()); }
static void set_white() { set_color(LEDColorWhite2()); }
#if ENABLED(NEO2_COLOR_PRESETS)
static const LEDColor defaultLEDColor;
static void set_default() { set_color(defaultLEDColor); }
static void set_red() { set_color(LEDColorRed()); }
static void set_orange() { set_color(LEDColorOrange()); }
static void set_yellow() { set_color(LEDColorYellow()); }
static void set_blue() { set_color(LEDColorBlue()); }
static void set_indigo() { set_color(LEDColorIndigo()); }
static void set_violet() { set_color(LEDColorViolet()); }
static const LED2Color_t defaultLEDColor2;
static void set_default() { set_color(defaultLEDColor2); }
static void set_red() { set_color(LEDColorRed2()); }
static void set_orange() { set_color(LEDColorOrange2()); }
static void set_yellow() { set_color(LEDColorYellow2()); }
static void set_blue() { set_color(LEDColorBlue2()); }
static void set_indigo() { set_color(LEDColorIndigo2()); }
static void set_violet() { set_color(LEDColorViolet2()); }
#endif
#if ENABLED(NEOPIXEL2_SEPARATE)
static LEDColor color; // last non-off color
static LED2Color_t color; // last non-off color
static bool lights_on; // the last set color was "on"
static void toggle(); // swap "off" with color
static void update() { set_color(color); }

View file

@ -103,7 +103,7 @@ void Marlin_NeoPixel::init() {
safe_delay(500);
set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
safe_delay(500);
#if HAS_WHITE_LED
#if HAS_WHITE_NEOPIXEL_1
set_color_startup(adaneo1.Color(0, 0, 0, 255)); // white
safe_delay(500);
#endif
@ -158,7 +158,7 @@ void Marlin_NeoPixel::init() {
safe_delay(500);
set_color_startup(adaneo.Color(0, 0, 255, 0)); // blue
safe_delay(500);
#if HAS_WHITE_LED2
#if HAS_WHITE_NEOPIXEL_2
set_color_startup(adaneo.Color(0, 0, 0, 255)); // white
safe_delay(500);
#endif

View file

@ -42,19 +42,17 @@
// Defines
// ------------------------
#define _NEO_IS_RGB(N) (N == NEO_RGB || N == NEO_RBG || N == NEO_GRB || N == NEO_GBR || N == NEO_BRG || N == NEO_BGR)
#define _NEO_IS_RGBW(N) ((N) & 0x30) != (((N) >> 2) & 0x30)
#if !_NEO_IS_RGB(NEOPIXEL_TYPE)
#define HAS_WHITE_LED 1
#if _NEO_IS_RGBW(NEOPIXEL_TYPE)
#define HAS_WHITE_NEOPIXEL_1 1
#endif
#if HAS_WHITE_LED
#define NEO_WHITE 0, 0, 0, 255
#else
#define NEO_WHITE 255, 255, 255
#endif
#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
#if ENABLED(NEOPIXEL2_SEPARATE)
#if _NEO_IS_RGBW(NEOPIXEL2_TYPE)
#define HAS_WHITE_NEOPIXEL_2 1
#endif
#elif defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE
#define MULTIPLE_NEOPIXEL_TYPES 1
#endif
@ -62,6 +60,8 @@
#define CONJOINED_NEOPIXEL 1
#endif
#undef _NEO_IS_RGBW
// ------------------------
// Types
// ------------------------
@ -141,8 +141,17 @@ public:
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)) {
return adaneo1.Color(r, g, b OPTARG(HAS_WHITE_LED, w));
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_NEOPIXEL_1, uint8_t w=0)) {
return adaneo1.Color(r, g, b OPTARG(HAS_WHITE_NEOPIXEL_1, w));
}
static uint32_t White() {
return Color(
#if HAS_WHITE_NEOPIXEL_1
0, 0, 0, 255
#else
255, 255, 255
#endif
);
}
};
@ -151,15 +160,6 @@ extern Marlin_NeoPixel neo;
// Neo pixel channel 2
#if ENABLED(NEOPIXEL2_SEPARATE)
#if _NEO_IS_RGB(NEOPIXEL2_TYPE)
#define NEOPIXEL2_IS_RGB 1
#define NEO2_WHITE 255, 255, 255
#else
#define NEOPIXEL2_IS_RGBW 1
#define HAS_WHITE_LED2 1 // A white component can be passed for NEOPIXEL2
#define NEO2_WHITE 0, 0, 0, 255
#endif
class Marlin_NeoPixel2 {
private:
static Adafruit_NeoPixel adaneo;
@ -184,13 +184,20 @@ extern Marlin_NeoPixel neo;
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 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));
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b OPTARG(HAS_WHITE_NEOPIXEL_2, uint8_t w=0)) {
return adaneo.Color(r, g, b OPTARG(HAS_WHITE_NEOPIXEL_2, w));
}
static uint32_t White() {
return Color(
#if HAS_WHITE_NEOPIXEL_2
0, 0, 0, 255
#else
255, 255, 255
#endif
);
}
};
extern Marlin_NeoPixel2 neo2;
#endif // NEOPIXEL2_SEPARATE
#undef _NEO_IS_RGB

View file

@ -68,7 +68,7 @@
#ifndef PCA9632_BLU
#define PCA9632_BLU 0x04
#endif
#if HAS_WHITE_LED && !defined(PCA9632_WHT)
#if ENABLED(PCA9632_RGBW) && !defined(PCA9632_WHT)
#define PCA9632_WHT 0x06
#endif
@ -124,7 +124,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
}
#endif
void PCA9632_set_led_color(const LEDColor &color) {
void PCA9632_set_led_color(const LED1Color_t &color) {
Wire.begin();
if (!PCA_init) {
PCA_init = 1;
@ -135,10 +135,7 @@ void PCA9632_set_led_color(const LEDColor &color) {
const byte LEDOUT = (color.r ? LED_PWM << PCA9632_RED : 0)
| (color.g ? LED_PWM << PCA9632_GRN : 0)
| (color.b ? LED_PWM << PCA9632_BLU : 0)
#if ENABLED(PCA9632_RGBW)
| (color.w ? LED_PWM << PCA9632_WHT : 0)
#endif
;
| (TERN0(PCA9632_RGBW, color.w ? LED_PWM << PCA9632_WHT : 0));
PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b
OPTARG(PCA9632_RGBW, color.w)

View file

@ -26,10 +26,9 @@
* Written by Robert Mendon Feb 2017.
*/
struct LEDColor;
typedef LEDColor LEDColor;
struct LED1Color_t;
void PCA9632_set_led_color(const LEDColor &color);
void PCA9632_set_led_color(const LED1Color_t &color);
#if ENABLED(PCA9632_BUZZER)
#include <stdint.h>

View file

@ -47,7 +47,7 @@ PrinterEventLEDs printerEventLEDs;
inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b OPTARG(HAS_WHITE_LED, const uint8_t w=0)) {
leds.set_color(
LEDColor(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, neo.brightness()))
LED1Color_t(r, g, b OPTARG(HAS_WHITE_LED, w) OPTARG(NEOPIXEL_LED, neo.brightness()))
OPTARG(NEOPIXEL_IS_SEQUENTIAL, true)
);
}

View file

@ -40,23 +40,23 @@ private:
public:
#if HAS_TEMP_HOTEND
static LEDColor onHotendHeatingStart() { old_intensity = 0; return leds.get_color(); }
static LED1Color_t onHotendHeatingStart() { old_intensity = 0; return leds.get_color(); }
static void onHotendHeating(const celsius_t start, const celsius_t current, const celsius_t target);
#endif
#if HAS_HEATED_BED
static LEDColor onBedHeatingStart() { old_intensity = 127; return leds.get_color(); }
static LED1Color_t onBedHeatingStart() { old_intensity = 127; return leds.get_color(); }
static void onBedHeating(const celsius_t start, const celsius_t current, const celsius_t target);
#endif
#if HAS_HEATED_CHAMBER
static LEDColor onChamberHeatingStart() { old_intensity = 127; return leds.get_color(); }
static LED1Color_t onChamberHeatingStart() { old_intensity = 127; return leds.get_color(); }
static void onChamberHeating(const celsius_t start, const celsius_t current, const celsius_t target);
#endif
#if HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_HEATED_CHAMBER
static void onHeatingDone() { leds.set_white(); }
static void onPIDTuningDone(LEDColor c) { leds.set_color(c); }
static void onPIDTuningDone(LED1Color_t c) { leds.set_color(c); }
#endif
#if HAS_MEDIA

View file

@ -46,24 +46,22 @@
* M710 I127 A1 S255 D160 ; Set controller fan idle speed 50%, AutoMode On, Fan speed 100%, duration to 160 Secs
*/
void GcodeSuite::M710() {
if (!parser.seen("ADIRS")) return M710_report();
const bool seenR = parser.seen('R');
if (seenR) controllerFan.reset();
if (parser.seen_test('R'))
controllerFan.reset();
const bool seenS = parser.seenval('S');
if (seenS) controllerFan.settings.active_speed = parser.value_byte();
if (parser.seenval('S'))
controllerFan.settings.active_speed = parser.value_byte();
const bool seenI = parser.seenval('I');
if (seenI) controllerFan.settings.idle_speed = parser.value_byte();
if (parser.seenval('I'))
controllerFan.settings.idle_speed = parser.value_byte();
const bool seenA = parser.seenval('A');
if (seenA) controllerFan.settings.auto_mode = parser.value_bool();
if (parser.seenval('A'))
controllerFan.settings.auto_mode = parser.value_bool();
const bool seenD = parser.seenval('D');
if (seenD) controllerFan.settings.duration = parser.value_ushort();
if (!(seenR || seenS || seenI || seenA || seenD))
M710_report();
if (parser.seenval('D'))
controllerFan.settings.duration = parser.value_ushort();
}
void GcodeSuite::M710_report(const bool forReplay/*=true*/) {

View file

@ -80,24 +80,28 @@ void GcodeSuite::M150() {
#endif
#endif
const LEDColor color = LEDColor(
parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 16) & 0xFF,
parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 8) & 0xFF,
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) : (old_color >> 24) & 0xFF)
OPTARG(NEOPIXEL_LED, parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness)
);
#if ENABLED(NEOPIXEL2_SEPARATE)
switch (unit) {
case 0: leds.set_color(color); return;
case 1: leds2.set_color(color); return;
}
const uint8_t valR = parser.seen('R') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 16) & 0xFF,
valU = parser.seen('U') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 8) & 0xFF,
valB = parser.seen('B') ? (parser.has_value() ? parser.value_byte() : 255) : old_color & 0xFF;
#if HAS_WHITE_LED || HAS_WHITE_LED2
const uint8_t valW = parser.seen('W') ? (parser.has_value() ? parser.value_byte() : 255) : (old_color >> 24) & 0xFF;
#endif
#if ENABLED(NEOPIXEL_LED)
const uint8_t valP = parser.seen('P') ? (parser.has_value() ? parser.value_byte() : 255) : brightness;
#endif
// If 'S' is not specified use both
leds.set_color(color);
TERN_(NEOPIXEL2_SEPARATE, leds2.set_color(color));
const LED1Color_t color = LED1Color_t(valR, valU, valB OPTARG(HAS_WHITE_LED, valW) OPTARG(NEOPIXEL_LED, valP) );
#if ENABLED(NEOPIXEL2_SEPARATE)
const LED2Color_t color2 = LED2Color_t(valR, valU, valB OPTARG(HAS_WHITE_LED2, valW) OPTARG(NEOPIXEL_LED, valP) );
switch (unit) {
case 0: leds.set_color(color); return;
case 1: leds2.set_color(color2); return;
}
leds2.set_color(color2); // If 'S' is not specified set both leds2...
#endif
leds.set_color(color); // ...and leds1
}
#endif // HAS_COLOR_LEDS

View file

@ -1020,11 +1020,14 @@
#define HAS_RESUME_CONTINUE 1
#endif
// Color LEDs (with optional White channel)
#if ANY(BLINKM, RGB_LED, RGBW_LED, PCA9632, PCA9533, NEOPIXEL_LED)
#define HAS_COLOR_LEDS 1
#else
#undef LED_POWEROFF_TIMEOUT
#endif
#if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, HAS_MEDIA)
#define HAS_LEDS_OFF_FLAG 1
#endif

View file

@ -2304,7 +2304,7 @@ void setMoveZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick(Z_MIN_POS, Z_MAX_POS,
#if HAS_COLOR_LEDS
bool enableLiveLedColor = true;
void applyLEDColor() {
hmiData.ledColor = LEDColor( {leds.color.r, leds.color.g, leds.color.b OPTARG(HAS_WHITE_LED, hmiData.ledColor.w) } );
hmiData.ledColor = LED1Color_t(leds.color.r, leds.color.g, leds.color.b OPTARG(HAS_WHITE_LED, hmiData.ledColor.w));
if (!enableLiveLedColor) leds.update();
}
void liveLEDColor(uint8_t *color) { *color = menuData.value; if (enableLiveLedColor) leds.update(); }

View file

@ -160,7 +160,7 @@ typedef struct {
#define Z_POST_CLEARANCE hmiData.zAfterHoming
#endif
#if ALL(LED_CONTROL_MENU, HAS_COLOR_LEDS)
LEDColor ledColor = defColorLeds;
LED1Color_t ledColor = defColorLeds;
#endif
#if HAS_GCODE_PREVIEW
bool enablePreview = true;

View file

@ -882,7 +882,7 @@ void Temperature::factory_reset() {
#if ENABLED(PRINTER_EVENT_LEDS)
const celsius_float_t start_temp = GHV(degChamber(), degBed(), degHotend(heater_id));
const LEDColor oldcolor = ONHEATINGSTART();
const LED1Color_t oldcolor = ONHEATINGSTART();
#endif
TERN_(TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = false);