diff --git a/Grbl_Esp32/src/GCode.cpp b/Grbl_Esp32/src/GCode.cpp index 5a24d342..6f8daf15 100644 --- a/Grbl_Esp32/src/GCode.cpp +++ b/Grbl_Esp32/src/GCode.cpp @@ -473,7 +473,7 @@ Error gc_execute_line(char* line, uint8_t client) { gc_block.modal.spindle = SpindleState::Cw; break; case 4: // Supported if SPINDLE_DIR_PIN is defined or laser mode is on. - if (spindle->is_reversable || laser_mode->get()) { + if (spindle->is_reversable || spindle->inLaserMode()) { gc_block.modal.spindle = SpindleState::Ccw; } else { FAIL(Error::GcodeUnsupportedCommand); @@ -1290,7 +1290,7 @@ Error gc_execute_line(char* line, uint8_t client) { return status; } // If in laser mode, setup laser power based on current and past parser conditions. - if (laser_mode->get()) { + if (spindle->inLaserMode()) { if (!((gc_block.modal.motion == Motion::Linear) || (gc_block.modal.motion == Motion::CwArc) || (gc_block.modal.motion == Motion::CcwArc))) { gc_parser_flags |= GCParserLaserDisable; diff --git a/Grbl_Esp32/src/Grbl.h b/Grbl_Esp32/src/Grbl.h index e5b624da..fa4fca3a 100644 --- a/Grbl_Esp32/src/Grbl.h +++ b/Grbl_Esp32/src/Grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system const char* const GRBL_VERSION = "1.3a"; -const char* const GRBL_VERSION_BUILD = "20201128"; +const char* const GRBL_VERSION_BUILD = "20201204"; //#include #include diff --git a/Grbl_Esp32/src/Motors/TrinamicDriver.cpp b/Grbl_Esp32/src/Motors/TrinamicDriver.cpp index 9c808c4e..4125332f 100644 --- a/Grbl_Esp32/src/Motors/TrinamicDriver.cpp +++ b/Grbl_Esp32/src/Motors/TrinamicDriver.cpp @@ -353,11 +353,7 @@ namespace Motors { auto n_axis = number_axis->get(); xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time. - while (true) { // don't ever return from this or the task dies - if (motorSettingChanged) { - motors_read_settings(); - motorSettingChanged = false; - } + while (true) { // don't ever return from this or the task dies if (stallguard_debug_mask->get() != 0) { if (sys.state == State::Cycle || sys.state == State::Homing || sys.state == State::Jog) { for (TrinamicDriver* p = List; p; p = p->link) { diff --git a/Grbl_Esp32/src/Protocol.cpp b/Grbl_Esp32/src/Protocol.cpp index 982cecca..bfda25f5 100644 --- a/Grbl_Esp32/src/Protocol.cpp +++ b/Grbl_Esp32/src/Protocol.cpp @@ -96,7 +96,7 @@ bool can_park() { #ifdef ENABLE_PARKING_OVERRIDE_CONTROL sys.override_ctrl == Override::ParkingMotion && #endif - homing_enable->get() && !laser_mode->get(); + homing_enable->get() && !spindle->inLaserMode(); } /* @@ -558,7 +558,7 @@ static void protocol_exec_rt_suspend() { restore_spindle_speed = block->spindle_speed; } #ifdef DISABLE_LASER_DURING_HOLD - if (laser_mode->get()) { + if (spindle->inLaserMode()) { sys_rt_exec_accessory_override.bit.spindleOvrStop = true; } #endif @@ -661,7 +661,7 @@ static void protocol_exec_rt_suspend() { if (gc_state.modal.spindle != SpindleState::Disable) { // Block if safety door re-opened during prior restore actions. if (!sys.suspend.bit.restartRetract) { - if (laser_mode->get()) { + if (spindle->inLaserMode()) { // When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts. sys.step_control.updateSpindleRpm = true; } else { @@ -717,7 +717,7 @@ static void protocol_exec_rt_suspend() { } else if (sys.spindle_stop_ovr.bit.restore || sys.spindle_stop_ovr.bit.restoreCycle) { if (gc_state.modal.spindle != SpindleState::Disable) { report_feedback_message(Message::SpindleRestore); - if (laser_mode->get()) { + if (spindle->inLaserMode()) { // When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts. sys.step_control.updateSpindleRpm = true; } else { diff --git a/Grbl_Esp32/src/SettingsDefinitions.cpp b/Grbl_Esp32/src/SettingsDefinitions.cpp index 0a11cdee..64757a24 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.cpp +++ b/Grbl_Esp32/src/SettingsDefinitions.cpp @@ -1,7 +1,5 @@ #include "Grbl.h" -bool motorSettingChanged = false; - FlagSetting* verbose_errors; FakeSetting* number_axis; @@ -177,22 +175,27 @@ static bool checkStartupLine(char* value) { } static bool postTMC(char* value) { - if (!value) { // No POST functionality - motorSettingChanged = true; + if (!value) { + motors_read_settings(); } return true; } static bool checkSpindleChange(char* val) { if (!val) { - spindle->deinit(); - Spindles::Spindle::select(); + // if not in disable (M5) ... + if (gc_state.modal.spindle != SpindleState::Disable) { + gc_state.modal.spindle = SpindleState::Disable; + if (spindle->use_delays && spindle_delay_spindown->get() != 0) { // old spindle + vTaskDelay(spindle_delay_spindown->get() * 1000); + } + grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Spindle turned off with setting change"); + } + gc_state.spindle_speed = 0; // Set S value to 0 + spindle->deinit(); // old spindle + Spindles::Spindle::select(); // get new spindle return true; } - if (gc_state.modal.spindle != SpindleState::Disable) { - grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Spindle must be off to make this change"); - return false; - } return true; } diff --git a/Grbl_Esp32/src/SettingsDefinitions.h b/Grbl_Esp32/src/SettingsDefinitions.h index 41599b99..d93ca82f 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.h +++ b/Grbl_Esp32/src/SettingsDefinitions.h @@ -1,7 +1,5 @@ #pragma once -extern bool motorSettingChanged; - extern FlagSetting* verbose_errors; extern FakeSetting* number_axis; diff --git a/Grbl_Esp32/src/Spindles/10vSpindle.cpp b/Grbl_Esp32/src/Spindles/10vSpindle.cpp index dd2284b5..09162c0c 100644 --- a/Grbl_Esp32/src/Spindles/10vSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/10vSpindle.cpp @@ -170,20 +170,25 @@ namespace Spindles { void _10v::deinit() { #ifdef SPINDLE_OUTPUT_PIN + gpio_reset_pin(SPINDLE_OUTPUT_PIN); pinMode(SPINDLE_OUTPUT_PIN, INPUT); #endif #ifdef SPINDLE_ENABLE_PIN + gpio_reset_pin(SPINDLE_ENABLE_PIN); pinMode(SPINDLE_ENABLE_PIN, INPUT); #endif #ifdef SPINDLE_DIR_PIN + gpio_reset_pin(SPINDLE_DIR_PIN); pinMode(SPINDLE_DIR_PIN, INPUT); #endif #ifdef SPINDLE_FORWARD_PIN + gpio_reset_pin(SPINDLE_FORWARD_PIN); pinMode(SPINDLE_FORWARD_PIN, INPUT); #endif #ifdef SPINDLE_REVERSE_PIN + gpio_reset_pin(SPINDLE_FORWARD_PIN); pinMode(SPINDLE_FORWARD_PIN, INPUT); #endif } diff --git a/Grbl_Esp32/src/Spindles/Laser.cpp b/Grbl_Esp32/src/Spindles/Laser.cpp index befdc0d9..6b7d9e6c 100644 --- a/Grbl_Esp32/src/Spindles/Laser.cpp +++ b/Grbl_Esp32/src/Spindles/Laser.cpp @@ -24,8 +24,8 @@ // ===================================== Laser ============================================== namespace Spindles { - bool Laser::isRateAdjusted() { - return true; // can use M4 (CCW) laser mode. + bool Laser::inLaserMode() { + return laser_mode->get(); // can use M4 (CCW) laser mode. } void Laser::config_message() { @@ -89,10 +89,12 @@ namespace Spindles { void Laser::deinit() { stop(); #ifdef LASER_OUTPUT_PIN + gpio_reset_pin(LASER_OUTPUT_PIN); pinMode(LASER_OUTPUT_PIN, INPUT); #endif #ifdef LASER_ENABLE_PIN + gpio_reset_pin(LASER_ENABLE_PIN); pinMode(LASER_ENABLE_PIN, INPUT); #endif } diff --git a/Grbl_Esp32/src/Spindles/Laser.h b/Grbl_Esp32/src/Spindles/Laser.h index 87673f62..10120a31 100644 --- a/Grbl_Esp32/src/Spindles/Laser.h +++ b/Grbl_Esp32/src/Spindles/Laser.h @@ -34,7 +34,7 @@ namespace Spindles { Laser& operator=(const Laser&) = delete; Laser& operator=(Laser&&) = delete; - bool isRateAdjusted() override; + bool inLaserMode() override; void config_message() override; void get_pins_and_settings() override; void deinit() override; diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp index 1ade8aa8..23477494 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp @@ -42,14 +42,15 @@ namespace Spindles { return; } + _current_state = SpindleState::Disable; + _current_pwm_duty = 0; + use_delays = true; + ledcSetup(_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel ledcAttachPin(_output_pin, _pwm_chan_num); // attach the PWM to the pin - pinMode(_enable_pin, OUTPUT); pinMode(_direction_pin, OUTPUT); - use_delays = true; - config_message(); } @@ -146,7 +147,7 @@ namespace Spindles { } } - set_enable_pin(_current_state != SpindleState::Disable); + set_enable_pin(gc_state.modal.spindle != SpindleState::Disable); set_output(pwm_value); return 0; @@ -225,6 +226,14 @@ namespace Spindles { } void PWM::set_enable_pin(bool enable) { + // static bool prev_enable = false; + + // if (prev_enable == enable) { + // return; + // } + + // prev_enable = enable; + if (_enable_pin == UNDEFINED_PIN) { return; } @@ -262,13 +271,16 @@ namespace Spindles { void PWM::deinit() { stop(); #ifdef SPINDLE_OUTPUT_PIN + gpio_reset_pin(SPINDLE_OUTPUT_PIN); pinMode(SPINDLE_OUTPUT_PIN, INPUT); #endif #ifdef SPINDLE_ENABLE_PIN + gpio_reset_pin(SPINDLE_ENABLE_PIN); pinMode(SPINDLE_ENABLE_PIN, INPUT); #endif #ifdef SPINDLE_DIR_PIN + gpio_reset_pin(SPINDLE_DIR_PIN); pinMode(SPINDLE_DIR_PIN, INPUT); #endif } diff --git a/Grbl_Esp32/src/Spindles/Spindle.cpp b/Grbl_Esp32/src/Spindles/Spindle.cpp index d0ec75a4..f705aea7 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.cpp +++ b/Grbl_Esp32/src/Spindles/Spindle.cpp @@ -89,7 +89,7 @@ namespace Spindles { // ========================= Spindle ================================== - bool Spindle::isRateAdjusted() { + bool Spindle::inLaserMode() { return false; // default for basic spindle is false } diff --git a/Grbl_Esp32/src/Spindles/Spindle.h b/Grbl_Esp32/src/Spindles/Spindle.h index 5fd37e5b..6851544a 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.h +++ b/Grbl_Esp32/src/Spindles/Spindle.h @@ -64,7 +64,7 @@ namespace Spindles { virtual SpindleState get_state() = 0; virtual void stop() = 0; virtual void config_message() = 0; - virtual bool isRateAdjusted(); + virtual bool inLaserMode(); virtual void sync(SpindleState state, uint32_t rpm); virtual void deinit(); diff --git a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp index a7a2636a..9b119c61 100644 --- a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp @@ -273,10 +273,10 @@ namespace Spindles { } // Initialization is complete, so now it's okay to run the queue task: - task_active = true; + task_active = true; if (vfd_cmd_queue != nullptr) { vfd_cmd_queue = xQueueCreate(VFD_RS485_QUEUE_SIZE, sizeof(ModbusCommand)); - } + } xTaskCreatePinnedToCore(vfd_cmd_task, // task "vfd_cmdTaskHandle", // name for task 2048, // size of task stack @@ -323,6 +323,7 @@ namespace Spindles { pins_settings_ok = false; #endif + // TODO Test no longer required. if (laser_mode->get()) { grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD spindle disabled in laser mode. Set $GCode/LaserMode=Off and restart"); pins_settings_ok = false; diff --git a/Grbl_Esp32/src/Stepper.cpp b/Grbl_Esp32/src/Stepper.cpp index ae4a56b2..83aee938 100644 --- a/Grbl_Esp32/src/Stepper.cpp +++ b/Grbl_Esp32/src/Stepper.cpp @@ -551,7 +551,7 @@ void st_prep_buffer() { prep.current_speed = sqrt(pl_block->entry_speed_sqr); } - if (spindle->isRateAdjusted()) { // laser_mode->get() { + if (spindle->inLaserMode()) { // if (pl_block->spindle == SpindleState::Ccw) { // Pre-compute inverse programmed rate to speed up PWM updating per step segment. prep.inv_rate = 1.0 / pl_block->programmed_rate;