Laser updates followup (#18237)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Luu Lac 2020-06-08 19:53:39 -05:00 committed by GitHub
parent 2f28e8ba13
commit 0fa345f98f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 16 deletions

View File

@ -91,8 +91,8 @@ public:
static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K
#endif #endif
static cutter_power_t menuPower; // Power as set via LCD menu in PWM, Percentage or RPM static cutter_power_t menuPower, // Power as set via LCD menu in PWM, Percentage or RPM
static cutter_power_t unitPower; // Power as displayed status in PWM, Percentage or RPM unitPower; // Power as displayed status in PWM, Percentage or RPM
static void init(); static void init();
@ -225,32 +225,37 @@ public:
static inline void inline_disable() { static inline void inline_disable() {
isReady = false; isReady = false;
unitPower = 0; unitPower = 0;
planner.laser_inline.status = 0; planner.laser_inline.status.isPlanned = false;
planner.laser_inline.status.isEnabled = false;
planner.laser_inline.power = 0; planner.laser_inline.power = 0;
} }
// Inline modes of all other functions; all enable planner inline power control // Inline modes of all other functions; all enable planner inline power control
static inline void set_inline_enabled(const bool enable) { static inline void set_inline_enabled(const bool enable) {
if (enable) { inline_power(cpwr_to_upwr(SPEED_POWER_STARTUP)); } if (enable)
else { unitPower = 0; isReady = false; menuPower = 0; TERN(SPINDLE_LASER_PWM, inline_ocr_power, inline_power)(0);} inline_power(cpwr_to_upwr(SPEED_POWER_STARTUP));
else {
isReady = false;
unitPower = menuPower = 0;
planner.laser_inline.status.isPlanned = false;
TERN(SPINDLE_LASER_PWM, inline_ocr_power, inline_power)(0);
}
} }
// Set the power for subsequent movement blocks // Set the power for subsequent movement blocks
static void inline_power(const cutter_power_t upwr) { static void inline_power(const cutter_power_t upwr) {
unitPower = upwr; unitPower = menuPower = upwr;
menuPower = unitPower;
#if ENABLED(SPINDLE_LASER_PWM) #if ENABLED(SPINDLE_LASER_PWM)
isReady = true;
#if ENABLED(SPEED_POWER_RELATIVE) && !CUTTER_UNIT_IS(RPM) // relative mode does not turn laser off at 0, except for RPM #if ENABLED(SPEED_POWER_RELATIVE) && !CUTTER_UNIT_IS(RPM) // relative mode does not turn laser off at 0, except for RPM
planner.laser_inline.status = 0x03; planner.laser_inline.status.isEnabled = true;
planner.laser_inline.power = upower_to_ocr(upwr); planner.laser_inline.power = upower_to_ocr(upwr);
isReady = true;
#else #else
if (upwr > 0)
inline_ocr_power(upower_to_ocr(upwr)); inline_ocr_power(upower_to_ocr(upwr));
#endif #endif
#else #else
planner.laser_inline.status = enabled(pwr) ? 0x03 : 0x01; planner.laser_inline.status.isEnabled = enabled(upwr);
planner.laser_inline.power = pwr; planner.laser_inline.power = upwr;
isReady = enabled(upwr); isReady = enabled(upwr);
#endif #endif
} }
@ -259,7 +264,8 @@ public:
#if ENABLED(SPINDLE_LASER_PWM) #if ENABLED(SPINDLE_LASER_PWM)
static inline void inline_ocr_power(const uint8_t ocrpwr) { static inline void inline_ocr_power(const uint8_t ocrpwr) {
planner.laser_inline.status = ocrpwr ? 0x03 : 0x01; isReady = ocrpwr > 0;
planner.laser_inline.status.isEnabled = ocrpwr > 0;
planner.laser_inline.power = ocrpwr; planner.laser_inline.power = ocrpwr;
} }
#endif #endif

View File

@ -1826,6 +1826,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
// Update block laser power // Update block laser power
#if ENABLED(LASER_POWER_INLINE) #if ENABLED(LASER_POWER_INLINE)
laser_inline.status.isPlanned = true;
block->laser.status = laser_inline.status; block->laser.status = laser_inline.status;
block->laser.power = laser_inline.power; block->laser.power = laser_inline.power;
#endif #endif

View File

@ -355,7 +355,7 @@ class Stepper {
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID) #if ENABLED(LASER_POWER_INLINE_TRAPEZOID)
typedef struct { typedef struct {
bool trap_en; // Trapezoid needed flag (i.e., laser on, planner in control) bool enabled; // Trapezoid needed flag (i.e., laser on, planner in control)
uint8_t cur_power; // Current laser power uint8_t cur_power; // Current laser power
bool cruise_set; // Power set up for cruising? bool cruise_set; // Power set up for cruising?
@ -367,7 +367,7 @@ class Stepper {
#endif #endif
} stepper_laser_t; } stepper_laser_t;
static stepper_laser_t laser; static stepper_laser_t laser_trap;
#endif #endif