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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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(FSTR_P const ptype, FSTR_P const fstr, const char extra_char/*='\0'*/) {
  96. prompt(ptype, false);
  97. PORT_REDIRECT(SerialMask::All);
  98. SERIAL_CHAR(' ');
  99. SERIAL_ECHOF(fstr);
  100. if (extra_char != '\0') SERIAL_CHAR(extra_char);
  101. SERIAL_EOL();
  102. }
  103. void HostUI::prompt_begin(const PromptReason reason, FSTR_P const fstr, const char extra_char/*='\0'*/) {
  104. prompt_end();
  105. host_prompt_reason = reason;
  106. prompt_plus(F("begin"), fstr, extra_char);
  107. }
  108. void HostUI::prompt_button(FSTR_P const fstr) { prompt_plus(F("button"), fstr); }
  109. void HostUI::prompt_end() { prompt(F("end")); }
  110. void HostUI::prompt_show() { prompt(F("show")); }
  111. void HostUI::_prompt_show(FSTR_P const btn1, FSTR_P const btn2) {
  112. if (btn1) prompt_button(btn1);
  113. if (btn2) prompt_button(btn2);
  114. prompt_show();
  115. }
  116. void HostUI::prompt_do(const PromptReason reason, FSTR_P const fstr, FSTR_P const btn1/*=nullptr*/, FSTR_P const btn2/*=nullptr*/) {
  117. prompt_begin(reason, fstr);
  118. _prompt_show(btn1, btn2);
  119. }
  120. 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*/) {
  121. prompt_begin(reason, fstr, extra_char);
  122. _prompt_show(btn1, btn2);
  123. }
  124. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  125. void HostUI::filament_load_prompt() {
  126. const bool disable_to_continue = TERN0(HAS_FILAMENT_SENSOR, runout.filament_ran_out);
  127. prompt_do(PROMPT_FILAMENT_RUNOUT, F("Paused"), F("PurgeMore"),
  128. disable_to_continue ? F("DisableRunout") : FPSTR(CONTINUE_STR)
  129. );
  130. }
  131. #endif
  132. //
  133. // Handle responses from the host, such as:
  134. // - Filament runout responses: Purge More, Continue
  135. // - General "Continue" response
  136. // - Resume Print response
  137. // - Dismissal of info
  138. //
  139. void HostUI::handle_response(const uint8_t response) {
  140. const PromptReason hpr = host_prompt_reason;
  141. host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic
  142. switch (hpr) {
  143. case PROMPT_FILAMENT_RUNOUT:
  144. switch (response) {
  145. case 0: // "Purge More" button
  146. #if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
  147. pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // Simulate menu selection (menu exits, doesn't extrude more)
  148. #endif
  149. break;
  150. case 1: // "Continue" / "Disable Runout" button
  151. #if BOTH(M600_PURGE_MORE_RESUMABLE, ADVANCED_PAUSE_FEATURE)
  152. pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // Simulate menu selection
  153. #endif
  154. #if HAS_FILAMENT_SENSOR
  155. if (runout.filament_ran_out) { // Disable a triggered sensor
  156. runout.enabled = false;
  157. runout.reset();
  158. }
  159. #endif
  160. break;
  161. }
  162. break;
  163. case PROMPT_USER_CONTINUE:
  164. TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
  165. break;
  166. case PROMPT_PAUSE_RESUME:
  167. #if BOTH(ADVANCED_PAUSE_FEATURE, SDSUPPORT)
  168. extern const char M24_STR[];
  169. queue.inject_P(M24_STR);
  170. #endif
  171. break;
  172. case PROMPT_INFO:
  173. break;
  174. default: break;
  175. }
  176. }
  177. #endif // HOST_PROMPT_SUPPORT
  178. #endif // HOST_ACTION_COMMANDS