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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. #if HAS_RESUME_CONTINUE
  59. extern bool wait_for_user;
  60. #endif
  61. PromptReason host_prompt_reason = PROMPT_NOT_DEFINED;
  62. void host_action_prompt(const char * const ptype, const bool eol=true) {
  63. host_action(PSTR("prompt_"), false);
  64. serialprintPGM(ptype);
  65. if (eol) SERIAL_EOL();
  66. }
  67. void host_action_prompt_plus(const char * const ptype, const char * const pstr, const bool eol=true) {
  68. host_action_prompt(ptype, false);
  69. SERIAL_CHAR(' ');
  70. serialprintPGM(pstr);
  71. if (eol) SERIAL_EOL();
  72. }
  73. void host_action_prompt_begin(const char * const pstr, const bool eol/*=true*/) { host_action_prompt_plus(PSTR("begin"), pstr, eol); }
  74. void host_action_prompt_button(const char * const pstr) { host_action_prompt_plus(PSTR("button"), pstr); }
  75. void host_action_prompt_end() { host_action_prompt(PSTR("end")); }
  76. void host_action_prompt_show() { host_action_prompt(PSTR("show")); }
  77. void host_prompt_do(const PromptReason reason, const char * const pstr, const char * const pbtn/*=nullptr*/) {
  78. host_prompt_reason = reason;
  79. host_action_prompt_end();
  80. host_action_prompt_begin(pstr);
  81. if (pbtn) host_action_prompt_button(pbtn);
  82. host_action_prompt_show();
  83. }
  84. inline void say_m876_response(const char * const pstr) {
  85. SERIAL_ECHOPGM("M876 Responding PROMPT_");
  86. serialprintPGM(pstr);
  87. SERIAL_EOL();
  88. }
  89. void host_response_handler(const uint8_t response) {
  90. #ifdef DEBUG_HOST_ACTIONS
  91. SERIAL_ECHOLNPAIR("M876 Handle Reason: ", host_prompt_reason);
  92. SERIAL_ECHOLNPAIR("M876 Handle Response: ", response);
  93. #endif
  94. const char *msg = PSTR("UNKNOWN STATE");
  95. const PromptReason hpr = host_prompt_reason;
  96. host_prompt_reason = PROMPT_NOT_DEFINED;
  97. switch (hpr) {
  98. case PROMPT_FILAMENT_RUNOUT:
  99. msg = PSTR("FILAMENT_RUNOUT");
  100. if (response == 0) {
  101. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  102. pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE;
  103. #endif
  104. host_action_prompt_end(); // Close current prompt
  105. host_action_prompt_begin(PSTR("Paused"));
  106. host_action_prompt_button(PSTR("Purge More"));
  107. if (false
  108. #if HAS_FILAMENT_SENSOR
  109. || runout.filament_ran_out
  110. #endif
  111. )
  112. host_action_prompt_button(PSTR("DisableRunout"));
  113. else {
  114. host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
  115. host_action_prompt_button(CONTINUE_STR);
  116. }
  117. host_action_prompt_show();
  118. }
  119. else if (response == 1) {
  120. #if HAS_FILAMENT_SENSOR
  121. if (runout.filament_ran_out) {
  122. runout.enabled = false;
  123. runout.reset();
  124. }
  125. #endif
  126. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  127. pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT;
  128. #endif
  129. }
  130. break;
  131. case PROMPT_USER_CONTINUE:
  132. #if HAS_RESUME_CONTINUE
  133. wait_for_user = false;
  134. #endif
  135. msg = PSTR("FILAMENT_RUNOUT_CONTINUE");
  136. break;
  137. case PROMPT_PAUSE_RESUME:
  138. msg = PSTR("LCD_PAUSE_RESUME");
  139. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  140. extern const char M24_STR[];
  141. queue.inject_P(M24_STR);
  142. #endif
  143. break;
  144. case PROMPT_INFO:
  145. msg = PSTR("GCODE_INFO");
  146. break;
  147. default: break;
  148. }
  149. say_m876_response(msg);
  150. }
  151. #endif // HOST_PROMPT_SUPPORT
  152. #endif // HOST_ACTION_COMMANDS