diff --git a/.travis.yml b/.travis.yml index 7e1c72d48331dbc8e410c139b7beceb39f755e2b..21fe9320225a1a9164f56777d27ccd7d66d65fb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -392,6 +392,7 @@ script: # - restore_configs - opt_enable NUM_SERVOS Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE + - opt_set NUM_SERVOS 1 - opt_enable AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM} # diff --git a/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp b/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp index 0da95d040ec52400c08a59c5ba54742c414004f6..c02dd4c203b52a075cf244aeea37fa3b3a60d51b 100644 --- a/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp +++ b/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp @@ -42,8 +42,8 @@ * * write() - Set the servo angle in degrees. (Invalid angles —over MIN_PULSE_WIDTH— are treated as µs.) * writeMicroseconds() - Set the servo pulse width in microseconds. - * move(pin, angle) - Sequence of attach(pin), write(angle), delay(SERVO_DELAY). - * With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after SERVO_DELAY. + * move(pin, angle) - Sequence of attach(pin), write(angle), safe_delay(servo_delay[servoIndex]). + * With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after servo_delay[servoIndex]. * read() - Get the last-written servo pulse width as an angle between 0 and 180. * readMicroseconds() - Get the last-written servo pulse width in microseconds. * attached() - Return true if a servo is attached. diff --git a/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp b/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp index 317433191c0a1b4d338bf8fd58dab726fb5db9ac..283cd5254716e067c1098ae541b1687f6ff65931 100644 --- a/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp @@ -42,8 +42,8 @@ * * write() - Set the servo angle in degrees. (Invalid angles —over MIN_PULSE_WIDTH— are treated as µs.) * writeMicroseconds() - Set the servo pulse width in microseconds. - * move(pin, angle) - Sequence of attach(pin), write(angle), delay(SERVO_DELAY). - * With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after SERVO_DELAY. + * move(pin, angle) - Sequence of attach(pin), write(angle), safe_delay(servo_delay[servoIndex]). + * With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after servo_delay[servoIndex]. * read() - Get the last-written servo pulse width as an angle between 0 and 180. * readMicroseconds() - Get the last-written servo pulse width in microseconds. * attached() - Return true if a servo is attached. @@ -148,7 +148,7 @@ static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long."); if (this->attach(0) >= 0) { // notice the pin number is zero here this->write(value); - delay(servo_delay[this->servoIndex]); + safe_delay(servo_delay[this->servoIndex]); #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE) this->detach(); LPC1768_PWM_detach_pin(servo_info[this->servoIndex].Pin.nbr); // shut down the PWM signal diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_Stm32f1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_Stm32f1.cpp index 2dea5131b84921aeab53e3897ebe976ddea624a4..fe293d50d41c8490323188351b51c5f110938f66 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_Stm32f1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_Servo_Stm32f1.cpp @@ -39,9 +39,11 @@ int8_t libServo::attach(const int pin, const int min, const int max) { } void libServo::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); + safe_delay(servo_delay[this->servoIndex]); #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE) this->detach(); #endif diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp b/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp index 87ebde5be9980eb5c21b4ddcae4f35457d3793e5..43d95e905914c51c5205001571702a6c7856b0f1 100644 --- a/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp +++ b/Marlin/src/HAL/HAL_STM32F7/HAL_Servo_STM32F7.cpp @@ -39,9 +39,11 @@ int8_t libServo::attach(const int pin, const int min, const int max) { } void libServo::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); + safe_delay(servo_delay[this->servoIndex]); #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE) this->detach(); #endif diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp index f8905fc1e31ace240aa2082a825deddb3155d79c..6a5e40127cb57f8faccabd480d94e6fed0d3a054 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp +++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp @@ -1,8 +1,11 @@ #if defined(__MK64FX512__) || defined(__MK66FX1M0__) -#include "HAL_Servo_Teensy.h" #include "../../inc/MarlinConfig.h" +#if HAS_SERVOS + +#include "HAL_Servo_Teensy.h" + int8_t libServo::attach(const int pin) { if (this->servoIndex >= MAX_SERVOS) return -1; return Servo::attach(pin); @@ -13,13 +16,17 @@ int8_t libServo::attach(const int pin, const int min, const int max) { } void libServo::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); + safe_delay(servo_delay[this->servoIndex]); #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE) this->detach(); #endif } } +#endif // HAS_SERVOS + #endif // __MK64FX512__ || __MK66FX1M0__ diff --git a/Marlin/src/HAL/servo.cpp b/Marlin/src/HAL/servo.cpp index 4ff27791535984c67b1a5601114e3716e1a5b3f4..1c3c003d8293050124e018c9af365f3cabd0ae69 100644 --- a/Marlin/src/HAL/servo.cpp +++ b/Marlin/src/HAL/servo.cpp @@ -42,8 +42,8 @@ * * write() - Set the servo angle in degrees. (Invalid angles —over MIN_PULSE_WIDTH— are treated as µs.) * writeMicroseconds() - Set the servo pulse width in microseconds. - * move(pin, angle) - Sequence of attach(pin), write(angle), delay(SERVO_DELAY). - * With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after SERVO_DELAY. + * move(pin, angle) - Sequence of attach(pin), write(angle), safe_delay(servo_delay[servoIndex]). + * With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after servo_delay[servoIndex]. * read() - Get the last-written servo pulse width as an angle between 0 and 180. * readMicroseconds() - Get the last-written servo pulse width in microseconds. * attached() - Return true if a servo is attached. @@ -160,4 +160,3 @@ void Servo::move(const int value) { } #endif // HAS_SERVOS -