Ver código fonte

🐛 E3V2 Brightness followup (#22821)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
Miguel Risco-Castillo 3 anos atrás
pai
commit
1ac7a56a82
Nenhuma conta vinculada ao e-mail do autor do commit

+ 1
- 1
Marlin/src/gcode/lcd/M250.cpp Ver arquivo

@@ -32,7 +32,7 @@
32 32
  */
33 33
 void GcodeSuite::M250() {
34 34
   if (parser.seenval('C'))
35
-    ui.set_contrast(parser.value_int());
35
+    ui.set_contrast(parser.value_byte());
36 36
   else
37 37
     M250_report();
38 38
 }

+ 14
- 11
Marlin/src/inc/Conditionals_LCD.h Ver arquivo

@@ -500,6 +500,20 @@
500 500
   #define HAS_DWIN_E3V2 1
501 501
 #endif
502 502
 
503
+// E3V2 extras
504
+#if HAS_DWIN_E3V2 || IS_DWIN_MARLINUI
505
+  #define SERIAL_CATCHALL 0
506
+  #ifndef LCD_SERIAL_PORT
507
+    #if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO)
508
+      #define LCD_SERIAL_PORT 1
509
+    #else
510
+      #define LCD_SERIAL_PORT 3 // Creality 4.x board
511
+    #endif
512
+  #endif
513
+  #define HAS_LCD_BRIGHTNESS 1
514
+  #define LCD_BRIGHTNESS_MAX 250
515
+#endif
516
+
503 517
 #if IS_ULTRA_LCD
504 518
   #define HAS_WIRED_LCD 1
505 519
   #if ENABLED(DOGLCD)
@@ -1111,17 +1125,6 @@
1111 1125
   #define HAS_ETHERNET 1
1112 1126
 #endif
1113 1127
 
1114
-#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
1115
-  #define SERIAL_CATCHALL 0
1116
-  #ifndef LCD_SERIAL_PORT
1117
-    #if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO)
1118
-      #define LCD_SERIAL_PORT 1
1119
-    #else
1120
-      #define LCD_SERIAL_PORT 3 // Creality 4.x board
1121
-    #endif
1122
-  #endif
1123
-#endif
1124
-
1125 1128
 // Fallback Stepper Driver types that don't depend on Configuration_adv.h
1126 1129
 #ifndef X_DRIVER_TYPE
1127 1130
   #define X_DRIVER_TYPE  A4988

+ 0
- 5
Marlin/src/inc/Conditionals_post.h Ver arquivo

@@ -423,11 +423,6 @@
423 423
   #endif
424 424
 #endif
425 425
 
426
-#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
427
-  #define HAS_LCD_BRIGHTNESS 1
428
-  #define MAX_LCD_BRIGHTNESS 31
429
-#endif
430
-
431 426
 /**
432 427
  * Override the SD_DETECT_STATE set in Configuration_adv.h
433 428
  * and enable sharing of onboard SD host drives (all platforms but AGCM4)

+ 3
- 6
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp Ver arquivo

@@ -376,12 +376,9 @@ void MarlinUI::clear_lcd() {
376 376
   lcd.clear_buffer();
377 377
 }
378 378
 
379
-int16_t MarlinUI::contrast; // Initialized by settings.load()
380
-
381
-void MarlinUI::set_contrast(const int16_t value) {
382
-  contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
383
-  lcd.setContrast(contrast);
384
-}
379
+#if HAS_LCD_CONTRAST
380
+  void MarlinUI::_set_contrast() { lcd.setContrast(contrast); }
381
+#endif
385 382
 
386 383
 static void center_text_P(PGM_P pstart, uint8_t y) {
387 384
   uint8_t len = utf8_strlen_P(pstart);

+ 1
- 8
Marlin/src/lcd/dogm/marlinui_DOGM.cpp Ver arquivo

@@ -93,14 +93,7 @@ U8G_CLASS u8g;
93 93
 #endif
94 94
 
95 95
 #if HAS_LCD_CONTRAST
96
-
97
-  int16_t MarlinUI::contrast = DEFAULT_LCD_CONTRAST;
98
-
99
-  void MarlinUI::set_contrast(const int16_t value) {
100
-    contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
101
-    u8g.setContrast(contrast);
102
-  }
103
-
96
+  void MarlinUI::_set_contrast() { u8g.setContrast(contrast); }
104 97
 #endif
105 98
 
106 99
 void MarlinUI::set_font(const MarlinFont font_nr) {

+ 10
- 8
Marlin/src/lcd/e3v2/common/dwin_api.cpp Ver arquivo

@@ -78,14 +78,16 @@ bool DWIN_Handshake() {
78 78
         && databuf[3] == 'K' );
79 79
 }
80 80
 
81
-// Set the backlight brightness
82
-//  brightness: (0x00-0x1F)
83
-void DWIN_LCD_Brightness(const uint8_t brightness) {
84
-  size_t i = 0;
85
-  DWIN_Byte(i, 0x30);
86
-  DWIN_Byte(i, _MAX(brightness, 0x1F));
87
-  DWIN_Send(i);
88
-}
81
+#if HAS_LCD_BRIGHTNESS
82
+  // Set LCD backlight (from DWIN Enhanced)
83
+  //  brightness: 0x00-0xFF
84
+  void DWIN_LCD_Brightness(const uint8_t brightness) {
85
+    size_t i = 0;
86
+    DWIN_Byte(i, 0x30);
87
+    DWIN_Byte(i, brightness);
88
+    DWIN_Send(i);
89
+  }
90
+#endif
89 91
 
90 92
 // Set screen display direction
91 93
 //  dir: 0=0°, 1=90°, 2=180°, 3=270°

+ 5
- 3
Marlin/src/lcd/e3v2/common/dwin_api.h Ver arquivo

@@ -87,9 +87,11 @@ bool DWIN_Handshake();
87 87
 // DWIN startup
88 88
 void DWIN_Startup();
89 89
 
90
-// Set the backlight brightness
91
-//  brightness: (0x00-0xFF)
92
-void DWIN_LCD_Brightness(const uint8_t brightness);
90
+#if HAS_LCD_BRIGHTNESS
91
+  // Set the backlight brightness
92
+  //  brightness: (0x00-0xFF)
93
+  void DWIN_LCD_Brightness(const uint8_t brightness);
94
+#endif
93 95
 
94 96
 // Set screen display direction
95 97
 //  dir: 0=0°, 1=90°, 2=180°, 3=270°

+ 4
- 0
Marlin/src/lcd/e3v2/creality/dwin.cpp Ver arquivo

@@ -1816,6 +1816,10 @@ void HMI_SDCardInit() { card.cdroot(); }
1816 1816
 
1817 1817
 void MarlinUI::refresh() { /* Nothing to see here */ }
1818 1818
 
1819
+#if HAS_LCD_BRIGHTNESS
1820
+  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
1821
+#endif
1822
+
1819 1823
 #if ENABLED(SCROLL_LONG_FILENAMES)
1820 1824
 
1821 1825
   char shift_name[LONG_FILENAME_LENGTH + 1];

+ 6
- 3
Marlin/src/lcd/e3v2/enhanced/dwin.cpp Ver arquivo

@@ -865,6 +865,10 @@ void HMI_SDCardInit() { card.cdroot(); }
865 865
 
866 866
 void MarlinUI::refresh() { /* Nothing to see here */ }
867 867
 
868
+#if HAS_LCD_BRIGHTNESS
869
+  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
870
+#endif
871
+
868 872
 #define ICON_Folder ICON_More
869 873
 
870 874
 #if ENABLED(SCROLL_LONG_FILENAMES)
@@ -2186,9 +2190,8 @@ void SetPID(celsius_t t, heater_id_t h) {
2186 2190
 #endif
2187 2191
 
2188 2192
 #if HAS_LCD_BRIGHTNESS
2189
-  void ApplyBrightness() { ui.set_brightness(HMI_value.Value); }
2190
-  void LiveBrightness() { DWIN_LCD_Brightness(HMI_value.Value); }
2191
-  void SetBrightness() { SetIntOnClick(MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, ui.brightness, ApplyBrightness, LiveBrightness); }
2193
+  void LiveBrightness() { ui.set_brightness(HMI_value.Value); }
2194
+  void SetBrightness() { SetIntOnClick(LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.brightness, nullptr, LiveBrightness); }
2192 2195
 #endif
2193 2196
 
2194 2197
 #if ENABLED(SOUND_MENU_ITEM)

+ 6
- 2
Marlin/src/lcd/e3v2/jyersui/dwin.cpp Ver arquivo

@@ -2717,7 +2717,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
2717 2717
             Draw_Float(ui.brightness, row, false, 1);
2718 2718
           }
2719 2719
           else
2720
-            Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness);
2720
+            Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness);
2721 2721
           break;
2722 2722
         case VISUAL_TIME_FORMAT:
2723 2723
           if (draw) {
@@ -3879,7 +3879,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3879 3879
             Draw_Float(ui.brightness, row, false, 1);
3880 3880
           }
3881 3881
           else
3882
-            Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness);
3882
+            Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness);
3883 3883
           break;
3884 3884
       }
3885 3885
       break;
@@ -4800,6 +4800,10 @@ void CrealityDWINClass::Update() {
4800 4800
 
4801 4801
 void MarlinUI::update() { CrealityDWIN.Update(); }
4802 4802
 
4803
+#if HAS_LCD_BRIGHTNESS
4804
+  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
4805
+#endif
4806
+
4803 4807
 void CrealityDWINClass::State_Update() {
4804 4808
   if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) {
4805 4809
     if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid()));

+ 4
- 0
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp Ver arquivo

@@ -254,6 +254,10 @@ void MarlinUI::draw_status_message(const bool blink) {
254 254
   #endif
255 255
 }
256 256
 
257
+#if HAS_LCD_BRIGHTNESS
258
+  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
259
+#endif
260
+
257 261
 #if HAS_LCD_MENU
258 262
 
259 263
   #include "../../menu/menu.h"

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

@@ -95,16 +95,23 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
95 95
   }
96 96
 #endif
97 97
 
98
+#if HAS_LCD_CONTRAST
99
+  uint8_t MarlinUI::contrast; // Initialized by settings.load()
100
+
101
+  void MarlinUI::set_contrast(const uint8_t value) {
102
+    contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
103
+    _set_contrast();
104
+  }
105
+#endif
106
+
98 107
 #if HAS_LCD_BRIGHTNESS
99 108
   uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS;
100 109
   bool MarlinUI::backlight = true;
101 110
 
102 111
   void MarlinUI::set_brightness(const uint8_t value) {
103 112
     backlight = !!value;
104
-    if (backlight) brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS);
105
-    // Set brightness on enabled LCD here
106
-    TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_LCD_Brightness(brightness));
107
-    TERN_(DWIN_CREALITY_LCD_JYERSUI, DWIN_LCD_Brightness(backlight ? brightness : 0));
113
+    if (backlight) brightness = constrain(value, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX);
114
+    _set_brightness();
108 115
   }
109 116
 #endif
110 117
 

+ 9
- 7
Marlin/src/lcd/marlinui.h Ver arquivo

@@ -247,17 +247,18 @@ public:
247 247
   #endif
248 248
 
249 249
   #if HAS_LCD_BRIGHTNESS
250
-    #ifndef MIN_LCD_BRIGHTNESS
251
-      #define MIN_LCD_BRIGHTNESS   1
250
+    #ifndef LCD_BRIGHTNESS_MIN
251
+      #define LCD_BRIGHTNESS_MIN   1
252 252
     #endif
253
-    #ifndef MAX_LCD_BRIGHTNESS
254
-      #define MAX_LCD_BRIGHTNESS 255
253
+    #ifndef LCD_BRIGHTNESS_MAX
254
+      #define LCD_BRIGHTNESS_MAX 255
255 255
     #endif
256 256
     #ifndef DEFAULT_LCD_BRIGHTNESS
257
-      #define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS
257
+      #define DEFAULT_LCD_BRIGHTNESS LCD_BRIGHTNESS_MAX
258 258
     #endif
259 259
     static uint8_t brightness;
260 260
     static bool backlight;
261
+    static void _set_brightness(); // Implementation-specific
261 262
     static void set_brightness(const uint8_t value);
262 263
     FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
263 264
   #endif
@@ -425,8 +426,9 @@ public:
425 426
       static uint8_t lcd_status_update_delay;
426 427
 
427 428
       #if HAS_LCD_CONTRAST
428
-        static int16_t contrast;
429
-        static void set_contrast(const int16_t value);
429
+        static uint8_t contrast;
430
+        static void _set_contrast(); // Implementation-specific
431
+        static void set_contrast(const uint8_t value);
430 432
         FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
431 433
       #endif
432 434
 

+ 4
- 1
Marlin/src/lcd/menu/menu_configuration.cpp Ver arquivo

@@ -528,8 +528,11 @@ void menu_configuration() {
528 528
     #endif
529 529
   #endif
530 530
 
531
+  #if HAS_LCD_BRIGHTNESS
532
+    EDIT_ITEM_FAST(uint8, MSG_BRIGHTNESS, &ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.refresh_brightness, true);
533
+  #endif
531 534
   #if HAS_LCD_CONTRAST
532
-    EDIT_ITEM(int3, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true);
535
+    EDIT_ITEM_FAST(uint8, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true);
533 536
   #endif
534 537
   #if ENABLED(FWRETRACT)
535 538
     SUBMENU(MSG_RETRACT, menu_config_retract);

+ 3
- 3
Marlin/src/module/settings.cpp Ver arquivo

@@ -352,7 +352,7 @@ typedef struct SettingsDataStruct {
352 352
   //
353 353
   // HAS_LCD_CONTRAST
354 354
   //
355
-  int16_t lcd_contrast;                                 // M250 C
355
+  uint8_t lcd_contrast;                                 // M250 C
356 356
 
357 357
   //
358 358
   // HAS_LCD_BRIGHTNESS
@@ -1017,7 +1017,7 @@ void MarlinSettings::postprocess() {
1017 1017
     //
1018 1018
     {
1019 1019
       _FIELD_TEST(lcd_contrast);
1020
-      const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
1020
+      const uint8_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
1021 1021
       EEPROM_WRITE(lcd_contrast);
1022 1022
     }
1023 1023
 
@@ -1884,7 +1884,7 @@ void MarlinSettings::postprocess() {
1884 1884
       //
1885 1885
       {
1886 1886
         _FIELD_TEST(lcd_contrast);
1887
-        int16_t lcd_contrast;
1887
+        uint8_t lcd_contrast;
1888 1888
         EEPROM_READ(lcd_contrast);
1889 1889
         if (!validating) {
1890 1890
           TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));

+ 1
- 1
buildroot/tests/STM32F103RET6_creality Ver arquivo

@@ -24,7 +24,7 @@ opt_enable DWIN_CREALITY_LCD_JYERSUI AUTO_BED_LEVELING_BILINEAR PROBE_MANUALLY
24 24
 exec_test $1 $2 "Ender 3 v2 with JyersUI" "$3"
25 25
 
26 26
 use_example_configs "Creality/Ender-3 V2/MarlinUI"
27
-opt_add SDCARD_EEPROM_EMULATION NOZZLE_AS_PROBE AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING
27
+opt_add SDCARD_EEPROM_EMULATION AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING
28 28
 exec_test $1 $2 "Ender 3 v2 with MarlinUI" "$3"
29 29
 
30 30
 restore_configs

Carregando…
Cancelar
Salvar