My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

host_actions.cpp 6.1KB

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