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.

e_parser.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. 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' ... '9':
  78. case '-': case ' ': break;
  79. case 'M': state = EP_M; break;
  80. default: state = EP_IGNORE;
  81. }
  82. break;
  83. case EP_M:
  84. switch (c) {
  85. case ' ': break;
  86. case '1': state = EP_M1; break;
  87. case '4': state = EP_M4; break;
  88. #if ENABLED(HOST_PROMPT_SUPPORT)
  89. case '8': state = EP_M8; break;
  90. #endif
  91. default: state = EP_IGNORE;
  92. }
  93. break;
  94. case EP_M1:
  95. switch (c) {
  96. case '0': state = EP_M10; break;
  97. case '1': state = EP_M11; break;
  98. default: state = EP_IGNORE;
  99. }
  100. break;
  101. case EP_M10:
  102. state = (c == '8') ? EP_M108 : EP_IGNORE;
  103. break;
  104. case EP_M11:
  105. state = (c == '2') ? EP_M112 : EP_IGNORE;
  106. break;
  107. case EP_M4:
  108. state = (c == '1') ? EP_M41 : EP_IGNORE;
  109. break;
  110. case EP_M41:
  111. state = (c == '0') ? EP_M410 : EP_IGNORE;
  112. break;
  113. #if ENABLED(HOST_PROMPT_SUPPORT)
  114. case EP_M8:
  115. state = (c == '7') ? EP_M87 : EP_IGNORE;
  116. break;
  117. case EP_M87:
  118. state = (c == '6') ? EP_M876 : EP_IGNORE;
  119. break;
  120. case EP_M876:
  121. switch (c) {
  122. case ' ': break;
  123. case 'S': state = EP_M876S; break;
  124. default: state = EP_IGNORE; break;
  125. }
  126. break;
  127. case EP_M876S:
  128. switch (c) {
  129. case ' ': break;
  130. case '0' ... '9':
  131. state = EP_M876SN;
  132. M876_reason = (uint8_t)(c - '0');
  133. break;
  134. }
  135. break;
  136. #endif
  137. case EP_IGNORE:
  138. if (ISEOL(c)) state = EP_RESET;
  139. break;
  140. default:
  141. if (ISEOL(c)) {
  142. if (enabled) switch (state) {
  143. case EP_M108: wait_for_user = wait_for_heatup = false; break;
  144. case EP_M112: killed_by_M112 = true; break;
  145. case EP_M410: quickstop_stepper(); break;
  146. #if ENABLED(HOST_PROMPT_SUPPORT)
  147. case EP_M876SN: host_response_handler(M876_reason); break;
  148. #endif
  149. default: break;
  150. }
  151. state = EP_RESET;
  152. }
  153. }
  154. }
  155. private:
  156. static bool enabled;
  157. };
  158. extern EmergencyParser emergency_parser;