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 7.1KB

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. #include "../inc/MarlinConfig.h"
  23. #if ENABLED(HOST_ACTION_COMMANDS)
  24. //#define DEBUG_HOST_ACTIONS
  25. #include "host_actions.h"
  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. HostUI hostui;
  34. void HostUI::action(FSTR_P const fstr, const bool eol) {
  35. PORT_REDIRECT(SerialMask::All);
  36. SERIAL_ECHOPGM("//action:");
  37. SERIAL_ECHOF(fstr);
  38. if (eol) SERIAL_EOL();
  39. }
  40. #ifdef ACTION_ON_KILL
  41. void HostUI::kill() { action(F(ACTION_ON_KILL)); }
  42. #endif
  43. #ifdef ACTION_ON_PAUSE
  44. void HostUI::pause(const bool eol/*=true*/) { action(F(ACTION_ON_PAUSE), eol); }
  45. #endif
  46. #ifdef ACTION_ON_PAUSED
  47. void HostUI::paused(const bool eol/*=true*/) { action(F(ACTION_ON_PAUSED), eol); }
  48. #endif
  49. #ifdef ACTION_ON_RESUME
  50. void HostUI::resume() { action(F(ACTION_ON_RESUME)); }
  51. #endif
  52. #ifdef ACTION_ON_RESUMED
  53. void HostUI::resumed() { action(F(ACTION_ON_RESUMED)); }
  54. #endif
  55. #ifdef ACTION_ON_CANCEL
  56. void HostUI::cancel() { action(F(ACTION_ON_CANCEL)); }
  57. #endif
  58. #ifdef ACTION_ON_START
  59. void HostUI::start() { action(F(ACTION_ON_START)); }
  60. #endif
  61. #if ENABLED(G29_RETRY_AND_RECOVER)
  62. #ifdef ACTION_ON_G29_RECOVER
  63. void HostUI::g29_recover() { action(F(ACTION_ON_G29_RECOVER)); }
  64. #endif
  65. #ifdef ACTION_ON_G29_FAILURE
  66. void HostUI::g29_failure() { action(F(ACTION_ON_G29_FAILURE)); }
  67. #endif
  68. #endif
  69. #ifdef SHUTDOWN_ACTION
  70. void HostUI::shutdown() { action(F(SHUTDOWN_ACTION)); }
  71. #endif
  72. #if ENABLED(HOST_PROMPT_SUPPORT)
  73. PromptReason HostUI::host_prompt_reason = PROMPT_NOT_DEFINED;
  74. PGMSTR(CONTINUE_STR, "Continue");
  75. PGMSTR(DISMISS_STR, "Dismiss");
  76. #if HAS_RESUME_CONTINUE
  77. extern bool wait_for_user;
  78. #endif
  79. void HostUI::notify(const char * const cstr) {
  80. PORT_REDIRECT(SerialMask::All);
  81. action(F("notification "), false);
  82. SERIAL_ECHOLN(cstr);
  83. }
  84. void HostUI::notify_P(PGM_P const pstr) {
  85. PORT_REDIRECT(SerialMask::All);
  86. action(F("notification "), false);
  87. SERIAL_ECHOLNPGM_P(pstr);
  88. }
  89. void HostUI::prompt(FSTR_P const ptype, const bool eol/*=true*/) {
  90. PORT_REDIRECT(SerialMask::All);
  91. action(F("prompt_"), false);
  92. SERIAL_ECHOF(ptype);
  93. if (eol) SERIAL_EOL();
  94. }
  95. void HostUI::prompt_plus(const bool pgm, FSTR_P const ptype, const char * const str, const char extra_char/*='\0'*/) {
  96. prompt(ptype, false);
  97. PORT_REDIRECT(SerialMask::All);
  98. SERIAL_CHAR(' ');
  99. if (pgm)
  100. SERIAL_ECHOPGM_P(str);
  101. else
  102. SERIAL_ECHO(str);
  103. if (extra_char != '\0') SERIAL_CHAR(extra_char);
  104. SERIAL_EOL();
  105. }
  106. void HostUI::prompt_begin(const PromptReason reason, FSTR_P const fstr, const char extra_char/*='\0'*/) {
  107. prompt_end();
  108. host_prompt_reason = reason;
  109. prompt_plus(F("begin"), fstr, extra_char);
  110. }
  111. void HostUI::prompt_begin(const PromptReason reason, const char * const cstr, const char extra_char/*='\0'*/) {
  112. prompt_end();
  113. host_prompt_reason = reason;
  114. prompt_plus(F("begin"), cstr, extra_char);
  115. }
  116. void HostUI::prompt_end() { prompt(F("end")); }
  117. void HostUI::prompt_show() { prompt(F("show")); }
  118. void HostUI::_prompt_show(FSTR_P const btn1, FSTR_P const btn2) {
  119. if (btn1) prompt_button(btn1);
  120. if (btn2) prompt_button(btn2);
  121. prompt_show();
  122. }
  123. void HostUI::prompt_button(FSTR_P const fstr) { prompt_plus(F("button"), fstr); }
  124. void HostUI::prompt_button(const char * const cstr) { prompt_plus(F("button"), cstr); }
  125. void HostUI::prompt_do(const PromptReason reason, FSTR_P const fstr, FSTR_P const btn1/*=nullptr*/, FSTR_P const btn2/*=nullptr*/) {
  126. prompt_begin(reason, fstr);
  127. _prompt_show(btn1, btn2);
  128. }
  129. void HostUI::prompt_do(const PromptReason reason, const char * const cstr, FSTR_P const btn1/*=nullptr*/, FSTR_P const btn2/*=nullptr*/) {
  130. prompt_begin(reason, cstr);
  131. _prompt_show(btn1, btn2);
  132. }
  133. void HostUI::prompt_do(const PromptReason reason, FSTR_P const fstr, const char extra_char, FSTR_P const btn1/*=nullptr*/, FSTR_P const btn2/*=nullptr*/) {
  134. prompt_begin(reason, fstr, extra_char);
  135. _prompt_show(btn1, btn2);
  136. }
  137. void HostUI::prompt_do(const PromptReason reason, const char * const cstr, const char extra_char, FSTR_P const btn1/*=nullptr*/, FSTR_P const btn2/*=nullptr*/) {
  138. prompt_begin(reason, cstr, extra_char);
  139. _prompt_show(btn1, btn2);
  140. }
  141. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  142. void HostUI::filament_load_prompt() {
  143. const bool disable_to_continue = TERN0(HAS_FILAMENT_SENSOR, runout.filament_ran_out);
  144. prompt_do(PROMPT_FILAMENT_RUNOUT, F("Paused"), F("PurgeMore"),
  145. disable_to_continue ? F("DisableRunout") : FPSTR(CONTINUE_STR)
  146. );
  147. }
  148. #endif
  149. //
  150. // Handle responses from the host, such as:
  151. // - Filament runout responses: Purge More, Continue
  152. // - General "Continue" response
  153. // - Resume Print response
  154. // - Dismissal of info
  155. //
  156. void HostUI::handle_response(const uint8_t response) {
  157. const PromptReason hpr = host_prompt_reason;
  158. host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic
  159. switch (hpr) {
  160. case PROMPT_FILAMENT_RUNOUT:
  161. switch (response) {
  162. case 0: // "Purge More" button
  163. #if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
  164. pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // Simulate menu selection (menu exits, doesn't extrude more)
  165. #endif
  166. break;
  167. case 1: // "Continue" / "Disable Runout" button
  168. #if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
  169. pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // Simulate menu selection
  170. #endif
  171. #if HAS_FILAMENT_SENSOR
  172. if (runout.filament_ran_out) { // Disable a triggered sensor
  173. runout.enabled = false;
  174. runout.reset();
  175. }
  176. #endif
  177. break;
  178. }
  179. break;
  180. case PROMPT_USER_CONTINUE:
  181. TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
  182. break;
  183. case PROMPT_PAUSE_RESUME:
  184. #if BOTH(ADVANCED_PAUSE_FEATURE, SDSUPPORT)
  185. extern const char M24_STR[];
  186. queue.inject_P(M24_STR);
  187. #endif
  188. break;
  189. case PROMPT_INFO:
  190. break;
  191. default: break;
  192. }
  193. }
  194. #endif // HOST_PROMPT_SUPPORT
  195. #endif // HOST_ACTION_COMMANDS