Browse Source

Merge pull request #1191 from thinkyhead/code_shrink

Shrink and Optimize
Bo Herrmannsen 10 years ago
parent
commit
a9c334e8bc
4 changed files with 160 additions and 476 deletions
  1. 4
    4
      Marlin/cardreader.cpp
  2. 79
    226
      Marlin/dogm_lcd_implementation.h
  3. 74
    244
      Marlin/ultralcd.cpp
  4. 3
    2
      Marlin/ultralcd.h

+ 4
- 4
Marlin/cardreader.cpp View File

@@ -91,10 +91,10 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
91 91
     {
92 92
       char pn0 = p.name[0];
93 93
       if (pn0 == DIR_NAME_FREE) break;
94
-      if (pn0 == DIR_NAME_DELETED || pn0 == '.'|| pn0 == '_') continue;
95
-      if (longFilename[0] != '\0' &&
96
-          (longFilename[0] == '.' || longFilename[0] == '_')) continue;
97
-      
94
+      if (pn0 == DIR_NAME_DELETED || pn0 == '.' || pn0 == '_') continue;
95
+      char lf0 = longFilename[0];
96
+      if (lf0 == '.' || lf0 == '_') continue;
97
+
98 98
       if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
99 99
       filenameIsDir=DIR_IS_SUBDIR(&p);
100 100
 

+ 79
- 226
Marlin/dogm_lcd_implementation.h View File

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

+ 74
- 244
Marlin/ultralcd.cpp View File

@@ -184,6 +184,14 @@ menuFunc_t callbackFunc;
184 184
 // place-holders for Ki and Kd edits
185 185
 float raw_Ki, raw_Kd;
186 186
 
187
+static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
188
+  if (currentMenu != menu) {
189
+    currentMenu = menu;
190
+    encoderPosition = encoder;
191
+    if (feedback) lcd_quick_feedback();
192
+  }
193
+}
194
+
187 195
 /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
188 196
 static void lcd_status_screen()
189 197
 {
@@ -218,9 +226,7 @@ static void lcd_status_screen()
218 226
 
219 227
     if (current_click)
220 228
     {
221
-        currentMenu = lcd_main_menu;
222
-        encoderPosition = 0;
223
-        lcd_quick_feedback();
229
+        lcd_goto_menu(lcd_main_menu);
224 230
         lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
225 231
 #ifdef FILAMENT_LCD_DISPLAY
226 232
         message_millis=millis();  //get status message to show up for a while
@@ -255,7 +261,7 @@ static void lcd_status_screen()
255 261
 
256 262
     if (feedmultiply < 10)
257 263
         feedmultiply = 10;
258
-    if (feedmultiply > 999)
264
+    else if (feedmultiply > 999)
259 265
         feedmultiply = 999;
260 266
 #endif//ULTIPANEL
261 267
 }
@@ -263,10 +269,8 @@ static void lcd_status_screen()
263 269
 #ifdef ULTIPANEL
264 270
 static void lcd_return_to_status()
265 271
 {
266
-    encoderPosition = 0;
267
-    currentMenu = lcd_status_screen;
272
+    lcd_goto_menu(lcd_status_screen, 0, false);
268 273
 }
269
-
270 274
 static void lcd_sdcard_pause()
271 275
 {
272 276
     card.pauseSDPrint();
@@ -357,65 +361,20 @@ void lcd_set_home_offsets()
357 361
 
358 362
 
359 363
 #ifdef BABYSTEPPING
360
-static void lcd_babystep_x()
361
-{
362
-    if (encoderPosition != 0)
363
-    {
364
-        babystepsTodo[X_AXIS]+=(int)encoderPosition;
365
-        encoderPosition=0;
366
-        lcdDrawUpdate = 1;
367
-    }
368
-    if (lcdDrawUpdate)
369
-    {
370
-        lcd_implementation_drawedit(PSTR(MSG_BABYSTEPPING_X),"");
371
-    }
372
-    if (LCD_CLICKED)
373
-    {
374
-        lcd_quick_feedback();
375
-        currentMenu = lcd_tune_menu;
376
-        encoderPosition = 0;
377
-    }
378
-}
379 364
 
380
-static void lcd_babystep_y()
381
-{
382
-    if (encoderPosition != 0)
383
-    {
384
-        babystepsTodo[Y_AXIS]+=(int)encoderPosition;
385
-        encoderPosition=0;
386
-        lcdDrawUpdate = 1;
387
-    }
388
-    if (lcdDrawUpdate)
389
-    {
390
-        lcd_implementation_drawedit(PSTR(MSG_BABYSTEPPING_Y),"");
365
+  static void _lcd_babystep(int axis, const char *msg) {
366
+    if (encoderPosition != 0) {
367
+      babystepsTodo[axis] += (int)encoderPosition;
368
+      encoderPosition = 0;
369
+      lcdDrawUpdate = 1;
391 370
     }
392
-    if (LCD_CLICKED)
393
-    {
394
-        lcd_quick_feedback();
395
-        currentMenu = lcd_tune_menu;
396
-        encoderPosition = 0;
397
-    }
398
-}
371
+    if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(msg), "");
372
+    if (LCD_CLICKED) lcd_goto_menu(lcd_tune_menu);
373
+  }
374
+  static void lcd_babystep_x() { _lcd_babystep(X_AXIS, MSG_BABYSTEPPING_X); }
375
+  static void lcd_babystep_y() { _lcd_babystep(Y_AXIS, MSG_BABYSTEPPING_Y); }
376
+  static void lcd_babystep_z() { _lcd_babystep(Z_AXIS, MSG_BABYSTEPPING_Z); }
399 377
 
400
-static void lcd_babystep_z()
401
-{
402
-    if (encoderPosition != 0)
403
-    {
404
-        babystepsTodo[Z_AXIS]+=BABYSTEP_Z_MULTIPLICATOR*(int)encoderPosition;
405
-        encoderPosition=0;
406
-        lcdDrawUpdate = 1;
407
-    }
408
-    if (lcdDrawUpdate)
409
-    {
410
-        lcd_implementation_drawedit(PSTR(MSG_BABYSTEPPING_Z),"");
411
-    }
412
-    if (LCD_CLICKED)
413
-    {
414
-        lcd_quick_feedback();
415
-        currentMenu = lcd_tune_menu;
416
-        encoderPosition = 0;
417
-    }
418
-}
419 378
 #endif //BABYSTEPPING
420 379
 
421 380
 static void lcd_tune_menu()
@@ -644,96 +603,28 @@ static void lcd_prepare_menu()
644 603
 float move_menu_scale;
645 604
 static void lcd_move_menu_axis();
646 605
 
647
-static void lcd_move_x()
648
-{
649
-    if (encoderPosition != 0)
650
-    {
651
-        refresh_cmd_timeout();
652
-        current_position[X_AXIS] += float((int)encoderPosition) * move_menu_scale;
653
-        if (min_software_endstops && current_position[X_AXIS] < X_MIN_POS)
654
-            current_position[X_AXIS] = X_MIN_POS;
655
-        if (max_software_endstops && current_position[X_AXIS] > X_MAX_POS)
656
-            current_position[X_AXIS] = X_MAX_POS;
657
-        encoderPosition = 0;
658
-        #ifdef DELTA
659
-        calculate_delta(current_position);
660
-        plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder);
661
-        #else
662
-        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[X_AXIS]/60, active_extruder);
663
-        #endif
664
-        lcdDrawUpdate = 1;
665
-    }
666
-    if (lcdDrawUpdate)
667
-    {
668
-        lcd_implementation_drawedit(PSTR("X"), ftostr31(current_position[X_AXIS]));
669
-    }
670
-    if (LCD_CLICKED)
671
-    {
672
-        lcd_quick_feedback();
673
-        currentMenu = lcd_move_menu_axis;
674
-        encoderPosition = 0;
675
-    }
676
-}
677
-static void lcd_move_y()
678
-{
679
-    if (encoderPosition != 0)
680
-    {
681
-        refresh_cmd_timeout();
682
-        current_position[Y_AXIS] += float((int)encoderPosition) * move_menu_scale;
683
-        if (min_software_endstops && current_position[Y_AXIS] < Y_MIN_POS)
684
-            current_position[Y_AXIS] = Y_MIN_POS;
685
-        if (max_software_endstops && current_position[Y_AXIS] > Y_MAX_POS)
686
-            current_position[Y_AXIS] = Y_MAX_POS;
687
-        encoderPosition = 0;
688
-        #ifdef DELTA
689
-        calculate_delta(current_position);
690
-        plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[Y_AXIS]/60, active_extruder);
691
-        #else
692
-        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Y_AXIS]/60, active_extruder);
693
-        #endif
694
-        lcdDrawUpdate = 1;
695
-    }
696
-    if (lcdDrawUpdate)
697
-    {
698
-        lcd_implementation_drawedit(PSTR("Y"), ftostr31(current_position[Y_AXIS]));
699
-    }
700
-    if (LCD_CLICKED)
701
-    {
702
-        lcd_quick_feedback();
703
-        currentMenu = lcd_move_menu_axis;
704
-        encoderPosition = 0;
705
-    }
706
-}
707
-static void lcd_move_z()
708
-{
709
-    if (encoderPosition != 0)
710
-    {
711
-        refresh_cmd_timeout();
712
-        current_position[Z_AXIS] += float((int)encoderPosition) * move_menu_scale;
713
-        if (min_software_endstops && current_position[Z_AXIS] < Z_MIN_POS)
714
-            current_position[Z_AXIS] = Z_MIN_POS;
715
-        if (max_software_endstops && current_position[Z_AXIS] > Z_MAX_POS)
716
-            current_position[Z_AXIS] = Z_MAX_POS;
717
-        encoderPosition = 0;
718
-        #ifdef DELTA
719
-        calculate_delta(current_position);
720
-        plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS]/60, active_extruder);
721
-        #else
722
-        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS]/60, active_extruder);
723
-        #endif
724
-        lcdDrawUpdate = 1;
725
-    }
726
-    if (lcdDrawUpdate)
727
-    {
728
-        lcd_implementation_drawedit(PSTR("Z"), ftostr31(current_position[Z_AXIS]));
729
-    }
730
-    if (LCD_CLICKED)
731
-    {
732
-        lcd_quick_feedback();
733
-        currentMenu = lcd_move_menu_axis;
734
-        encoderPosition = 0;
735
-    }
606
+static void _lcd_move(const char *name, int axis, int min, int max) {
607
+  if (encoderPosition != 0) {
608
+    refresh_cmd_timeout();
609
+    current_position[axis] += float((int)encoderPosition) * move_menu_scale;
610
+    if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
611
+    if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
612
+    encoderPosition = 0;
613
+    #ifdef DELTA
614
+      calculate_delta(current_position);
615
+      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
616
+    #else
617
+      plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
618
+    #endif
619
+    lcdDrawUpdate = 1;
620
+  }
621
+  if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
622
+  if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
736 623
 }
624
+static void lcd_move_x() { _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS); }
625
+static void lcd_move_y() { _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
626
+static void lcd_move_z() { _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
627
+
737 628
 static void lcd_move_e()
738 629
 {
739 630
     if (encoderPosition != 0)
@@ -752,12 +643,7 @@ static void lcd_move_e()
752 643
     {
753 644
         lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
754 645
     }
755
-    if (LCD_CLICKED)
756
-    {
757
-        lcd_quick_feedback();
758
-        currentMenu = lcd_move_menu_axis;
759
-        encoderPosition = 0;
760
-    }
646
+    if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
761 647
 }
762 648
 
763 649
 static void lcd_move_menu_axis()
@@ -951,12 +837,7 @@ static void lcd_set_contrast()
951 837
     {
952 838
         lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
953 839
     }
954
-    if (LCD_CLICKED)
955
-    {
956
-        lcd_quick_feedback();
957
-        currentMenu = lcd_control_menu;
958
-        encoderPosition = 0;
959
-    }
840
+    if (LCD_CLICKED) lcd_goto_menu(lcd_control_menu);
960 841
 }
961 842
 #endif
962 843
 
@@ -979,7 +860,8 @@ static void lcd_control_retract_menu()
979 860
     MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
980 861
     END_MENU();
981 862
 }
982
-#endif
863
+
864
+#endif //FWRETRACT
983 865
 
984 866
 #if SDCARDDETECT == -1
985 867
 static void lcd_sd_refresh()
@@ -1052,27 +934,12 @@ void lcd_sdcard_menu()
1052 934
         if (LCD_CLICKED) \
1053 935
         { \
1054 936
             *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
1055
-            lcd_quick_feedback(); \
1056
-            currentMenu = prevMenu; \
1057
-            encoderPosition = prevEncoderPosition; \
937
+            lcd_goto_menu(prevMenu, prevEncoderPosition); \
1058 938
         } \
1059 939
     } \
1060
-    void menu_edit_callback_ ## _name () \
1061
-    { \
1062
-        if ((int32_t)encoderPosition < 0) \
1063
-            encoderPosition = 0; \
1064
-        if ((int32_t)encoderPosition > maxEditValue) \
1065
-            encoderPosition = maxEditValue; \
1066
-        if (lcdDrawUpdate) \
1067
-            lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
1068
-        if (LCD_CLICKED) \
1069
-        { \
1070
-            *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
1071
-            lcd_quick_feedback(); \
1072
-            currentMenu = prevMenu; \
1073
-            encoderPosition = prevEncoderPosition; \
1074
-            (*callbackFunc)();\
1075
-        } \
940
+    void menu_edit_callback_ ## _name () { \
941
+        menu_edit_ ## _name (); \
942
+        if (LCD_CLICKED) (*callbackFunc)(); \
1076 943
     } \
1077 944
     static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
1078 945
     { \
@@ -1157,24 +1024,10 @@ static void lcd_quick_feedback()
1157 1024
 }
1158 1025
 
1159 1026
 /** Menu action functions **/
1160
-static void menu_action_back(menuFunc_t data)
1161
-{
1162
-    currentMenu = data;
1163
-    encoderPosition = 0;
1164
-}
1165
-static void menu_action_submenu(menuFunc_t data)
1166
-{
1167
-    currentMenu = data;
1168
-    encoderPosition = 0;
1169
-}
1170
-static void menu_action_gcode(const char* pgcode)
1171
-{
1172
-    enquecommand_P(pgcode);
1173
-}
1174
-static void menu_action_function(menuFunc_t data)
1175
-{
1176
-    (*data)();
1177
-}
1027
+static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
1028
+static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
1029
+static void menu_action_gcode(const char* pgcode) { enquecommand_P(pgcode); }
1030
+static void menu_action_function(menuFunc_t data) { (*data)(); }
1178 1031
 static void menu_action_sdfile(const char* filename, char* longFilename)
1179 1032
 {
1180 1033
     char cmd[30];
@@ -1459,10 +1312,8 @@ void lcd_buttons_update()
1459 1312
 
1460 1313
     //manage encoder rotation
1461 1314
     uint8_t enc=0;
1462
-    if(buttons&EN_A)
1463
-        enc|=(1<<0);
1464
-    if(buttons&EN_B)
1465
-        enc|=(1<<1);
1315
+    if (buttons & EN_A) enc |= B01;
1316
+    if (buttons & EN_B) enc |= B10;
1466 1317
     if(enc != lastEncoderBits)
1467 1318
     {
1468 1319
         switch(enc)
@@ -1611,6 +1462,7 @@ char *itostr31(const int &xx)
1611 1462
   return conv;
1612 1463
 }
1613 1464
 
1465
+// Convert int to rj string with 123 or -12 format
1614 1466
 char *itostr3(const int &x)
1615 1467
 {
1616 1468
   int xx = x;
@@ -1653,47 +1505,25 @@ char *itostr3left(const int &xx)
1653 1505
   return conv;
1654 1506
 }
1655 1507
 
1656
-char *itostr4(const int &xx)
1657
-{
1658
-  if (xx >= 1000)
1659
-    conv[0]=(xx/1000)%10+'0';
1660
-  else
1661
-    conv[0]=' ';
1662
-  if (xx >= 100)
1663
-    conv[1]=(xx/100)%10+'0';
1664
-  else
1665
-    conv[1]=' ';
1666
-  if (xx >= 10)
1667
-    conv[2]=(xx/10)%10+'0';
1668
-  else
1669
-    conv[2]=' ';
1670
-  conv[3]=(xx)%10+'0';
1671
-  conv[4]=0;
1508
+// Convert int to rj string with 1234 format
1509
+char *itostr4(const int &xx) {
1510
+  conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
1511
+  conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
1512
+  conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
1513
+  conv[3] = xx % 10 + '0';
1514
+  conv[4] = 0;
1672 1515
   return conv;
1673 1516
 }
1674 1517
 
1675
-//  convert float to string with 12345 format
1676
-char *ftostr5(const float &x)
1677
-{
1678
-  long xx=abs(x);
1679
-  if (xx >= 10000)
1680
-    conv[0]=(xx/10000)%10+'0';
1681
-  else
1682
-    conv[0]=' ';
1683
-  if (xx >= 1000)
1684
-    conv[1]=(xx/1000)%10+'0';
1685
-  else
1686
-    conv[1]=' ';
1687
-  if (xx >= 100)
1688
-    conv[2]=(xx/100)%10+'0';
1689
-  else
1690
-    conv[2]=' ';
1691
-  if (xx >= 10)
1692
-    conv[3]=(xx/10)%10+'0';
1693
-  else
1694
-    conv[3]=' ';
1695
-  conv[4]=(xx)%10+'0';
1696
-  conv[5]=0;
1518
+//  convert float to rj string with 12345 format
1519
+char *ftostr5(const float &x) {
1520
+  long xx = abs(x);
1521
+  conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
1522
+  conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
1523
+  conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
1524
+  conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
1525
+  conv[4] = xx % 10 + '0';
1526
+  conv[5] = 0;
1697 1527
   return conv;
1698 1528
 }
1699 1529
 

+ 3
- 2
Marlin/ultralcd.h View File

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

Loading…
Cancel
Save