My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M20-M30_M32-M34_M524_M928.cpp 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. #include "../../inc/MarlinConfig.h"
  23. #if ENABLED(SDSUPPORT)
  24. #include "../gcode.h"
  25. #include "../../sd/cardreader.h"
  26. #include "../../module/printcounter.h"
  27. #include "../../module/stepper.h"
  28. #include "../../lcd/ultralcd.h"
  29. #if ENABLED(POWER_LOSS_RECOVERY)
  30. #include "../../feature/power_loss_recovery.h"
  31. #endif
  32. #if ENABLED(PARK_HEAD_ON_PAUSE)
  33. #include "../../feature/pause.h"
  34. #endif
  35. #if ENABLED(PARK_HEAD_ON_PAUSE) || NUM_SERIAL > 1
  36. #include "../queue.h"
  37. #endif
  38. /**
  39. * M20: List SD card to serial output
  40. */
  41. void GcodeSuite::M20() {
  42. #if NUM_SERIAL > 1
  43. const int16_t port = command_queue_port[cmd_queue_index_r];
  44. #endif
  45. SERIAL_PROTOCOLLNPGM_P(port, MSG_BEGIN_FILE_LIST);
  46. card.ls(
  47. #if NUM_SERIAL > 1
  48. port
  49. #endif
  50. );
  51. SERIAL_PROTOCOLLNPGM_P(port, MSG_END_FILE_LIST);
  52. }
  53. /**
  54. * M21: Init SD Card
  55. */
  56. void GcodeSuite::M21() { card.initsd(); }
  57. /**
  58. * M22: Release SD Card
  59. */
  60. void GcodeSuite::M22() { card.release(); }
  61. /**
  62. * M23: Open a file
  63. */
  64. void GcodeSuite::M23() {
  65. #if ENABLED(POWER_LOSS_RECOVERY)
  66. card.removeJobRecoveryFile();
  67. #endif
  68. // Simplify3D includes the size, so zero out all spaces (#7227)
  69. for (char *fn = parser.string_arg; *fn; ++fn) if (*fn == ' ') *fn = '\0';
  70. card.openFile(parser.string_arg, true);
  71. }
  72. /**
  73. * M24: Start or Resume SD Print
  74. */
  75. void GcodeSuite::M24() {
  76. #if ENABLED(PARK_HEAD_ON_PAUSE)
  77. resume_print();
  78. #endif
  79. #if ENABLED(POWER_LOSS_RECOVERY)
  80. if (parser.seenval('S')) card.setIndex(parser.value_long());
  81. #endif
  82. card.startFileprint();
  83. #if ENABLED(POWER_LOSS_RECOVERY)
  84. if (parser.seenval('T'))
  85. print_job_timer.resume(parser.value_long());
  86. else
  87. #endif
  88. print_job_timer.start();
  89. ui.reset_status();
  90. }
  91. /**
  92. * M25: Pause SD Print
  93. */
  94. void GcodeSuite::M25() {
  95. card.pauseSDPrint();
  96. print_job_timer.pause();
  97. #if ENABLED(PARK_HEAD_ON_PAUSE)
  98. enqueue_and_echo_commands_P(PSTR("M125")); // Must be enqueued with pauseSDPrint set to be last in the buffer
  99. #endif
  100. }
  101. /**
  102. * M26: Set SD Card file index
  103. */
  104. void GcodeSuite::M26() {
  105. if (card.flag.cardOK && parser.seenval('S'))
  106. card.setIndex(parser.value_long());
  107. }
  108. /**
  109. * M27: Get SD Card status
  110. * OR, with 'S<seconds>' set the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS)
  111. * OR, with 'C' get the current filename.
  112. */
  113. void GcodeSuite::M27() {
  114. #if NUM_SERIAL > 1
  115. const int16_t port = command_queue_port[cmd_queue_index_r];
  116. #endif
  117. if (parser.seen('C')) {
  118. SERIAL_ECHOPGM_P(port, "Current file: ");
  119. card.printFilename();
  120. }
  121. #if ENABLED(AUTO_REPORT_SD_STATUS)
  122. else if (parser.seenval('S'))
  123. card.set_auto_report_interval(parser.value_byte()
  124. #if NUM_SERIAL > 1
  125. , port
  126. #endif
  127. );
  128. #endif
  129. else
  130. card.getStatus(
  131. #if NUM_SERIAL > 1
  132. port
  133. #endif
  134. );
  135. }
  136. /**
  137. * M28: Start SD Write
  138. */
  139. void GcodeSuite::M28() {
  140. #if ENABLED(FAST_FILE_TRANSFER)
  141. const int16_t port =
  142. #if NUM_SERIAL > 1
  143. command_queue_port[cmd_queue_index_r]
  144. #else
  145. 0
  146. #endif
  147. ;
  148. bool binary_mode = false;
  149. char *p = parser.string_arg;
  150. if (p[0] == 'B' && NUMERIC(p[1])) {
  151. binary_mode = p[1] > '0';
  152. p += 2;
  153. while (*p == ' ') ++p;
  154. }
  155. // Binary transfer mode
  156. if ((card.flag.binary_mode = binary_mode)) {
  157. SERIAL_ECHO_START_P(port);
  158. SERIAL_ECHO_P(port, " preparing to receive: ");
  159. SERIAL_ECHOLN_P(port, p);
  160. card.openFile(p, false);
  161. #if NUM_SERIAL > 1
  162. card.transfer_port = port;
  163. #endif
  164. }
  165. else
  166. card.openFile(p, false);
  167. #else
  168. card.openFile(parser.string_arg, false);
  169. #endif
  170. }
  171. /**
  172. * M29: Stop SD Write
  173. * Processed in write to file routine
  174. */
  175. void GcodeSuite::M29() {
  176. // card.flag.saving = false;
  177. }
  178. /**
  179. * M30 <filename>: Delete SD Card file
  180. */
  181. void GcodeSuite::M30() {
  182. if (card.flag.cardOK) {
  183. card.closefile();
  184. card.removeFile(parser.string_arg);
  185. }
  186. }
  187. /**
  188. * M32: Select file and start SD Print
  189. *
  190. * Examples:
  191. *
  192. * M32 !PATH/TO/FILE.GCO# ; Start FILE.GCO
  193. * M32 P !PATH/TO/FILE.GCO# ; Start FILE.GCO as a procedure
  194. * M32 S60 !PATH/TO/FILE.GCO# ; Start FILE.GCO at byte 60
  195. *
  196. */
  197. void GcodeSuite::M32() {
  198. if (IS_SD_PRINTING()) planner.synchronize();
  199. if (card.flag.cardOK) {
  200. const bool call_procedure = parser.boolval('P');
  201. card.openFile(parser.string_arg, true, call_procedure);
  202. if (parser.seenval('S')) card.setIndex(parser.value_long());
  203. card.startFileprint();
  204. // Procedure calls count as normal print time.
  205. if (!call_procedure) print_job_timer.start();
  206. }
  207. }
  208. #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
  209. /**
  210. * M33: Get the long full path of a file or folder
  211. *
  212. * Parameters:
  213. * <dospath> Case-insensitive DOS-style path to a file or folder
  214. *
  215. * Example:
  216. * M33 miscel~1/armchair/armcha~1.gco
  217. *
  218. * Output:
  219. * /Miscellaneous/Armchair/Armchair.gcode
  220. */
  221. void GcodeSuite::M33() {
  222. card.printLongPath(parser.string_arg
  223. #if NUM_SERIAL > 1
  224. , command_queue_port[cmd_queue_index_r]
  225. #endif
  226. );
  227. }
  228. #endif // LONG_FILENAME_HOST_SUPPORT
  229. #if ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_GCODE)
  230. /**
  231. * M34: Set SD Card Sorting Options
  232. */
  233. void GcodeSuite::M34() {
  234. if (parser.seen('S')) card.setSortOn(parser.value_bool());
  235. if (parser.seenval('F')) {
  236. const int v = parser.value_long();
  237. card.setSortFolders(v < 0 ? -1 : v > 0 ? 1 : 0);
  238. }
  239. //if (parser.seen('R')) card.setSortReverse(parser.value_bool());
  240. }
  241. #endif // SDCARD_SORT_ALPHA && SDSORT_GCODE
  242. /**
  243. * M524: Abort the current SD print job (started with M24)
  244. */
  245. void GcodeSuite::M524() {
  246. if (IS_SD_PRINTING()) card.flag.abort_sd_printing = true;
  247. }
  248. /**
  249. * M928: Start SD Write
  250. */
  251. void GcodeSuite::M928() {
  252. card.openLogFile(parser.string_arg);
  253. }
  254. #endif // SDSUPPORT