My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

spindle_laser.h 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <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 inline uint8_t powerPercent(const uint8_t pp) { return ui8_to_percent(pp); } // for display
  45. static void init();
  46. static inline bool enabled() { return !!power; }
  47. static inline void set_power(const cutter_power_t pwr) { power = pwr; }
  48. static inline void refresh() { apply_power(power); }
  49. static inline void set_enabled(const bool enable) {
  50. const bool was = enabled();
  51. set_power(enable ? 255 : 0);
  52. if (was != enable) power_delay();
  53. }
  54. static void apply_power(const cutter_power_t inpow);
  55. //static bool active() { return READ(SPINDLE_LASER_ENA_PIN) == SPINDLE_LASER_ACTIVE_HIGH; }
  56. static void update_output();
  57. #if ENABLED(SPINDLE_LASER_PWM)
  58. static void set_ocr(const uint8_t ocr);
  59. static inline void set_ocr_power(const cutter_power_t pwr) { power = pwr; set_ocr(pwr); }
  60. #endif
  61. // Wait for spindle to spin up or spin down
  62. static inline void power_delay() {
  63. #if SPINDLE_LASER_POWERUP_DELAY || SPINDLE_LASER_POWERDOWN_DELAY
  64. safe_delay(enabled() ? SPINDLE_LASER_POWERUP_DELAY : SPINDLE_LASER_POWERDOWN_DELAY);
  65. #endif
  66. }
  67. #if ENABLED(SPINDLE_CHANGE_DIR)
  68. static void set_direction(const bool reverse);
  69. #else
  70. static inline void set_direction(const bool) {}
  71. #endif
  72. static inline void disable() { set_enabled(false); }
  73. static inline void enable_forward() { set_direction(false); set_enabled(true); }
  74. static inline void enable_reverse() { set_direction(true); set_enabled(true); }
  75. };
  76. extern SpindleLaser cutter;