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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /**
  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. /**
  35. * Called by FilamentSensorSwitch::run when filament is detected.
  36. * Called by FilamentSensorEncoder::block_completed when motion is detected.
  37. */
  38. void FilamentSensorBase::filament_present(const uint8_t extruder) {
  39. runout.filament_present(extruder); // calls response.filament_present(extruder)
  40. }
  41. #if ENABLED(FILAMENT_MOTION_SENSOR)
  42. uint8_t FilamentSensorEncoder::motion_detected;
  43. #endif
  44. #ifdef FILAMENT_RUNOUT_DISTANCE_MM
  45. float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
  46. volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
  47. #else
  48. int8_t RunoutResponseDebounced::runout_count; // = 0
  49. #endif
  50. //
  51. // Filament Runout event handler
  52. //
  53. #include "../Marlin.h"
  54. #include "../gcode/queue.h"
  55. #if ENABLED(HOST_ACTION_COMMANDS)
  56. #include "host_actions.h"
  57. #endif
  58. #if ENABLED(EXTENSIBLE_UI)
  59. #include "../lcd/extensible_ui/ui_api.h"
  60. #endif
  61. void event_filament_runout() {
  62. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  63. if (did_pause_print) return; // Action already in progress. Purge triggered repeated runout.
  64. #endif
  65. #if ENABLED(EXTENSIBLE_UI)
  66. ExtUI::onFilamentRunout(ExtUI::getActiveTool());
  67. #endif
  68. #if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS)
  69. const char tool = '0'
  70. #if NUM_RUNOUT_SENSORS > 1
  71. + active_extruder
  72. #endif
  73. ;
  74. #endif
  75. //action:out_of_filament
  76. #if ENABLED(HOST_PROMPT_SUPPORT)
  77. host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
  78. host_action_prompt_end();
  79. host_action_prompt_begin(PSTR("FilamentRunout T"), false);
  80. SERIAL_CHAR(tool);
  81. SERIAL_EOL();
  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. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  90. || strstr(FILAMENT_RUNOUT_SCRIPT, "M25")
  91. #endif
  92. )
  93. ) {
  94. host_action_paused(false);
  95. }
  96. else {
  97. // Legacy Repetier command for use until newer version supports standard dialog
  98. // To be removed later when pause command also triggers dialog
  99. #ifdef ACTION_ON_FILAMENT_RUNOUT
  100. host_action(PSTR(ACTION_ON_FILAMENT_RUNOUT " T"), false);
  101. SERIAL_CHAR(tool);
  102. SERIAL_EOL();
  103. #endif
  104. host_action_pause(false);
  105. }
  106. SERIAL_ECHOPGM(" " ACTION_REASON_ON_FILAMENT_RUNOUT " ");
  107. SERIAL_CHAR(tool);
  108. SERIAL_EOL();
  109. #endif // HOST_ACTION_COMMANDS
  110. if (run_runout_script)
  111. queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
  112. }
  113. #endif // HAS_FILAMENT_SENSOR