Преглед изворни кода

added contrast control function for gLCDs

Michael Mayer пре 11 година
родитељ
комит
e509cdbeb0

+ 7
- 0
Marlin/Configuration.h Прегледај датотеку

@@ -517,6 +517,13 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
517 517
   #endif
518 518
 #endif
519 519
 
520
+// default LCD contrast for dogm-like LCD displays
521
+#ifdef DOGLCD
522
+# ifndef DEFAULT_LCD_CONTRAST
523
+#  define DEFAULT_LCD_CONTRAST 32
524
+# endif
525
+#endif
526
+
520 527
 // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino
521 528
 //#define FAST_PWM_FAN
522 529
 

+ 12
- 1
Marlin/ConfigurationStore.cpp Прегледај датотеку

@@ -37,7 +37,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size)
37 37
 // the default values are used whenever there is a change to the data, to prevent
38 38
 // wrong data being written to the variables.
39 39
 // ALSO:  always make sure the variables in the Store and retrieve sections are in the same order.
40
-#define EEPROM_VERSION "V07"
40
+#define EEPROM_VERSION "V08"
41 41
 
42 42
 #ifdef EEPROM_SETTINGS
43 43
 void Config_StoreSettings() 
@@ -78,6 +78,10 @@ void Config_StoreSettings()
78 78
     EEPROM_WRITE_VAR(i,dummy);
79 79
     EEPROM_WRITE_VAR(i,dummy);
80 80
   #endif
81
+  #ifndef DOGLCD
82
+    int lcd_contrast = 32;
83
+  #endif
84
+  EEPROM_WRITE_VAR(i,lcd_contrast);
81 85
   char ver2[4]=EEPROM_VERSION;
82 86
   i=EEPROM_OFFSET;
83 87
   EEPROM_WRITE_VAR(i,ver2); // validate data
@@ -198,6 +202,10 @@ void Config_RetrieveSettings()
198 202
         EEPROM_READ_VAR(i,Kp);
199 203
         EEPROM_READ_VAR(i,Ki);
200 204
         EEPROM_READ_VAR(i,Kd);
205
+        #ifndef DOGLCD
206
+        int lcd_contrast;
207
+        #endif
208
+        EEPROM_READ_VAR(i,lcd_contrast);
201 209
 
202 210
 		// Call updatePID (similar to when we have processed M301)
203 211
 		updatePID();
@@ -244,6 +252,9 @@ void Config_ResetDefault()
244 252
     absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP;
245 253
     absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
246 254
 #endif
255
+#ifdef DOGLCD
256
+    lcd_contrast = DEFAULT_LCD_CONTRAST;
257
+#endif
247 258
 #ifdef PIDTEMP
248 259
     Kp = DEFAULT_Kp;
249 260
     Ki = scalePID_i(DEFAULT_Ki);

+ 14
- 0
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -125,6 +125,7 @@
125 125
 // M220 S<factor in percent>- set speed factor override percentage
126 126
 // M221 S<factor in percent>- set extrude factor override percentage
127 127
 // M240 - Trigger a camera to take a photograph
128
+// M250 - Set LCD contrast C<contrast value> (value 0..63)
128 129
 // M280 - set servo position absolute. P: servo index, S: angle or microseconds
129 130
 // M300 - Play beepsound S<frequency Hz> P<duration ms>
130 131
 // M301 - Set PID parameters P I and D
@@ -421,6 +422,7 @@ void setup()
421 422
   servo_init();
422 423
 
423 424
   lcd_init();
425
+  _delay_ms(1000);	// wait 1sec to display the splash screen
424 426
   
425 427
   #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
426 428
     SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan
@@ -1699,6 +1701,18 @@ void process_commands()
1699 1701
       #endif
1700 1702
      }
1701 1703
     break;
1704
+#ifdef DOGLCD
1705
+    case 250: // M250  Set LCD contrast value: C<value> (value 0..63)
1706
+     {
1707
+	  if (code_seen('C')) {
1708
+	   lcd_setcontrast( ((int)code_value())&63 );
1709
+          }
1710
+          SERIAL_PROTOCOLPGM("lcd contrast value: ");
1711
+          SERIAL_PROTOCOL(lcd_contrast);
1712
+          SERIAL_PROTOCOLLN("");
1713
+     }
1714
+    break;
1715
+#endif
1702 1716
     #ifdef PREVENT_DANGEROUS_EXTRUDE
1703 1717
     case 302: // allow cold extrudes, or set the minimum extrude temperature
1704 1718
     {

+ 10
- 2
Marlin/dogm_lcd_implementation.h Прегледај датотеку

@@ -74,6 +74,8 @@
74 74
 
75 75
 #define FONT_STATUSMENU	u8g_font_6x9
76 76
 
77
+int lcd_contrast;
78
+
77 79
 // LCD selection
78 80
 #ifdef U8GLIB_ST7920
79 81
 //U8GLIB_ST7920_128X64_RRD u8g(0,0,0);
@@ -88,6 +90,12 @@ U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);	// HW-SPI Com: CS, A0
88 90
 
89 91
 static void lcd_implementation_init()
90 92
 {
93
+#ifdef LCD_PIN_BL
94
+	pinMode(LCD_PIN_BL, OUTPUT);	// Enable LCD backlight
95
+	digitalWrite(LCD_PIN_BL, HIGH);
96
+#endif
97
+
98
+        u8g.setContrast(lcd_contrast);	
91 99
 	//  Uncomment this if you have the first generation (V1.10) of STBs board
92 100
 	//  pinMode(17, OUTPUT);	// Enable LCD backlight
93 101
 	//  digitalWrite(17, HIGH);
@@ -121,14 +129,14 @@ static void lcd_implementation_init()
121 129
 			u8g.setFont(u8g_font_6x10_marlin);
122 130
 			u8g.drawStr(62,10,"MARLIN"); 
123 131
 			u8g.setFont(u8g_font_5x8);
124
-			u8g.drawStr(62,19,"V1.0.0 RC2");
132
+			u8g.drawStr(62,19,"V1.0.0 RC2-mm");
125 133
 			u8g.setFont(u8g_font_6x10_marlin);
126 134
 			u8g.drawStr(62,28,"by ErikZalm");
127 135
 			u8g.drawStr(62,41,"DOGM128 LCD");
128 136
 			u8g.setFont(u8g_font_5x8);
129 137
 			u8g.drawStr(62,48,"enhancements");
130 138
 			u8g.setFont(u8g_font_5x8);
131
-			u8g.drawStr(62,55,"by STB");
139
+			u8g.drawStr(62,55,"by STB, MM");
132 140
 			u8g.drawStr(62,61,"uses u");
133 141
 			u8g.drawStr90(92,57,"8");
134 142
 			u8g.drawStr(100,61,"glib");

+ 9
- 2
Marlin/language.h Прегледај датотеку

@@ -101,6 +101,7 @@
101 101
 	#define MSG_RECTRACT "Rectract"
102 102
 	#define MSG_TEMPERATURE "Temperature"
103 103
 	#define MSG_MOTION "Motion"
104
+	#define MSG_CONTRAST "LCD contrast"
104 105
 	#define MSG_STORE_EPROM "Store memory"
105 106
 	#define MSG_LOAD_EPROM "Load memory"
106 107
 	#define MSG_RESTORE_FAILSAFE "Restore Failsafe"
@@ -260,6 +261,7 @@
260 261
 	#define MSG_RECTRACT "Wycofanie"
261 262
 	#define MSG_TEMPERATURE "Temperatura"
262 263
 	#define MSG_MOTION "Ruch"
264
+	#define MSG_CONTRAST "LCD contrast"
263 265
 	#define MSG_STORE_EPROM "Zapisz w pamieci"
264 266
 	#define MSG_LOAD_EPROM "Wczytaj z pamieci"
265 267
 	#define MSG_RESTORE_FAILSAFE " Ustawienia fabryczne"
@@ -423,6 +425,7 @@
423 425
 #define MSG_TEMPERATURE_WIDE " Temperature \x7E"
424 426
 #define MSG_TEMPERATURE_RTN " Temperature \003"
425 427
 #define MSG_MOTION_WIDE " Mouvement \x7E"
428
+	#define MSG_CONTRAST "LCD contrast"
426 429
 #define MSG_STORE_EPROM " Sauvegarder memoire"
427 430
 #define MSG_LOAD_EPROM " Lire memoire"
428 431
 #define MSG_RESTORE_FAILSAFE " Restaurer memoire"
@@ -535,7 +538,7 @@
535 538
 
536 539
 	#define MSG_SD_INSERTED      "SDKarte erkannt"
537 540
 	#define MSG_SD_REMOVED       "SDKarte entfernt"
538
-	#define MSG_MAIN             "Hauptmneü"
541
+	#define MSG_MAIN             "Hauptmenü"
539 542
 	#define MSG_AUTOSTART        "Autostart"
540 543
 	#define MSG_DISABLE_STEPPERS "Stepper abschalten"
541 544
 	#define MSG_AUTO_HOME        "Auto Nullpunkt"
@@ -554,7 +557,7 @@
554 557
 	#define MSG_NOZZLE2          "Düse3"
555 558
 	#define MSG_BED              "Bett"
556 559
 	#define MSG_FAN_SPEED        "Lüftergeschw."
557
-	#define MSG_FLOW             "Fluß"
560
+	#define MSG_FLOW             "Fluss"
558 561
 	#define MSG_CONTROL          "Einstellungen"
559 562
 	#define MSG_MIN              "\002 Min"
560 563
 	#define MSG_MAX              "\002 Max"
@@ -587,6 +590,7 @@
587 590
 	#define MSG_WATCH            "Beobachten"
588 591
 	#define MSG_TEMPERATURE      "Temperatur"
589 592
 	#define MSG_MOTION           "Bewegung"
593
+	#define MSG_CONTRAST "LCD contrast"
590 594
 	#define MSG_STORE_EPROM      "EPROM speichern"
591 595
 	#define MSG_LOAD_EPROM       "EPROM laden"
592 596
 	#define MSG_RESTORE_FAILSAFE "Standardkonfig."
@@ -906,6 +910,7 @@
906 910
 #define MSG_RECTRACT    					" Откат подачи      \x7E"
907 911
 #define MSG_TEMPERATURE  				" Температура       \x7E"
908 912
 #define MSG_MOTION						" Скорости          \x7E"
913
+	#define MSG_CONTRAST "LCD contrast"
909 914
 #define MSG_STORE_EPROM						" Сохранить настройки"
910 915
 #define MSG_LOAD_EPROM						" Загрузить настройки"
911 916
 #define MSG_RESTORE_FAILSAFE				" Сброс настроек     "
@@ -1061,6 +1066,7 @@
1061 1066
 	#define MSG_RECTRACT             "Ritrai"
1062 1067
 	#define MSG_TEMPERATURE          "Temperatura"
1063 1068
 	#define MSG_MOTION               "Movimento"
1069
+	#define MSG_CONTRAST "LCD contrast"
1064 1070
 	#define MSG_STORE_EPROM          "Salva in EEPROM"
1065 1071
 	#define MSG_LOAD_EPROM           "Carica da EEPROM"
1066 1072
 	#define MSG_RESTORE_FAILSAFE     "Impostaz. default"
@@ -1391,6 +1397,7 @@
1391 1397
 	#define MSG_RECTRACT "Veda takaisin"
1392 1398
 	#define MSG_TEMPERATURE "Lampotila"
1393 1399
 	#define MSG_MOTION "Liike"
1400
+	#define MSG_CONTRAST "LCD contrast"
1394 1401
 	#define MSG_STORE_EPROM "Tallenna muistiin"
1395 1402
 	#define MSG_LOAD_EPROM "Lataa muistista"
1396 1403
 	#define MSG_RESTORE_FAILSAFE "Palauta oletus"

+ 40
- 0
Marlin/ultralcd.cpp Прегледај датотеку

@@ -47,6 +47,9 @@ static void lcd_control_temperature_menu();
47 47
 static void lcd_control_temperature_preheat_pla_settings_menu();
48 48
 static void lcd_control_temperature_preheat_abs_settings_menu();
49 49
 static void lcd_control_motion_menu();
50
+#ifdef DOGLCD
51
+static void lcd_set_contrast();
52
+#endif
50 53
 static void lcd_control_retract_menu();
51 54
 static void lcd_sdcard_menu();
52 55
 
@@ -492,6 +495,10 @@ static void lcd_control_menu()
492 495
     MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
493 496
     MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
494 497
     MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
498
+#ifdef DOGLCD
499
+//    MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
500
+    MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
501
+#endif
495 502
 #ifdef FWRETRACT
496 503
     MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
497 504
 #endif
@@ -603,6 +610,31 @@ static void lcd_control_motion_menu()
603 610
     END_MENU();
604 611
 }
605 612
 
613
+#ifdef DOGLCD
614
+static void lcd_set_contrast()
615
+{
616
+    if (encoderPosition != 0)
617
+    {
618
+        lcd_contrast -= encoderPosition;
619
+        if (lcd_contrast < 0) lcd_contrast = 0;
620
+        else if (lcd_contrast > 63) lcd_contrast = 63;
621
+        encoderPosition = 0;
622
+        lcdDrawUpdate = 1;
623
+        u8g.setContrast(lcd_contrast);
624
+    }
625
+    if (lcdDrawUpdate)
626
+    {
627
+        lcd_implementation_drawedit(PSTR("Contrast"), itostr2(lcd_contrast));
628
+    }
629
+    if (LCD_CLICKED)
630
+    {
631
+        lcd_quick_feedback();
632
+        currentMenu = lcd_control_menu;
633
+        encoderPosition = 0;
634
+    }
635
+}
636
+#endif
637
+
606 638
 #ifdef FWRETRACT
607 639
 static void lcd_control_retract_menu()
608 640
 {
@@ -962,6 +994,14 @@ void lcd_reset_alert_level()
962 994
     lcd_status_message_level = 0;
963 995
 }
964 996
 
997
+#ifdef DOGLCD
998
+void lcd_setcontrast(uint8_t value)
999
+{
1000
+    lcd_contrast = value & 63;
1001
+    u8g.setContrast(lcd_contrast);	
1002
+}
1003
+#endif
1004
+
965 1005
 #ifdef ULTIPANEL
966 1006
 /* Warning: This function is called from interrupt context */
967 1007
 void lcd_buttons_update()

+ 6
- 1
Marlin/ultralcd.h Прегледај датотеку

@@ -11,7 +11,12 @@
11 11
   void lcd_setstatuspgm(const char* message);
12 12
   void lcd_setalertstatuspgm(const char* message);
13 13
   void lcd_reset_alert_level();
14
-  
14
+
15
+#ifdef DOGLCD
16
+  extern int lcd_contrast;
17
+  void lcd_setcontrast(uint8_t value);
18
+#endif
19
+
15 20
   static unsigned char blink = 0;	// Variable for visualisation of fan rotation in GLCD
16 21
 
17 22
   #define LCD_MESSAGEPGM(x) lcd_setstatuspgm(PSTR(x))

Loading…
Откажи
Сачувај