My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

runout.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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.h - Runout sensor support
  24. */
  25. #ifndef _RUNOUT_H_
  26. #define _RUNOUT_H_
  27. #include "../sd/cardreader.h"
  28. #include "../module/printcounter.h"
  29. #include "../module/stepper.h"
  30. #include "../gcode/queue.h"
  31. #include "../inc/MarlinConfig.h"
  32. #if ENABLED(EXTENSIBLE_UI)
  33. #include "../lcd/extensible_ui/ui_api.h"
  34. #endif
  35. #define FIL_RUNOUT_THRESHOLD 5
  36. class FilamentRunoutSensor {
  37. public:
  38. static bool enabled;
  39. FilamentRunoutSensor() {}
  40. static void setup();
  41. FORCE_INLINE static void reset() { runout_count = 0; filament_ran_out = false; }
  42. FORCE_INLINE static void run() {
  43. if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) {
  44. filament_ran_out = true;
  45. #if ENABLED(EXTENSIBLE_UI)
  46. UI::onFilamentRunout();
  47. #endif
  48. enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
  49. planner.synchronize();
  50. }
  51. }
  52. private:
  53. static bool filament_ran_out;
  54. static uint8_t runout_count;
  55. FORCE_INLINE static bool check() {
  56. if (!enabled) return false;
  57. #if NUM_RUNOUT_SENSORS < 2
  58. // A single sensor applying to all extruders
  59. const bool is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
  60. #else
  61. // Read the sensor for the active extruder
  62. bool is_out;
  63. #if ENABLED(DUAL_X_CARRIAGE)
  64. const bool out1 = READ(FIL_RUNOUT_PIN ) == FIL_RUNOUT_INVERTING,
  65. out2 = READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING;
  66. if (extruder_duplication_enabled)
  67. is_out = out1 || out2;
  68. else
  69. is_out = active_extruder ? out2 : out1;
  70. #else
  71. switch (active_extruder) {
  72. case 0: is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; break;
  73. case 1: is_out = READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING; break;
  74. #if NUM_RUNOUT_SENSORS > 2
  75. case 2: is_out = READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING; break;
  76. #if NUM_RUNOUT_SENSORS > 3
  77. case 3: is_out = READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING; break;
  78. #if NUM_RUNOUT_SENSORS > 4
  79. case 4: is_out = READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING; break;
  80. #if NUM_RUNOUT_SENSORS > 5
  81. case 5: is_out = READ(FIL_RUNOUT6_PIN) == FIL_RUNOUT_INVERTING; break;
  82. #endif // > 5
  83. #endif // > 4
  84. #endif // > 3
  85. #endif // > 2
  86. }
  87. #endif
  88. #endif
  89. return (is_out ? ++runout_count : (runout_count = 0)) > FIL_RUNOUT_THRESHOLD;
  90. }
  91. };
  92. extern FilamentRunoutSensor runout;
  93. #endif // _RUNOUT_H_