Quellcode durchsuchen

Reduce dogm lcd code

Scott Lahteine vor 10 Jahren
Ursprung
Commit
e69313fc2b
2 geänderte Dateien mit 82 neuen und 228 gelöschten Zeilen
  1. 79
    226
      Marlin/dogm_lcd_implementation.h
  2. 3
    2
      Marlin/ultralcd.h

+ 79
- 226
Marlin/dogm_lcd_implementation.h Datei anzeigen

@@ -39,7 +39,6 @@
39 39
 #include "ultralcd.h"
40 40
 #include "ultralcd_st7920_u8glib_rrd.h"
41 41
 
42
-
43 42
 /* Russian language not supported yet, needs custom font
44 43
 
45 44
 #if LANGUAGE_CHOICE == 6
@@ -57,20 +56,18 @@
57 56
 #define DOG_CHAR_WIDTH_LARGE	9
58 57
 #define DOG_CHAR_HEIGHT_LARGE	18
59 58
 
60
-
61 59
 #define START_ROW				0
62 60
 
63
-
64 61
 /* Custom characters defined in font font_6x10_marlin.c */
65
-#define LCD_STR_BEDTEMP     "\xFE"
66 62
 #define LCD_STR_DEGREE      "\xB0"
67
-#define LCD_STR_THERMOMETER "\xFF"
68
-#define LCD_STR_UPLEVEL     "\xFB"
69 63
 #define LCD_STR_REFRESH     "\xF8"
70 64
 #define LCD_STR_FOLDER      "\xF9"
71
-#define LCD_STR_FEEDRATE    "\xFD"
72
-#define LCD_STR_CLOCK       "\xFC"
73 65
 #define LCD_STR_ARROW_RIGHT "\xFA"
66
+#define LCD_STR_UPLEVEL     "\xFB"
67
+#define LCD_STR_CLOCK       "\xFC"
68
+#define LCD_STR_FEEDRATE    "\xFD"
69
+#define LCD_STR_BEDTEMP     "\xFE"
70
+#define LCD_STR_THERMOMETER "\xFF"
74 71
 
75 72
 #define FONT_STATUSMENU	u8g_font_6x9
76 73
 
@@ -167,6 +164,25 @@ static void lcd_printPGM(const char* str)
167 164
     }
168 165
 }
169 166
 
167
+static void _draw_heater_status(int x, int heater) {
168
+  bool isBed = heater < 0;
169
+  int y = 17 + (isBed ? 1 : 0);
170
+  u8g.setFont(FONT_STATUSMENU);
171
+  u8g.setPrintPos(x,6);
172
+  u8g.print(itostr3(int((heater >= 0 ? degTargetHotend(heater) : degTargetBed()) + 0.5)));
173
+  lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
174
+  u8g.setPrintPos(x,27);
175
+  u8g.print(itostr3(int(heater >= 0 ? degHotend(heater) : degBed()) + 0.5));
176
+  lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
177
+  if (!isHeatingHotend(0)) {
178
+    u8g.drawBox(x+7,y,2,2);
179
+  }
180
+  else {
181
+    u8g.setColorIndex(0); // white on black
182
+    u8g.drawBox(x+7,y,2,2);
183
+    u8g.setColorIndex(1); // black on white
184
+  }
185
+}
170 186
 
171 187
 static void lcd_implementation_status_screen()
172 188
 {
@@ -176,8 +192,7 @@ static void lcd_implementation_status_screen()
176 192
  u8g.setColorIndex(1);	// black on white
177 193
  
178 194
  // Symbols menu graphics, animated fan
179
- if ((blink % 2) &&  fanSpeed )	u8g.drawBitmapP(9,1,STATUS_SCREENBYTEWIDTH,STATUS_SCREENHEIGHT,status_screen0_bmp);
180
-	else u8g.drawBitmapP(9,1,STATUS_SCREENBYTEWIDTH,STATUS_SCREENHEIGHT,status_screen1_bmp);
195
+ u8g.drawBitmapP(9,1,STATUS_SCREENBYTEWIDTH,STATUS_SCREENHEIGHT, (blink % 2) && fanSpeed ? status_screen0_bmp : status_screen1_bmp);
181 196
  
182 197
  #ifdef SDSUPPORT
183 198
  //SD Card Symbol
@@ -213,73 +228,17 @@ static void lcd_implementation_status_screen()
213 228
 		 }
214 229
  #endif
215 230
  
216
- // Extruder 1
217
- u8g.setFont(FONT_STATUSMENU);
218
- u8g.setPrintPos(6,6);
219
- u8g.print(itostr3(int(degTargetHotend(0) + 0.5)));
220
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
221
- u8g.setPrintPos(6,27);
222
- u8g.print(itostr3(int(degHotend(0) + 0.5)));
223
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
224
- if (!isHeatingHotend(0)) u8g.drawBox(13,17,2,2);
225
-	else
226
-		{
227
-		 u8g.setColorIndex(0);	// white on black
228
-		 u8g.drawBox(13,17,2,2);
229
-		 u8g.setColorIndex(1);	// black on white
230
-		}
231
- 
232
- // Extruder 2
233
- u8g.setFont(FONT_STATUSMENU);
234
- #if EXTRUDERS > 1
235
- u8g.setPrintPos(31,6);
236
- u8g.print(itostr3(int(degTargetHotend(1) + 0.5)));
237
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
238
- u8g.setPrintPos(31,27);
239
- u8g.print(itostr3(int(degHotend(1) + 0.5)));
240
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
241
- if (!isHeatingHotend(1)) u8g.drawBox(38,17,2,2);
242
-	else
243
-		{
244
-		 u8g.setColorIndex(0);	// white on black
245
-		 u8g.drawBox(38,17,2,2);
246
-		 u8g.setColorIndex(1);	// black on white
247
-		}
248
- #endif
249
- 
250
- // Extruder 3
251
- u8g.setFont(FONT_STATUSMENU);
252
- # if EXTRUDERS > 2
253
- u8g.setPrintPos(55,6);
254
- u8g.print(itostr3(int(degTargetHotend(2) + 0.5)));
255
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
256
- u8g.setPrintPos(55,27);
257
- u8g.print(itostr3(int(degHotend(2) + 0.5)));
258
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
259
- if (!isHeatingHotend(2)) u8g.drawBox(62,17,2,2);
260
-	else
261
-		{
262
-		 u8g.setColorIndex(0);	// white on black
263
-		 u8g.drawBox(62,17,2,2);
264
-		 u8g.setColorIndex(1);	// black on white
265
-		}
266
- #endif
267
- 
268
- // Heatbed
269
- u8g.setFont(FONT_STATUSMENU);
270
- u8g.setPrintPos(81,6);
271
- u8g.print(itostr3(int(degTargetBed() + 0.5)));
272
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
273
- u8g.setPrintPos(81,27);
274
- u8g.print(itostr3(int(degBed() + 0.5)));
275
- lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
276
- if (!isHeatingBed()) u8g.drawBox(88,18,2,2);
277
-	else
278
-		{
279
-		 u8g.setColorIndex(0);	// white on black
280
-		 u8g.drawBox(88,18,2,2);
281
-		 u8g.setColorIndex(1);	// black on white
282
-		}
231
+  // Extruders
232
+  _draw_heater_status(6, 0);
233
+  #if EXTRUDERS > 1
234
+    _draw_heater_status(31, 1);
235
+    #if EXTRUDERS > 2
236
+      _draw_heater_status(55, 2);
237
+    #endif
238
+  #endif
239
+
240
+  // Heatbed
241
+  _draw_heater_status(81, -1);
283 242
  
284 243
  // Fan
285 244
  u8g.setFont(FONT_STATUSMENU);
@@ -360,7 +319,7 @@ static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, c
360 319
 		   } else u8g.setColorIndex(1); // unmarked text is black on white
361 320
 		
362 321
 		u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
363
-		if (pre_char != '>') u8g.print(pre_char); else u8g.print(' ');	// Row selector is obsolete
322
+		u8g.print(pre_char == '>' ? ' ' : pre_char);	// Row selector is obsolete
364 323
 
365 324
 
366 325
     while( (c = pgm_read_byte(pstr)) != '\0' )
@@ -378,57 +337,29 @@ static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, c
378 337
 		u8g.setColorIndex(1);		// restore settings to black on white
379 338
 }
380 339
 
381
-static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data)
382
-{
383
-    static unsigned int fkt_cnt = 0;
384
-	char c;
385
-    uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data);
386
-		
387
-		u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
388
-		u8g.print(pre_char);
389
-	
390
-    while( (c = pgm_read_byte(pstr)) != '\0' )
391
-    {
392
-			u8g.print(c);
340
+static void _drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data, bool pgm) {
341
+  char c;
342
+  uint8_t n = LCD_WIDTH - 1 - 2 - (pgm ? strlen_P(data) : strlen(data));
393 343
 		
394
-        pstr++;
395
-        n--;
396
-    }
397
-	
398
-		u8g.print(':');
399
-
400
-    while(n--){
401
-					u8g.print(' ');
402
-			  }
344
+  u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
345
+  u8g.print(pre_char);
403 346
 
404
-		u8g.print(data);
405
-}
406
-
407
-static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data)
408
-{
409
-    char c;
410
-    uint8_t n= LCD_WIDTH - 1 - 2 - strlen_P(data);
347
+  while( (c = pgm_read_byte(pstr)) != '\0' ) {
348
+    u8g.print(c);
349
+    pstr++;
350
+    n--;
351
+  }
411 352
 
412
-		u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
413
-		u8g.print(pre_char);
414
-	
415
-    while( (c = pgm_read_byte(pstr)) != '\0' )
416
-    {
417
-			u8g.print(c);
418
-		
419
-        pstr++;
420
-        n--;
421
-    }
353
+  u8g.print(':');
422 354
 
423
-		u8g.print(':');
424
-	
425
-    while(n--){
426
-					u8g.print(' ');
427
-			  }
355
+  while(n--) u8g.print(' ');
428 356
 
429
-		lcd_printPGM(data);
357
+  if (pgm) { lcd_printPGM(data); } else { u8g.print(data); }
430 358
 }
431 359
 
360
+#define lcd_implementation_drawmenu_setting_edit_generic(row, pstr, pre_char, data) _drawmenu_setting_edit_generic(row, pstr, pre_char, data, false)
361
+#define lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, pre_char, data) _drawmenu_setting_edit_generic(row, pstr, pre_char, data, true)
362
+
432 363
 #define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
433 364
 #define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
434 365
 #define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
@@ -474,118 +405,40 @@ void lcd_implementation_drawedit(const char* pstr, char* value)
474 405
 		u8g.print(value);
475 406
 }
476 407
 
477
-static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
478
-{
479
-    char c;
480
-    uint8_t n = LCD_WIDTH - 1;
408
+static void _drawmenu_sd(uint8_t row, const char* pstr, const char* filename, char * const longFilename, bool isDir, bool isSelected) {
409
+  char c;
410
+  uint8_t n = LCD_WIDTH - 1;
481 411
 
482
-    if (longFilename[0] != '\0')
483
-    {
484
-        filename = longFilename;
485
-        longFilename[LCD_WIDTH-1] = '\0';
486
-    }
412
+  if (longFilename[0] != '\0') {
413
+    filename = longFilename;
414
+    longFilename[n] = '\0';
415
+  }
487 416
 
488
-		u8g.setColorIndex(1);		// black on white
489
-		u8g.drawBox (0, row*DOG_CHAR_HEIGHT + 3, 128, DOG_CHAR_HEIGHT);
490
-		u8g.setColorIndex(0);		// following text must be white on black
491
-		u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
492
-		u8g.print(' ');	// Indent by 1 char
493
-	   
494
-    while((c = *filename) != '\0')
495
-    {
496
-		u8g.print(c);
497
-        filename++;
498
-        n--;
499
-    }
500
-    while(n--){
501
-					u8g.print(' ');
502
-			   }
503
-	u8g.setColorIndex(1);		// black on white
504
-}
505
-
506
-static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename)
507
-{
508
-    char c;
509
-    uint8_t n = LCD_WIDTH - 1;
417
+  if (isSelected) {
418
+    u8g.setColorIndex(1); // black on white
419
+    u8g.drawBox (0, row*DOG_CHAR_HEIGHT + 3, 128, DOG_CHAR_HEIGHT);
420
+    u8g.setColorIndex(0); // following text must be white on black
421
+  }
510 422
 
511
-    if (longFilename[0] != '\0')
512
-    {
513
-        filename = longFilename;
514
-        longFilename[LCD_WIDTH-1] = '\0';
515
-    }
423
+  u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
424
+  u8g.print(' ');	// Indent by 1 char
516 425
 
517
-		u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
518
-		u8g.print(' ');
519
-		
520
-while((c = *filename) != '\0')
521
-    {
522
-			u8g.print(c);
523
-		
524
-        filename++;
525
-        n--;
526
-    }
527
-    while(n--){
528
-					u8g.print(' ');
529
-			   }
426
+  if (isDir) u8g.print(LCD_STR_FOLDER[0]);
530 427
 
531
-}
428
+  while((c = *filename) != '\0') {
429
+    u8g.print(c);
430
+    filename++;
431
+    n--;
432
+  }
433
+  while(n--) u8g.print(' ');
532 434
 
533
-static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename)
534
-{
535
-    char c;
536
-    uint8_t n = LCD_WIDTH - 2;
537
-		
538
-    if (longFilename[0] != '\0')
539
-    {
540
-        filename = longFilename;
541
-        longFilename[LCD_WIDTH-2] = '\0';
542
-    }
543
-		u8g.setColorIndex(1);		// black on white
544
-		u8g.drawBox (0, row*DOG_CHAR_HEIGHT + 3, 128, DOG_CHAR_HEIGHT);
545
-		u8g.setColorIndex(0);		// following text must be white on black
546
-		u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
547
-		u8g.print(' ');	// Indent by 1 char
548
-		u8g.print(LCD_STR_FOLDER[0]);		
549
-	   
550
-    while((c = *filename) != '\0')
551
-    {
552
-			u8g.print(c);
553
-		
554
-        filename++;
555
-        n--;
556
-    }
557
-    while(n--){
558
-					u8g.print(' ');
559
-			   }
560
-	u8g.setColorIndex(1);		// black on white
435
+  if (isSelected) u8g.setColorIndex(1); // black on white
561 436
 }
562 437
 
563
-static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename)
564
-{
565
-    char c;
566
-    uint8_t n = LCD_WIDTH - 2;
567
-
568
-    if (longFilename[0] != '\0')
569
-    {
570
-        filename = longFilename;
571
-        longFilename[LCD_WIDTH-2] = '\0';
572
-    }
573
-
574
-		u8g.setPrintPos(0 * DOG_CHAR_WIDTH, (row + 1) * DOG_CHAR_HEIGHT);
575
-		u8g.print(' ');
576
-		u8g.print(LCD_STR_FOLDER[0]);
577
-
578
-    while((c = *filename) != '\0')
579
-    {
580
-			u8g.print(c);
581
-		
582
-        filename++;
583
-        n--;
584
-    }
585
-    while(n--){
586
-					u8g.print(' ');
587
-			   }
588
-}
438
+#define lcd_implementation_drawmenu_sdfile_selected(row, pstr, filename, longFilename) _drawmenu_sd(row, pstr, filename, longFilename, false, true)
439
+#define lcd_implementation_drawmenu_sdfile(row, pstr, filename, longFilename) _drawmenu_sd(row, pstr, filename, longFilename, false, false)
440
+#define lcd_implementation_drawmenu_sddirectory_selected(row, pstr, filename, longFilename) _drawmenu_sd(row, pstr, filename, longFilename, true, true)
441
+#define lcd_implementation_drawmenu_sddirectory(row, pstr, filename, longFilename) _drawmenu_sd(row, pstr, filename, longFilename, true, false)
589 442
 
590 443
 #define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
591 444
 #define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0])

+ 3
- 2
Marlin/ultralcd.h Datei anzeigen

@@ -105,7 +105,8 @@
105 105
 
106 106
   #define LCD_MESSAGEPGM(x) 
107 107
   #define LCD_ALERTMESSAGEPGM(x) 
108
-#endif 
108
+
109
+#endif //ULTRA_LCD
109 110
 
110 111
 char *itostr2(const uint8_t &x);
111 112
 char *itostr31(const int &xx);
@@ -122,4 +123,4 @@ char *ftostr5(const float &x);
122 123
 char *ftostr51(const float &x);
123 124
 char *ftostr52(const float &x);
124 125
 
125
-#endif //ULTRALCD
126
+#endif //ULTRALCD_H

Laden…
Abbrechen
Speichern