Bladeren bron

Improved LCD contrast handling

Based on MarlinFirmware/MarlinDev#200 from @eboston
Scott Lahteine 8 jaren geleden
bovenliggende
commit
efa7209acf
4 gewijzigde bestanden met toevoegingen van 26 en 19 verwijderingen
  1. 14
    2
      Marlin/Conditionals.h
  2. 1
    1
      Marlin/Marlin_main.cpp
  3. 10
    15
      Marlin/ultralcd.cpp
  4. 1
    1
      Marlin/ultralcd.h

+ 14
- 2
Marlin/Conditionals.h Bestand weergeven

@@ -61,10 +61,14 @@
61 61
     #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
62 62
 
63 63
     #if ENABLED(miniVIKI)
64
+      #define LCD_CONTRAST_MIN  75
65
+      #define LCD_CONTRAST_MAX 115
64 66
       #define DEFAULT_LCD_CONTRAST 95
65 67
     #elif ENABLED(VIKI2)
66 68
       #define DEFAULT_LCD_CONTRAST 40
67 69
     #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
70
+      #define LCD_CONTRAST_MIN  90
71
+      #define LCD_CONTRAST_MAX 130
68 72
       #define DEFAULT_LCD_CONTRAST 110
69 73
       #define U8GLIB_LM6059_AF
70 74
       #define SD_DETECT_INVERTED
@@ -246,8 +250,16 @@
246 250
    */
247 251
   #if ENABLED(DOGLCD)
248 252
     #define HAS_LCD_CONTRAST (DISABLED(U8GLIB_ST7920) && DISABLED(U8GLIB_SSD1306) && DISABLED(U8GLIB_SH1106))
249
-    #if HAS_LCD_CONTRAST && !defined(DEFAULT_LCD_CONTRAST)
250
-      #define DEFAULT_LCD_CONTRAST 32
253
+    #if HAS_LCD_CONTRAST
254
+      #ifndef LCD_CONTRAST_MIN
255
+        #define LCD_CONTRAST_MIN 0
256
+      #endif
257
+      #ifndef LCD_CONTRAST_MAX
258
+        #define LCD_CONTRAST_MAX 63
259
+      #endif
260
+      #ifndef DEFAULT_LCD_CONTRAST
261
+        #define DEFAULT_LCD_CONTRAST 32
262
+      #endif
251 263
     #endif
252 264
   #endif
253 265
 

+ 1
- 1
Marlin/Marlin_main.cpp Bestand weergeven

@@ -5636,7 +5636,7 @@ inline void gcode_M226() {
5636 5636
    * M250: Read and optionally set the LCD contrast
5637 5637
    */
5638 5638
   inline void gcode_M250() {
5639
-    if (code_seen('C')) lcd_setcontrast(code_value_short() & 0x3F);
5639
+    if (code_seen('C')) set_lcd_contrast(code_value_short());
5640 5640
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
5641 5641
     SERIAL_PROTOCOL(lcd_contrast);
5642 5642
     SERIAL_EOL;

+ 10
- 15
Marlin/ultralcd.cpp Bestand weergeven

@@ -1716,23 +1716,18 @@ static void lcd_control_volumetric_menu() {
1716 1716
   static void lcd_set_contrast() {
1717 1717
     ENCODER_DIRECTION_NORMAL();
1718 1718
     if (encoderPosition) {
1719
-      #if ENABLED(U8GLIB_LM6059_AF)
1720
-        lcd_contrast += encoderPosition;
1721
-        lcd_contrast &= 0xFF;
1722
-      #else
1723
-        lcd_contrast -= encoderPosition;
1724
-        lcd_contrast &= 0x3F;
1725
-      #endif
1719
+      set_lcd_contrast(lcd_contrast + encoderPosition);
1726 1720
       encoderPosition = 0;
1727 1721
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1728
-      u8g.setContrast(lcd_contrast);
1729 1722
     }
1730 1723
     if (lcdDrawUpdate) {
1731
-      #if ENABLED(U8GLIB_LM6059_AF)
1732
-        lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr3(lcd_contrast));
1733
-      #else
1734
-        lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
1735
-      #endif
1724
+      lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
1725
+        #if LCD_CONTRAST_MAX >= 100
1726
+          itostr3(lcd_contrast)
1727
+        #else
1728
+          itostr2(lcd_contrast)
1729
+        #endif
1730
+      );
1736 1731
     }
1737 1732
     if (LCD_CLICKED) lcd_goto_previous_menu(true);
1738 1733
   }
@@ -2384,8 +2379,8 @@ void lcd_setalertstatuspgm(const char* message) {
2384 2379
 void lcd_reset_alert_level() { lcd_status_message_level = 0; }
2385 2380
 
2386 2381
 #if HAS_LCD_CONTRAST
2387
-  void lcd_setcontrast(uint8_t value) {
2388
-    lcd_contrast = value & 0x3F;
2382
+  void set_lcd_contrast(int value) {
2383
+    lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
2389 2384
     u8g.setContrast(lcd_contrast);
2390 2385
   }
2391 2386
 #endif

+ 1
- 1
Marlin/ultralcd.h Bestand weergeven

@@ -53,7 +53,7 @@
53 53
 
54 54
   #if ENABLED(DOGLCD)
55 55
     extern int lcd_contrast;
56
-    void lcd_setcontrast(uint8_t value);
56
+    void set_lcd_contrast(int value);
57 57
   #endif
58 58
 
59 59
   #define LCD_MESSAGEPGM(x) lcd_setstatuspgm(PSTR(x))

Laden…
Annuleren
Opslaan