Fix Spindle/Laser Control menu (#20347)

This commit is contained in:
Mike La Spina
2020-12-09 04:29:33 -06:00
committed by Scott Lahteine
parent edb2a83e71
commit 3e68e4b418
7 changed files with 33 additions and 23 deletions

View File

@ -118,7 +118,7 @@ void SpindleLaser::apply_power(const uint8_t opwr) {
// Set the spindle direction and apply immediately
// Stop on direction change if SPINDLE_STOP_ON_DIR_CHANGE is enabled
//
void SpindleLaser::set_direction(const bool reverse) {
void SpindleLaser::set_reverse(const bool reverse) {
const bool dir_state = (reverse == SPINDLE_INVERT_DIR); // Forward (M3) HIGH when not inverted
if (TERN0(SPINDLE_STOP_ON_DIR_CHANGE, enabled()) && READ(SPINDLE_DIR_PIN) != dir_state) disable();
WRITE(SPINDLE_DIR_PIN, dir_state);

View File

@ -57,7 +57,7 @@ public:
static const inline uint8_t cpwr_to_pct(const cutter_cpower_t cpwr) {
constexpr cutter_cpower_t power_floor = TERN(CUTTER_POWER_RELATIVE, SPEED_POWER_MIN, 0),
power_range = SPEED_POWER_MAX - power_floor;
return unitPower ? round(100.0f * (cpwr - power_floor) / power_range) : 0;
return cpwr ? round(100.0f * (cpwr - power_floor) / power_range) : 0;
}
// Convert a cpower (e.g., SPEED_POWER_STARTUP) to unit power (upwr, upower),
@ -191,9 +191,11 @@ public:
}
#if ENABLED(SPINDLE_CHANGE_DIR)
static void set_direction(const bool reverse);
static void set_reverse(const bool reverse);
static bool is_reverse() { return READ(SPINDLE_DIR_PIN) == SPINDLE_INVERT_DIR; }
#else
static inline void set_direction(const bool) {}
static inline void set_reverse(const bool) {}
static bool is_reverse() { return false; }
#endif
static inline void disable() { isReady = false; set_enabled(false); }
@ -208,11 +210,12 @@ public:
else
menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP);
unitPower = menuPower;
set_direction(reverse);
set_reverse(reverse);
set_enabled(true);
}
FORCE_INLINE static void enable_forward() { enable_with_dir(false); }
FORCE_INLINE static void enable_reverse() { enable_with_dir(true); }
FORCE_INLINE static void enable_same_dir() { enable_with_dir(is_reverse()); }
#if ENABLED(SPINDLE_LASER_PWM)
static inline void update_from_mpower() {