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.

spindle_laser.h 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #pragma once
  23. /**
  24. * feature/spindle_laser.h
  25. * Support for Laser Power or Spindle Power & Direction
  26. */
  27. #include "../inc/MarlinConfig.h"
  28. #if ENABLED(SPINDLE_FEATURE)
  29. #define _MSG_CUTTER(M) MSG_SPINDLE_##M
  30. #else
  31. #define _MSG_CUTTER(M) MSG_LASER_##M
  32. #endif
  33. #define MSG_CUTTER(M) _MSG_CUTTER(M)
  34. #if SPEED_POWER_MAX > 255
  35. typedef uint16_t cutter_power_t;
  36. #define CUTTER_MENU_TYPE uint16_5
  37. #else
  38. typedef uint8_t cutter_power_t;
  39. #define CUTTER_MENU_TYPE uint8
  40. #endif
  41. class SpindleLaser {
  42. public:
  43. static cutter_power_t power;
  44. static void init();
  45. static inline bool enabled() { return !!power; }
  46. static inline void set_power(const cutter_power_t pwr) { power = pwr; }
  47. static inline void refresh() { apply_power(power); }
  48. static inline void set_enabled(const bool enable) {
  49. const bool was = enabled();
  50. set_power(enable ? 255 : 0);
  51. if (was != enable) power_delay();
  52. }
  53. static void apply_power(const cutter_power_t inpow);
  54. //static bool active() { return READ(SPINDLE_LASER_ENA_PIN) == SPINDLE_LASER_ACTIVE_HIGH; }
  55. static void update_output();
  56. #if ENABLED(SPINDLE_LASER_PWM)
  57. static void set_ocr(const uint8_t ocr);
  58. static inline void set_ocr_power(const cutter_power_t pwr) { power = pwr; set_ocr(pwr); }
  59. #endif
  60. // Wait for spindle to spin up or spin down
  61. static inline void power_delay() {
  62. #if SPINDLE_LASER_POWERUP_DELAY || SPINDLE_LASER_POWERDOWN_DELAY
  63. safe_delay(enabled() ? SPINDLE_LASER_POWERUP_DELAY : SPINDLE_LASER_POWERDOWN_DELAY);
  64. #endif
  65. }
  66. #if ENABLED(SPINDLE_CHANGE_DIR)
  67. static void set_direction(const bool reverse);
  68. #else
  69. static inline void set_direction(const bool) {}
  70. #endif
  71. static inline void disable() { set_enabled(false); }
  72. static inline void enable_forward() { set_direction(false); set_enabled(true); }
  73. static inline void enable_reverse() { set_direction(true); set_enabled(true); }
  74. };
  75. extern SpindleLaser cutter;