Browse Source

M256 LCD brightness (#22478)

Scott Lahteine 2 years ago
parent
commit
1e33c1a2a7
No account linked to committer's email address

+ 4
- 0
Marlin/src/gcode/gcode.cpp View File

@@ -729,6 +729,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
729 729
         case 250: M250(); break;                                  // M250: Set LCD contrast
730 730
       #endif
731 731
 
732
+      #if HAS_LCD_BRIGHTNESS
733
+        case 256: M256(); break;                                  // M256: Set LCD brightness
734
+      #endif
735
+
732 736
       #if ENABLED(EXPERIMENTAL_I2CBUS)
733 737
         case 260: M260(); break;                                  // M260: Send data to an i2c slave
734 738
         case 261: M261(); break;                                  // M261: Request data from an i2c slave

+ 5
- 0
Marlin/src/gcode/gcode.h View File

@@ -191,6 +191,7 @@
191 191
  * M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL)
192 192
  * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
193 193
  * M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support)
194
+ * M256 - Set LCD brightness: "M256 B<brightness>" (0-255). (Requires an LCD with brightness control)
194 195
  * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
195 196
  * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
196 197
  * M280 - Set servo position absolute: "M280 P<index> S<angle|µs>". (Requires servos)
@@ -820,6 +821,10 @@ private:
820 821
     static void M250();
821 822
   #endif
822 823
 
824
+  #if HAS_LCD_BRIGHTNESS
825
+    static void M256();
826
+  #endif
827
+
823 828
   #if ENABLED(EXPERIMENTAL_I2CBUS)
824 829
     static void M260();
825 830
     static void M261();

+ 37
- 0
Marlin/src/gcode/lcd/M256.cpp View File

@@ -0,0 +1,37 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#include "../../inc/MarlinConfig.h"
23
+
24
+#if HAS_LCD_BRIGHTNESS
25
+
26
+#include "../gcode.h"
27
+#include "../../lcd/marlinui.h"
28
+
29
+/**
30
+ * M256: Set the LCD brightness
31
+ */
32
+void GcodeSuite::M256() {
33
+  if (parser.seenval('B')) ui.set_brightness(parser.value_int());
34
+  SERIAL_ECHOLNPAIR("LCD Brightness: ", ui.brightness);
35
+}
36
+
37
+#endif // HAS_LCD_BRIGHTNESS

+ 2
- 2
Marlin/src/gcode/lcd/M73.cpp View File

@@ -35,13 +35,13 @@
35 35
  *   M73 P25 ; Set progress to 25%
36 36
  */
37 37
 void GcodeSuite::M73() {
38
-  if (parser.seen('P'))
38
+  if (parser.seenval('P'))
39 39
     ui.set_progress((PROGRESS_SCALE) > 1
40 40
       ? parser.value_float() * (PROGRESS_SCALE)
41 41
       : parser.value_byte()
42 42
     );
43 43
   #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
44
-    if (parser.seen('R')) ui.set_remaining_time(60 * parser.value_ulong());
44
+    if (parser.seenval('R')) ui.set_remaining_time(60 * parser.value_ulong());
45 45
   #endif
46 46
 }
47 47
 

+ 11
- 0
Marlin/src/lcd/marlinui.cpp View File

@@ -91,6 +91,17 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
91 91
   }
92 92
 #endif
93 93
 
94
+#if HAS_LCD_BRIGHTNESS
95
+  uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS;
96
+  bool MarlinUI::backlight = true;
97
+
98
+  void MarlinUI::set_brightness(const uint8_t value) {
99
+    backlight = !!value;
100
+    if (backlight) brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS);
101
+    // Set brightness on enabled LCD here
102
+  }
103
+#endif
104
+
94 105
 #if ENABLED(SOUND_MENU_ITEM)
95 106
   bool MarlinUI::buzzer_enabled = true;
96 107
 #endif

+ 16
- 0
Marlin/src/lcd/marlinui.h View File

@@ -239,6 +239,22 @@ public:
239 239
     static void media_changed(const uint8_t old_stat, const uint8_t stat);
240 240
   #endif
241 241
 
242
+  #if HAS_LCD_BRIGHTNESS
243
+    #ifndef MIN_LCD_BRIGHTNESS
244
+      #define MIN_LCD_BRIGHTNESS   1
245
+    #endif
246
+    #ifndef MAX_LCD_BRIGHTNESS
247
+      #define MAX_LCD_BRIGHTNESS 255
248
+    #endif
249
+    #ifndef DEFAULT_LCD_BRIGHTNESS
250
+      #define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS
251
+    #endif
252
+    static uint8_t brightness;
253
+    static bool backlight;
254
+    static void set_brightness(const uint8_t value);
255
+    FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
256
+  #endif
257
+
242 258
   #if ENABLED(DWIN_CREALITY_LCD)
243 259
     static void refresh();
244 260
   #else

+ 36
- 9
Marlin/src/module/settings.cpp View File

@@ -36,7 +36,7 @@
36 36
  */
37 37
 
38 38
 // Change EEPROM version if the structure changes
39
-#define EEPROM_VERSION "V83"
39
+#define EEPROM_VERSION "V84"
40 40
 #define EEPROM_OFFSET 100
41 41
 
42 42
 // Check the integrity of data offsets.
@@ -354,6 +354,11 @@ typedef struct SettingsDataStruct {
354 354
   int16_t lcd_contrast;                                 // M250 C
355 355
 
356 356
   //
357
+  // HAS_LCD_BRIGHTNESS
358
+  //
359
+  uint8_t lcd_brightness;                               // M256 B
360
+
361
+  //
357 362
   // Controller fan settings
358 363
   //
359 364
   controllerFan_settings_t controllerFan_settings;      // M710
@@ -999,18 +1004,20 @@ void MarlinSettings::postprocess() {
999 1004
     //
1000 1005
     {
1001 1006
       _FIELD_TEST(lcd_contrast);
1002
-
1003
-      const int16_t lcd_contrast =
1004
-        #if HAS_LCD_CONTRAST
1005
-          ui.contrast
1006
-        #else
1007
-          127
1008
-        #endif
1009
-      ;
1007
+      const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
1010 1008
       EEPROM_WRITE(lcd_contrast);
1011 1009
     }
1012 1010
 
1013 1011
     //
1012
+    // LCD Brightness
1013
+    //
1014
+    {
1015
+      _FIELD_TEST(lcd_brightness);
1016
+      const uint8_t lcd_brightness = TERN(HAS_LCD_BRIGHTNESS, ui.brightness, 255);
1017
+      EEPROM_WRITE(lcd_brightness);
1018
+    }
1019
+
1020
+    //
1014 1021
     // Controller Fan
1015 1022
     //
1016 1023
     {
@@ -1847,6 +1854,16 @@ void MarlinSettings::postprocess() {
1847 1854
       }
1848 1855
 
1849 1856
       //
1857
+      // LCD Brightness
1858
+      //
1859
+      {
1860
+        _FIELD_TEST(lcd_brightness);
1861
+        uint8_t lcd_brightness;
1862
+        EEPROM_READ(lcd_brightness);
1863
+        TERN_(HAS_LCD_BRIGHTNESS, if (!validating) ui.set_brightness(lcd_brightness));
1864
+      }
1865
+
1866
+      //
1850 1867
       // Controller Fan
1851 1868
       //
1852 1869
       {
@@ -2830,6 +2847,11 @@ void MarlinSettings::reset() {
2830 2847
   TERN_(HAS_LCD_CONTRAST, ui.set_contrast(DEFAULT_LCD_CONTRAST));
2831 2848
 
2832 2849
   //
2850
+  // LCD Brightness
2851
+  //
2852
+  TERN_(HAS_LCD_BRIGHTNESS, ui.set_brightness(DEFAULT_LCD_BRIGHTNESS));
2853
+
2854
+  //
2833 2855
   // Controller Fan
2834 2856
   //
2835 2857
   TERN_(USE_CONTROLLER_FAN, controllerFan.reset());
@@ -3406,6 +3428,11 @@ void MarlinSettings::reset() {
3406 3428
       CONFIG_ECHO_MSG("  M250 C", ui.contrast);
3407 3429
     #endif
3408 3430
 
3431
+    #if HAS_LCD_BRIGHTNESS
3432
+      CONFIG_ECHO_HEADING("LCD Brightness:");
3433
+      CONFIG_ECHO_MSG("  M256 B", ui.brightness);
3434
+    #endif
3435
+
3409 3436
     TERN_(CONTROLLER_FAN_EDITABLE, M710_report(forReplay));
3410 3437
 
3411 3438
     #if ENABLED(POWER_LOSS_RECOVERY)

+ 1
- 1
Marlin/src/module/stepper/trinamic.cpp View File

@@ -1008,7 +1008,7 @@ void reset_trinamic_drivers() {
1008 1008
     TMC_SW_DETAIL(Y), TMC_SW_DETAIL(Y2),
1009 1009
     TMC_SW_DETAIL(Z), TMC_SW_DETAIL(Z2), TMC_SW_DETAIL(Z3), TMC_SW_DETAIL(Z4),
1010 1010
     TMC_SW_DETAIL(I), TMC_SW_DETAIL(J), TMC_SW_DETAIL(K),
1011
-  	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)
1011
+    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)
1012 1012
   };
1013 1013
 
1014 1014
   constexpr bool sc_sw_done(size_t start, size_t end) { return start == end; }

+ 1
- 0
ini/features.ini View File

@@ -189,6 +189,7 @@ HAS_GCODE_M876                         = src_filter=+<src/gcode/host/M876.cpp>
189 189
 HAS_RESUME_CONTINUE                    = src_filter=+<src/gcode/lcd/M0_M1.cpp>
190 190
 HAS_STATUS_MESSAGE                     = src_filter=+<src/gcode/lcd/M117.cpp>
191 191
 HAS_LCD_CONTRAST                       = src_filter=+<src/gcode/lcd/M250.cpp>
192
+HAS_LCD_BRIGHTNESS                     = src_filter=+<src/gcode/lcd/M256.cpp>
192 193
 HAS_BUZZER                             = src_filter=+<src/gcode/lcd/M300.cpp>
193 194
 LCD_SET_PROGRESS_MANUALLY              = src_filter=+<src/gcode/lcd/M73.cpp>
194 195
 TOUCH_SCREEN_CALIBRATION               = src_filter=+<src/gcode/lcd/M995.cpp>

+ 1
- 1
platformio.ini View File

@@ -206,7 +206,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
206 206
   -<src/gcode/host/M876.cpp>
207 207
   -<src/gcode/lcd/M0_M1.cpp>
208 208
   -<src/gcode/lcd/M117.cpp>
209
-  -<src/gcode/lcd/M250.cpp>
209
+  -<src/gcode/lcd/M250.cpp> -<src/gcode/lcd/M256.cpp>
210 210
   -<src/gcode/lcd/M300.cpp>
211 211
   -<src/gcode/lcd/M414.cpp>
212 212
   -<src/gcode/lcd/M73.cpp>

Loading…
Cancel
Save