浏览代码

Move SD_REPRINT_LAST_SELECTED_FILE to ultralcd.cpp

Scott Lahteine 7 年前
父节点
当前提交
8949c8c0a5
共有 3 个文件被更改,包括 45 次插入33 次删除
  1. 40
    15
      Marlin/src/lcd/ultralcd.cpp
  2. 4
    0
      Marlin/src/lcd/ultralcd.h
  3. 1
    18
      Marlin/src/sd/cardreader.cpp

+ 40
- 15
Marlin/src/lcd/ultralcd.cpp 查看文件

@@ -3745,22 +3745,45 @@ void kill_screen(const char* lcd_msg) {
3745 3745
      * "Print from SD" submenu
3746 3746
      *
3747 3747
      */
3748
+
3748 3749
     #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
3749
-      uint32_t saved_encoderPosition = 0;
3750
-      static millis_t assume_print_finished = 0;
3750
+      uint32_t last_sdfile_encoderPosition = 0xFFFF;
3751
+
3752
+      void lcd_reselect_last_file() {
3753
+        if (last_sdfile_encoderPosition == 0xFFFF) return;
3754
+        #if ENABLED(DOGLCD)
3755
+          // Some of this is a hack to force the screen update to work.
3756
+          // TODO: Fix the real issue that causes this!
3757
+          lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
3758
+          _lcd_synchronize();
3759
+          safe_delay(50);
3760
+          _lcd_synchronize();
3761
+          lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
3762
+          drawing_screen = screen_changed = true;
3763
+        #endif
3764
+
3765
+        lcd_goto_screen(lcd_sdcard_menu, last_sdfile_encoderPosition);
3766
+        defer_return_to_status = true;
3767
+        last_sdfile_encoderPosition == 0xFFFF;
3768
+
3769
+        #if ENABLED(DOGLCD)
3770
+          lcd_update();
3771
+        #endif
3772
+      }
3751 3773
     #endif
3752 3774
 
3753 3775
     void lcd_sdcard_menu() {
3754 3776
       ENCODER_DIRECTION_MENUS();
3755 3777
 
3756 3778
       #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
3779
+        static millis_t assume_print_finished = 0;
3757 3780
         if (ELAPSED(millis(), assume_print_finished)) { // if the printer has been busy printing, lcd_sdcard_menu() should not
3758 3781
           lcdDrawUpdate = LCDVIEW_REDRAW_NOW;           // have been active for 5 seconds.  In this case, restore the previous
3759
-          encoderPosition = saved_encoderPosition;      // encoderPosition to the last selected item.
3782
+          encoderPosition = last_sdfile_encoderPosition;      // encoderPosition to the last selected item.
3760 3783
           assume_print_finished = millis() + 5000;
3761 3784
         }
3762
-        saved_encoderPosition = encoderPosition;
3763
-        defer_return_to_status = true;
3785
+        last_sdfile_encoderPosition = encoderPosition;   // needed as a workaround for the 5s timer
3786
+        //defer_return_to_status = true;           // already done in lcd_reselect_last_file
3764 3787
       #endif
3765 3788
 
3766 3789
       const uint16_t fileCnt = card.getnrfilenames();
@@ -4414,7 +4437,7 @@ void kill_screen(const char* lcd_msg) {
4414 4437
 
4415 4438
     void menu_action_sdfile(const char* filename, char* longFilename) {
4416 4439
       #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
4417
-        saved_encoderPosition = encoderPosition;  // Save which file was selected for later use
4440
+        last_sdfile_encoderPosition = encoderPosition;  // Save which file was selected for later use
4418 4441
       #endif
4419 4442
       UNUSED(longFilename);
4420 4443
       card.openAndPrintFile(filename);
@@ -4722,16 +4745,18 @@ void lcd_update() {
4722 4745
     // then we want to use 1/2 of the time only.
4723 4746
     uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
4724 4747
 
4725
-    #if ENABLED(DOGLCD)
4726
-      if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)
4727
-      #if ENABLED(SDSUPPORT)
4728
-        || (currentScreen == lcd_sdcard_menu)
4748
+    if (
4749
+      #if ENABLED(DOGLCD)
4750
+        (lcdDrawUpdate || drawing_screen) && (
4751
+          !bbr2 || (bbr2 > max_display_update_time)
4752
+          #if ENABLED(SDSUPPORT)
4753
+            || currentScreen == lcd_sdcard_menu
4754
+          #endif
4755
+        )
4756
+      #else
4757
+        lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time))
4729 4758
       #endif
4730
-      ))
4731
-    #else
4732
-      if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
4733
-    #endif
4734
-    {
4759
+    ) {
4735 4760
       #if ENABLED(DOGLCD)
4736 4761
         if (!drawing_screen)
4737 4762
       #endif

+ 4
- 0
Marlin/src/lcd/ultralcd.h 查看文件

@@ -223,4 +223,8 @@ void lcd_reset_status();
223 223
   #define BUZZ(d,f) lcd_buzz(d, f)
224 224
 #endif
225 225
 
226
+#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
227
+  void lcd_reselect_last_file();
228
+#endif
229
+
226 230
 #endif // ULTRALCD_H

+ 1
- 18
Marlin/src/sd/cardreader.cpp 查看文件

@@ -892,15 +892,6 @@ uint16_t CardReader::get_num_Files() {
892 892
   ;
893 893
 }
894 894
 
895
-#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
896
-  typedef void (*screenFunc_t)();
897
-  extern void lcd_sdcard_menu();
898
-  extern void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0);
899
-  extern uint32_t saved_encoderPosition;
900
-  extern bool screen_changed, drawing_screen, defer_return_to_status;
901
-  void _lcd_synchronize();  // Not declared in any LCD header file.  Probably, that should be changed.
902
-#endif
903
-
904 895
 void CardReader::printingHasFinished() {
905 896
   stepper.synchronize();
906 897
   file.close();
@@ -922,15 +913,7 @@ void CardReader::printingHasFinished() {
922 913
     #endif
923 914
 
924 915
     #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
925
-      lcdDrawUpdate  = LCDVIEW_CALL_REDRAW_NEXT;
926
-      _lcd_synchronize();
927
-      safe_delay(50);
928
-      _lcd_synchronize();
929
-      lcdDrawUpdate  = LCDVIEW_CALL_REDRAW_NEXT;
930
-      drawing_screen = screen_changed = true;
931
-      lcd_goto_screen(lcd_sdcard_menu, saved_encoderPosition);
932
-      defer_return_to_status = true;
933
-      lcd_update();
916
+      lcd_reselect_last_file();
934 917
     #endif
935 918
   }
936 919
 }

正在加载...
取消
保存