From 5dc3f0d5f2f80e71a439f83d3804910fc8be61c6 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Fri, 16 Jul 2021 09:36:12 -1000 Subject: [PATCH] Created Spindle::linearSpeeds factor to reduce repetition --- Grbl_Esp32/src/Spindles/Laser.cpp | 3 +-- Grbl_Esp32/src/Spindles/OnOffSpindle.cpp | 3 +-- Grbl_Esp32/src/Spindles/PWMSpindle.cpp | 3 +-- Grbl_Esp32/src/Spindles/Spindle.cpp | 6 ++++++ Grbl_Esp32/src/Spindles/Spindle.h | 1 + 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/Laser.cpp b/Grbl_Esp32/src/Spindles/Laser.cpp index 0964412d..10aa665a 100644 --- a/Grbl_Esp32/src/Spindles/Laser.cpp +++ b/Grbl_Esp32/src/Spindles/Laser.cpp @@ -52,8 +52,7 @@ namespace Spindles { if (_speeds.size() == 0) { // The default speed map for a Laser is linear from 0=0% to 255=100% - _speeds.push_back({ 0, 0 }); - _speeds.push_back({ 255, 100 }); + linearSpeeds(255, 100.0f); } setupSpeeds(_pwm_period); diff --git a/Grbl_Esp32/src/Spindles/OnOffSpindle.cpp b/Grbl_Esp32/src/Spindles/OnOffSpindle.cpp index a2ed64e9..44548020 100644 --- a/Grbl_Esp32/src/Spindles/OnOffSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/OnOffSpindle.cpp @@ -20,8 +20,7 @@ namespace Spindles { // The default speed map for an On/Off spindle is off - 0% - // for speed 0 and on - 100% - for any nonzero speedl // In other words there is a step transition right at 0. - _speeds.push_back({ 0, 0 }); - _speeds.push_back({ 0, 100 }); + linearSpeeds(0, 100.0f); } setupSpeeds(1); config_message(); diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp index 5a980b3e..689bb925 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp @@ -66,8 +66,7 @@ namespace Spindles { if (_speeds.size() == 0) { // The default speed map for a PWM spindle is linear from 0=0% to 10000=100% - _speeds.push_back({ 0, 0 }); - _speeds.push_back({ 10000, 100 }); + linearSpeeds(10000, 100.0f); } setupSpeeds(_pwm_period); config_message(); diff --git a/Grbl_Esp32/src/Spindles/Spindle.cpp b/Grbl_Esp32/src/Spindles/Spindle.cpp index ec59c86c..aa196286 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.cpp +++ b/Grbl_Esp32/src/Spindles/Spindle.cpp @@ -98,6 +98,12 @@ namespace Spindles { void Spindle::afterParse() {} + void Spindle::linearSpeeds(SpindleSpeed maxSpeed, float maxPercent) { + _speeds.clear(); + _speeds.push_back({ 0, 0.0f }); + _speeds.push_back({ maxSpeed, maxPercent }); + } + void Spindle::shelfSpeeds(SpindleSpeed min, SpindleSpeed max) { float minPercent = 100.0f * min / max; _speeds.clear(); diff --git a/Grbl_Esp32/src/Spindles/Spindle.h b/Grbl_Esp32/src/Spindles/Spindle.h index a2457f4e..58abcba8 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.h +++ b/Grbl_Esp32/src/Spindles/Spindle.h @@ -56,6 +56,7 @@ namespace Spindles { uint32_t mapSpeed(SpindleSpeed speed); void setupSpeeds(uint32_t max_dev_speed); void shelfSpeeds(SpindleSpeed min, SpindleSpeed max); + void linearSpeeds(SpindleSpeed maxSpeed, float maxPercent); static void switchSpindle(uint8_t new_tool, SpindleList spindles, Spindle*& spindle);