From e297748b2253a8b15fea49cc244f34a537972a94 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 8 Mar 2018 19:23:10 -0600 Subject: [PATCH] Apply const, safe_delay in servo.* --- Marlin/src/HAL/servo.cpp | 12 ++++-------- Marlin/src/HAL/servo.h | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Marlin/src/HAL/servo.cpp b/Marlin/src/HAL/servo.cpp index 1ccd73afa4..26cf9533b4 100644 --- a/Marlin/src/HAL/servo.cpp +++ b/Marlin/src/HAL/servo.cpp @@ -54,19 +54,15 @@ #include "../inc/MarlinConfig.h" -#include "HAL.h" - #if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768)) //#include - #include "servo.h" #include "servo_private.h" ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures uint8_t ServoCount = 0; // the total number of attached servos - #define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo #define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo @@ -92,11 +88,11 @@ Servo::Servo() { this->servoIndex = INVALID_SERVO; // too many servos } -int8_t Servo::attach(int pin) { +int8_t Servo::attach(const int pin) { return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); } -int8_t Servo::attach(int pin, int min, int max) { +int8_t Servo::attach(const int pin, const int min, const int max) { if (this->servoIndex >= MAX_SERVOS) return -1; @@ -151,12 +147,12 @@ int Servo::readMicroseconds() { bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; } -void Servo::move(int value) { +void Servo::move(const int value) { constexpr uint16_t servo_delay[] = SERVO_DELAY; static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long."); if (this->attach(0) >= 0) { this->write(value); - delay(servo_delay[this->servoIndex]); + safe_delay(servo_delay[this->servoIndex]); #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE) this->detach(); #endif diff --git a/Marlin/src/HAL/servo.h b/Marlin/src/HAL/servo.h index 39bca93e16..7c521da0b5 100644 --- a/Marlin/src/HAL/servo.h +++ b/Marlin/src/HAL/servo.h @@ -89,12 +89,12 @@ class Servo { public: Servo(); - int8_t attach(int pin); // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail) - int8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. + int8_t attach(const int pin); // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail) + int8_t attach(const int pin, const int min, const int max); // as above but also sets min and max values for writes. void detach(); void write(int value); // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds void writeMicroseconds(int value); // write pulse width in microseconds - void move(int value); // attach the servo, then move to value + void move(const int value); // attach the servo, then move to value // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds // if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach int read(); // returns current pulse width as an angle between 0 and 180 degrees