Browse Source

🩹 Fix non-PWM cutter compile (#23169)

vanilla_fb_2.0.x
Mike La Spina 3 years ago
committed by Scott Lahteine
parent
commit
c3b8b3e7e6
  1. 12
      Marlin/src/feature/spindle_laser.h
  2. 24
      Marlin/src/feature/spindle_laser_types.h
  3. 2
      Marlin/src/gcode/control/M3-M5.cpp
  4. 6
      buildroot/tests/mega1280

12
Marlin/src/feature/spindle_laser.h

@ -41,18 +41,10 @@
#define PCT_TO_PWM(X) ((X) * 255 / 100) #define PCT_TO_PWM(X) ((X) * 255 / 100)
#define PCT_TO_SERVO(X) ((X) * 180 / 100) #define PCT_TO_SERVO(X) ((X) * 180 / 100)
#ifndef SPEED_POWER_INTERCEPT
#define SPEED_POWER_INTERCEPT 0
#endif
// #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1)) // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1))
class SpindleLaser { class SpindleLaser {
public: public:
static constexpr float
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_t pct) { return uint8_t(PCT_TO_PWM(pct)); } static const inline uint8_t pct_to_ocr(const_float_t pct) { return uint8_t(PCT_TO_PWM(pct)); }
// cpower = configured values (e.g., SPEED_POWER_MAX) // cpower = configured values (e.g., SPEED_POWER_MAX)
@ -158,6 +150,9 @@ public:
} }
static inline cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) { static inline cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) {
static constexpr float
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);
if (pwr <= 0) return 0; if (pwr <= 0) return 0;
cutter_power_t upwr; cutter_power_t upwr;
switch (pwrUnit) { switch (pwrUnit) {
@ -186,6 +181,7 @@ public:
} }
return upwr; return upwr;
} }
#endif // SPINDLE_LASER_USE_PWM #endif // SPINDLE_LASER_USE_PWM
/** /**

24
Marlin/src/feature/spindle_laser_types.h

@ -28,12 +28,34 @@
#include "../inc/MarlinConfigPre.h" #include "../inc/MarlinConfigPre.h"
#define MSG_CUTTER(M) _MSG_CUTTER(M)
#ifndef SPEED_POWER_INTERCEPT
#define SPEED_POWER_INTERCEPT 0
#endif
#if ENABLED(SPINDLE_FEATURE) #if ENABLED(SPINDLE_FEATURE)
#define _MSG_CUTTER(M) MSG_SPINDLE_##M #define _MSG_CUTTER(M) MSG_SPINDLE_##M
#ifndef SPEED_POWER_MIN
#define SPEED_POWER_MIN 5000
#endif
#ifndef SPEED_POWER_MAX
#define SPEED_POWER_MAX 30000
#endif
#ifndef SPEED_POWER_STARTUP
#define SPEED_POWER_STARTUP 25000
#endif
#else #else
#define _MSG_CUTTER(M) MSG_LASER_##M #define _MSG_CUTTER(M) MSG_LASER_##M
#ifndef SPEED_POWER_MIN
#define SPEED_POWER_MIN 0
#endif
#ifndef SPEED_POWER_MAX
#define SPEED_POWER_MAX 255
#endif
#ifndef SPEED_POWER_STARTUP
#define SPEED_POWER_STARTUP 255
#endif
#endif #endif
#define MSG_CUTTER(M) _MSG_CUTTER(M)
typedef IF<(SPEED_POWER_MAX > 255), uint16_t, uint8_t>::type cutter_cpower_t; typedef IF<(SPEED_POWER_MAX > 255), uint16_t, uint8_t>::type cutter_cpower_t;

2
Marlin/src/gcode/control/M3-M5.cpp

@ -66,6 +66,7 @@
* PWM duty cycle goes from 0 (off) to 255 (always on). * PWM duty cycle goes from 0 (off) to 255 (always on).
*/ */
void GcodeSuite::M3_M4(const bool is_M4) { void GcodeSuite::M3_M4(const bool is_M4) {
#if EITHER(SPINDLE_LASER_USE_PWM, SPINDLE_SERVO)
auto get_s_power = [] { auto get_s_power = [] {
if (parser.seenval('S')) { if (parser.seenval('S')) {
const float spwr = parser.value_float(); const float spwr = parser.value_float();
@ -81,6 +82,7 @@ void GcodeSuite::M3_M4(const bool is_M4) {
cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP); cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);
return cutter.unitPower; return cutter.unitPower;
}; };
#endif
#if ENABLED(LASER_POWER_INLINE) #if ENABLED(LASER_POWER_INLINE)
if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) { if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) {

6
buildroot/tests/mega1280

@ -27,6 +27,12 @@ opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \
EXTERNAL_CLOSED_LOOP_CONTROLLER POWER_MONITOR_CURRENT POWER_MONITOR_VOLTAGE EXTERNAL_CLOSED_LOOP_CONTROLLER POWER_MONITOR_CURRENT POWER_MONITOR_VOLTAGE
exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD" "$3" exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD" "$3"
#
# ...and without PWM
#
opt_disable SPINDLE_LASER_USE_PWM
exec_test $1 $2 "(No PWM)" "$3"
# #
# Test DUAL_X_CARRIAGE # Test DUAL_X_CARRIAGE
# #

Loading…
Cancel
Save