Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add M3/M4 'O' parameter support for laser/spindle #26883

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Marlin/src/feature/spindle_laser.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
// Inline laser power
#include "../module/planner.h"

#define RPM_TO_PWM(X) ((X) * 255 / (SPEED_POWER_MAX))
#define PWM_TO_RPM(X) ((X) * (SPEED_POWER_MAX) / 255)
#define PCT_TO_PWM(X) ((X) * 255 / 100)
#define PWM_TO_PCT(X) ((X) * 100 / 255)
#define PCT_TO_SERVO(X) ((X) * 180 / 100)
#define CUTTER_PWM_TO_SPWR(X) (CUTTER_UNIT_IS(PERCENT) ? PWM_TO_PCT(X) : (CUTTER_UNIT_IS(RPM) ? PWM_TO_RPM(X) : X))

// Laser/Cutter operation mode
enum CutterMode : int8_t {
Expand Down
7 changes: 6 additions & 1 deletion Marlin/src/gcode/control/M3-M5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
*
* Parameters:
* S<power> - Set power. S0 will turn the spindle/laser off.
* O<power> - Set power in PWM units 0-255
*
* If no PWM pin is defined then M3/M4 just turns it on or off.
*
Expand Down Expand Up @@ -91,7 +92,11 @@ void GcodeSuite::M3_M4(const bool is_M4) {
auto get_s_power = [] {
if (parser.seenval('S')) {
const float v = parser.value_float();
cutter.menuPower = cutter.unitPower = TERN(LASER_POWER_TRAP, v, cutter.power_to_range(v));
cutter.menuPower = cutter.unitPower = TERN(LASER_POWER_TRAP, constrain( v, 0, CUTTER_POWER_MAX), cutter.power_to_range(v));
}
else if (parser.seenval('O')) { // pwr in PWM units
const float v = parser.value_float();
cutter.menuPower = cutter.unitPower = CUTTER_PWM_TO_SPWR(constrain(v, 0, 255));
}
else if (cutter.cutter_mode == CUTTER_MODE_STANDARD)
cutter.menuPower = cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP);
Expand Down
Loading