|
@@ -0,0 +1,137 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
4
|
+ *
|
|
5
|
+ * Based on Sprinter and grbl.
|
|
6
|
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
7
|
+ *
|
|
8
|
+ * This program is free software: you can redistribute it and/or modify
|
|
9
|
+ * it under the terms of the GNU General Public License as published by
|
|
10
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+ * (at your option) any later version.
|
|
12
|
+ *
|
|
13
|
+ * This program is distributed in the hope that it will be useful,
|
|
14
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+ * GNU General Public License for more details.
|
|
17
|
+ *
|
|
18
|
+ * You should have received a copy of the GNU General Public License
|
|
19
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+ *
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+//
|
|
24
|
+// SD Card Menu
|
|
25
|
+//
|
|
26
|
+
|
|
27
|
+#include "../../inc/MarlinConfigPre.h"
|
|
28
|
+
|
|
29
|
+#if HAS_LCD_MENU && ENABLED(SDSUPPORT)
|
|
30
|
+
|
|
31
|
+#include "menu.h"
|
|
32
|
+#include "../../sd/cardreader.h"
|
|
33
|
+
|
|
34
|
+#if !PIN_EXISTS(SD_DETECT)
|
|
35
|
+ void lcd_sd_refresh() {
|
|
36
|
+ card.initsd();
|
|
37
|
+ encoderTopLine = 0;
|
|
38
|
+ }
|
|
39
|
+#endif
|
|
40
|
+
|
|
41
|
+void lcd_sd_updir() {
|
|
42
|
+ encoderPosition = card.updir() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
|
|
43
|
+ encoderTopLine = 0;
|
|
44
|
+ screen_changed = true;
|
|
45
|
+ lcd_refresh();
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
|
49
|
+ uint32_t last_sdfile_encoderPosition = 0xFFFF;
|
|
50
|
+
|
|
51
|
+ void lcd_reselect_last_file() {
|
|
52
|
+ if (last_sdfile_encoderPosition == 0xFFFF) return;
|
|
53
|
+ #if HAS_GRAPHICAL_LCD
|
|
54
|
+ // Some of this is a hack to force the screen update to work.
|
|
55
|
+ // TODO: Fix the real issue that causes this!
|
|
56
|
+ lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
|
|
57
|
+ lcd_synchronize();
|
|
58
|
+ safe_delay(50);
|
|
59
|
+ lcd_synchronize();
|
|
60
|
+ lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
|
|
61
|
+ drawing_screen = screen_changed = true;
|
|
62
|
+ #endif
|
|
63
|
+
|
|
64
|
+ lcd_goto_screen(menu_sdcard, last_sdfile_encoderPosition);
|
|
65
|
+ defer_return_to_status = true;
|
|
66
|
+ last_sdfile_encoderPosition = 0xFFFF;
|
|
67
|
+
|
|
68
|
+ #if HAS_GRAPHICAL_LCD
|
|
69
|
+ lcd_update();
|
|
70
|
+ #endif
|
|
71
|
+ }
|
|
72
|
+#endif
|
|
73
|
+
|
|
74
|
+void menu_action_sdfile(CardReader &theCard) {
|
|
75
|
+ #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
|
76
|
+ last_sdfile_encoderPosition = encoderPosition; // Save which file was selected for later use
|
|
77
|
+ #endif
|
|
78
|
+ card.openAndPrintFile(theCard.filename);
|
|
79
|
+ lcd_return_to_status();
|
|
80
|
+ lcd_reset_status();
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+void menu_action_sddirectory(CardReader &theCard) {
|
|
84
|
+ card.chdir(theCard.filename);
|
|
85
|
+ encoderTopLine = 0;
|
|
86
|
+ encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
|
|
87
|
+ screen_changed = true;
|
|
88
|
+ #if HAS_GRAPHICAL_LCD
|
|
89
|
+ drawing_screen = false;
|
|
90
|
+ #endif
|
|
91
|
+ lcd_refresh();
|
|
92
|
+}
|
|
93
|
+
|
|
94
|
+void menu_sdcard() {
|
|
95
|
+ ENCODER_DIRECTION_MENUS();
|
|
96
|
+
|
|
97
|
+ const uint16_t fileCnt = card.get_num_Files();
|
|
98
|
+
|
|
99
|
+ START_MENU();
|
|
100
|
+ MENU_BACK(MSG_MAIN);
|
|
101
|
+ card.getWorkDirName();
|
|
102
|
+ if (card.filename[0] == '/') {
|
|
103
|
+ #if !PIN_EXISTS(SD_DETECT)
|
|
104
|
+ MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
|
|
105
|
+ #endif
|
|
106
|
+ }
|
|
107
|
+ else {
|
|
108
|
+ MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ for (uint16_t i = 0; i < fileCnt; i++) {
|
|
112
|
+ if (_menuLineNr == _thisItemNr) {
|
|
113
|
+ const uint16_t nr =
|
|
114
|
+ #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
|
|
115
|
+ fileCnt - 1 -
|
|
116
|
+ #endif
|
|
117
|
+ i;
|
|
118
|
+
|
|
119
|
+ #if ENABLED(SDCARD_SORT_ALPHA)
|
|
120
|
+ card.getfilename_sorted(nr);
|
|
121
|
+ #else
|
|
122
|
+ card.getfilename(nr);
|
|
123
|
+ #endif
|
|
124
|
+
|
|
125
|
+ if (card.filenameIsDir)
|
|
126
|
+ MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
|
|
127
|
+ else
|
|
128
|
+ MENU_ITEM(sdfile, MSG_CARD_MENU, card);
|
|
129
|
+ }
|
|
130
|
+ else {
|
|
131
|
+ MENU_ITEM_DUMMY();
|
|
132
|
+ }
|
|
133
|
+ }
|
|
134
|
+ END_MENU();
|
|
135
|
+}
|
|
136
|
+
|
|
137
|
+#endif // HAS_LCD_MENU && SDSUPPORT
|