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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * e_parser.h - Intercept special commands directly in the serial stream
  25. */
  26. #include "../inc/MarlinConfigPre.h"
  27. #if ENABLED(HOST_PROMPT_SUPPORT)
  28. #include "host_actions.h"
  29. #endif
  30. // External references
  31. extern bool wait_for_user, wait_for_heatup;
  32. #if ENABLED(REALTIME_REPORTING_COMMANDS)
  33. // From motion.h, which cannot be included here
  34. void report_current_position_moving();
  35. void quickpause_stepper();
  36. void quickresume_stepper();
  37. #endif
  38. #if ENABLED(SOFT_RESET_VIA_SERIAL)
  39. void HAL_reboot();
  40. #endif
  41. class EmergencyParser {
  42. public:
  43. // Currently looking for: M108, M112, M410, M876 S[0-9], S000, P000, R000
  44. enum State : uint8_t {
  45. EP_RESET,
  46. EP_N,
  47. EP_M,
  48. EP_M1,
  49. EP_M10, EP_M108,
  50. EP_M11, EP_M112,
  51. EP_M4, EP_M41, EP_M410,
  52. #if ENABLED(HOST_PROMPT_SUPPORT)
  53. EP_M8, EP_M87, EP_M876, EP_M876S, EP_M876SN,
  54. #endif
  55. #if ENABLED(REALTIME_REPORTING_COMMANDS)
  56. EP_S, EP_S0, EP_S00, EP_GRBL_STATUS,
  57. EP_R, EP_R0, EP_R00, EP_GRBL_RESUME,
  58. EP_P, EP_P0, EP_P00, EP_GRBL_PAUSE,
  59. #endif
  60. #if ENABLED(SOFT_RESET_VIA_SERIAL)
  61. EP_ctrl,
  62. EP_K, EP_KI, EP_KIL, EP_KILL,
  63. #endif
  64. EP_IGNORE // to '\n'
  65. };
  66. static bool killed_by_M112;
  67. static bool quickstop_by_M410;
  68. #if ENABLED(HOST_PROMPT_SUPPORT)
  69. static uint8_t M876_reason;
  70. #endif
  71. EmergencyParser() { enable(); }
  72. FORCE_INLINE static void enable() { enabled = true; }
  73. FORCE_INLINE static void disable() { enabled = false; }
  74. FORCE_INLINE static void update(State &state, const uint8_t c) {
  75. switch (state) {
  76. case EP_RESET:
  77. switch (c) {
  78. case ' ': case '\n': case '\r': break;
  79. case 'N': state = EP_N; break;
  80. case 'M': state = EP_M; break;
  81. #if ENABLED(REALTIME_REPORTING_COMMANDS)
  82. case 'S': state = EP_S; break;
  83. case 'P': state = EP_P; break;
  84. case 'R': state = EP_R; break;
  85. #endif
  86. #if ENABLED(SOFT_RESET_VIA_SERIAL)
  87. case '^': state = EP_ctrl; break;
  88. case 'K': state = EP_K; break;
  89. #endif
  90. default: state = EP_IGNORE;
  91. }
  92. break;
  93. case EP_N:
  94. switch (c) {
  95. case '0' ... '9':
  96. case '-': case ' ': break;
  97. case 'M': state = EP_M; break;
  98. #if ENABLED(REALTIME_REPORTING_COMMANDS)
  99. case 'S': state = EP_S; break;
  100. case 'P': state = EP_P; break;
  101. case 'R': state = EP_R; break;
  102. #endif
  103. default: state = EP_IGNORE;
  104. }
  105. break;
  106. #if ENABLED(REALTIME_REPORTING_COMMANDS)
  107. case EP_S: state = (c == '0') ? EP_S0 : EP_IGNORE; break;
  108. case EP_S0: state = (c == '0') ? EP_S00 : EP_IGNORE; break;
  109. case EP_S00: state = (c == '0') ? EP_GRBL_STATUS : EP_IGNORE; break;
  110. case EP_R: state = (c == '0') ? EP_R0 : EP_IGNORE; break;
  111. case EP_R0: state = (c == '0') ? EP_R00 : EP_IGNORE; break;
  112. case EP_R00: state = (c == '0') ? EP_GRBL_RESUME : EP_IGNORE; break;
  113. case EP_P: state = (c == '0') ? EP_P0 : EP_IGNORE; break;
  114. case EP_P0: state = (c == '0') ? EP_P00 : EP_IGNORE; break;
  115. case EP_P00: state = (c == '0') ? EP_GRBL_PAUSE : EP_IGNORE; break;
  116. #endif
  117. #if ENABLED(SOFT_RESET_VIA_SERIAL)
  118. case EP_ctrl: state = (c == 'X') ? EP_KILL : EP_IGNORE; break;
  119. case EP_K: state = (c == 'I') ? EP_KI : EP_IGNORE; break;
  120. case EP_KI: state = (c == 'L') ? EP_KIL : EP_IGNORE; break;
  121. case EP_KIL: state = (c == 'L') ? EP_KILL : EP_IGNORE; break;
  122. #endif
  123. case EP_M:
  124. switch (c) {
  125. case ' ': break;
  126. case '1': state = EP_M1; break;
  127. case '4': state = EP_M4; break;
  128. #if ENABLED(HOST_PROMPT_SUPPORT)
  129. case '8': state = EP_M8; break;
  130. #endif
  131. default: state = EP_IGNORE;
  132. }
  133. break;
  134. case EP_M1:
  135. switch (c) {
  136. case '0': state = EP_M10; break;
  137. case '1': state = EP_M11; break;
  138. default: state = EP_IGNORE;
  139. }
  140. break;
  141. case EP_M10: state = (c == '8') ? EP_M108 : EP_IGNORE; break;
  142. case EP_M11: state = (c == '2') ? EP_M112 : EP_IGNORE; break;
  143. case EP_M4: state = (c == '1') ? EP_M41 : EP_IGNORE; break;
  144. case EP_M41: state = (c == '0') ? EP_M410 : EP_IGNORE; break;
  145. #if ENABLED(HOST_PROMPT_SUPPORT)
  146. case EP_M8: state = (c == '7') ? EP_M87 : EP_IGNORE; break;
  147. case EP_M87: state = (c == '6') ? EP_M876 : EP_IGNORE; break;
  148. case EP_M876:
  149. switch (c) {
  150. case ' ': break;
  151. case 'S': state = EP_M876S; break;
  152. default: state = EP_IGNORE; break;
  153. }
  154. break;
  155. case EP_M876S:
  156. switch (c) {
  157. case ' ': break;
  158. case '0' ... '9':
  159. state = EP_M876SN;
  160. M876_reason = uint8_t(c - '0');
  161. break;
  162. }
  163. break;
  164. #endif
  165. case EP_IGNORE:
  166. if (ISEOL(c)) state = EP_RESET;
  167. break;
  168. default:
  169. if (ISEOL(c)) {
  170. if (enabled) switch (state) {
  171. case EP_M108: wait_for_user = wait_for_heatup = false; break;
  172. case EP_M112: killed_by_M112 = true; break;
  173. case EP_M410: quickstop_by_M410 = true; break;
  174. #if ENABLED(HOST_PROMPT_SUPPORT)
  175. case EP_M876SN: hostui.handle_response(M876_reason); break;
  176. #endif
  177. #if ENABLED(REALTIME_REPORTING_COMMANDS)
  178. case EP_GRBL_STATUS: report_current_position_moving(); break;
  179. case EP_GRBL_PAUSE: quickpause_stepper(); break;
  180. case EP_GRBL_RESUME: quickresume_stepper(); break;
  181. #endif
  182. #if ENABLED(SOFT_RESET_VIA_SERIAL)
  183. case EP_KILL: HAL_reboot(); break;
  184. #endif
  185. default: break;
  186. }
  187. state = EP_RESET;
  188. }
  189. }
  190. }
  191. private:
  192. static bool enabled;
  193. };
  194. extern EmergencyParser emergency_parser;