mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-01-22 17:52:57 +00:00
✨ M3 / M4 O for laser/spindle (#26883)
This commit is contained in:
parent
43d9d1ce1b
commit
23d9020a65
2 changed files with 10 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue