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.

host_actions.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #include "../inc/MarlinConfig.h"
  23. #if ENABLED(HOST_ACTION_COMMANDS)
  24. #include "host_actions.h"
  25. //#define DEBUG_HOST_ACTIONS
  26. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  27. #include "pause.h"
  28. #include "../gcode/queue.h"
  29. #endif
  30. #if HAS_FILAMENT_SENSOR
  31. #include "runout.h"
  32. #endif
  33. void host_action(PGM_P const pstr, const bool eol) {
  34. PORT_REDIRECT(SERIAL_BOTH);
  35. SERIAL_ECHOPGM("//action:");
  36. serialprintPGM(pstr);
  37. if (eol) SERIAL_EOL();
  38. }
  39. #ifdef ACTION_ON_KILL
  40. void host_action_kill() { host_action(PSTR(ACTION_ON_KILL)); }
  41. #endif
  42. #ifdef ACTION_ON_PAUSE
  43. void host_action_pause(const bool eol/*=true*/) { host_action(PSTR(ACTION_ON_PAUSE), eol); }
  44. #endif
  45. #ifdef ACTION_ON_PAUSED
  46. void host_action_paused(const bool eol/*=true*/) { host_action(PSTR(ACTION_ON_PAUSED), eol); }
  47. #endif
  48. #ifdef ACTION_ON_RESUME
  49. void host_action_resume() { host_action(PSTR(ACTION_ON_RESUME)); }
  50. #endif
  51. #ifdef ACTION_ON_RESUMED
  52. void host_action_resumed() { host_action(PSTR(ACTION_ON_RESUMED)); }
  53. #endif
  54. #ifdef ACTION_ON_CANCEL
  55. void host_action_cancel() { host_action(PSTR(ACTION_ON_CANCEL)); }
  56. #endif
  57. #ifdef ACTION_ON_START
  58. void host_action_start() { host_action(PSTR(ACTION_ON_START)); }
  59. #endif
  60. #if ENABLED(HOST_PROMPT_SUPPORT)
  61. PGMSTR(CONTINUE_STR, "Continue");
  62. PGMSTR(DISMISS_STR, "Dismiss");
  63. #if HAS_RESUME_CONTINUE
  64. extern bool wait_for_user;
  65. #endif
  66. PromptReason host_prompt_reason = PROMPT_NOT_DEFINED;
  67. void host_action_notify(const char * const message) {
  68. PORT_REDIRECT(SERIAL_BOTH);
  69. host_action(PSTR("notification "), false);
  70. SERIAL_ECHOLN(message);
  71. }
  72. void host_action_notify_P(PGM_P const message) {
  73. PORT_REDIRECT(SERIAL_BOTH);
  74. host_action(PSTR("notification "), false);
  75. serialprintPGM(message);
  76. SERIAL_EOL();
  77. }
  78. void host_action_prompt(PGM_P const ptype, const bool eol=true) {
  79. PORT_REDIRECT(SERIAL_BOTH);
  80. host_action(PSTR("prompt_"), false);
  81. serialprintPGM(ptype);
  82. if (eol) SERIAL_EOL();
  83. }
  84. void host_action_prompt_plus(PGM_P const ptype, PGM_P const pstr, const char extra_char='\0') {
  85. host_action_prompt(ptype, false);
  86. PORT_REDIRECT(SERIAL_BOTH);
  87. SERIAL_CHAR(' ');
  88. serialprintPGM(pstr);
  89. if (extra_char != '\0') SERIAL_CHAR(extra_char);
  90. SERIAL_EOL();
  91. }
  92. void host_action_prompt_begin(const PromptReason reason, PGM_P const pstr, const char extra_char/*='\0'*/) {
  93. host_action_prompt_end();
  94. host_prompt_reason = reason;
  95. host_action_prompt_plus(PSTR("begin"), pstr, extra_char);
  96. }
  97. void host_action_prompt_button(PGM_P const pstr) { host_action_prompt_plus(PSTR("button"), pstr); }
  98. void host_action_prompt_end() { host_action_prompt(PSTR("end")); }
  99. void host_action_prompt_show() { host_action_prompt(PSTR("show")); }
  100. void host_prompt_do(const PromptReason reason, PGM_P const pstr, PGM_P const btn1/*=nullptr*/, PGM_P const btn2/*=nullptr*/) {
  101. host_action_prompt_begin(reason, pstr);
  102. if (btn1) host_action_prompt_button(btn1);
  103. if (btn2) host_action_prompt_button(btn2);
  104. host_action_prompt_show();
  105. }
  106. void filament_load_host_prompt() {
  107. const bool disable_to_continue = TERN0(HAS_FILAMENT_SENSOR, runout.filament_ran_out);
  108. host_prompt_do(PROMPT_FILAMENT_RUNOUT, PSTR("Paused"), PSTR("PurgeMore"),
  109. disable_to_continue ? PSTR("DisableRunout") : CONTINUE_STR
  110. );
  111. }
  112. //
  113. // Handle responses from the host, such as:
  114. // - Filament runout responses: Purge More, Continue
  115. // - General "Continue" response
  116. // - Resume Print response
  117. // - Dismissal of info
  118. //
  119. void host_response_handler(const uint8_t response) {
  120. #ifdef DEBUG_HOST_ACTIONS
  121. static PGMSTR(m876_prefix, "M876 Handle Re");
  122. serialprintPGM(m876_prefix); SERIAL_ECHOLNPAIR("ason: ", host_prompt_reason);
  123. serialprintPGM(m876_prefix); SERIAL_ECHOLNPAIR("sponse: ", response);
  124. #endif
  125. PGM_P msg = PSTR("UNKNOWN STATE");
  126. const PromptReason hpr = host_prompt_reason;
  127. host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic
  128. switch (hpr) {
  129. case PROMPT_FILAMENT_RUNOUT:
  130. msg = PSTR("FILAMENT_RUNOUT");
  131. switch (response) {
  132. case 0: // "Purge More" button
  133. #if BOTH(HAS_LCD_MENU, ADVANCED_PAUSE_FEATURE)
  134. pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // Simulate menu selection (menu exits, doesn't extrude more)
  135. #endif
  136. filament_load_host_prompt(); // Initiate another host prompt. (NOTE: The loop in load_filament may also do this!)
  137. break;
  138. case 1: // "Continue" / "Disable Runout" button
  139. #if BOTH(HAS_LCD_MENU, ADVANCED_PAUSE_FEATURE)
  140. pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // Simulate menu selection
  141. #endif
  142. #if HAS_FILAMENT_SENSOR
  143. if (runout.filament_ran_out) { // Disable a triggered sensor
  144. runout.enabled = false;
  145. runout.reset();
  146. }
  147. #endif
  148. break;
  149. }
  150. break;
  151. case PROMPT_USER_CONTINUE:
  152. TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
  153. msg = PSTR("FILAMENT_RUNOUT_CONTINUE");
  154. break;
  155. case PROMPT_PAUSE_RESUME:
  156. msg = PSTR("LCD_PAUSE_RESUME");
  157. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  158. extern const char M24_STR[];
  159. queue.inject_P(M24_STR);
  160. #endif
  161. break;
  162. case PROMPT_INFO:
  163. msg = PSTR("GCODE_INFO");
  164. break;
  165. default: break;
  166. }
  167. SERIAL_ECHOPGM("M876 Responding PROMPT_");
  168. serialprintPGM(msg);
  169. SERIAL_EOL();
  170. }
  171. #endif // HOST_PROMPT_SUPPORT
  172. #endif // HOST_ACTION_COMMANDS