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.

fancheck.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. #if HAS_FANCHECK
  25. #include "../MarlinCore.h"
  26. #include "../lcd/marlinui.h"
  27. #if ENABLED(AUTO_REPORT_FANS)
  28. #include "../libs/autoreport.h"
  29. #endif
  30. #if ENABLED(PARK_HEAD_ON_PAUSE)
  31. #include "../gcode/queue.h"
  32. #endif
  33. /**
  34. * fancheck.h
  35. */
  36. #define TACHO_COUNT TERN(HAS_E7_FAN_TACHO, 8, TERN(HAS_E6_FAN_TACHO, 7, TERN(HAS_E5_FAN_TACHO, 6, TERN(HAS_E4_FAN_TACHO, 5, TERN(HAS_E3_FAN_TACHO, 4, TERN(HAS_E2_FAN_TACHO, 3, TERN(HAS_E1_FAN_TACHO, 2, 1)))))))
  37. class FanCheck {
  38. private:
  39. enum class TachoError : uint8_t { NONE, DETECTED, REPORTED, FIXED };
  40. #if HAS_PWMFANCHECK
  41. static bool measuring; // For future use (3 wires PWM controlled fans)
  42. #else
  43. static constexpr bool measuring = true;
  44. #endif
  45. static Flags<TACHO_COUNT> tacho_state;
  46. static uint16_t edge_counter[TACHO_COUNT];
  47. static uint8_t rps[TACHO_COUNT];
  48. static TachoError error;
  49. static void report_speed_error(uint8_t fan);
  50. public:
  51. static bool enabled;
  52. static void init();
  53. static void update_tachometers();
  54. static void compute_speed(uint16_t elapsedTime);
  55. static void print_fan_states();
  56. #if HAS_PWMFANCHECK
  57. static void toggle_measuring() { measuring = !measuring; }
  58. static bool is_measuring() { return measuring; }
  59. #endif
  60. static void check_deferred_error() {
  61. if (error == TachoError::DETECTED) {
  62. error = TachoError::REPORTED;
  63. TERN(PARK_HEAD_ON_PAUSE, queue.inject(F("M125")), kill(GET_TEXT_F(MSG_FAN_SPEED_FAULT)));
  64. }
  65. }
  66. #if ENABLED(AUTO_REPORT_FANS)
  67. struct AutoReportFan { static void report(); };
  68. static AutoReporter<AutoReportFan> auto_reporter;
  69. #endif
  70. };
  71. extern FanCheck fan_check;
  72. #endif // HAS_FANCHECK