Skip to content

Commit 6c6476c

Browse files
authored
Merge pull request #4851 from 3d-gussner/MK3_LCD_Brightness
Add M256 [ B | D | S | T ]
2 parents a29c246 + a768299 commit 6c6476c

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

Firmware/Configuration.h

+4
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ your extruder heater takes 2 minutes to hit the target on heating.
324324
#define SDSUPPORT
325325
#define LCD_WIDTH 20
326326
#define LCD_HEIGHT 4
327+
#define LCD_BACKLIGHT_LEVEL_HIGH 130
328+
#define LCD_BACKLIGHT_LEVEL_LOW 50
329+
#define LCD_BACKLIGHT_FORCE_ON 30
330+
#define LCD_BACKLIGHT_TIMEOUT 15
327331

328332

329333
// Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino

Firmware/Marlin_main.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,7 @@ extern uint8_t st_backlash_y;
37103710
//!@n M221 - Set extrude factor override percentage
37113711
//!@n M226 - Wait for Pin state
37123712
//!@n M240 - Trigger camera
3713-
//!@n M250 - Set LCD contrast C<contrast value> (value 0..63)
3713+
//!@n M256 - Set LCD brightness
37143714
//!@n M300 - Play tone
37153715
//!@n M301 - Set hotend PID
37163716
//!@n M302 - Allow cold extrude, or set minimum extrude temperature
@@ -6641,6 +6641,37 @@ void process_commands()
66416641
break;
66426642
#ifdef PREVENT_DANGEROUS_EXTRUDE
66436643

6644+
/*!
6645+
### M256 - Set LCD brightness <a href="https://reprap.org/wiki/G-code#M256:_Set_LCD_brightness">M256: Set LCD brightness</a>
6646+
Set and/or get the LCD brightness. The value is constrained based on the LCD, but typically a value of 0 is the dimmest and 255 is the brightest.
6647+
#### Usage
6648+
6649+
M256 [ B | D | S | T ]
6650+
6651+
#### Parameters
6652+
- `B` - Normal Brightness value (0 - 255), default 130
6653+
- `D` - Dimmed Brightness value (0 - 255), default 50
6654+
- `S` - Brightness mode, default Auto
6655+
- `0` - Dim
6656+
- `1` - Bright
6657+
- `2` - Auto
6658+
- `T` - Brightness timeout (15 - 900), default 15 seconds
6659+
*/
6660+
#ifdef LCD_BL_PIN
6661+
case 256:
6662+
{
6663+
if (backlightSupport) {
6664+
if (code_seen('B') ) backlightLevel_HIGH = code_value_uint8();
6665+
if (code_seen('D')) backlightLevel_LOW = code_value_uint8();
6666+
if (code_seen('S')) backlightMode = max(static_cast<Backlight_Mode>(code_value_uint8()), BACKLIGHT_MODE_AUTO);
6667+
if (code_seen('T')) backlightTimer_period = constrain(code_value_short(), LCD_BACKLIGHT_TIMEOUT, LCD_BACKLIGHT_TIMEOUT*60);
6668+
printf_P(PSTR("M256 B%d D%d S%d T%u\n"), backlightLevel_HIGH, backlightLevel_LOW, backlightMode, backlightTimer_period);
6669+
backlight_save();
6670+
}
6671+
}
6672+
break;
6673+
#endif //LCD_BL_PIN
6674+
66446675
/*!
66456676
### M302 - Allow cold extrude, or set minimum extrude temperature <a href="https://reprap.org/wiki/G-code#M302:_Allow_cold_extrudes">M302: Allow cold extrudes</a>
66466677
This tells the printer to allow movement of the extruder motor above a certain temperature, or if disabled, to allow extruder movement when the hotend is below a safe printing temperature.

Firmware/backlight.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bool backlightSupport = 0; //only if it's true will any of the settings be visib
1717
uint8_t backlightLevel_HIGH = 0;
1818
uint8_t backlightLevel_LOW = 0;
1919
uint8_t backlightMode = BACKLIGHT_MODE_BRIGHT;
20-
int16_t backlightTimer_period = 10;
20+
int16_t backlightTimer_period = LCD_BACKLIGHT_TIMEOUT;
2121
LongTimer backlightTimer;
2222

2323
static void backlightTimer_reset() //used for resetting the timer and waking the display. Triggered on user interactions.
@@ -32,7 +32,7 @@ void force_bl_on(bool section_start)
3232
if (section_start)
3333
{
3434
backlightMode = BACKLIGHT_MODE_BRIGHT;
35-
if (backlightLevel_HIGH < 30) backlightLevel_HIGH = 30;
35+
if (backlightLevel_HIGH < LCD_BACKLIGHT_FORCE_ON) backlightLevel_HIGH = LCD_BACKLIGHT_FORCE_ON;
3636
}
3737
else
3838
{
@@ -93,9 +93,9 @@ void backlight_init()
9393

9494
//initialize backlight
9595
backlightMode = eeprom_init_default_byte((uint8_t *)EEPROM_BACKLIGHT_MODE, BACKLIGHT_MODE_AUTO);
96-
backlightLevel_HIGH = eeprom_init_default_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_HIGH, 130);
97-
backlightLevel_LOW = eeprom_init_default_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_LOW, 50);
98-
backlightTimer_period = eeprom_init_default_word((uint16_t *)EEPROM_BACKLIGHT_TIMEOUT, 10); // in seconds
96+
backlightLevel_HIGH = eeprom_init_default_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_HIGH, LCD_BACKLIGHT_LEVEL_HIGH);
97+
backlightLevel_LOW = eeprom_init_default_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_LOW, LCD_BACKLIGHT_LEVEL_LOW);
98+
backlightTimer_period = eeprom_init_default_word((uint16_t *)EEPROM_BACKLIGHT_TIMEOUT, LCD_BACKLIGHT_TIMEOUT); // in seconds
9999

100100
SET_OUTPUT(LCD_BL_PIN);
101101
backlightTimer_reset();

Firmware/menu.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,8 @@ static void _menu_edit_P()
475475
// disable after first use and/or if the initial value is not minEditValue
476476
_md->minJumpValue = 0;
477477
}
478-
479478
_md->currentValue += lcd_encoder;
480479
lcd_encoder = 0; // Consume knob rotation event
481-
482480
// Constrain the value in case it's outside the allowed limits
483481
_md->currentValue = constrain(_md->currentValue, _md->minEditValue, _md->maxEditValue);
484482
lcd_set_cursor(0, 1);

Firmware/ultralcd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5620,7 +5620,7 @@ static void lcd_backlight_menu()
56205620
MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
56215621
MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
56225622
MENU_ITEM_TOGGLE_P(_T(MSG_MODE), ((backlightMode==BACKLIGHT_MODE_BRIGHT) ? _T(MSG_BRIGHT) : ((backlightMode==BACKLIGHT_MODE_DIM) ? _T(MSG_DIM) : _T(MSG_AUTO))), backlight_mode_toggle);
5623-
MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
5623+
MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, LCD_BACKLIGHT_TIMEOUT, LCD_BACKLIGHT_TIMEOUT*60);
56245624

56255625
MENU_END();
56265626
}

0 commit comments

Comments
 (0)