浏览代码

Changes in dogm_lcd_implementation.h in detail.

Top -> down
- We don't need the old Marlion_font package any more - we made new.
- But we need information about configured fonts and the mappers.
- We support Cyrillic now.
- LCD_CLASS is not used in this file. LiquidCrystalRus.h is deleted anyway.
- define some fonts
- BIG_EDIT_FONT works only together with western languages.
- Select a matching FONT for the MENUE depending on the defined language.
- Number the different font-types. Wanted to avoid to store complete font-structures when changing fonts back and forth.
- Marlin special symbols are now at the lower end - like in 'ultralcd_implementation_hitachi_HD44780.h'
- insert the new remembering setFont function.
- insert the new counting lcd_print functions.
- make use of the new setFont and lcd_print functions.
- On some places redefined one character long strings with chars to avoid overhead and reduce warnings.
AnHardt 10 年前
父节点
当前提交
ae76b1e8a8
共有 1 个文件被更改,包括 165 次插入80 次删除
  1. 165
    80
      Marlin/dogm_lcd_implementation.h

+ 165
- 80
Marlin/dogm_lcd_implementation.h 查看文件

@@ -17,8 +17,8 @@
17 17
 #define MARLIN_VERSION "1.0.2"
18 18
 
19 19
 /**
20
-* Implementation of the LCD display routines for a DOGM128 graphic display. These are common LCD 128x64 pixel graphic displays.
21
-**/
20
+ * Implementation of the LCD display routines for a DOGM128 graphic display. These are common LCD 128x64 pixel graphic displays.
21
+ */
22 22
 
23 23
 #ifdef ULTIPANEL
24 24
   #define BLEN_A 0
@@ -32,35 +32,72 @@
32 32
 
33 33
 #include <U8glib.h>
34 34
 #include "DOGMbitmaps.h"
35
-#include "dogm_font_data_marlin.h"
36 35
 #include "ultralcd.h"
37 36
 #include "ultralcd_st7920_u8glib_rrd.h"
37
+#include "configuration.h"
38
+#include "utf_mapper.h"
38 39
 
39
-/* Russian language not supported yet, needs custom font
40
+#include <utility/u8g.h>
41
+#include "dogm_font_data_6x9_marlin.h"       // Height of 'A' is only 5 pixel.
42
+#include "dogm_font_data_Marlin_symbols.h"   // The Marlin special symbols
40 43
 
41
-#ifdef LANGUAGE_RU
42
-#include "LiquidCrystalRus.h"
43
-#define LCD_CLASS LiquidCrystalRus
44
-#else
45
-#include <LiquidCrystal.h>
46
-#define LCD_CLASS LiquidCrystal
44
+#define FONT_STATUSMENU_NAME u8g_font_6x9    // we don't have a small font for Cyrillic, Kana or Kanji
45
+#define FONT_SPECIAL_NAME Marlin_symbols
46
+
47
+// save 3120 bytes of PROGMEM by commenting out the next #define
48
+// we don't have a big font for Cyrillic, Kana or Kanji
49
+#if defined( MAPPER_C2C3 ) || defined( MAPPER_NON )
50
+  #define USE_BIG_EDIT_FONT
47 51
 #endif
48
-*/
49 52
 
50
-#define USE_BIG_EDIT_FONT                // save 3120 bytes of PROGMEM by commenting out this line
51
-#define FONT_STATUSMENU u8g_font_6x9
52
-#define FONT_MENU u8g_font_6x10_marlin
53
+#if defined( MAPPER_C2C3 )
54
+  #include <utility/u8g.h> // System font. This is ISO10646-1
55
+  #define FONT_MENU_NAME u8g_font_6x10
56
+
57
+#elif defined( MAPPER_D0D1 )
58
+  #include "dogm_font_data_ISO10646_5_Cyrillic.h"
59
+  #define FONT_MENU_NAME ISO10646_5_Cyrillic_5x7
60
+
61
+#elif defined( MAPPER_E382E383 )
62
+  #include "dogm_font_data_ISO10646_Kana.h"
63
+  #define FONT_MENU_NAME ISO10646_Kana_5x7
64
+
65
+#elif defined( DISPLAY_CHARSET_KANJI ) && defined( MAPPER_NON )
66
+  #include "dogm_font_data_6x10_marlin_Kanji.h"
67
+  #define FONT_MENU_NAME u8g_font_6x10_marlin
68
+
69
+#elif defined( DISPLAY_CHARSET_HD44780_JAPAN )
70
+  #include "dogm_font_data_HD44780_J.h"
71
+  #define FONT_MENU_NAME HD44780_J_5x7
72
+
73
+#elif defined( DISPLAY_CHARSET_HD44780_WESTERN )
74
+  #include "dogm_font_data_HD44780_W.h"
75
+  #define FONT_MENU_NAME HD44780_W_5x7
76
+
77
+#elif defined( DISPLAY_CHARSET_HD44780_CYRILIC )
78
+  #include "dogm_font_data_HD44780_C.h"
79
+  #define FONT_MENU_NAME HD44780_C_5x7
80
+
81
+#else // #if defined( MAPPER_C2C3 )  // fall-back
82
+  #include <utility/u8g.h> // system font
83
+  #define FONT_MENU_NAME u8g_font_6x10
84
+#endif
85
+
86
+#define FONT_STATUSMENU 1
87
+#define FONT_SPECIAL 2
88
+#define FONT_MENU_EDIT 3
89
+#define FONT_MENU 4
53 90
 
54 91
 // DOGM parameters (size in pixels)
55 92
 #define DOG_CHAR_WIDTH         6
56 93
 #define DOG_CHAR_HEIGHT        12
57 94
 #ifdef USE_BIG_EDIT_FONT
58
-  #define FONT_MENU_EDIT u8g_font_9x18
95
+  #define FONT_MENU_EDIT_NAME u8g_font_9x18
59 96
   #define DOG_CHAR_WIDTH_EDIT  9
60 97
   #define DOG_CHAR_HEIGHT_EDIT 18
61 98
   #define LCD_WIDTH_EDIT       14
62 99
 #else
63
-  #define FONT_MENU_EDIT u8g_font_6x10_marlin
100
+  #define FONT_MENU_EDIT_NAME FONT_MENU_NAME
64 101
   #define DOG_CHAR_WIDTH_EDIT  6
65 102
   #define DOG_CHAR_HEIGHT_EDIT 12
66 103
   #define LCD_WIDTH_EDIT       22
@@ -68,16 +105,21 @@
68 105
 
69 106
 #define START_ROW              0
70 107
 
71
-/* Custom characters defined in font font_6x10_marlin.c */
72
-#define LCD_STR_DEGREE      "\xB0"
73
-#define LCD_STR_REFRESH     "\xF8"
74
-#define LCD_STR_FOLDER      "\xF9"
75
-#define LCD_STR_ARROW_RIGHT "\xFA"
76
-#define LCD_STR_UPLEVEL     "\xFB"
77
-#define LCD_STR_CLOCK       "\xFC"
78
-#define LCD_STR_FEEDRATE    "\xFD"
79
-#define LCD_STR_BEDTEMP     "\xFE"
80
-#define LCD_STR_THERMOMETER "\xFF"
108
+/* Custom characters defined in font font_6x10_marlin_symbols */
109
+// \x00 intentionally skipped to avoid problems in strings
110
+#define LCD_STR_REFRESH     "\x01"
111
+#define LCD_STR_FOLDER      "\x02"
112
+#define LCD_STR_ARROW_RIGHT "\x03"
113
+#define LCD_STR_UPLEVEL     "\x04"
114
+#define LCD_STR_CLOCK       "\x05"
115
+#define LCD_STR_FEEDRATE    "\x06"
116
+#define LCD_STR_BEDTEMP     "\x07"
117
+#define LCD_STR_THERMOMETER "\x08"
118
+#define LCD_STR_DEGREE      "\x09"
119
+
120
+#define LCD_STR_SPECIAL_MAX LCD_STR_DEGREE
121
+// Maximum here is 0x1f because 0x20 is ' ' (space) and the normal charsets begin.
122
+// Better stay below 0x10 because DISPLAY_CHARSET_HD44780_WESTERN begins here.
81 123
 
82 124
 int lcd_contrast;
83 125
 
@@ -96,6 +138,49 @@ U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0);
96 138
 U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);  // HW-SPI Com: CS, A0
97 139
 #endif
98 140
 
141
+char currentfont = 0;
142
+
143
+static void lcd_setFont(char font_nr) {
144
+  switch(font_nr) {
145
+    case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
146
+    case FONT_MENU       : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
147
+    case FONT_SPECIAL    : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
148
+    case FONT_MENU_EDIT  : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
149
+    break;
150
+  }
151
+}
152
+
153
+char lcd_print(char c) {
154
+  if ((c > 0) && (c < ' ')) {
155
+    u8g.setFont(FONT_SPECIAL_NAME);
156
+    u8g.print(c);
157
+    lcd_setFont(currentfont);
158
+    return 1;
159
+  } else {
160
+    return charset_mapper(c);
161
+  }
162
+}
163
+
164
+char lcd_print(char* str) {
165
+  char c;
166
+  int i = 0;
167
+  char n = 0;
168
+  while ((c = str[i++])) {
169
+    n += lcd_print(c);
170
+  }
171
+  return n;
172
+}
173
+
174
+/* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
175
+char lcd_printPGM(const char* str) {
176
+  char c;
177
+  char n = 0;
178
+  while ((c = pgm_read_byte(str++))) {
179
+    n += lcd_print(c);
180
+  }
181
+  return n;
182
+}
183
+
99 184
 static void lcd_implementation_init()
100 185
 {
101 186
   #ifdef LCD_PIN_BL // Enable LCD backlight
@@ -130,7 +215,7 @@ static void lcd_implementation_init()
130 215
 	u8g.firstPage();
131 216
 	do {
132 217
     u8g.drawBitmapP(offx, offy, START_BMPBYTEWIDTH, START_BMPHEIGHT, start_bmp);
133
-    u8g.setFont(FONT_MENU);
218
+    lcd_setFont(FONT_MENU);
134 219
     #ifndef STRING_SPLASH_LINE2
135 220
       u8g.drawStr(txt1X, u8g.getHeight() - DOG_CHAR_HEIGHT, STRING_SPLASH_LINE1);
136 221
     #else
@@ -143,21 +228,15 @@ static void lcd_implementation_init()
143 228
 
144 229
 static void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
145 230
 
146
-/* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
147
-static void lcd_printPGM(const char* str) {
148
-  char c;
149
-  while ((c = pgm_read_byte(str++))) u8g.print(c);
150
-}
151
-
152 231
 static void _draw_heater_status(int x, int heater) {
153 232
   bool isBed = heater < 0;
154 233
   int y = 17 + (isBed ? 1 : 0);
155
-  u8g.setFont(FONT_STATUSMENU);
234
+  lcd_setFont(FONT_STATUSMENU);
156 235
   u8g.setPrintPos(x,6);
157
-  u8g.print(itostr3(int((heater >= 0 ? degTargetHotend(heater) : degTargetBed()) + 0.5)));
236
+  lcd_print(itostr3(int((heater >= 0 ? degTargetHotend(heater) : degTargetBed()) + 0.5)));
158 237
   lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
159 238
   u8g.setPrintPos(x,27);
160
-  u8g.print(itostr3(int(heater >= 0 ? degHotend(heater) : degBed()) + 0.5));
239
+  lcd_print(itostr3(int(heater >= 0 ? degHotend(heater) : degBed()) + 0.5));
161 240
   lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
162 241
   if (!isHeatingHotend(0)) {
163 242
     u8g.drawBox(x+7,y,2,2);
@@ -189,7 +268,7 @@ static void lcd_implementation_status_screen() {
189 268
     u8g.drawFrame(54,49,73,4);
190 269
 
191 270
     // SD Card Progress bar and clock
192
-    u8g.setFont(FONT_STATUSMENU);
271
+    lcd_setFont(FONT_STATUSMENU);
193 272
  
194 273
     if (IS_SD_PRINTING) {
195 274
       // Progress bar solid part
@@ -199,9 +278,9 @@ static void lcd_implementation_status_screen() {
199 278
     u8g.setPrintPos(80,47);
200 279
     if (starttime != 0) {
201 280
       uint16_t time = (millis() - starttime) / 60000;
202
-      u8g.print(itostr2(time/60));
203
-      u8g.print(':');
204
-      u8g.print(itostr2(time%60));
281
+      lcd_print(itostr2(time/60));
282
+      lcd_print(':');
283
+      lcd_print(itostr2(time%60));
205 284
     }
206 285
     else {
207 286
       lcd_printPGM(PSTR("--:--"));
@@ -215,68 +294,77 @@ static void lcd_implementation_status_screen() {
215 294
   if (EXTRUDERS < 4) _draw_heater_status(81, -1);
216 295
  
217 296
   // Fan
218
-  u8g.setFont(FONT_STATUSMENU);
297
+  lcd_setFont(FONT_STATUSMENU);
219 298
   u8g.setPrintPos(104,27);
220 299
   #if defined(FAN_PIN) && FAN_PIN > -1
221 300
     int per = ((fanSpeed + 1) * 100) / 256;
222 301
     if (per) {
223
-      u8g.print(itostr3(per));
224
-      u8g.print("%");
302
+      lcd_print(itostr3(per));
303
+      lcd_print('%');
225 304
     }
226 305
     else
227 306
   #endif
228 307
     {
229
-      u8g.print("---");
308
+      lcd_printPGM(PSTR("---"));
230 309
     }
231 310
 
232 311
   // X, Y, Z-Coordinates
233
-  u8g.setFont(FONT_STATUSMENU);
312
+  lcd_setFont(FONT_STATUSMENU);
234 313
   u8g.drawBox(0,29,128,10);
235 314
   u8g.setColorIndex(0); // white on black
236 315
   u8g.setPrintPos(2,37);
237
-  u8g.print("X");
316
+  lcd_print('X');
238 317
   u8g.drawPixel(8,33);
239 318
   u8g.drawPixel(8,35);
240 319
   u8g.setPrintPos(10,37);
241
-  u8g.print(ftostr31ns(current_position[X_AXIS]));
320
+  lcd_print(ftostr31ns(current_position[X_AXIS]));
242 321
   u8g.setPrintPos(43,37);
243
-  lcd_printPGM(PSTR("Y"));
322
+  lcd_print('Y');
244 323
   u8g.drawPixel(49,33);
245 324
   u8g.drawPixel(49,35);
246 325
   u8g.setPrintPos(51,37);
247
-  u8g.print(ftostr31ns(current_position[Y_AXIS]));
326
+  lcd_print(ftostr31ns(current_position[Y_AXIS]));
248 327
   u8g.setPrintPos(83,37);
249
-  u8g.print("Z");
328
+  lcd_print('Z');
250 329
   u8g.drawPixel(89,33);
251 330
   u8g.drawPixel(89,35);
252 331
   u8g.setPrintPos(91,37);
253
-  u8g.print(ftostr31(current_position[Z_AXIS]));
332
+  lcd_print(ftostr31(current_position[Z_AXIS]));
254 333
   u8g.setColorIndex(1); // black on white
255 334
  
256 335
   // Feedrate
257
-  u8g.setFont(FONT_MENU);
336
+  lcd_setFont(FONT_MENU);
258 337
   u8g.setPrintPos(3,49);
259
-  u8g.print(LCD_STR_FEEDRATE[0]);
260
-  u8g.setFont(FONT_STATUSMENU);
338
+  lcd_print(LCD_STR_FEEDRATE[0]);
339
+  lcd_setFont(FONT_STATUSMENU);
261 340
   u8g.setPrintPos(12,48);
262
-  u8g.print(itostr3(feedmultiply));
263
-  u8g.print('%');
341
+  lcd_print(itostr3(feedmultiply));
342
+  lcd_print('%');
264 343
 
265 344
   // Status line
266
-  u8g.setFont(FONT_STATUSMENU);
345
+/* The new fonts are small enough
346
+  #ifndef MAPPER_C2C3
347
+    lcd_setFont(FONT_MENU);
348
+  #else
349
+    lcd_setFont(FONT_STATUSMENU);
350
+  #endif
351
+*/
352
+  lcd_setFont(FONT_MENU);
353
+
267 354
   u8g.setPrintPos(0,61);
355
+
268 356
   #ifndef FILAMENT_LCD_DISPLAY
269
-    u8g.print(lcd_status_message);
357
+    lcd_print(lcd_status_message);
270 358
   #else
271 359
     if (millis() < message_millis + 5000) {  //Display both Status message line and Filament display on the last line
272
-      u8g.print(lcd_status_message);
360
+      lcd_print(lcd_status_message);
273 361
     }
274 362
     else {
275 363
       lcd_printPGM(PSTR("dia:"));
276
-      u8g.print(ftostr12ns(filament_width_meas));
364
+      lcd_print(ftostr12ns(filament_width_meas));
277 365
       lcd_printPGM(PSTR(" factor:"));
278
-      u8g.print(itostr3(extrudemultiply));
279
-      u8g.print('%');
366
+      lcd_print(itostr3(extrudemultiply));
367
+      lcd_print('%');
280 368
     }
281 369
   #endif
282 370
 }
@@ -300,13 +388,12 @@ static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, c
300 388
   lcd_implementation_mark_as_selected(row, pre_char);
301 389
 
302 390
   while((c = pgm_read_byte(pstr))) {
303
-    u8g.print(c);
391
+    n -= lcd_print(c);
304 392
     pstr++;
305
-    n--;
306 393
   }
307
-  while(n--) u8g.print(' ');
308
-  u8g.print(post_char);
309
-  u8g.print(' ');
394
+  while(n--) lcd_print(' ');
395
+  lcd_print(post_char);
396
+  lcd_print(' ');
310 397
 }
311 398
 
312 399
 static void _drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, const char* data, bool pgm) {
@@ -316,13 +403,12 @@ static void _drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char p
316 403
   lcd_implementation_mark_as_selected(row, pre_char);
317 404
 
318 405
   while( (c = pgm_read_byte(pstr))) {
319
-    u8g.print(c);
406
+    n -= lcd_print(c);
320 407
     pstr++;
321
-    n--;
322 408
   }
323
-  u8g.print(':');
324
-  while(n--) u8g.print(' ');
325
-  if (pgm) { lcd_printPGM(data); } else { u8g.print(data); }
409
+  lcd_print(':');
410
+  while(n--) lcd_print(' ');
411
+  if (pgm) { lcd_printPGM(data); } else { lcd_print((char *)data); }
326 412
 }
327 413
 
328 414
 #define lcd_implementation_drawmenu_setting_edit_generic(row, pstr, pre_char, data) _drawmenu_setting_edit_generic(row, pstr, pre_char, data, false)
@@ -374,13 +460,13 @@ void lcd_implementation_drawedit(const char* pstr, char* value) {
374 460
 
375 461
   #ifdef USE_BIG_EDIT_FONT
376 462
     if (lcd_strlen_P(pstr) <= LCD_WIDTH_EDIT - 1) {
377
-      u8g.setFont(FONT_MENU_EDIT);
463
+      lcd_setFont(FONT_MENU_EDIT);
378 464
       lcd_width = LCD_WIDTH_EDIT + 1;
379 465
       char_width = DOG_CHAR_WIDTH_EDIT;
380 466
       if (lcd_strlen_P(pstr) >= LCD_WIDTH_EDIT - lcd_strlen(value)) rows = 2;
381 467
     }
382 468
     else {
383
-      u8g.setFont(FONT_MENU);
469
+      lcd_setFont(FONT_MENU);
384 470
     }
385 471
   #endif
386 472
 
@@ -391,9 +477,9 @@ void lcd_implementation_drawedit(const char* pstr, char* value) {
391 477
 
392 478
   u8g.setPrintPos(0, rowHeight + kHalfChar);
393 479
   lcd_printPGM(pstr);
394
-  u8g.print(':');
480
+  lcd_print(':');
395 481
   u8g.setPrintPos((lcd_width-1-lcd_strlen(value)) * char_width, rows * rowHeight + kHalfChar);
396
-  u8g.print(value);
482
+  lcd_print(value);
397 483
 }
398 484
 
399 485
 static void _drawmenu_sd(uint8_t row, const char* pstr, const char* filename, char * const longFilename, bool isDir, bool isSelected) {
@@ -407,13 +493,12 @@ static void _drawmenu_sd(uint8_t row, const char* pstr, const char* filename, ch
407 493
 
408 494
   lcd_implementation_mark_as_selected(row, ((isSelected) ? '>' : ' '));
409 495
 
410
-  if (isDir) u8g.print(LCD_STR_FOLDER[0]);
496
+  if (isDir) lcd_print(LCD_STR_FOLDER[0]);
411 497
   while((c = *filename) != '\0') {
412
-    u8g.print(c);
498
+    n -= lcd_print(c);
413 499
     filename++;
414
-    n--;
415 500
   }
416
-  while(n--) u8g.print(' ');
501
+  while(n--) lcd_print(' ');
417 502
 }
418 503
 
419 504
 #define lcd_implementation_drawmenu_sdfile_selected(row, pstr, filename, longFilename) _drawmenu_sd(row, pstr, filename, longFilename, false, true)

正在加载...
取消
保存