Skip to content

Commit b1e71e0

Browse files
Daranbalt4EvilGremlin
authored andcommitted
✨ LCD_BACKLIGHT_TIMEOUT for Neopixel LCD (MarlinFirmware#25438)
1 parent f207d0f commit b1e71e0

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

Marlin/Configuration.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -3408,7 +3408,8 @@
34083408
// Use some of the NeoPixel LEDs for static (background) lighting
34093409
//#define NEOPIXEL_BKGD_INDEX_FIRST 0 // Index of the first background LED
34103410
//#define NEOPIXEL_BKGD_INDEX_LAST 5 // Index of the last background LED
3411-
//#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
3411+
//#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
3412+
//#define NEOPIXEL_BKGD_TIMEOUT_COLOR { 25, 25, 25, 0 } // R, G, B, W
34123413
//#define NEOPIXEL_BKGD_ALWAYS_ON // Keep the backlight on when other NeoPixels are off
34133414
#endif
34143415

Marlin/src/feature/leds/neopixel.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
5454
set_background_color(background_color);
5555
}
5656

57-
#endif
57+
void Marlin_NeoPixel::set_background_off() {
58+
#ifndef NEOPIXEL_BKGD_TIMEOUT_COLOR
59+
#define NEOPIXEL_BKGD_TIMEOUT_COLOR { 0, 0, 0, 0 }
60+
#endif
61+
constexpr uint8_t background_color_off[4] = NEOPIXEL_BKGD_TIMEOUT_COLOR;
62+
set_background_color(background_color_off);
63+
}
64+
65+
#endif // NEOPIXEL_BKGD_INDEX_FIRST
5866

5967
void Marlin_NeoPixel::set_color(const uint32_t color) {
6068
if (neoindex >= 0) {

Marlin/src/feature/leds/neopixel.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class Marlin_NeoPixel {
9191
static void set_background_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w);
9292
static void set_background_color(const uint8_t (&rgbw)[4]) { set_background_color(rgbw[0], rgbw[1], rgbw[2], rgbw[3]); }
9393
static void reset_background_color();
94+
static void set_background_off();
9495
#endif
9596

9697
static void begin() {

Marlin/src/inc/SanityCheck.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -3241,8 +3241,14 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
32413241
#if LCD_BACKLIGHT_TIMEOUT_MINS
32423242
#if !HAS_ENCODER_ACTION
32433243
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
3244+
#elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST)
3245+
#if PIN_EXISTS(LCD_BACKLIGHT)
3246+
#error "LCD_BACKLIGHT_PIN and NEOPIXEL_BKGD_INDEX_FIRST are not supported at the same time."
3247+
#elif ENABLED(NEOPIXEL_BKGD_ALWAYS_ON)
3248+
#error "LCD_BACKLIGHT_TIMEOUT is not compatible with NEOPIXEL_BKGD_ALWAYS_ON."
3249+
#endif
32443250
#elif !PIN_EXISTS(LCD_BACKLIGHT)
3245-
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN."
3251+
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires either LCD_BACKLIGHT_PIN or NEOPIXEL_BKGD_INDEX_FIRST."
32463252
#endif
32473253
#endif
32483254

Marlin/src/lcd/marlinui.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "../MarlinCore.h" // for printingIsPaused
2626

27-
#if LED_POWEROFF_TIMEOUT > 0 || BOTH(HAS_WIRED_LCD, PRINTER_EVENT_LEDS)
27+
#if LED_POWEROFF_TIMEOUT > 0 || BOTH(HAS_WIRED_LCD, PRINTER_EVENT_LEDS) || (defined(LCD_BACKLIGHT_TIMEOUT_MINS) && defined(NEOPIXEL_BKGD_INDEX_FIRST))
2828
#include "../feature/leds/leds.h"
2929
#endif
3030

@@ -186,12 +186,17 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
186186
#if LCD_BACKLIGHT_TIMEOUT_MINS
187187

188188
constexpr uint8_t MarlinUI::backlight_timeout_min, MarlinUI::backlight_timeout_max;
189-
190189
uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load()
191190
millis_t MarlinUI::backlight_off_ms = 0;
191+
192192
void MarlinUI::refresh_backlight_timeout() {
193193
backlight_off_ms = backlight_timeout_minutes ? millis() + backlight_timeout_minutes * 60UL * 1000UL : 0;
194-
WRITE(LCD_BACKLIGHT_PIN, HIGH);
194+
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
195+
neo.reset_background_color();
196+
neo.show();
197+
#elif PIN_EXISTS(LCD_BACKLIGHT)
198+
WRITE(LCD_BACKLIGHT_PIN, HIGH);
199+
#endif
195200
}
196201

197202
#elif HAS_DISPLAY_SLEEP
@@ -1196,8 +1201,14 @@ void MarlinUI::init() {
11961201
#endif
11971202

11981203
#if LCD_BACKLIGHT_TIMEOUT_MINS
1204+
11991205
if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) {
1200-
WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
1206+
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
1207+
neo.set_background_off();
1208+
neo.show();
1209+
#elif PIN_EXIST(LCD_BACKLIGHT)
1210+
WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
1211+
#endif
12011212
backlight_off_ms = 0;
12021213
}
12031214
#elif HAS_DISPLAY_SLEEP

buildroot/tests/LPC1768

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ restore_configs
1717
opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EFB SERIAL_PORT_3 3 \
1818
NEOPIXEL_TYPE NEO_RGB RGB_LED_R_PIN P2_12 RGB_LED_G_PIN P1_23 RGB_LED_B_PIN P1_22 RGB_LED_W_PIN P1_24
1919
opt_enable FYSETC_MINI_12864_2_1 SDSUPPORT SDCARD_READONLY SERIAL_PORT_2 RGBW_LED E_DUAL_STEPPER_DRIVERS \
20-
NEOPIXEL_LED NEOPIXEL_IS_SEQUENTIAL NEOPIXEL_STARTUP_TEST NEOPIXEL_BKGD_INDEX_FIRST NEOPIXEL_BKGD_INDEX_LAST NEOPIXEL_BKGD_COLOR NEOPIXEL_BKGD_ALWAYS_ON
20+
NEOPIXEL_LED NEOPIXEL_IS_SEQUENTIAL NEOPIXEL_STARTUP_TEST NEOPIXEL_BKGD_INDEX_FIRST NEOPIXEL_BKGD_INDEX_LAST NEOPIXEL_BKGD_COLOR NEOPIXEL_BKGD_TIMEOUT_COLOR NEOPIXEL_BKGD_ALWAYS_ON
2121
exec_test $1 $2 "ReARM EFB VIKI2, SDSUPPORT, 2 Serial ports (USB CDC + UART0), NeoPixel" "$3"
2222

2323
#restore_configs

0 commit comments

Comments
 (0)