RGB Caselight (#20341)
This commit is contained in:
parent
971fb8729a
commit
6183cd0731
|
@ -2650,6 +2650,7 @@
|
|||
// Use a single NeoPixel LED for static (background) lighting
|
||||
//#define NEOPIXEL_BKGD_LED_INDEX 0 // Index of the LED to use
|
||||
//#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
|
||||
//#define NEOPIXEL_BKGD_ALWAYS_ON // Keep the backlight on when other NeoPixels are off
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -519,12 +519,17 @@
|
|||
#define INVERT_CASE_LIGHT false // Set true if Case Light is ON when pin is LOW
|
||||
#define CASE_LIGHT_DEFAULT_ON true // Set default power-up state on
|
||||
#define CASE_LIGHT_DEFAULT_BRIGHTNESS 105 // Set default power-up brightness (0-255, requires PWM pin)
|
||||
//#define CASE_LIGHT_NO_BRIGHTNESS // Disable brightness control. Enable for non-PWM lighting.
|
||||
//#define CASE_LIGHT_MAX_PWM 128 // Limit PWM duty cycle (0-255)
|
||||
//#define CASE_LIGHT_MENU // Add Case Light options to the LCD menu
|
||||
//#define CASE_LIGHT_NO_BRIGHTNESS // Disable brightness control. Enable for non-PWM lighting.
|
||||
//#define CASE_LIGHT_USE_NEOPIXEL // Use NeoPixel LED as case light, requires NEOPIXEL_LED.
|
||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
#define CASE_LIGHT_NEOPIXEL_COLOR { 255, 255, 255, 255 } // { Red, Green, Blue, White }
|
||||
#if ENABLED(NEOPIXEL_LED)
|
||||
//#define CASE_LIGHT_USE_NEOPIXEL // Use NeoPixel LED as case light
|
||||
#endif
|
||||
#if EITHER(RGB_LED, RGBW_LED)
|
||||
//#define CASE_LIGHT_USE_RGB_LED // Use RGB / RGBW LED as case light
|
||||
#endif
|
||||
#if EITHER(CASE_LIGHT_USE_NEOPIXEL, CASE_LIGHT_USE_RGB_LED)
|
||||
#define CASE_LIGHT_DEFAULT_COLOR { 255, 255, 255, 255 } // { Red, Green, Blue, White }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1136,10 +1136,7 @@ void setup() {
|
|||
#endif
|
||||
|
||||
#if ENABLED(CASE_LIGHT_ENABLE)
|
||||
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
|
||||
#endif
|
||||
SETUP_RUN(caselight.update_brightness());
|
||||
SETUP_RUN(caselight.init());
|
||||
#endif
|
||||
|
||||
#if HAS_PRUSA_MMU1
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
|
||||
CaseLight caselight;
|
||||
|
||||
#if CASE_LIGHT_IS_COLOR_LED
|
||||
#include "leds/leds.h"
|
||||
#endif
|
||||
|
||||
#if CASELIGHT_USES_BRIGHTNESS && !defined(CASE_LIGHT_DEFAULT_BRIGHTNESS)
|
||||
#define CASE_LIGHT_DEFAULT_BRIGHTNESS 0 // For use on PWM pin as non-PWM just sets a default
|
||||
#endif
|
||||
|
@ -38,10 +42,10 @@ CaseLight caselight;
|
|||
|
||||
bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
#if CASE_LIGHT_IS_COLOR_LED
|
||||
LEDColor CaseLight::color =
|
||||
#ifdef CASE_LIGHT_NEOPIXEL_COLOR
|
||||
CASE_LIGHT_NEOPIXEL_COLOR
|
||||
#ifdef CASE_LIGHT_DEFAULT_COLOR
|
||||
CASE_LIGHT_DEFAULT_COLOR
|
||||
#else
|
||||
{ 255, 255, 255, 255 }
|
||||
#endif
|
||||
|
@ -71,17 +75,17 @@ void CaseLight::update(const bool sflag) {
|
|||
const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
|
||||
#endif
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
#if CASE_LIGHT_IS_COLOR_LED
|
||||
|
||||
leds.set_color(
|
||||
MakeLEDColor(color.r, color.g, color.b, color.w, n10ct),
|
||||
false
|
||||
);
|
||||
|
||||
#else // !CASE_LIGHT_USE_NEOPIXEL
|
||||
#else // !CASE_LIGHT_IS_COLOR_LED
|
||||
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
if (PWM_PIN(CASE_LIGHT_PIN))
|
||||
if (pin_is_pwm())
|
||||
analogWrite(pin_t(CASE_LIGHT_PIN), (
|
||||
#if CASE_LIGHT_MAX_PWM == 255
|
||||
n10ct
|
||||
|
@ -96,7 +100,11 @@ void CaseLight::update(const bool sflag) {
|
|||
WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);
|
||||
}
|
||||
|
||||
#endif // !CASE_LIGHT_USE_NEOPIXEL
|
||||
#endif // !CASE_LIGHT_IS_COLOR_LED
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_RGB_LED)
|
||||
if (leds.lights_on) leds.update(); else leds.set_off();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // CASE_LIGHT_ENABLE
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../inc/MarlinConfigPre.h"
|
||||
#include "../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
#include "leds/leds.h"
|
||||
#if CASE_LIGHT_IS_COLOR_LED
|
||||
#include "leds/leds.h" // for LEDColor
|
||||
#endif
|
||||
|
||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) || ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
|
@ -33,19 +33,25 @@
|
|||
|
||||
class CaseLight {
|
||||
public:
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
static uint8_t brightness;
|
||||
#endif
|
||||
static bool on;
|
||||
TERN_(CASELIGHT_USES_BRIGHTNESS, static uint8_t brightness);
|
||||
|
||||
static bool pin_is_pwm() { return TERN0(NEED_CASE_LIGHT_PIN, PWM_PIN(CASE_LIGHT_PIN)); }
|
||||
static bool has_brightness() { return TERN0(CASELIGHT_USES_BRIGHTNESS, TERN(CASE_LIGHT_USE_NEOPIXEL, true, pin_is_pwm())); }
|
||||
|
||||
static void init() {
|
||||
#if NEED_CASE_LIGHT_PIN
|
||||
if (pin_is_pwm()) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
|
||||
#endif
|
||||
update_brightness();
|
||||
}
|
||||
|
||||
static void update(const bool sflag);
|
||||
static inline void update_brightness() { update(false); }
|
||||
static inline void update_enabled() { update(true); }
|
||||
static inline void update_enabled() { update(true); }
|
||||
|
||||
private:
|
||||
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
|
||||
static LEDColor color;
|
||||
#endif
|
||||
TERN_(CASE_LIGHT_IS_COLOR_LED, static LEDColor color);
|
||||
};
|
||||
|
||||
extern CaseLight caselight;
|
||||
|
|
|
@ -42,6 +42,10 @@
|
|||
#include "pca9533.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(CASE_LIGHT_USE_RGB_LED)
|
||||
#include "../../feature/caselight.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(LED_COLOR_PRESETS)
|
||||
const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
|
||||
LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE,
|
||||
|
@ -85,8 +89,11 @@ void LEDLights::set_color(const LEDColor &incol
|
|||
|
||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||
if (NEOPIXEL_BKGD_LED_INDEX == nextLed) {
|
||||
if (++nextLed >= neo.pixels()) nextLed = 0;
|
||||
return;
|
||||
neo.set_color_background();
|
||||
if (++nextLed >= neo.pixels()) {
|
||||
nextLed = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -114,12 +121,13 @@ void LEDLights::set_color(const LEDColor &incol
|
|||
|
||||
// This variant uses 3-4 separate pins for the RGB(W) components.
|
||||
// If the pins can do PWM then their intensity will be set.
|
||||
#define UPDATE_RGBW(C,c) do { \
|
||||
if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \
|
||||
else \
|
||||
WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); \
|
||||
#define _UPDATE_RGBW(C,c) do { \
|
||||
if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
analogWrite(pin_t(RGB_LED_##C##_PIN), c); \
|
||||
else \
|
||||
WRITE(RGB_LED_##C##_PIN, c ? HIGH : LOW); \
|
||||
}while(0)
|
||||
#define UPDATE_RGBW(C,c) _UPDATE_RGBW(C, TERN1(CASE_LIGHT_USE_RGB_LED, caselight.on) ? incol.c : 0)
|
||||
UPDATE_RGBW(R,r); UPDATE_RGBW(G,g); UPDATE_RGBW(B,b);
|
||||
#if ENABLED(RGBW_LED)
|
||||
UPDATE_RGBW(W,w);
|
||||
|
|
|
@ -194,6 +194,8 @@ public:
|
|||
|
||||
#if ENABLED(LED_CONTROL_MENU)
|
||||
static void toggle(); // swap "off" with color
|
||||
#endif
|
||||
#if EITHER(LED_CONTROL_MENU, CASE_LIGHT_USE_RGB_LED)
|
||||
static inline void update() { set_color(color); }
|
||||
#endif
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ void Marlin_NeoPixel::set_color(const uint32_t color) {
|
|||
else {
|
||||
for (uint16_t i = 0; i < pixels(); ++i) {
|
||||
#ifdef NEOPIXEL_BKGD_LED_INDEX
|
||||
if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
|
||||
if (i == NEOPIXEL_BKGD_LED_INDEX && TERN(ENABLED(NEOPIXEL_BKGD_ALWAYS_ON), true, color != 0x000000)) {
|
||||
set_color_background();
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ void GcodeSuite::M115() {
|
|||
|
||||
// TOGGLE_LIGHTS (M355)
|
||||
cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE));
|
||||
cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, TERN0(CASELIGHT_USES_BRIGHTNESS, TERN(CASE_LIGHT_USE_NEOPIXEL, true, PWM_PIN(CASE_LIGHT_PIN)))));
|
||||
cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, caselight.has_brightness()));
|
||||
|
||||
// EMERGENCY_PARSER (M108, M112, M410, M876)
|
||||
cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER));
|
||||
|
|
|
@ -506,6 +506,15 @@
|
|||
#define NEED_HEX_PRINT 1
|
||||
#endif
|
||||
|
||||
// Flags for Case Light having a color property or a single pin
|
||||
#if ENABLED(CASE_LIGHT_ENABLE)
|
||||
#if EITHER(CASE_LIGHT_USE_NEOPIXEL, CASE_LIGHT_USE_RGB_LED)
|
||||
#define CASE_LIGHT_IS_COLOR_LED 1
|
||||
#else
|
||||
#define NEED_CASE_LIGHT_PIN 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Flag whether least_squares_fit.cpp is used
|
||||
#if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
|
||||
#define NEED_LSF 1
|
||||
|
|
|
@ -437,6 +437,8 @@
|
|||
#error "DUAL_NOZZLE_DUPLICATION_MODE is now MULTI_NOZZLE_DUPLICATION."
|
||||
#elif defined(MENU_ITEM_CASE_LIGHT)
|
||||
#error "MENU_ITEM_CASE_LIGHT is now CASE_LIGHT_MENU."
|
||||
#elif defined(CASE_LIGHT_NEOPIXEL_COLOR)
|
||||
#error "CASE_LIGHT_NEOPIXEL_COLOR is now CASE_LIGHT_DEFAULT_COLOR."
|
||||
#elif defined(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
|
||||
#error "ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED is now SD_ABORT_ON_ENDSTOP_HIT."
|
||||
#elif defined(LPC_SD_LCD) || defined(LPC_SD_ONBOARD) || defined(LPC_SD_CUSTOM_CABLE)
|
||||
|
@ -1704,9 +1706,9 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
|
|||
/**
|
||||
* Case Light requirements
|
||||
*/
|
||||
#if ENABLED(CASE_LIGHT_ENABLE)
|
||||
#if NEED_CASE_LIGHT_PIN
|
||||
#if !PIN_EXISTS(CASE_LIGHT)
|
||||
#error "CASE_LIGHT_ENABLE requires CASE_LIGHT_PIN to be defined."
|
||||
#error "CASE_LIGHT_ENABLE requires CASE_LIGHT_PIN, CASE_LIGHT_USE_NEOPIXEL, or CASE_LIGHT_USE_RGB_LED."
|
||||
#elif CASE_LIGHT_PIN == FAN_PIN
|
||||
#error "CASE_LIGHT_PIN conflicts with FAN_PIN. Resolve before continuing."
|
||||
#endif
|
||||
|
|
|
@ -105,12 +105,14 @@
|
|||
#if ENABLED(CASE_LIGHT_MENU)
|
||||
#include "../../feature/caselight.h"
|
||||
|
||||
#define CASELIGHT_TOGGLE_ITEM() EDIT_ITEM(bool, MSG_CASE_LIGHT, (bool*)&caselight.on, caselight.update_enabled)
|
||||
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
void menu_case_light() {
|
||||
START_MENU();
|
||||
BACK_ITEM(MSG_CONFIGURATION);
|
||||
EDIT_ITEM(percent, MSG_CASE_LIGHT_BRIGHTNESS, &caselight.brightness, 0, 255, caselight.update_brightness, true);
|
||||
EDIT_ITEM(bool, MSG_CASE_LIGHT, (bool*)&caselight.on, caselight.update_enabled);
|
||||
CASELIGHT_TOGGLE_ITEM();
|
||||
END_MENU();
|
||||
}
|
||||
#endif
|
||||
|
@ -155,13 +157,14 @@ void menu_led() {
|
|||
// Set Case light on/off/brightness
|
||||
//
|
||||
#if ENABLED(CASE_LIGHT_MENU)
|
||||
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
|
||||
if (TERN1(CASE_LIGHT_USE_NEOPIXEL, PWM_PIN(CASE_LIGHT_PIN)))
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
if (caselight.has_brightness())
|
||||
SUBMENU(MSG_CASE_LIGHT, menu_case_light);
|
||||
else
|
||||
#endif
|
||||
EDIT_ITEM(bool, MSG_CASE_LIGHT, (bool*)&caselight.on, caselight.update_enabled);
|
||||
CASELIGHT_TOGGLE_ITEM();
|
||||
#endif
|
||||
|
||||
END_MENU();
|
||||
}
|
||||
|
||||
|
|
|
@ -876,5 +876,9 @@
|
|||
#undef BOARD_ST7920_DELAY_3
|
||||
#endif
|
||||
|
||||
#if !NEED_CASE_LIGHT_PIN
|
||||
#undef CASE_LIGHT_PIN
|
||||
#endif
|
||||
|
||||
#undef HAS_FREE_AUX2_PINS
|
||||
#undef DIAG_REMAPPED
|
||||
|
|
|
@ -18,7 +18,7 @@ opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS \
|
|||
ASSISTED_TRAMMING ASSISTED_TRAMMING_WIZARD REPORT_TRAMMING_MM ASSISTED_TRAMMING_WAIT_POSITION \
|
||||
EEPROM_SETTINGS SDSUPPORT BINARY_FILE_TRANSFER \
|
||||
BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \
|
||||
NEOPIXEL_LED CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_MENU \
|
||||
NEOPIXEL_LED CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_USE_RGB_LED CASE_LIGHT_MENU \
|
||||
NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE FILAMENT_RUNOUT_DISTANCE_MM FILAMENT_RUNOUT_SENSOR \
|
||||
AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \
|
||||
SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE CALIBRATION_GCODE \
|
||||
|
|
Loading…
Reference in a new issue