Browse Source

M256 LCD brightness (#22478)

vanilla_fb_2.0.x
Scott Lahteine 3 years ago
parent
commit
4b2fdbeeb1
  1. 4
      Marlin/src/gcode/gcode.cpp
  2. 5
      Marlin/src/gcode/gcode.h
  3. 37
      Marlin/src/gcode/lcd/M256.cpp
  4. 4
      Marlin/src/gcode/lcd/M73.cpp
  5. 11
      Marlin/src/lcd/marlinui.cpp
  6. 16
      Marlin/src/lcd/marlinui.h
  7. 45
      Marlin/src/module/settings.cpp
  8. 2
      Marlin/src/module/stepper/trinamic.cpp
  9. 1
      ini/features.ini
  10. 2
      platformio.ini

4
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

5
Marlin/src/gcode/gcode.h

@ -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

@ -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

4
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
}

11
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

16
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

45
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)

2
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; }

1
ini/features.ini

@ -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>

2
platformio.ini

@ -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…
Cancel
Save