Browse Source

Merge pull request #3944 from thinkyhead/rc_eboston_lcd_contrast

Improved LCD contrast handling
Scott Lahteine 9 years ago
parent
commit
32f8300cc6
5 changed files with 42 additions and 21 deletions
  1. 22
    3
      Marlin/Conditionals.h
  2. 1
    1
      Marlin/Marlin_main.cpp
  3. 8
    1
      Marlin/SanityCheck.h
  4. 10
    15
      Marlin/ultralcd.cpp
  5. 1
    1
      Marlin/ultralcd.h

+ 22
- 3
Marlin/Conditionals.h View File

@@ -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
@@ -245,9 +249,24 @@
245 249
    * Default LCD contrast for dogm-like LCD displays
246 250
    */
247 251
   #if ENABLED(DOGLCD)
248
-    #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
252
+
253
+    #define HAS_LCD_CONTRAST ( \
254
+        ENABLED(MAKRPANEL) \
255
+     || ENABLED(VIKI2) \
256
+     || ENABLED(miniVIKI) \
257
+     || ENABLED(ELB_FULL_GRAPHIC_CONTROLLER) \
258
+    )
259
+
260
+    #if HAS_LCD_CONTRAST
261
+      #ifndef LCD_CONTRAST_MIN
262
+        #define LCD_CONTRAST_MIN 0
263
+      #endif
264
+      #ifndef LCD_CONTRAST_MAX
265
+        #define LCD_CONTRAST_MAX 63
266
+      #endif
267
+      #ifndef DEFAULT_LCD_CONTRAST
268
+        #define DEFAULT_LCD_CONTRAST 32
269
+      #endif
251 270
     #endif
252 271
   #endif
253 272
 

+ 1
- 1
Marlin/Marlin_main.cpp View File

@@ -5655,7 +5655,7 @@ inline void gcode_M226() {
5655 5655
    * M250: Read and optionally set the LCD contrast
5656 5656
    */
5657 5657
   inline void gcode_M250() {
5658
-    if (code_seen('C')) lcd_setcontrast(code_value_short() & 0x3F);
5658
+    if (code_seen('C')) set_lcd_contrast(code_value_short());
5659 5659
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
5660 5660
     SERIAL_PROTOCOL(lcd_contrast);
5661 5661
     SERIAL_EOL;

+ 8
- 1
Marlin/SanityCheck.h View File

@@ -367,7 +367,14 @@
367 367
 #endif
368 368
 
369 369
 #if ENCODER_PULSES_PER_STEP < 0
370
-  #error "ENCODER_PULSES_PER_STEP should not be negative, use REVERSE_MENU_DIRECTION instead"
370
+  #error "ENCODER_PULSES_PER_STEP should not be negative, use REVERSE_MENU_DIRECTION instead."
371
+#endif
372
+
373
+/**
374
+ * SAV_3DGLCD display options
375
+ */
376
+#if ENABLED(U8GLIB_SSD1306) && ENABLED(U8GLIB_SH1106)
377
+  #error "Only enable one SAV_3DGLCD display type: U8GLIB_SSD1306 or U8GLIB_SH1106."
371 378
 #endif
372 379
 
373 380
 /**

+ 10
- 15
Marlin/ultralcd.cpp View File

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

+ 1
- 1
Marlin/ultralcd.h View File

@@ -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))

Loading…
Cancel
Save