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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * emergency_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. void quickstop_stepper();
  33. class EmergencyParser {
  34. public:
  35. // Currently looking for: M108, M112, M410, M876
  36. enum State : char {
  37. EP_RESET,
  38. EP_N,
  39. EP_M,
  40. EP_M1,
  41. EP_M10,
  42. EP_M108,
  43. EP_M11,
  44. EP_M112,
  45. EP_M4,
  46. EP_M41,
  47. EP_M410,
  48. #if ENABLED(HOST_PROMPT_SUPPORT)
  49. EP_M8,
  50. EP_M87,
  51. EP_M876,
  52. EP_M876S,
  53. EP_M876SN,
  54. #endif
  55. EP_IGNORE // to '\n'
  56. };
  57. static bool killed_by_M112;
  58. #if ENABLED(HOST_PROMPT_SUPPORT)
  59. static uint8_t M876_reason;
  60. #endif
  61. EmergencyParser() { enable(); }
  62. FORCE_INLINE static void enable() { enabled = true; }
  63. FORCE_INLINE static void disable() { enabled = false; }
  64. FORCE_INLINE static void update(State &state, const uint8_t c) {
  65. #define ISEOL(C) ((C) == '\n' || (C) == '\r')
  66. switch (state) {
  67. case EP_RESET:
  68. switch (c) {
  69. case ' ': case '\n': case '\r': break;
  70. case 'N': state = EP_N; break;
  71. case 'M': state = EP_M; break;
  72. default: state = EP_IGNORE;
  73. }
  74. break;
  75. case EP_N:
  76. switch (c) {
  77. case '0': case '1': case '2':
  78. case '3': case '4': case '5':
  79. case '6': case '7': case '8':
  80. case '9': case '-': case ' ': break;
  81. case 'M': state = EP_M; break;
  82. default: state = EP_IGNORE;
  83. }
  84. break;
  85. case EP_M:
  86. switch (c) {
  87. case ' ': break;
  88. case '1': state = EP_M1; break;
  89. case '4': state = EP_M4; break;
  90. #if ENABLED(HOST_PROMPT_SUPPORT)
  91. case '8': state = EP_M8; break;
  92. #endif
  93. default: state = EP_IGNORE;
  94. }
  95. break;
  96. case EP_M1:
  97. switch (c) {
  98. case '0': state = EP_M10; break;
  99. case '1': state = EP_M11; break;
  100. default: state = EP_IGNORE;
  101. }
  102. break;
  103. case EP_M10:
  104. state = (c == '8') ? EP_M108 : EP_IGNORE;
  105. break;
  106. case EP_M11:
  107. state = (c == '2') ? EP_M112 : EP_IGNORE;
  108. break;
  109. case EP_M4:
  110. state = (c == '1') ? EP_M41 : EP_IGNORE;
  111. break;
  112. case EP_M41:
  113. state = (c == '0') ? EP_M410 : EP_IGNORE;
  114. break;
  115. #if ENABLED(HOST_PROMPT_SUPPORT)
  116. case EP_M8:
  117. state = (c == '7') ? EP_M87 : EP_IGNORE;
  118. break;
  119. case EP_M87:
  120. state = (c == '6') ? EP_M876 : EP_IGNORE;
  121. break;
  122. case EP_M876:
  123. switch (c) {
  124. case ' ': break;
  125. case 'S': state = EP_M876S; break;
  126. default: state = EP_IGNORE; break;
  127. }
  128. break;
  129. case EP_M876S:
  130. switch (c) {
  131. case ' ': break;
  132. case '0': case '1': case '2':
  133. case '3': case '4': case '5':
  134. case '6': case '7': case '8':
  135. case '9':
  136. state = EP_M876SN;
  137. M876_reason = (uint8_t)(c - '0');
  138. break;
  139. }
  140. break;
  141. #endif
  142. case EP_IGNORE:
  143. if (ISEOL(c)) state = EP_RESET;
  144. break;
  145. default:
  146. if (ISEOL(c)) {
  147. if (enabled) switch (state) {
  148. case EP_M108: wait_for_user = wait_for_heatup = false; break;
  149. case EP_M112: killed_by_M112 = true; break;
  150. case EP_M410: quickstop_stepper(); break;
  151. #if ENABLED(HOST_PROMPT_SUPPORT)
  152. case EP_M876SN: host_response_handler(M876_reason); break;
  153. #endif
  154. default: break;
  155. }
  156. state = EP_RESET;
  157. }
  158. }
  159. }
  160. private:
  161. static bool enabled;
  162. };
  163. extern EmergencyParser emergency_parser;