Browse Source

Improved LCD contrast handling

Based on MarlinFirmware/MarlinDev#200 from @eboston
Scott Lahteine 8 years ago
parent
commit
efa7209acf
4 changed files with 26 additions and 19 deletions
  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 View File

61
     #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
61
     #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
62
 
62
 
63
     #if ENABLED(miniVIKI)
63
     #if ENABLED(miniVIKI)
64
+      #define LCD_CONTRAST_MIN  75
65
+      #define LCD_CONTRAST_MAX 115
64
       #define DEFAULT_LCD_CONTRAST 95
66
       #define DEFAULT_LCD_CONTRAST 95
65
     #elif ENABLED(VIKI2)
67
     #elif ENABLED(VIKI2)
66
       #define DEFAULT_LCD_CONTRAST 40
68
       #define DEFAULT_LCD_CONTRAST 40
67
     #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
69
     #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
70
+      #define LCD_CONTRAST_MIN  90
71
+      #define LCD_CONTRAST_MAX 130
68
       #define DEFAULT_LCD_CONTRAST 110
72
       #define DEFAULT_LCD_CONTRAST 110
69
       #define U8GLIB_LM6059_AF
73
       #define U8GLIB_LM6059_AF
70
       #define SD_DETECT_INVERTED
74
       #define SD_DETECT_INVERTED
246
    */
250
    */
247
   #if ENABLED(DOGLCD)
251
   #if ENABLED(DOGLCD)
248
     #define HAS_LCD_CONTRAST (DISABLED(U8GLIB_ST7920) && DISABLED(U8GLIB_SSD1306) && DISABLED(U8GLIB_SH1106))
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
     #endif
263
     #endif
252
   #endif
264
   #endif
253
 
265
 

+ 1
- 1
Marlin/Marlin_main.cpp View File

5636
    * M250: Read and optionally set the LCD contrast
5636
    * M250: Read and optionally set the LCD contrast
5637
    */
5637
    */
5638
   inline void gcode_M250() {
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
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
5640
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
5641
     SERIAL_PROTOCOL(lcd_contrast);
5641
     SERIAL_PROTOCOL(lcd_contrast);
5642
     SERIAL_EOL;
5642
     SERIAL_EOL;

+ 10
- 15
Marlin/ultralcd.cpp View File

1716
   static void lcd_set_contrast() {
1716
   static void lcd_set_contrast() {
1717
     ENCODER_DIRECTION_NORMAL();
1717
     ENCODER_DIRECTION_NORMAL();
1718
     if (encoderPosition) {
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
       encoderPosition = 0;
1720
       encoderPosition = 0;
1727
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1721
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1728
-      u8g.setContrast(lcd_contrast);
1729
     }
1722
     }
1730
     if (lcdDrawUpdate) {
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
     if (LCD_CLICKED) lcd_goto_previous_menu(true);
1732
     if (LCD_CLICKED) lcd_goto_previous_menu(true);
1738
   }
1733
   }
2384
 void lcd_reset_alert_level() { lcd_status_message_level = 0; }
2379
 void lcd_reset_alert_level() { lcd_status_message_level = 0; }
2385
 
2380
 
2386
 #if HAS_LCD_CONTRAST
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
     u8g.setContrast(lcd_contrast);
2384
     u8g.setContrast(lcd_contrast);
2390
   }
2385
   }
2391
 #endif
2386
 #endif

+ 1
- 1
Marlin/ultralcd.h View File

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

Loading…
Cancel
Save