mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-26 13:25:54 +00:00
✨ M256 LCD brightness (#22478)
This commit is contained in:
parent
eeac85642f
commit
4b2fdbeeb1
@ -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
|
||||
|
@ -191,6 +191,7 @@
|
||||
* M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL)
|
||||
* M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
|
||||
* M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support)
|
||||
* M256 - Set LCD brightness: "M256 B<brightness>" (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<index> S<angle|µ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();
|
||||
|
37
Marlin/src/gcode/lcd/M256.cpp
Normal file
37
Marlin/src/gcode/lcd/M256.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#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
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -189,6 +189,7 @@ HAS_GCODE_M876 = src_filter=+<src/gcode/host/M876.cpp>
|
||||
HAS_RESUME_CONTINUE = src_filter=+<src/gcode/lcd/M0_M1.cpp>
|
||||
HAS_STATUS_MESSAGE = src_filter=+<src/gcode/lcd/M117.cpp>
|
||||
HAS_LCD_CONTRAST = src_filter=+<src/gcode/lcd/M250.cpp>
|
||||
HAS_LCD_BRIGHTNESS = src_filter=+<src/gcode/lcd/M256.cpp>
|
||||
HAS_BUZZER = src_filter=+<src/gcode/lcd/M300.cpp>
|
||||
LCD_SET_PROGRESS_MANUALLY = src_filter=+<src/gcode/lcd/M73.cpp>
|
||||
TOUCH_SCREEN_CALIBRATION = src_filter=+<src/gcode/lcd/M995.cpp>
|
||||
|
@ -206,7 +206,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
|
||||
-<src/gcode/host/M876.cpp>
|
||||
-<src/gcode/lcd/M0_M1.cpp>
|
||||
-<src/gcode/lcd/M117.cpp>
|
||||
-<src/gcode/lcd/M250.cpp>
|
||||
-<src/gcode/lcd/M250.cpp> -<src/gcode/lcd/M256.cpp>
|
||||
-<src/gcode/lcd/M300.cpp>
|
||||
-<src/gcode/lcd/M414.cpp>
|
||||
-<src/gcode/lcd/M73.cpp>
|
||||
|
Loading…
Reference in New Issue
Block a user