Browse Source

Merge pull request #11238 from xC0000005/MalyanLCDUpdate

[2.0.x] Malyan LCD Feedrate + Better Temp Handling
Scott Lahteine 7 years ago
parent
commit
c83109c0ae
No account linked to committer's email address

+ 31
- 19
Marlin/src/lcd/malyanlcd.cpp View File

@@ -77,6 +77,9 @@
77 77
 // Track incoming command bytes from the LCD
78 78
 int inbound_count;
79 79
 
80
+// For sending print completion messages
81
+bool last_printing_status = false;
82
+
80 83
 // Everything written needs the high bit set.
81 84
 void write_to_lcd_P(const char * const message) {
82 85
   char encoded_message[MAX_CURLY_COMMAND];
@@ -106,22 +109,23 @@ void write_to_lcd(const char * const message) {
106 109
  * {C:P050}
107 110
  * Set temp for bed to 50
108 111
  *
112
+ * {C:S09} set feedrate to 90 %.
113
+ * {C:S12} set feedrate to 120 %.
114
+ *
109 115
  * the command portion begins after the :
110 116
  */
111 117
 void process_lcd_c_command(const char* command) {
112 118
   switch (command[0]) {
119
+    case 'C': {
120
+      int raw_feedrate = atoi(command + 1);
121
+      feedrate_percentage = raw_feedrate * 10;
122
+      feedrate_percentage = constrain(feedrate_percentage, 10, 999);
123
+    } break;
113 124
     case 'T': {
114
-      // M104 S<temperature>
115
-      char cmd[20];
116
-      sprintf_P(cmd, PSTR("M104 S%s"), command + 1);
117
-      enqueue_and_echo_command_now(cmd);
125
+      thermalManager.setTargetHotend(atoi(command + 1), 0);
118 126
     } break;
119
-
120 127
     case 'P': {
121
-      // M140 S<temperature>
122
-      char cmd[20];
123
-      sprintf_P(cmd, PSTR("M140 S%s"), command + 1);
124
-      enqueue_and_echo_command_now(cmd);
128
+      thermalManager.setTargetBed(atoi(command + 1));
125 129
     } break;
126 130
 
127 131
     default:
@@ -240,6 +244,7 @@ void process_lcd_p_command(const char* command) {
240 244
       #if ENABLED(SDSUPPORT)
241 245
         // cancel print
242 246
         write_to_lcd_P(PSTR("{SYS:CANCELING}"));
247
+        last_printing_status = false;
243 248
         card.stopSDPrint(
244 249
           #if SD_RESORT
245 250
             true
@@ -280,7 +285,7 @@ void process_lcd_p_command(const char* command) {
280 285
         }
281 286
         else {
282 287
           char message_buffer[MAX_CURLY_COMMAND];
283
-          sprintf_P(message_buffer, PSTR("{PRINTFILE:%s}"), card.filename);
288
+          sprintf_P(message_buffer, PSTR("{PRINTFILE:%s}"), card.longest_filename());
284 289
           write_to_lcd(message_buffer);
285 290
           write_to_lcd_P(PSTR("{SYS:BUILD}"));
286 291
           card.openAndPrintFile(card.filename);
@@ -321,7 +326,7 @@ void process_lcd_s_command(const char* command) {
321 326
 
322 327
     case 'H':
323 328
       // Home all axis
324
-      enqueue_and_echo_command("G28");
329
+      enqueue_and_echo_command("G28", false);
325 330
       break;
326 331
 
327 332
     case 'L': {
@@ -338,7 +343,7 @@ void process_lcd_s_command(const char* command) {
338 343
         uint16_t file_count = card.get_num_Files();
339 344
         for (uint16_t i = 0; i < file_count; i++) {
340 345
           card.getfilename(i);
341
-          sprintf_P(message_buffer, card.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.filename);
346
+          sprintf_P(message_buffer, card.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.longest_filename());
342 347
           write_to_lcd(message_buffer);
343 348
         }
344 349
 
@@ -395,7 +400,7 @@ void process_lcd_command(const char* command) {
395 400
 /**
396 401
  * UC means connected.
397 402
  * UD means disconnected
398
- * The stock firmware considers USB initialied as "connected."
403
+ * The stock firmware considers USB initialized as "connected."
399 404
  */
400 405
 void update_usb_status(const bool forceUpdate) {
401 406
   static bool last_usb_connected_status = false;
@@ -433,14 +438,21 @@ void lcd_update() {
433 438
   }
434 439
 
435 440
   #if ENABLED(SDSUPPORT)
436
-    // If there's a print in progress, we need to emit the status as
437
-    // {TQ:<PERCENT>}
438
-    if (card.sdprinting) {
439
-      // We also need to send: T:-2538.0 E:0
440
-      // I have no idea what this means.
441
+    // The way last printing status works is simple:
442
+    // The UI needs to see at least one TQ which is not 100%
443
+    // and then when the print is complete, one which is.
444
+    static uint8_t last_percent_done = 100;
445
+
446
+    // If there was a print in progress, we need to emit the final
447
+    // print status as {TQ:100}. Reset last percent done so a new print will
448
+    // issue a percent of 0.
449
+    const uint8_t percent_done = card.sdprinting ? card.percentDone() : last_printing_status ? 100 : 0;
450
+    if (percent_done != last_percent_done) {
441 451
       char message_buffer[10];
442
-      sprintf_P(message_buffer, PSTR("{TQ:%03i}"), card.percentDone());
452
+      sprintf_P(message_buffer, PSTR("{TQ:%03i}"), percent_done);
443 453
       write_to_lcd(message_buffer);
454
+      last_percent_done = percent_done;
455
+      last_printing_status = card.sdprinting;
444 456
     }
445 457
   #endif
446 458
 }

+ 13
- 15
Marlin/src/lcd/ultralcd.cpp View File

@@ -277,8 +277,8 @@ uint16_t max_display_update_time = 0;
277 277
 
278 278
   #if ENABLED(SDSUPPORT)
279 279
     void lcd_sdcard_menu();
280
-    void menu_action_sdfile(const char* filename, char* longFilename);
281
-    void menu_action_sddirectory(const char* filename, char* longFilename);
280
+    void menu_action_sdfile(CardReader &theCard);
281
+    void menu_action_sddirectory(CardReader &theCard);
282 282
   #endif
283 283
 
284 284
   ////////////////////////////////////////////
@@ -768,7 +768,7 @@ void lcd_reset_status() {
768 768
     msg = paused;
769 769
   #if ENABLED(SDSUPPORT)
770 770
     else if (card.sdprinting)
771
-      return lcd_setstatus(card.longFilename[0] ? card.longFilename : card.filename, true);
771
+      return lcd_setstatus(card.longest_filename(), true);
772 772
   #endif
773 773
   else if (print_job_timer.isRunning())
774 774
     msg = printing;
@@ -1002,9 +1002,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
1002 1002
       bar_percent = constrain(bar_percent, 0, 100);
1003 1003
       encoderPosition = 0;
1004 1004
       lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
1005
-      lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
1006
-      lcd.print(itostr3(bar_percent)); lcd.write('%');
1007
-      lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
1005
+      lcd_moveto((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
1006
+      lcd_put_u8str(int(bar_percent)); lcd_put_wchar('%');
1007
+      lcd_moveto(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
1008 1008
     }
1009 1009
 
1010 1010
     void _progress_bar_test() {
@@ -2938,7 +2938,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
2938 2938
         destination[manual_move_axis] += manual_move_offset;
2939 2939
 
2940 2940
         // Reset for the next move
2941
-        manual_move_offset = 0.0;
2941
+        manual_move_offset = 0;
2942 2942
         manual_move_axis = (int8_t)NO_AXIS;
2943 2943
 
2944 2944
         // DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
@@ -4042,9 +4042,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
4042 4042
           #endif
4043 4043
 
4044 4044
           if (card.filenameIsDir)
4045
-            MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
4045
+            MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
4046 4046
           else
4047
-            MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
4047
+            MENU_ITEM(sdfile, MSG_CARD_MENU, card);
4048 4048
         }
4049 4049
         else {
4050 4050
           MENU_ITEM_DUMMY();
@@ -4965,19 +4965,17 @@ void lcd_quick_feedback(const bool clear_buttons) {
4965 4965
 
4966 4966
   #if ENABLED(SDSUPPORT)
4967 4967
 
4968
-    void menu_action_sdfile(const char* filename, char* longFilename) {
4968
+    void menu_action_sdfile(CardReader &theCard) {
4969 4969
       #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
4970 4970
         last_sdfile_encoderPosition = encoderPosition;  // Save which file was selected for later use
4971 4971
       #endif
4972
-      UNUSED(longFilename);
4973
-      card.openAndPrintFile(filename);
4972
+      card.openAndPrintFile(theCard.filename);
4974 4973
       lcd_return_to_status();
4975 4974
       lcd_reset_status();
4976 4975
     }
4977 4976
 
4978
-    void menu_action_sddirectory(const char* filename, char* longFilename) {
4979
-      UNUSED(longFilename);
4980
-      card.chdir(filename);
4977
+    void menu_action_sddirectory(CardReader &theCard) {
4978
+      card.chdir(theCard.filename);
4981 4979
       encoderTopLine = 0;
4982 4980
       encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
4983 4981
       screen_changed = true;

+ 8
- 8
Marlin/src/lcd/ultralcd_impl_DOGM.h View File

@@ -518,7 +518,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
518 518
 
519 519
   #if ENABLED(SDSUPPORT)
520 520
 
521
-    static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) {
521
+    static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, CardReader &theCard, const bool isDir) {
522 522
       UNUSED(pstr);
523 523
 
524 524
       lcd_implementation_mark_as_selected(row, isSelected);
@@ -526,23 +526,23 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
526 526
       if (!PAGE_CONTAINS(row_y1, row_y2)) return;
527 527
 
528 528
       constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
529
-      const char *outstr = longFilename[0] ? longFilename : filename;
530
-      if (longFilename[0]) {
529
+      const char *outstr = theCard.longest_filename();
530
+      if (theCard.longFilename[0]) {
531 531
         #if ENABLED(SCROLL_LONG_FILENAMES)
532 532
           if (isSelected) {
533 533
             uint8_t name_hash = row;
534 534
             for (uint8_t l = FILENAME_LENGTH; l--;)
535
-              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l];  // rotate, xor
535
+              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l];  // rotate, xor
536 536
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
537 537
               filename_scroll_hash = name_hash;                                 // Save the new hash
538
-              filename_scroll_max = MAX(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit
538
+              filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
539 539
               filename_scroll_pos = 0;                                          // Reset scroll to the start
540 540
               lcd_status_update_delay = 8;                                      // Don't scroll right away
541 541
             }
542 542
             outstr += filename_scroll_pos;
543 543
           }
544 544
         #else
545
-          longFilename[maxlen] = '\0'; // cutoff at screen edge
545
+          theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
546 546
         #endif
547 547
       }
548 548
 
@@ -554,8 +554,8 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
554 554
       while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
555 555
     }
556 556
 
557
-    #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
558
-    #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
557
+    #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, false)
558
+    #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, true)
559 559
 
560 560
   #endif // SDSUPPORT
561 561
 

+ 10
- 10
Marlin/src/lcd/ultralcd_impl_HD44780.h View File

@@ -926,29 +926,29 @@ static void lcd_implementation_status_screen() {
926 926
 
927 927
   #if ENABLED(SDSUPPORT)
928 928
 
929
-    static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const uint8_t concat, const char post_char) {
929
+    static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, CardReader &theCard, const uint8_t concat, const char post_char) {
930 930
       UNUSED(pstr);
931 931
       lcd_moveto(0, row);
932 932
       lcd_put_wchar(sel ? '>' : ' ');
933 933
 
934 934
       uint8_t n = LCD_WIDTH - concat;
935
-      const char *outstr = longFilename[0] ? longFilename : filename;
936
-      if (longFilename[0]) {
935
+      const char *outstr = theCard.longest_filename();
936
+      if (theCard.longFilename[0]) {
937 937
         #if ENABLED(SCROLL_LONG_FILENAMES)
938 938
           if (sel) {
939 939
             uint8_t name_hash = row;
940 940
             for (uint8_t l = FILENAME_LENGTH; l--;)
941
-              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l];  // rotate, xor
941
+              name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l];  // rotate, xor
942 942
             if (filename_scroll_hash != name_hash) {                            // If the hash changed...
943 943
               filename_scroll_hash = name_hash;                                 // Save the new hash
944
-              filename_scroll_max = MAX(0, utf8_strlen(longFilename) - n);  // Update the scroll limit
944
+              filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - n);  // Update the scroll limit
945 945
               filename_scroll_pos = 0;                                          // Reset scroll to the start
946 946
               lcd_status_update_delay = 8;                                      // Don't scroll right away
947 947
             }
948 948
             outstr += filename_scroll_pos;
949 949
           }
950 950
         #else
951
-          longFilename[n] = '\0'; // cutoff at screen edge
951
+          theCard.longFilename[n] = '\0'; // cutoff at screen edge
952 952
         #endif
953 953
       }
954 954
 
@@ -960,12 +960,12 @@ static void lcd_implementation_status_screen() {
960 960
       lcd_put_wchar(post_char);
961 961
     }
962 962
 
963
-    static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
964
-      lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, ' ');
963
+    static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
964
+      lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, ' ');
965 965
     }
966 966
 
967
-    static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
968
-      lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, LCD_STR_FOLDER[0]);
967
+    static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
968
+      lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, LCD_STR_FOLDER[0]);
969 969
     }
970 970
 
971 971
   #endif // SDSUPPORT

+ 8
- 10
Marlin/src/sd/cardreader.cpp View File

@@ -43,8 +43,6 @@
43 43
 
44 44
 #include <ctype.h>
45 45
 
46
-#define LONGEST_FILENAME (longFilename[0] ? longFilename : filename)
47
-
48 46
 CardReader::CardReader() {
49 47
   #if ENABLED(SDCARD_SORT_ALPHA)
50 48
     sort_count = 0;
@@ -771,7 +769,7 @@ void CardReader::setroot() {
771 769
             getfilename(i);
772 770
             #if ENABLED(SDSORT_DYNAMIC_RAM)
773 771
               // Use dynamic method to copy long filename
774
-              sortnames[i] = strdup(LONGEST_FILENAME);
772
+              sortnames[i] = strdup(longest_filename());
775 773
               #if ENABLED(SDSORT_CACHE_NAMES)
776 774
                 // When caching also store the short name, since
777 775
                 // we're replacing the getfilename() behavior.
@@ -780,10 +778,10 @@ void CardReader::setroot() {
780 778
             #else
781 779
               // Copy filenames into the static array
782 780
               #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
783
-                strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
781
+                strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
784 782
                 sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
785 783
               #else
786
-                strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
784
+                strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
787 785
               #endif
788 786
               #if ENABLED(SDSORT_CACHE_NAMES)
789 787
                 strcpy(sortshort[i], filename);
@@ -831,12 +829,12 @@ void CardReader::setroot() {
831 829
             // throughout the loop. Slow if there are many.
832 830
             #if DISABLED(SDSORT_USES_RAM)
833 831
               getfilename(o1);
834
-              strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
832
+              strcpy(name1, longest_filename()); // save (or getfilename below will trounce it)
835 833
               #if HAS_FOLDER_SORTING
836 834
                 bool dir1 = filenameIsDir;
837 835
               #endif
838 836
               getfilename(o2);
839
-              char *name2 = LONGEST_FILENAME; // use the string in-place
837
+              char *name2 = longest_filename(); // use the string in-place
840 838
             #endif // !SDSORT_USES_RAM
841 839
 
842 840
             // Sort the current pair according to settings.
@@ -874,7 +872,7 @@ void CardReader::setroot() {
874 872
           getfilename(0);
875 873
           #if ENABLED(SDSORT_DYNAMIC_RAM)
876 874
             sortnames = new char*[1];
877
-            sortnames[0] = strdup(LONGEST_FILENAME); // malloc
875
+            sortnames[0] = strdup(longest_filename()); // malloc
878 876
             #if ENABLED(SDSORT_CACHE_NAMES)
879 877
               sortshort = new char*[1];
880 878
               sortshort[0] = strdup(filename);       // malloc
@@ -882,10 +880,10 @@ void CardReader::setroot() {
882 880
             isDir = new uint8_t[1];
883 881
           #else
884 882
             #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
885
-              strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
883
+              strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
886 884
               sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
887 885
             #else
888
-              strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
886
+              strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
889 887
             #endif
890 888
             #if ENABLED(SDSORT_CACHE_NAMES)
891 889
               strcpy(sortshort[0], filename);

+ 2
- 0
Marlin/src/sd/cardreader.h View File

@@ -144,6 +144,8 @@ public:
144 144
     }
145 145
   #endif
146 146
 
147
+  FORCE_INLINE char* longest_filename() { return longFilename[0] ? longFilename : filename; }
148
+
147 149
 public:
148 150
   bool saving, logging, sdprinting, cardOK, filenameIsDir;
149 151
   char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];

Loading…
Cancel
Save