Skip to content

Commit

Permalink
Set LCD_BACKLIGHT_TIMEOUT in minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 20, 2022
1 parent e13d94b commit bf5e95a
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@
//
// LCD Backlight Timeout
//
//#define LCD_BACKLIGHT_TIMEOUT 30 // (s) Timeout before turning off the backlight
//#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight

#if HAS_BED_PROBE && EITHER(HAS_MARLINUI_MENU, HAS_TFT_LVGL_UI)
//#define PROBE_OFFSET_WIZARD // Add a Probe Z Offset calibration option to the LCD menu
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/lcd/M255.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void GcodeSuite::M255() {
const int m = parser.value_int();
ui.sleep_timeout_minutes = constrain(m, ui.sleep_timeout_min, ui.sleep_timeout_max);
#else
const unsigned int s = MIN_TO_SEC(parser.value_ushort());
ui.backlight_timeout = constrain(s, ui.backlight_timeout_min, ui.backlight_timeout_max);
const int m = parser.value_int();
ui.backlight_timeout_minutes = constrain(m, ui.backlight_timeout_min, ui.backlight_timeout_max);
#endif
}
else
Expand All @@ -47,7 +47,7 @@ void GcodeSuite::M255() {
void GcodeSuite::M255_report(const bool forReplay/*=true*/) {
report_heading_etc(forReplay, F(STR_DISPLAY_SLEEP));
SERIAL_ECHOLNPGM(" M255 S",
TERN(HAS_DISPLAY_SLEEP, ui.sleep_timeout_minutes, SEC_TO_MIN(ui.backlight_timeout)),
TERN(HAS_DISPLAY_SLEEP, ui.sleep_timeout_minutes, ui.backlight_timeout_minutes),
" ; (minutes)"
);
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@
#ifdef DISPLAY_SLEEP_MINUTES || TOUCH_IDLE_SLEEP_MINS
#define HAS_DISPLAY_SLEEP 1
#endif
#if HAS_DISPLAY_SLEEP || LCD_BACKLIGHT_TIMEOUT
#if HAS_DISPLAY_SLEEP || LCD_BACKLIGHT_TIMEOUT_MINS
#define HAS_GCODE_M255 1
#endif

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3034,11 +3034,11 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#endif
#endif

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS
#if !HAS_ENCODER_ACTION
#error "LCD_BACKLIGHT_TIMEOUT requires an LCD with encoder or keypad."
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
#elif !PIN_EXISTS(LCD_BACKLIGHT)
#error "LCD_BACKLIGHT_TIMEOUT requires LCD_BACKLIGHT_PIN."
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN."
#endif
#endif

Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_de.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ namespace Language_de {
LSTR MSG_ADVANCE_K_E = _UxGT("Vorschubfaktor *");
LSTR MSG_CONTRAST = _UxGT("LCD-Kontrast");
LSTR MSG_BRIGHTNESS = _UxGT("LCD-Helligkeit");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("LCD-Ruhezustand (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("LCD Timeout (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("LCD ausschalten");
LSTR MSG_STORE_EEPROM = _UxGT("Konfig. speichern");
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ namespace Language_en {
LSTR MSG_ADVANCE_K_E = _UxGT("Advance K *");
LSTR MSG_CONTRAST = _UxGT("LCD Contrast");
LSTR MSG_BRIGHTNESS = _UxGT("LCD Brightness");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("LCD Timeout (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("LCD Timeout (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Backlight Off");
LSTR MSG_STORE_EEPROM = _UxGT("Store Settings");
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/language/language_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ namespace Language_fr {
LSTR MSG_ADVANCE_K_E = _UxGT("Avance K *");
LSTR MSG_BRIGHTNESS = _UxGT("Luminosité LCD");
LSTR MSG_CONTRAST = _UxGT("Contraste LCD");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("Veille LCD (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("Veille LCD (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Éteindre l'écran LCD");
LSTR MSG_STORE_EEPROM = _UxGT("Enregistrer config.");
LSTR MSG_LOAD_EEPROM = _UxGT("Charger config.");
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ namespace Language_it {
LSTR MSG_ADVANCE_K_E = _UxGT("K Avanzamento *");
LSTR MSG_CONTRAST = _UxGT("Contrasto LCD");
LSTR MSG_BRIGHTNESS = _UxGT("Luminosità LCD");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("Timeout LCD (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("Timeout LCD (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Spegni Retroillum.");
LSTR MSG_STORE_EEPROM = _UxGT("Salva impostazioni");
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/language/language_sk.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ namespace Language_sk {
LSTR MSG_ADVANCE_K_E = _UxGT("K pre posun *");
LSTR MSG_CONTRAST = _UxGT("Kontrast LCD");
LSTR MSG_BRIGHTNESS = _UxGT("Jas LCD");
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("Čas. limit LCD (s)");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("Čas. limit LCD (m)");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Podsviet. vyp.");
LSTR MSG_STORE_EEPROM = _UxGT("Uložiť nastavenie");
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/language/language_uk.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ namespace Language_uk {
LSTR MSG_CONTRAST = _UxGT("Контраст");
LSTR MSG_BRIGHTNESS = _UxGT("Яскравість");
#endif
LSTR MSG_LCD_TIMEOUT_SEC = _UxGT("LCD Таймаут, с");
LSTR MSG_SCREEN_TIMEOUT = _UxGT("LCD Таймаут, x");
LSTR MSG_BRIGHTNESS_OFF = _UxGT("Підсвітка вимк.");
LSTR MSG_STORE_EEPROM = _UxGT("Зберегти в EEPROM");
LSTR MSG_LOAD_EEPROM = _UxGT("Зчитати з EEPROM");
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,20 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
#endif

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS

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

uint16_t MarlinUI::backlight_timeout; // Initialized by settings.load()
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 ? millis() + backlight_timeout * 1000UL : 0;
backlight_off_ms = backlight_timeout_minutes ? millis() + backlight_timeout_minutes * 60UL * 1000UL : 0;
WRITE(LCD_BACKLIGHT_PIN, HIGH);
}

#elif HAS_DISPLAY_SLEEP

constexpr uint16_t MarlinUI::sleep_timeout_min, MarlinUI::sleep_timeout_max;
constexpr uint8_t MarlinUI::sleep_timeout_min, MarlinUI::sleep_timeout_max;

uint8_t MarlinUI::sleep_timeout_minutes; // Initialized by settings.load()
millis_t MarlinUI::screen_timeout_millis = 0;
Expand Down Expand Up @@ -1063,7 +1063,7 @@ void MarlinUI::init() {

reset_status_timeout(ms);

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS
refresh_backlight_timeout();
#elif HAS_DISPLAY_SLEEP
refresh_screen_timeout();
Expand Down Expand Up @@ -1173,7 +1173,7 @@ void MarlinUI::init() {
return_to_status();
#endif

#if LCD_BACKLIGHT_TIMEOUT
#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;
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ class MarlinUI {
FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
#endif

#if LCD_BACKLIGHT_TIMEOUT
static constexpr uint16_t backlight_timeout_min = 1;
static constexpr uint16_t backlight_timeout_max = UINT16_MAX;
static uint16_t backlight_timeout;
#if LCD_BACKLIGHT_TIMEOUT_MINS
static constexpr uint8_t backlight_timeout_min = 0;
static constexpr uint8_t backlight_timeout_max = 99;
static uint8_t backlight_timeout_minutes;
static millis_t backlight_off_ms;
static void refresh_backlight_timeout();
#elif HAS_DISPLAY_SLEEP
static constexpr uint16_t sleep_timeout_min = 0;
static constexpr uint16_t sleep_timeout_max = 99;
static constexpr uint8_t sleep_timeout_min = 0;
static constexpr uint8_t sleep_timeout_max = 99;
static uint8_t sleep_timeout_minutes;
static millis_t screen_timeout_millis;
static void refresh_screen_timeout();
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ void menu_configuration() {
//
// Set display backlight / sleep timeout
//
#if LCD_BACKLIGHT_TIMEOUT
EDIT_ITEM(uint16_4, MSG_LCD_TIMEOUT_SEC, &ui.backlight_timeout, ui.backlight_timeout_min, ui.backlight_timeout_max, ui.refresh_backlight_timeout);
#if LCD_BACKLIGHT_TIMEOUT_MINS
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.backlight_timeout_minutes, ui.backlight_timeout_min, ui.backlight_timeout_max, ui.refresh_backlight_timeout);
#elif HAS_DISPLAY_SLEEP
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, ui.sleep_timeout_min, ui.sleep_timeout_max, ui.refresh_screen_timeout);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool Touch::get_point(int16_t *x, int16_t *y) {
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
}
next_sleep_ms = millis() + SEC_TO_MS(MIN_TO_SEC(ui.sleep_timeout_minutes));
next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60);
}

#endif // HAS_TOUCH_SLEEP
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TouchButtons touchBt;

void TouchButtons::init() {
touchIO.Init();
TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(MIN_TO_SEC(ui.sleep_timeout_minutes)));
TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60));
}

uint8_t TouchButtons::read_buttons() {
Expand Down Expand Up @@ -135,7 +135,7 @@ uint8_t TouchButtons::read_buttons() {
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
}
next_sleep_ms = millis() + SEC_TO_MS(MIN_TO_SEC(ui.sleep_timeout_minutes));
next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60);
}

#endif // HAS_TOUCH_SLEEP
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ typedef struct SettingsDataStruct {
//
// Display Sleep
//
#if LCD_BACKLIGHT_TIMEOUT
uint16_t backlight_timeout; // M255 S
#if LCD_BACKLIGHT_TIMEOUT_MINS
uint8_t backlight_timeout_minutes; // M255 S
#elif HAS_DISPLAY_SLEEP
uint8_t sleep_timeout_minutes; // M255 S
#endif
Expand Down Expand Up @@ -640,7 +640,7 @@ void MarlinSettings::postprocess() {
TERN_(HAS_LCD_CONTRAST, ui.refresh_contrast());
TERN_(HAS_LCD_BRIGHTNESS, ui.refresh_brightness());

#if LCD_BACKLIGHT_TIMEOUT
#if LCD_BACKLIGHT_TIMEOUT_MINS
ui.refresh_backlight_timeout();
#elif HAS_DISPLAY_SLEEP
ui.refresh_screen_timeout();
Expand Down Expand Up @@ -1157,8 +1157,8 @@ void MarlinSettings::postprocess() {
//
// LCD Backlight / Sleep Timeout
//
#if LCD_BACKLIGHT_TIMEOUT
EEPROM_WRITE(ui.backlight_timeout);
#if LCD_BACKLIGHT_TIMEOUT_MINS
EEPROM_WRITE(ui.backlight_timeout_minutes);
#elif HAS_DISPLAY_SLEEP
EEPROM_WRITE(ui.sleep_timeout_minutes);
#endif
Expand Down Expand Up @@ -2108,8 +2108,8 @@ void MarlinSettings::postprocess() {
//
// LCD Backlight / Sleep Timeout
//
#if LCD_BACKLIGHT_TIMEOUT
EEPROM_READ(ui.backlight_timeout);
#if LCD_BACKLIGHT_TIMEOUT_MINS
EEPROM_READ(ui.backlight_timeout_minutes);
#elif HAS_DISPLAY_SLEEP
EEPROM_READ(ui.sleep_timeout_minutes);
#endif
Expand Down Expand Up @@ -3198,8 +3198,8 @@ void MarlinSettings::reset() {
//
// LCD Backlight / Sleep Timeout
//
#if LCD_BACKLIGHT_TIMEOUT
ui.backlight_timeout = LCD_BACKLIGHT_TIMEOUT;
#if LCD_BACKLIGHT_TIMEOUT_MINS
ui.backlight_timeout_minutes = LCD_BACKLIGHT_TIMEOUT_MINS;
#elif HAS_DISPLAY_SLEEP
ui.sleep_timeout_minutes = DISPLAY_SLEEP_MINUTES;
#endif
Expand Down
2 changes: 1 addition & 1 deletion buildroot/tests/mega2560
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ opt_set MOTHERBOARD BOARD_RAMPS_14_EFB EXTRUDERS 1 \
TEMP_SENSOR_0 -2 TEMP_SENSOR_REDUNDANT -2 \
TEMP_SENSOR_REDUNDANT_SOURCE E1 TEMP_SENSOR_REDUNDANT_TARGET E0 \
TEMP_0_CS_PIN 11 TEMP_1_CS_PIN 12 \
LCD_BACKLIGHT_TIMEOUT 30
LCD_BACKLIGHT_TIMEOUT_MINS 2
opt_enable MPCTEMP MINIPANEL
opt_disable PIDTEMP
exec_test $1 $2 "MEGA2560 RAMPS | Redundant temperature sensor | 2x MAX6675 | BL Timeout" "$3"
Expand Down

0 comments on commit bf5e95a

Please sign in to comment.