From 24c525900500b164b5165af127c6f39accf69c3a Mon Sep 17 00:00:00 2001 From: Julien Lirochon Date: Sat, 31 Oct 2020 19:45:10 +0100 Subject: [PATCH] Fix SpindleLaser::cpwr_to_pct() maths (#19970) --- Marlin/src/feature/spindle_laser.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index e8db3aa608..9d21c96fb9 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -46,14 +46,14 @@ class SpindleLaser { public: static constexpr float - min_pct = round(TERN(CUTTER_POWER_RELATIVE, 0, (100 * float(SPEED_POWER_MIN) / TERN(SPINDLE_FEATURE, float(SPEED_POWER_MAX), 100)))), - max_pct = round(TERN(SPINDLE_FEATURE, 100, float(SPEED_POWER_MAX))); + min_pct = TERN(CUTTER_POWER_RELATIVE, 0, TERN(SPINDLE_FEATURE, round(100.0f * (SPEED_POWER_MIN) / (SPEED_POWER_MAX)), SPEED_POWER_MIN))), + max_pct = TERN(SPINDLE_FEATURE, 100, SPEED_POWER_MAX); static const inline uint8_t pct_to_ocr(const float pct) { return uint8_t(PCT_TO_PWM(pct)); } // cpower = configured values (ie SPEED_POWER_MAX) static const inline uint8_t cpwr_to_pct(const cutter_cpower_t cpwr) { // configured value to pct - return unitPower ? round(100 * (cpwr - SPEED_POWER_FLOOR) / (SPEED_POWER_MAX - SPEED_POWER_FLOOR)) : 0; + return unitPower ? round(100.0f * (cpwr - (SPEED_POWER_FLOOR)) / (SPEED_POWER_MAX - (SPEED_POWER_FLOOR))) : 0; } // Convert a configured value (cpower)(ie SPEED_POWER_STARTUP) to unit power (upwr, upower),