Skip to content

Commit 06710e5

Browse files
✨ EDITABLE_DISPLAY_TIMEOUT (MarlinFirmware#26517)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent 81cfa23 commit 06710e5

21 files changed

+102
-82
lines changed

Marlin/Configuration_adv.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -1471,11 +1471,6 @@
14711471
#define FEEDRATE_CHANGE_BEEP_FREQUENCY 440
14721472
#endif
14731473

1474-
//
1475-
// LCD Backlight Timeout
1476-
//
1477-
//#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight
1478-
14791474
#if HAS_BED_PROBE && ANY(HAS_MARLINUI_MENU, HAS_TFT_LVGL_UI)
14801475
//#define PROBE_OFFSET_WIZARD // Add a Probe Z Offset calibration option to the LCD menu
14811476
#if ENABLED(PROBE_OFFSET_WIZARD)
@@ -2206,6 +2201,15 @@
22062201
//#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan
22072202
#endif
22082203

2204+
//
2205+
// LCD Backlight Timeout
2206+
// Requires a display with a controllable backlight
2207+
//
2208+
//#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight
2209+
#if defined(DISPLAY_SLEEP_MINUTES) || defined(LCD_BACKLIGHT_TIMEOUT_MINS)
2210+
#define EDITABLE_DISPLAY_TIMEOUT // Edit timeout with M255 S<minutes> and a menu item
2211+
#endif
2212+
22092213
//
22102214
// ADC Button Debounce
22112215
//

Marlin/src/core/types.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ typedef Flags<8> flags_8_t;
198198
typedef Flags<16> flags_16_t;
199199

200200
// Flags for some axis states, with per-axis aliases xyzijkuvwe
201-
typedef struct AxisFlags {
201+
typedef struct {
202202
union {
203203
struct Flags<LOGICAL_AXES> flags;
204204
struct { bool LOGICAL_AXIS_LIST(e:1, x:1, y:1, z:1, i:1, j:1, k:1, u:1, v:1, w:1); };
@@ -212,7 +212,7 @@ typedef struct AxisFlags {
212212
FI bool operator[](const int n) const { return flags[n]; }
213213
FI int size() const { return sizeof(flags); }
214214
FI operator bool() const { return flags; }
215-
} axis_flags_t;
215+
} AxisFlags;
216216

217217
//
218218
// Enumerated axis indices

Marlin/src/feature/bedlevel/bdl/bdl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void BDS_Leveling::process() {
195195
safe_delay(10);
196196
if (config_state == BDS_CALIBRATE_START) {
197197
config_state = BDS_CALIBRATING;
198-
REMEMBER(gsit, gcode.stepper_inactive_time, SEC_TO_MS(60 * 5));
198+
REMEMBER(gsit, gcode.stepper_inactive_time, MIN_TO_MS(5));
199199
SERIAL_ECHOLNPGM("c_z0:", planner.get_axis_position_mm(Z_AXIS), "-", pos_zero_offset);
200200

201201
// Move the z axis instead of enabling the Z axis with M17

Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,8 @@ void unified_bed_leveling::shift_mesh_height() {
772772
const grid_count_t point_num = (GRID_MAX_POINTS - count) + 1;
773773
SERIAL_ECHOLNPGM("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, ".");
774774
TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), point_num, int(GRID_MAX_POINTS)));
775-
TERN_(LCD_BACKLIGHT_TIMEOUT_MINS, ui.refresh_backlight_timeout());
775+
TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout());
776+
TERN_(DWIN_LCD_PROUI, dwinRedrawScreen());
776777

777778
#if HAS_MARLINUI_MENU
778779
if (ui.button_pressed()) {

Marlin/src/gcode/calibrate/G76_M871.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256

257257
say_waiting_for_probe_heating();
258258
SERIAL_ECHOLNPGM(" Bed:", target_bed, " Probe:", target_probe);
259-
const millis_t probe_timeout_ms = millis() + SEC_TO_MS(900UL);
259+
const millis_t probe_timeout_ms = millis() + MIN_TO_MS(15);
260260
while (thermalManager.degProbe() < target_probe) {
261261
if (report_temps(next_temp_report, probe_timeout_ms)) {
262262
SERIAL_ECHOLNPGM("!Probe heating timed out.");

Marlin/src/gcode/gcode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
793793
case 250: M250(); break; // M250: Set LCD contrast
794794
#endif
795795

796-
#if HAS_GCODE_M255
796+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
797797
case 255: M255(); break; // M255: Set LCD Sleep/Backlight Timeout (Minutes)
798798
#endif
799799

Marlin/src/gcode/gcode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ class GcodeSuite {
909909
static void M250_report(const bool forReplay=true);
910910
#endif
911911

912-
#if HAS_GCODE_M255
912+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
913913
static void M255();
914914
static void M255_report(const bool forReplay=true);
915915
#endif

Marlin/src/gcode/lcd/M255.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
#include "../../inc/MarlinConfig.h"
2323

24-
#if HAS_GCODE_M255
24+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
2525

2626
#include "../gcode.h"
2727
#include "../../lcd/marlinui.h"
@@ -51,4 +51,4 @@ void GcodeSuite::M255_report(const bool forReplay/*=true*/) {
5151
);
5252
}
5353

54-
#endif // HAS_GCODE_M255
54+
#endif // EDITABLE_DISPLAY_TIMEOUT

Marlin/src/inc/Conditionals_adv.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -893,11 +893,11 @@
893893
#if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, HAS_MEDIA)
894894
#define HAS_LEDS_OFF_FLAG 1
895895
#endif
896-
#if DISPLAY_SLEEP_MINUTES || TOUCH_IDLE_SLEEP_MINS
896+
#if defined(DISPLAY_SLEEP_MINUTES) || defined(TOUCH_IDLE_SLEEP_MINS)
897897
#define HAS_DISPLAY_SLEEP 1
898898
#endif
899-
#if HAS_DISPLAY_SLEEP || LCD_BACKLIGHT_TIMEOUT_MINS
900-
#define HAS_GCODE_M255 1
899+
#ifdef LCD_BACKLIGHT_TIMEOUT_MINS
900+
#define HAS_BACKLIGHT_TIMEOUT 1
901901
#endif
902902

903903
#if ANY(DIGIPOT_MCP4018, DIGIPOT_MCP4451)

Marlin/src/inc/SanityCheck.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,7 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
27622762
#endif
27632763
#endif
27642764

2765-
#if LCD_BACKLIGHT_TIMEOUT_MINS
2765+
#if HAS_BACKLIGHT_TIMEOUT
27662766
#if !HAS_ENCODER_ACTION && DISABLED(HAS_DWIN_E3V2)
27672767
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
27682768
#elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST)

Marlin/src/lcd/e3v2/common/encoder.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ EncoderState encoderReceiveAnalyze() {
8787
#if PIN_EXISTS(LCD_LED)
8888
//LED_Action();
8989
#endif
90-
#if LCD_BACKLIGHT_TIMEOUT_MINS
91-
ui.refresh_backlight_timeout();
92-
#endif
90+
TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout());
9391
if (!ui.backlight) {
9492
ui.refresh_brightness();
9593
return ENCODER_DIFF_NO;
@@ -161,9 +159,7 @@ EncoderState encoderReceiveAnalyze() {
161159
temp_diff = 0;
162160
}
163161
if (temp_diffState != ENCODER_DIFF_NO) {
164-
#if LCD_BACKLIGHT_TIMEOUT_MINS
165-
ui.refresh_backlight_timeout();
166-
#endif
162+
TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout());
167163
if (!ui.backlight) ui.refresh_brightness();
168164
}
169165
return temp_diffState;

Marlin/src/lcd/e3v2/proui/dwin.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ void eachMomentUpdate() {
12491249
static millis_t next_var_update_ms = 0, next_rts_update_ms = 0, next_status_update_ms = 0;
12501250
const millis_t ms = millis();
12511251

1252-
#if LCD_BACKLIGHT_TIMEOUT_MINS
1252+
#if HAS_BACKLIGHT_TIMEOUT
12531253
if (ui.backlight_off_ms && ELAPSED(ms, ui.backlight_off_ms)) {
12541254
turnOffBacklight(); // Backlight off
12551255
ui.backlight_off_ms = 0;
@@ -2235,7 +2235,7 @@ void setMoveZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick(Z_MIN_POS, Z_MAX_POS,
22352235

22362236
#endif
22372237

2238-
#if LCD_BACKLIGHT_TIMEOUT_MINS
2238+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
22392239
void applyTimer() { ui.backlight_timeout_minutes = menuData.value; }
22402240
void setTimer() { setIntOnClick(ui.backlight_timeout_min, ui.backlight_timeout_max, ui.backlight_timeout_minutes, applyTimer); }
22412241
#endif
@@ -3123,7 +3123,7 @@ void drawAdvancedSettingsMenu() {
31233123
#if HAS_LOCKSCREEN
31243124
MENU_ITEM(ICON_Lock, MSG_LOCKSCREEN, onDrawMenuItem, dwinLockScreen);
31253125
#endif
3126-
#if LCD_BACKLIGHT_TIMEOUT_MINS
3126+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
31273127
EDIT_ITEM(ICON_Brightness, MSG_SCREEN_TIMEOUT, onDrawPIntMenu, setTimer, &ui.backlight_timeout_minutes);
31283128
#endif
31293129
#if ENABLED(SOUND_MENU_ITEM)
@@ -3347,7 +3347,7 @@ void drawTuneMenu() {
33473347
EDIT_ITEM(ICON_Brightness, MSG_BRIGHTNESS, onDrawPInt8Menu, setBrightness, &ui.brightness);
33483348
MENU_ITEM(ICON_Brightness, MSG_BRIGHTNESS_OFF, onDrawMenuItem, turnOffBacklight);
33493349
#endif
3350-
#if LCD_BACKLIGHT_TIMEOUT_MINS
3350+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
33513351
EDIT_ITEM(ICON_Brightness, MSG_SCREEN_TIMEOUT, onDrawPIntMenu, setTimer, &ui.backlight_timeout_minutes);
33523352
#endif
33533353
#if ENABLED(CASE_LIGHT_MENU)

Marlin/src/lcd/e3v2/proui/plot.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ void Plot::update(const_float_t value) {
7373
dwinDrawPoint(COLOR_YELLOW, 1, 1, x2 - 1, y);
7474
}
7575
graphpoints++;
76-
#if LCD_BACKLIGHT_TIMEOUT_MINS
77-
ui.refresh_backlight_timeout();
78-
#endif
76+
TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout());
7977
}
8078

8179
#endif // PROUI_TUNING_GRAPH

Marlin/src/lcd/marlinui.cpp

+17-10
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 || ALL(HAS_WIRED_LCD, PRINTER_EVENT_LEDS) || (defined(LCD_BACKLIGHT_TIMEOUT_MINS) && defined(NEOPIXEL_BKGD_INDEX_FIRST))
27+
#if LED_POWEROFF_TIMEOUT > 0 || ALL(HAS_WIRED_LCD, PRINTER_EVENT_LEDS) || (HAS_BACKLIGHT_TIMEOUT && defined(NEOPIXEL_BKGD_INDEX_FIRST))
2828
#include "../feature/leds/leds.h"
2929
#endif
3030

@@ -185,10 +185,14 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
185185
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
186186
#endif
187187

188-
#if LCD_BACKLIGHT_TIMEOUT_MINS
188+
#if HAS_BACKLIGHT_TIMEOUT
189189

190+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
191+
uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load()
192+
#else
193+
constexpr uint8_t MarlinUI::backlight_timeout_minutes;
194+
#endif
190195
constexpr uint8_t MarlinUI::backlight_timeout_min, MarlinUI::backlight_timeout_max;
191-
uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load()
192196
millis_t MarlinUI::backlight_off_ms = 0;
193197

194198
void MarlinUI::refresh_backlight_timeout() {
@@ -203,12 +207,16 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
203207

204208
#elif HAS_DISPLAY_SLEEP
205209

210+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
211+
uint8_t MarlinUI::sleep_timeout_minutes; // Initialized by settings.load()
212+
#else
213+
constexpr uint8_t MarlinUI::sleep_timeout_minutes;
214+
#endif
206215
constexpr uint8_t MarlinUI::sleep_timeout_min, MarlinUI::sleep_timeout_max;
207216

208-
uint8_t MarlinUI::sleep_timeout_minutes; // Initialized by settings.load()
209-
millis_t MarlinUI::screen_timeout_millis = 0;
217+
millis_t MarlinUI::screen_timeout_ms = 0;
210218
void MarlinUI::refresh_screen_timeout() {
211-
screen_timeout_millis = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0;
219+
screen_timeout_ms = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0;
212220
sleep_display(false);
213221
}
214222

@@ -1092,7 +1100,7 @@ void MarlinUI::init() {
10921100
if (encoderPastThreshold || lcd_clicked) {
10931101
reset_status_timeout(ms);
10941102

1095-
#if LCD_BACKLIGHT_TIMEOUT_MINS
1103+
#if HAS_BACKLIGHT_TIMEOUT
10961104
refresh_backlight_timeout();
10971105
#elif HAS_DISPLAY_SLEEP
10981106
refresh_screen_timeout();
@@ -1202,8 +1210,7 @@ void MarlinUI::init() {
12021210
return_to_status();
12031211
#endif
12041212

1205-
#if LCD_BACKLIGHT_TIMEOUT_MINS
1206-
1213+
#if HAS_BACKLIGHT_TIMEOUT
12071214
if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) {
12081215
#ifdef NEOPIXEL_BKGD_INDEX_FIRST
12091216
neo.set_background_off();
@@ -1214,7 +1221,7 @@ void MarlinUI::init() {
12141221
backlight_off_ms = 0;
12151222
}
12161223
#elif HAS_DISPLAY_SLEEP
1217-
if (screen_timeout_millis && ELAPSED(ms, screen_timeout_millis))
1224+
if (screen_timeout_ms && ELAPSED(ms, screen_timeout_ms))
12181225
sleep_display();
12191226
#endif
12201227

Marlin/src/lcd/marlinui.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,25 @@ class MarlinUI {
272272
FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
273273
#endif
274274

275-
#if LCD_BACKLIGHT_TIMEOUT_MINS
275+
#if HAS_BACKLIGHT_TIMEOUT
276+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
277+
static uint8_t backlight_timeout_minutes;
278+
#else
279+
static constexpr uint8_t backlight_timeout_minutes = LCD_BACKLIGHT_TIMEOUT_MINS;
280+
#endif
276281
static constexpr uint8_t backlight_timeout_min = 0;
277282
static constexpr uint8_t backlight_timeout_max = 99;
278-
static uint8_t backlight_timeout_minutes;
279283
static millis_t backlight_off_ms;
280284
static void refresh_backlight_timeout();
281285
#elif HAS_DISPLAY_SLEEP
286+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
287+
static uint8_t sleep_timeout_minutes;
288+
#else
289+
static constexpr uint8_t sleep_timeout_minutes = DISPLAY_SLEEP_MINUTES;
290+
#endif
282291
static constexpr uint8_t sleep_timeout_min = 0;
283292
static constexpr uint8_t sleep_timeout_max = 99;
284-
static uint8_t sleep_timeout_minutes;
285-
static millis_t screen_timeout_millis;
293+
static millis_t screen_timeout_ms;
286294
static void refresh_screen_timeout();
287295
static void sleep_display(const bool sleep=true);
288296
#endif

Marlin/src/lcd/menu/menu_configuration.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,12 @@ void menu_configuration() {
618618
//
619619
// Set display backlight / sleep timeout
620620
//
621-
#if LCD_BACKLIGHT_TIMEOUT_MINS
622-
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.backlight_timeout_minutes, ui.backlight_timeout_min, ui.backlight_timeout_max, ui.refresh_backlight_timeout);
623-
#elif HAS_DISPLAY_SLEEP
624-
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, ui.sleep_timeout_min, ui.sleep_timeout_max, ui.refresh_screen_timeout);
621+
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
622+
#if HAS_BACKLIGHT_TIMEOUT
623+
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.backlight_timeout_minutes, ui.backlight_timeout_min, ui.backlight_timeout_max, ui.refresh_backlight_timeout);
624+
#elif HAS_DISPLAY_SLEEP
625+
EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, ui.sleep_timeout_min, ui.sleep_timeout_max, ui.refresh_screen_timeout);
626+
#endif
625627
#endif
626628

627629
#if ENABLED(FWRETRACT)

Marlin/src/lcd/tft/touch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ bool Touch::get_point(int16_t * const x, int16_t * const y) {
308308
next_touch_ms = millis() + 100;
309309
safe_delay(20);
310310
}
311-
next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60);
311+
next_sleep_ms = millis() + MIN_TO_MS(ui.sleep_timeout_minutes);
312312
}
313313

314314
#endif // HAS_TOUCH_SLEEP

Marlin/src/lcd/touch/touch_buttons.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ uint8_t TouchButtons::read_buttons() {
147147
WRITE(TFT_BACKLIGHT_PIN, HIGH);
148148
#endif
149149
}
150-
next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60);
150+
next_sleep_ms = millis() + MIN_TO_MS(ui.sleep_timeout_minutes);
151151
}
152152

153153
#endif // HAS_TOUCH_SLEEP

0 commit comments

Comments
 (0)