Skip to content

Commit

Permalink
LCD_BACKLIGHT_TIMEOUT_MINS support for LCDs with
Browse files Browse the repository at this point in the history
NEOPIXEL backlight.
fixes #25406
  • Loading branch information
Daranbalt4 committed Feb 26, 2023
1 parent b1f45b3 commit cb78984
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
1 change: 1 addition & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,7 @@
//#define NEOPIXEL_BKGD_INDEX_FIRST 0 // Index of the first background LED
//#define NEOPIXEL_BKGD_INDEX_LAST 5 // Index of the last background LED
//#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
//#define NEOPIXEL_BKGD_TIMEOUT_COLOR { 25, 25, 25, 0} // R, G, B, W
//#define NEOPIXEL_BKGD_ALWAYS_ON // Keep the backlight on when other NeoPixels are off
#endif

Expand Down
12 changes: 12 additions & 0 deletions Marlin/src/feature/leds/neopixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
set_background_color(background_color);
}

#ifdef NEOPIXEL_BKGD_TIMEOUT_COLOR
void Marlin_NeoPixel::set_background_off() {
constexpr uint8_t background_color_off[4] = NEOPIXEL_BKGD_TIMEOUT_COLOR;
set_background_color(background_color_off);
}
#else
void Marlin_NeoPixel::set_background_off() {
constexpr uint8_t background_color_off[4] = { 0, 0, 0, 0};
set_background_color(background_color_off);
}
#endif

#endif

void Marlin_NeoPixel::set_color(const uint32_t color) {
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/feature/leds/neopixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class Marlin_NeoPixel {
static void set_background_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w);
static void set_background_color(const uint8_t (&rgbw)[4]) { set_background_color(rgbw[0], rgbw[1], rgbw[2], rgbw[3]); }
static void reset_background_color();

#ifdef LCD_BACKLIGHT_TIMEOUT_MINS
static void set_background_off();
#endif

#endif

static void begin() {
Expand Down
8 changes: 7 additions & 1 deletion Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3241,8 +3241,14 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#if LCD_BACKLIGHT_TIMEOUT_MINS
#if !HAS_ENCODER_ACTION
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
#elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST)
#if PIN_EXISTS(LCD_BACKLIGHT)
#error "LCD_BACKLIGHT_PIN and NEOPIXEL_BKGD_INDEX_FIRST are not supported at the same time."
#elif ENABLED(NEOPIXEL_BKGD_ALWAYS_ON)
#error "LCD_BACKLIGHT_TIMEOUT is not compatible with NEOPIXEL_BKGD_ALWAYS_ON."
#endif
#elif !PIN_EXISTS(LCD_BACKLIGHT)
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN."
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires either LCD_BACKLIGHT_PIN or NEOPIXEL_BKGD_INDEX_FIRST."
#endif
#endif

Expand Down
50 changes: 37 additions & 13 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

#if LED_POWEROFF_TIMEOUT > 0 || BOTH(HAS_WIRED_LCD, PRINTER_EVENT_LEDS)
#if LED_POWEROFF_TIMEOUT > 0 || BOTH(HAS_WIRED_LCD, PRINTER_EVENT_LEDS) || BOTH(LCD_BACKLIGHT_TIMEOUT_MINS, NEOPIXEL_BKGD_TIMEOUT_COLOR)
#include "../feature/leds/leds.h"
#endif

Expand Down Expand Up @@ -185,14 +185,29 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;

#if LCD_BACKLIGHT_TIMEOUT_MINS

constexpr uint8_t MarlinUI::backlight_timeout_min, MarlinUI::backlight_timeout_max;

uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load()
millis_t MarlinUI::backlight_off_ms = 0;
void MarlinUI::refresh_backlight_timeout() {
backlight_off_ms = backlight_timeout_minutes ? millis() + backlight_timeout_minutes * 60UL * 1000UL : 0;
WRITE(LCD_BACKLIGHT_PIN, HIGH);
}
#ifdef NEOPIXEL_BKGD_INDEX_FIRST

constexpr uint8_t MarlinUI::backlight_timeout_min, MarlinUI::backlight_timeout_max;

uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load()
millis_t MarlinUI::backlight_off_ms = 0;
void MarlinUI::refresh_backlight_timeout() {
backlight_off_ms = backlight_timeout_minutes ? millis() + backlight_timeout_minutes * 60UL * 1000UL : 0;
neo.reset_background_color();
neo.show();
}

#elif PIN_EXISTS(LCD_BACKLIGHT)

constexpr uint8_t MarlinUI::backlight_timeout_min, MarlinUI::backlight_timeout_max;

uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load()
millis_t MarlinUI::backlight_off_ms = 0;
void MarlinUI::refresh_backlight_timeout() {
backlight_off_ms = backlight_timeout_minutes ? millis() + backlight_timeout_minutes * 60UL * 1000UL : 0;
WRITE(LCD_BACKLIGHT_PIN, HIGH);
}
#endif

#elif HAS_DISPLAY_SLEEP

Expand Down Expand Up @@ -1196,10 +1211,19 @@ void MarlinUI::init() {
#endif

#if LCD_BACKLIGHT_TIMEOUT_MINS
if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) {
WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
backlight_off_ms = 0;
}

#ifdef NEOPIXEL_BKGD_INDEX_FIRST
if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) {
neo.set_background_off(); // Backlight off
neo.show();
backlight_off_ms = 0;
}
#elif PIN_EXIST(LCD_BACKLIGHT)
if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) {
WRITE(LCD_BACKLIGHT_PIN, LOW); // Backlight off
backlight_off_ms = 0;
}
#endif
#elif HAS_DISPLAY_SLEEP
if (screen_timeout_millis && ELAPSED(ms, screen_timeout_millis))
sleep_display();
Expand Down

0 comments on commit cb78984

Please sign in to comment.