Only the first M3,4 Sxxx spead is read unless a M5 is sent the rpm doesnt change
I 'fixed' it.......
void CNCDriver::spindleOff()
{
spindleRpm=0;
spindleSpeed=0;
if(direction == 0) return; // already off
if(EVENT_SPINDLE_OFF){
#if CNC_ENABLE_PIN > -1
WRITE(CNC_ENABLE_PIN,!CNC_ENABLE_WITH);
#endif
}
HAL::delayMilliseconds(CNC_WAIT_ON_DISABLE);
direction = 0;
}
/** Turns spindle on. Default implementation uses a enable pin CNC_ENABLE_PIN. If
CNC_DIRECTION_PIN is not -1 it sets direction to CNC_DIRECTION_CW. rpm is ignored.
To override with event system, return false for the event
EVENT_SPINDLE_CW(rpm)
/
void CNCDriver::spindleOnCW(int32_t rpm)
{
if (rpm > CNC_RPM_MAX)
rpm=CNC_RPM_MAX;
spindleSpeed=map(rpm,0,CNC_RPM_MAX,0,CNC_PWM_MAX); // linear interpolation
spindleRpm=rpm; // for display
if(direction == 1)
return;
// spindleOff();
// spindleRpm=rpm;// for display
direction = 1;
if(EVENT_SPINDLE_CW(rpm)) {
#if CNC_DIRECTION_PIN > -1
WRITE(CNC_DIRECTION_PIN, CNC_DIRECTION_CW);
#endif
#if CNC_ENABLE_PIN > -1
WRITE(CNC_ENABLE_PIN, CNC_ENABLE_WITH);
#endif
}
HAL::delayMilliseconds(CNC_WAIT_ON_ENABLE);
}
/** Turns spindle on. Default implementation uses a enable pin CNC_ENABLE_PIN. If
CNC_DIRECTION_PIN is not -1 it sets direction to !CNC_DIRECTION_CW. rpm is ignored.
To override with event system, return false for the event
EVENT_SPINDLE_CCW(rpm)
*/
void CNCDriver::spindleOnCCW(int32_t rpm)
{ if (rpm > CNC_RPM_MAX)
rpm=CNC_RPM_MAX;
spindleSpeed=map(rpm,0,CNC_RPM_MAX,0,CNC_PWM_MAX); // linear interpolation
spindleRpm=rpm; // for display
if(direction == -1)
return;
spindleOff();
spindleRpm=rpm;// for display
direction = -1;
if(EVENT_SPINDLE_CCW(rpm)) {
#if CNC_DIRECTION_PIN > -1
WRITE(CNC_DIRECTION_PIN, !CNC_DIRECTION_CW);
#endif
#if CNC_ENABLE_PIN > -1
WRITE(CNC_ENABLE_PIN, CNC_ENABLE_WITH);
#endif
}
HAL::delayMilliseconds(CNC_WAIT_ON_ENABLE);
}
#endif