diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 12fd231ca8..7933c3141a 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -729,6 +729,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 250: M250(); break; // M250: Set LCD contrast #endif + #if HAS_LCD_BRIGHTNESS + case 256: M256(); break; // M256: Set LCD brightness + #endif + #if ENABLED(EXPERIMENTAL_I2CBUS) case 260: M260(); break; // M260: Send data to an i2c slave case 261: M261(); break; // M261: Request data from an i2c slave diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 6b9d0eb47d..9f47c9f679 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -191,6 +191,7 @@ * M226 - Wait until a pin is in a given state: "M226 P S" (Requires DIRECT_PIN_CONTROL) * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE) * M250 - Set LCD contrast: "M250 C" (0-63). (Requires LCD support) + * M256 - Set LCD brightness: "M256 B" (0-255). (Requires an LCD with brightness control) * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS) * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS) * M280 - Set servo position absolute: "M280 P S". (Requires servos) @@ -818,6 +819,10 @@ private: static void M250(); #endif + #if HAS_LCD_BRIGHTNESS + static void M256(); + #endif + #if ENABLED(EXPERIMENTAL_I2CBUS) static void M260(); static void M261(); diff --git a/Marlin/src/gcode/lcd/M256.cpp b/Marlin/src/gcode/lcd/M256.cpp new file mode 100644 index 0000000000..e292acc4ed --- /dev/null +++ b/Marlin/src/gcode/lcd/M256.cpp @@ -0,0 +1,37 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#include "../../inc/MarlinConfig.h" + +#if HAS_LCD_BRIGHTNESS + +#include "../gcode.h" +#include "../../lcd/marlinui.h" + +/** + * M256: Set the LCD brightness + */ +void GcodeSuite::M256() { + if (parser.seenval('B')) ui.set_brightness(parser.value_int()); + SERIAL_ECHOLNPAIR("LCD Brightness: ", ui.brightness); +} + +#endif // HAS_LCD_BRIGHTNESS diff --git a/Marlin/src/gcode/lcd/M73.cpp b/Marlin/src/gcode/lcd/M73.cpp index 5b135bdff8..e94a2825f7 100644 --- a/Marlin/src/gcode/lcd/M73.cpp +++ b/Marlin/src/gcode/lcd/M73.cpp @@ -35,13 +35,13 @@ * M73 P25 ; Set progress to 25% */ void GcodeSuite::M73() { - if (parser.seen('P')) + if (parser.seenval('P')) ui.set_progress((PROGRESS_SCALE) > 1 ? parser.value_float() * (PROGRESS_SCALE) : parser.value_byte() ); #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME) - if (parser.seen('R')) ui.set_remaining_time(60 * parser.value_ulong()); + if (parser.seenval('R')) ui.set_remaining_time(60 * parser.value_ulong()); #endif } diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 0d3e3ac1ea..e38a05c55d 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -98,6 +98,17 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; } #endif +#if HAS_LCD_BRIGHTNESS + uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS; + bool MarlinUI::backlight = true; + + void MarlinUI::set_brightness(const uint8_t value) { + backlight = !!value; + if (backlight) brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS); + // Set brightness on enabled LCD here + } +#endif + #if ENABLED(SOUND_MENU_ITEM) bool MarlinUI::buzzer_enabled = true; #endif diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index a1821d9066..a50e85af1d 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -239,6 +239,22 @@ public: static void media_changed(const uint8_t old_stat, const uint8_t stat); #endif + #if HAS_LCD_BRIGHTNESS + #ifndef MIN_LCD_BRIGHTNESS + #define MIN_LCD_BRIGHTNESS 1 + #endif + #ifndef MAX_LCD_BRIGHTNESS + #define MAX_LCD_BRIGHTNESS 255 + #endif + #ifndef DEFAULT_LCD_BRIGHTNESS + #define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS + #endif + static uint8_t brightness; + static bool backlight; + static void set_brightness(const uint8_t value); + FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); } + #endif + #if ENABLED(DWIN_CREALITY_LCD) static void refresh(); #else diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 33e6b15f9a..b30c82260f 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -36,7 +36,7 @@ */ // Change EEPROM version if the structure changes -#define EEPROM_VERSION "V83" +#define EEPROM_VERSION "V84" #define EEPROM_OFFSET 100 // Check the integrity of data offsets. @@ -353,6 +353,11 @@ typedef struct SettingsDataStruct { // int16_t lcd_contrast; // M250 C + // + // HAS_LCD_BRIGHTNESS + // + uint8_t lcd_brightness; // M256 B + // // Controller fan settings // @@ -999,17 +1004,19 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(lcd_contrast); - - const int16_t lcd_contrast = - #if HAS_LCD_CONTRAST - ui.contrast - #else - 127 - #endif - ; + const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127); EEPROM_WRITE(lcd_contrast); } + // + // LCD Brightness + // + { + _FIELD_TEST(lcd_brightness); + const uint8_t lcd_brightness = TERN(HAS_LCD_BRIGHTNESS, ui.brightness, 255); + EEPROM_WRITE(lcd_brightness); + } + // // Controller Fan // @@ -1846,6 +1853,16 @@ void MarlinSettings::postprocess() { } } + // + // LCD Brightness + // + { + _FIELD_TEST(lcd_brightness); + uint8_t lcd_brightness; + EEPROM_READ(lcd_brightness); + TERN_(HAS_LCD_BRIGHTNESS, if (!validating) ui.set_brightness(lcd_brightness)); + } + // // Controller Fan // @@ -2829,6 +2846,11 @@ void MarlinSettings::reset() { // TERN_(HAS_LCD_CONTRAST, ui.set_contrast(DEFAULT_LCD_CONTRAST)); + // + // LCD Brightness + // + TERN_(HAS_LCD_BRIGHTNESS, ui.set_brightness(DEFAULT_LCD_BRIGHTNESS)); + // // Controller Fan // @@ -3406,6 +3428,11 @@ void MarlinSettings::reset() { CONFIG_ECHO_MSG(" M250 C", ui.contrast); #endif + #if HAS_LCD_BRIGHTNESS + CONFIG_ECHO_HEADING("LCD Brightness:"); + CONFIG_ECHO_MSG(" M256 B", ui.brightness); + #endif + TERN_(CONTROLLER_FAN_EDITABLE, M710_report(forReplay)); #if ENABLED(POWER_LOSS_RECOVERY) diff --git a/Marlin/src/module/stepper/trinamic.cpp b/Marlin/src/module/stepper/trinamic.cpp index a5d7e5ad6b..f9ed43acbf 100644 --- a/Marlin/src/module/stepper/trinamic.cpp +++ b/Marlin/src/module/stepper/trinamic.cpp @@ -1008,7 +1008,7 @@ void reset_trinamic_drivers() { TMC_SW_DETAIL(Y), TMC_SW_DETAIL(Y2), TMC_SW_DETAIL(Z), TMC_SW_DETAIL(Z2), TMC_SW_DETAIL(Z3), TMC_SW_DETAIL(Z4), TMC_SW_DETAIL(I), TMC_SW_DETAIL(J), TMC_SW_DETAIL(K), - TMC_SW_DETAIL(E0), TMC_SW_DETAIL(E1), TMC_SW_DETAIL(E2), TMC_SW_DETAIL(E3), TMC_SW_DETAIL(E4), TMC_SW_DETAIL(E5), TMC_SW_DETAIL(E6), TMC_SW_DETAIL(E7) + TMC_SW_DETAIL(E0), TMC_SW_DETAIL(E1), TMC_SW_DETAIL(E2), TMC_SW_DETAIL(E3), TMC_SW_DETAIL(E4), TMC_SW_DETAIL(E5), TMC_SW_DETAIL(E6), TMC_SW_DETAIL(E7) }; constexpr bool sc_sw_done(size_t start, size_t end) { return start == end; } diff --git a/ini/features.ini b/ini/features.ini index 4ee927e98d..815a43cbf4 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -189,6 +189,7 @@ HAS_GCODE_M876 = src_filter=+ HAS_RESUME_CONTINUE = src_filter=+ HAS_STATUS_MESSAGE = src_filter=+ HAS_LCD_CONTRAST = src_filter=+ +HAS_LCD_BRIGHTNESS = src_filter=+ HAS_BUZZER = src_filter=+ LCD_SET_PROGRESS_MANUALLY = src_filter=+ TOUCH_SCREEN_CALIBRATION = src_filter=+ diff --git a/platformio.ini b/platformio.ini index 1fb9ba55e6..68fa4e3d4e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -206,7 +206,7 @@ default_src_filter = + - - + - - - - - + - - - - -