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.

runout.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /**
  23. * feature/runout.cpp - Runout sensor support
  24. */
  25. #include "../inc/MarlinConfigPre.h"
  26. #if HAS_FILAMENT_SENSOR
  27. #include "runout.h"
  28. FilamentMonitor runout;
  29. bool FilamentMonitorBase::enabled = true,
  30. FilamentMonitorBase::filament_ran_out; // = false
  31. #if ENABLED(HOST_ACTION_COMMANDS)
  32. bool FilamentMonitorBase::host_handling; // = false
  33. #endif
  34. #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
  35. #include "../module/tool_change.h"
  36. #define DEBUG_OUT ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
  37. #include "../core/debug_out.h"
  38. #endif
  39. #if HAS_FILAMENT_RUNOUT_DISTANCE
  40. float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
  41. volatile float RunoutResponseDelayed::runout_mm_countdown[NUM_RUNOUT_SENSORS];
  42. #if ENABLED(FILAMENT_MOTION_SENSOR)
  43. uint8_t FilamentSensorEncoder::motion_detected;
  44. #endif
  45. #else
  46. int8_t RunoutResponseDebounced::runout_count[NUM_RUNOUT_SENSORS]; // = 0
  47. #endif
  48. //
  49. // Filament Runout event handler
  50. //
  51. #include "../MarlinCore.h"
  52. #include "../feature/pause.h"
  53. #include "../gcode/queue.h"
  54. #if ENABLED(HOST_ACTION_COMMANDS)
  55. #include "host_actions.h"
  56. #endif
  57. #if ENABLED(EXTENSIBLE_UI)
  58. #include "../lcd/extui/ui_api.h"
  59. #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
  60. #include "../lcd/e3v2/enhanced/dwin.h"
  61. #endif
  62. void event_filament_runout(const uint8_t extruder) {
  63. if (did_pause_print) return; // Action already in progress. Purge triggered repeated runout.
  64. #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
  65. if (migration.in_progress) {
  66. DEBUG_ECHOLNPGM("Migration Already In Progress");
  67. return; // Action already in progress. Purge triggered repeated runout.
  68. }
  69. if (migration.automode) {
  70. DEBUG_ECHOLNPGM("Migration Starting");
  71. if (extruder_migration()) return;
  72. }
  73. #endif
  74. TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getTool(extruder)));
  75. TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_FilamentRunout(extruder));
  76. #if ANY(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS, MULTI_FILAMENT_SENSOR)
  77. const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, extruder);
  78. #endif
  79. //action:out_of_filament
  80. #if ENABLED(HOST_PROMPT_SUPPORT)
  81. host_action_prompt_begin(PROMPT_FILAMENT_RUNOUT, PSTR("FilamentRunout T"), tool);
  82. host_action_prompt_show();
  83. #endif
  84. const bool run_runout_script = !runout.host_handling;
  85. #if ENABLED(HOST_ACTION_COMMANDS)
  86. if (run_runout_script
  87. && ( strstr(FILAMENT_RUNOUT_SCRIPT, "M600")
  88. || strstr(FILAMENT_RUNOUT_SCRIPT, "M125")
  89. || TERN0(ADVANCED_PAUSE_FEATURE, strstr(FILAMENT_RUNOUT_SCRIPT, "M25"))
  90. )
  91. ) {
  92. host_action_paused(false);
  93. }
  94. else {
  95. // Legacy Repetier command for use until newer version supports standard dialog
  96. // To be removed later when pause command also triggers dialog
  97. #ifdef ACTION_ON_FILAMENT_RUNOUT
  98. host_action(PSTR(ACTION_ON_FILAMENT_RUNOUT " T"), false);
  99. SERIAL_CHAR(tool);
  100. SERIAL_EOL();
  101. #endif
  102. host_action_pause(false);
  103. }
  104. SERIAL_ECHOPGM(" " ACTION_REASON_ON_FILAMENT_RUNOUT " ");
  105. SERIAL_CHAR(tool);
  106. SERIAL_EOL();
  107. #endif // HOST_ACTION_COMMANDS
  108. if (run_runout_script) {
  109. #if MULTI_FILAMENT_SENSOR
  110. char script[strlen(FILAMENT_RUNOUT_SCRIPT) + 1];
  111. sprintf_P(script, PSTR(FILAMENT_RUNOUT_SCRIPT), tool);
  112. #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
  113. SERIAL_ECHOLNPGM("Runout Command: ", script);
  114. #endif
  115. queue.inject(script);
  116. #else
  117. #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
  118. SERIAL_ECHOPGM("Runout Command: ");
  119. SERIAL_ECHOLNPGM(FILAMENT_RUNOUT_SCRIPT);
  120. #endif
  121. queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
  122. #endif
  123. }
  124. }
  125. #endif // HAS_FILAMENT_SENSOR