From f8ad403439f1cbb4ffb5dc7e8337291e9d3e21db Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Sun, 20 Jun 2021 08:40:06 -1000 Subject: [PATCH] Improved the initial selection of spindle. --- Grbl_Esp32/src/Grbl.cpp | 2 ++ Grbl_Esp32/src/MachineConfig.cpp | 4 +--- Grbl_Esp32/src/Spindles/Spindle.cpp | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Grbl_Esp32/src/Grbl.cpp b/Grbl_Esp32/src/Grbl.cpp index 31f39cb0..f4da50c3 100644 --- a/Grbl_Esp32/src/Grbl.cpp +++ b/Grbl_Esp32/src/Grbl.cpp @@ -111,6 +111,8 @@ void grbl_init() { for (auto s : config->_spindles) { s->init(); } + Spindles::Spindle::switchSpindle(0, config->_spindles, spindle); + config->_coolant->init(); limits_init(); config->_probe->init(); diff --git a/Grbl_Esp32/src/MachineConfig.cpp b/Grbl_Esp32/src/MachineConfig.cpp index 76456722..272a41bd 100644 --- a/Grbl_Esp32/src/MachineConfig.cpp +++ b/Grbl_Esp32/src/MachineConfig.cpp @@ -476,11 +476,9 @@ void MachineConfig::afterParse() { } if (_spindles.size() == 0) { - log_info("Using null spindle"); + log_info("Spindle config missing; using null spindle"); _spindles.push_back(new Spindles::Null()); } - spindle = _spindles[0]; - uint32_t next_tool = 100; for (auto s : _spindles) { if (s->_tool == -1) { diff --git a/Grbl_Esp32/src/Spindles/Spindle.cpp b/Grbl_Esp32/src/Spindles/Spindle.cpp index 6de370a2..74efa19e 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.cpp +++ b/Grbl_Esp32/src/Spindles/Spindle.cpp @@ -39,11 +39,17 @@ namespace Spindles { } if (candidate) { if (candidate != spindle) { - spindle->stop(); + if (spindle != nullptr) { + spindle->stop(); + } spindle = candidate; } } else { - if (!spindle) { + if (spindle == nullptr) { + if (spindles.size() == 0) { + log_error("No spindles are defined"); + return; + } spindle = spindles[0]; } }