Skip to content

Commit

Permalink
Laser updates followup (MarlinFirmware#18237)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
2 people authored and Alexander Yasnogor committed Aug 7, 2020
1 parent d90a466 commit c318748
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
34 changes: 20 additions & 14 deletions Marlin/src/feature/spindle_laser.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class SpindleLaser {
static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K
#endif

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
static cutter_power_t menuPower, // Power as set via LCD menu in PWM, Percentage or RPM
unitPower; // Power as displayed status in PWM, Percentage or RPM

static void init();

Expand Down Expand Up @@ -225,32 +225,37 @@ class SpindleLaser {
static inline void inline_disable() {
isReady = false;
unitPower = 0;
planner.laser_inline.status = 0;
planner.laser_inline.status.isPlanned = false;
planner.laser_inline.status.isEnabled = false;
planner.laser_inline.power = 0;
}

// Inline modes of all other functions; all enable planner inline power control
static inline void set_inline_enabled(const bool enable) {
if (enable) { inline_power(cpwr_to_upwr(SPEED_POWER_STARTUP)); }
else { unitPower = 0; isReady = false; menuPower = 0; TERN(SPINDLE_LASER_PWM, inline_ocr_power, inline_power)(0);}
if (enable)
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
static void inline_power(const cutter_power_t upwr) {
unitPower = upwr;
menuPower = unitPower;
unitPower = menuPower = upwr;
#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
planner.laser_inline.status = 0x03;
planner.laser_inline.status.isEnabled = true;
planner.laser_inline.power = upower_to_ocr(upwr);
isReady = true;
#else
if (upwr > 0)
inline_ocr_power(upower_to_ocr(upwr));
inline_ocr_power(upower_to_ocr(upwr));
#endif
#else
planner.laser_inline.status = enabled(pwr) ? 0x03 : 0x01;
planner.laser_inline.power = pwr;
planner.laser_inline.status.isEnabled = enabled(upwr);
planner.laser_inline.power = upwr;
isReady = enabled(upwr);
#endif
}
Expand All @@ -259,7 +264,8 @@ class SpindleLaser {

#if ENABLED(SPINDLE_LASER_PWM)
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;
}
#endif
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,

// Update block laser power
#if ENABLED(LASER_POWER_INLINE)
laser_inline.status.isPlanned = true;
block->laser.status = laser_inline.status;
block->laser.power = laser_inline.power;
#endif
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class Stepper {
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID)

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
bool cruise_set; // Power set up for cruising?

Expand All @@ -367,7 +367,7 @@ class Stepper {
#endif
} stepper_laser_t;

static stepper_laser_t laser;
static stepper_laser_t laser_trap;

#endif

Expand Down

0 comments on commit c318748

Please sign in to comment.