Add SPINDLE_SERVO option (#19971)
This commit is contained in:
@ -30,6 +30,10 @@
|
||||
|
||||
#include "spindle_laser.h"
|
||||
|
||||
#if ENABLED(SPINDLE_SERVO)
|
||||
#include "../module/servo.h"
|
||||
#endif
|
||||
|
||||
SpindleLaser cutter;
|
||||
uint8_t SpindleLaser::power;
|
||||
bool SpindleLaser::isReady; // Ready to apply power setting from the UI to OCR
|
||||
@ -45,7 +49,11 @@ cutter_power_t SpindleLaser::menuPower, // Power s
|
||||
// Init the cutter to a safe OFF state
|
||||
//
|
||||
void SpindleLaser::init() {
|
||||
OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off
|
||||
#if ENABLED(SPINDLE_SERVO)
|
||||
MOVE_SERVO(SPINDLE_SERVO_NR, SPINDLE_SERVO_MIN);
|
||||
#else
|
||||
OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off
|
||||
#endif
|
||||
#if ENABLED(SPINDLE_CHANGE_DIR)
|
||||
OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3)
|
||||
#endif
|
||||
@ -97,6 +105,8 @@ void SpindleLaser::apply_power(const uint8_t opwr) {
|
||||
ocr_off();
|
||||
isReady = false;
|
||||
}
|
||||
#elif ENABLED(SPINDLE_SERVO)
|
||||
MOVE_SERVO(SPINDLE_SERVO_NR, power);
|
||||
#else
|
||||
WRITE(SPINDLE_LASER_ENA_PIN, enabled() ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE);
|
||||
isReady = true;
|
||||
|
@ -35,6 +35,7 @@
|
||||
#endif
|
||||
|
||||
#define PCT_TO_PWM(X) ((X) * 255 / 100)
|
||||
#define PCT_TO_SERVO(X) ((X) * 180 / 100)
|
||||
|
||||
#ifndef SPEED_POWER_INTERCEPT
|
||||
#define SPEED_POWER_INTERCEPT 0
|
||||
@ -60,7 +61,7 @@ public:
|
||||
}
|
||||
|
||||
// Convert a cpower (e.g., SPEED_POWER_STARTUP) to unit power (upwr, upower),
|
||||
// which can be PWM, Percent, or RPM (rel/abs).
|
||||
// which can be PWM, Percent, Servo angle, or RPM (rel/abs).
|
||||
static const inline cutter_power_t cpwr_to_upwr(const cutter_cpower_t cpwr) { // STARTUP power to Unit power
|
||||
const cutter_power_t upwr = (
|
||||
#if ENABLED(SPINDLE_FEATURE)
|
||||
@ -69,6 +70,8 @@ public:
|
||||
cpwr // to RPM
|
||||
#elif CUTTER_UNIT_IS(PERCENT) // to PCT
|
||||
cpwr_to_pct(cpwr)
|
||||
#elif CUTTER_UNIT_IS(SERVO) // to SERVO angle
|
||||
PCT_TO_SERVO(cpwr_to_pct(cpwr))
|
||||
#else // to PWM
|
||||
PCT_TO_PWM(cpwr_to_pct(cpwr))
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user