Ver código fonte

M256 LCD brightness (#22478)

Scott Lahteine 2 anos atrás
pai
commit
1e33c1a2a7
Nenhuma conta vinculada ao e-mail do autor do commit

+ 4
- 0
Marlin/src/gcode/gcode.cpp Ver arquivo

729
         case 250: M250(); break;                                  // M250: Set LCD contrast
729
         case 250: M250(); break;                                  // M250: Set LCD contrast
730
       #endif
730
       #endif
731
 
731
 
732
+      #if HAS_LCD_BRIGHTNESS
733
+        case 256: M256(); break;                                  // M256: Set LCD brightness
734
+      #endif
735
+
732
       #if ENABLED(EXPERIMENTAL_I2CBUS)
736
       #if ENABLED(EXPERIMENTAL_I2CBUS)
733
         case 260: M260(); break;                                  // M260: Send data to an i2c slave
737
         case 260: M260(); break;                                  // M260: Send data to an i2c slave
734
         case 261: M261(); break;                                  // M261: Request data from an i2c slave
738
         case 261: M261(); break;                                  // M261: Request data from an i2c slave

+ 5
- 0
Marlin/src/gcode/gcode.h Ver arquivo

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

+ 37
- 0
Marlin/src/gcode/lcd/M256.cpp Ver arquivo

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 Ver arquivo

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

+ 11
- 0
Marlin/src/lcd/marlinui.cpp Ver arquivo

91
   }
91
   }
92
 #endif
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
 #if ENABLED(SOUND_MENU_ITEM)
105
 #if ENABLED(SOUND_MENU_ITEM)
95
   bool MarlinUI::buzzer_enabled = true;
106
   bool MarlinUI::buzzer_enabled = true;
96
 #endif
107
 #endif

+ 16
- 0
Marlin/src/lcd/marlinui.h Ver arquivo

239
     static void media_changed(const uint8_t old_stat, const uint8_t stat);
239
     static void media_changed(const uint8_t old_stat, const uint8_t stat);
240
   #endif
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
   #if ENABLED(DWIN_CREALITY_LCD)
258
   #if ENABLED(DWIN_CREALITY_LCD)
243
     static void refresh();
259
     static void refresh();
244
   #else
260
   #else

+ 36
- 9
Marlin/src/module/settings.cpp Ver arquivo

36
  */
36
  */
37
 
37
 
38
 // Change EEPROM version if the structure changes
38
 // Change EEPROM version if the structure changes
39
-#define EEPROM_VERSION "V83"
39
+#define EEPROM_VERSION "V84"
40
 #define EEPROM_OFFSET 100
40
 #define EEPROM_OFFSET 100
41
 
41
 
42
 // Check the integrity of data offsets.
42
 // Check the integrity of data offsets.
354
   int16_t lcd_contrast;                                 // M250 C
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
   // Controller fan settings
362
   // Controller fan settings
358
   //
363
   //
359
   controllerFan_settings_t controllerFan_settings;      // M710
364
   controllerFan_settings_t controllerFan_settings;      // M710
999
     //
1004
     //
1000
     {
1005
     {
1001
       _FIELD_TEST(lcd_contrast);
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
       EEPROM_WRITE(lcd_contrast);
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
     // Controller Fan
1021
     // Controller Fan
1015
     //
1022
     //
1016
     {
1023
     {
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
       // Controller Fan
1867
       // Controller Fan
1851
       //
1868
       //
1852
       {
1869
       {
2830
   TERN_(HAS_LCD_CONTRAST, ui.set_contrast(DEFAULT_LCD_CONTRAST));
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
   // Controller Fan
2855
   // Controller Fan
2834
   //
2856
   //
2835
   TERN_(USE_CONTROLLER_FAN, controllerFan.reset());
2857
   TERN_(USE_CONTROLLER_FAN, controllerFan.reset());
3406
       CONFIG_ECHO_MSG("  M250 C", ui.contrast);
3428
       CONFIG_ECHO_MSG("  M250 C", ui.contrast);
3407
     #endif
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
     TERN_(CONTROLLER_FAN_EDITABLE, M710_report(forReplay));
3436
     TERN_(CONTROLLER_FAN_EDITABLE, M710_report(forReplay));
3410
 
3437
 
3411
     #if ENABLED(POWER_LOSS_RECOVERY)
3438
     #if ENABLED(POWER_LOSS_RECOVERY)

+ 1
- 1
Marlin/src/module/stepper/trinamic.cpp Ver arquivo

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

+ 1
- 0
ini/features.ini Ver arquivo

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

+ 1
- 1
platformio.ini Ver arquivo

206
   -<src/gcode/host/M876.cpp>
206
   -<src/gcode/host/M876.cpp>
207
   -<src/gcode/lcd/M0_M1.cpp>
207
   -<src/gcode/lcd/M0_M1.cpp>
208
   -<src/gcode/lcd/M117.cpp>
208
   -<src/gcode/lcd/M117.cpp>
209
-  -<src/gcode/lcd/M250.cpp>
209
+  -<src/gcode/lcd/M250.cpp> -<src/gcode/lcd/M256.cpp>
210
   -<src/gcode/lcd/M300.cpp>
210
   -<src/gcode/lcd/M300.cpp>
211
   -<src/gcode/lcd/M414.cpp>
211
   -<src/gcode/lcd/M414.cpp>
212
   -<src/gcode/lcd/M73.cpp>
212
   -<src/gcode/lcd/M73.cpp>

Carregando…
Cancelar
Salvar