Browse Source

🐛 E3V2 Brightness followup (#22821)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
Miguel Risco-Castillo 3 years ago
parent
commit
1ac7a56a82
No account linked to committer's email address

+ 1
- 1
Marlin/src/gcode/lcd/M250.cpp View File

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

+ 14
- 11
Marlin/src/inc/Conditionals_LCD.h View File

500
   #define HAS_DWIN_E3V2 1
500
   #define HAS_DWIN_E3V2 1
501
 #endif
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
 #if IS_ULTRA_LCD
517
 #if IS_ULTRA_LCD
504
   #define HAS_WIRED_LCD 1
518
   #define HAS_WIRED_LCD 1
505
   #if ENABLED(DOGLCD)
519
   #if ENABLED(DOGLCD)
1111
   #define HAS_ETHERNET 1
1125
   #define HAS_ETHERNET 1
1112
 #endif
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
 // Fallback Stepper Driver types that don't depend on Configuration_adv.h
1128
 // Fallback Stepper Driver types that don't depend on Configuration_adv.h
1126
 #ifndef X_DRIVER_TYPE
1129
 #ifndef X_DRIVER_TYPE
1127
   #define X_DRIVER_TYPE  A4988
1130
   #define X_DRIVER_TYPE  A4988

+ 0
- 5
Marlin/src/inc/Conditionals_post.h View File

423
   #endif
423
   #endif
424
 #endif
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
  * Override the SD_DETECT_STATE set in Configuration_adv.h
427
  * Override the SD_DETECT_STATE set in Configuration_adv.h
433
  * and enable sharing of onboard SD host drives (all platforms but AGCM4)
428
  * and enable sharing of onboard SD host drives (all platforms but AGCM4)

+ 3
- 6
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp View File

376
   lcd.clear_buffer();
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
 static void center_text_P(PGM_P pstart, uint8_t y) {
383
 static void center_text_P(PGM_P pstart, uint8_t y) {
387
   uint8_t len = utf8_strlen_P(pstart);
384
   uint8_t len = utf8_strlen_P(pstart);

+ 1
- 8
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

93
 #endif
93
 #endif
94
 
94
 
95
 #if HAS_LCD_CONTRAST
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
 #endif
97
 #endif
105
 
98
 
106
 void MarlinUI::set_font(const MarlinFont font_nr) {
99
 void MarlinUI::set_font(const MarlinFont font_nr) {

+ 10
- 8
Marlin/src/lcd/e3v2/common/dwin_api.cpp View File

78
         && databuf[3] == 'K' );
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
 // Set screen display direction
92
 // Set screen display direction
91
 //  dir: 0=0°, 1=90°, 2=180°, 3=270°
93
 //  dir: 0=0°, 1=90°, 2=180°, 3=270°

+ 5
- 3
Marlin/src/lcd/e3v2/common/dwin_api.h View File

87
 // DWIN startup
87
 // DWIN startup
88
 void DWIN_Startup();
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
 // Set screen display direction
96
 // Set screen display direction
95
 //  dir: 0=0°, 1=90°, 2=180°, 3=270°
97
 //  dir: 0=0°, 1=90°, 2=180°, 3=270°

+ 4
- 0
Marlin/src/lcd/e3v2/creality/dwin.cpp View File

1816
 
1816
 
1817
 void MarlinUI::refresh() { /* Nothing to see here */ }
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
 #if ENABLED(SCROLL_LONG_FILENAMES)
1823
 #if ENABLED(SCROLL_LONG_FILENAMES)
1820
 
1824
 
1821
   char shift_name[LONG_FILENAME_LENGTH + 1];
1825
   char shift_name[LONG_FILENAME_LENGTH + 1];

+ 6
- 3
Marlin/src/lcd/e3v2/enhanced/dwin.cpp View File

865
 
865
 
866
 void MarlinUI::refresh() { /* Nothing to see here */ }
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
 #define ICON_Folder ICON_More
872
 #define ICON_Folder ICON_More
869
 
873
 
870
 #if ENABLED(SCROLL_LONG_FILENAMES)
874
 #if ENABLED(SCROLL_LONG_FILENAMES)
2186
 #endif
2190
 #endif
2187
 
2191
 
2188
 #if HAS_LCD_BRIGHTNESS
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
 #endif
2195
 #endif
2193
 
2196
 
2194
 #if ENABLED(SOUND_MENU_ITEM)
2197
 #if ENABLED(SOUND_MENU_ITEM)

+ 6
- 2
Marlin/src/lcd/e3v2/jyersui/dwin.cpp View File

2717
             Draw_Float(ui.brightness, row, false, 1);
2717
             Draw_Float(ui.brightness, row, false, 1);
2718
           }
2718
           }
2719
           else
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
           break;
2721
           break;
2722
         case VISUAL_TIME_FORMAT:
2722
         case VISUAL_TIME_FORMAT:
2723
           if (draw) {
2723
           if (draw) {
3879
             Draw_Float(ui.brightness, row, false, 1);
3879
             Draw_Float(ui.brightness, row, false, 1);
3880
           }
3880
           }
3881
           else
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
           break;
3883
           break;
3884
       }
3884
       }
3885
       break;
3885
       break;
4800
 
4800
 
4801
 void MarlinUI::update() { CrealityDWIN.Update(); }
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
 void CrealityDWINClass::State_Update() {
4807
 void CrealityDWINClass::State_Update() {
4804
   if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) {
4808
   if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) {
4805
     if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid()));
4809
     if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid()));

+ 4
- 0
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp View File

254
   #endif
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
 #if HAS_LCD_MENU
261
 #if HAS_LCD_MENU
258
 
262
 
259
   #include "../../menu/menu.h"
263
   #include "../../menu/menu.h"

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

95
   }
95
   }
96
 #endif
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
 #if HAS_LCD_BRIGHTNESS
107
 #if HAS_LCD_BRIGHTNESS
99
   uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS;
108
   uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS;
100
   bool MarlinUI::backlight = true;
109
   bool MarlinUI::backlight = true;
101
 
110
 
102
   void MarlinUI::set_brightness(const uint8_t value) {
111
   void MarlinUI::set_brightness(const uint8_t value) {
103
     backlight = !!value;
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
 #endif
116
 #endif
110
 
117
 

+ 9
- 7
Marlin/src/lcd/marlinui.h View File

247
   #endif
247
   #endif
248
 
248
 
249
   #if HAS_LCD_BRIGHTNESS
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
     #endif
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
     #endif
255
     #endif
256
     #ifndef DEFAULT_LCD_BRIGHTNESS
256
     #ifndef DEFAULT_LCD_BRIGHTNESS
257
-      #define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS
257
+      #define DEFAULT_LCD_BRIGHTNESS LCD_BRIGHTNESS_MAX
258
     #endif
258
     #endif
259
     static uint8_t brightness;
259
     static uint8_t brightness;
260
     static bool backlight;
260
     static bool backlight;
261
+    static void _set_brightness(); // Implementation-specific
261
     static void set_brightness(const uint8_t value);
262
     static void set_brightness(const uint8_t value);
262
     FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
263
     FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
263
   #endif
264
   #endif
425
       static uint8_t lcd_status_update_delay;
426
       static uint8_t lcd_status_update_delay;
426
 
427
 
427
       #if HAS_LCD_CONTRAST
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
         FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
432
         FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
431
       #endif
433
       #endif
432
 
434
 

+ 4
- 1
Marlin/src/lcd/menu/menu_configuration.cpp View File

528
     #endif
528
     #endif
529
   #endif
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
   #if HAS_LCD_CONTRAST
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
   #endif
536
   #endif
534
   #if ENABLED(FWRETRACT)
537
   #if ENABLED(FWRETRACT)
535
     SUBMENU(MSG_RETRACT, menu_config_retract);
538
     SUBMENU(MSG_RETRACT, menu_config_retract);

+ 3
- 3
Marlin/src/module/settings.cpp View File

352
   //
352
   //
353
   // HAS_LCD_CONTRAST
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
   // HAS_LCD_BRIGHTNESS
358
   // HAS_LCD_BRIGHTNESS
1017
     //
1017
     //
1018
     {
1018
     {
1019
       _FIELD_TEST(lcd_contrast);
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
       EEPROM_WRITE(lcd_contrast);
1021
       EEPROM_WRITE(lcd_contrast);
1022
     }
1022
     }
1023
 
1023
 
1884
       //
1884
       //
1885
       {
1885
       {
1886
         _FIELD_TEST(lcd_contrast);
1886
         _FIELD_TEST(lcd_contrast);
1887
-        int16_t lcd_contrast;
1887
+        uint8_t lcd_contrast;
1888
         EEPROM_READ(lcd_contrast);
1888
         EEPROM_READ(lcd_contrast);
1889
         if (!validating) {
1889
         if (!validating) {
1890
           TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));
1890
           TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));

+ 1
- 1
buildroot/tests/STM32F103RET6_creality View File

24
 exec_test $1 $2 "Ender 3 v2 with JyersUI" "$3"
24
 exec_test $1 $2 "Ender 3 v2 with JyersUI" "$3"
25
 
25
 
26
 use_example_configs "Creality/Ender-3 V2/MarlinUI"
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
 exec_test $1 $2 "Ender 3 v2 with MarlinUI" "$3"
28
 exec_test $1 $2 "Ender 3 v2 with MarlinUI" "$3"
29
 
29
 
30
 restore_configs
30
 restore_configs

Loading…
Cancel
Save