|
|
|
@ -28,25 +28,30 @@
|
|
|
|
|
|
|
|
|
|
#include "Servo.h"
|
|
|
|
|
|
|
|
|
|
uint8_t servoPin[MAX_SERVOS] = { 0 };
|
|
|
|
|
static uint_fast8_t servoCount = 0;
|
|
|
|
|
constexpr millis_t servoDelay[] = SERVO_DELAY;
|
|
|
|
|
static_assert(COUNT(servoDelay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
|
|
|
|
|
|
|
|
|
|
libServo::libServo()
|
|
|
|
|
: delay(servoDelay[servoCount++])
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
int8_t libServo::attach(const int pin) {
|
|
|
|
|
if (servoIndex >= MAX_SERVOS) return -1;
|
|
|
|
|
if (pin > 0) servoPin[servoIndex] = pin;
|
|
|
|
|
return super::attach(servoPin[servoIndex]);
|
|
|
|
|
if (servoCount >= MAX_SERVOS) return -1;
|
|
|
|
|
if (pin > 0) servo_pin = pin;
|
|
|
|
|
return super::attach(servo_pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int8_t libServo::attach(const int pin, const int min, const int max) {
|
|
|
|
|
if (pin > 0) servoPin[servoIndex] = pin;
|
|
|
|
|
return super::attach(servoPin[servoIndex], min, max);
|
|
|
|
|
if (servoCount >= MAX_SERVOS) return -1;
|
|
|
|
|
if (pin > 0) servo_pin = pin;
|
|
|
|
|
return super::attach(servo_pin, min, 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 (attach(0) >= 0) {
|
|
|
|
|
write(value);
|
|
|
|
|
safe_delay(servo_delay[servoIndex]);
|
|
|
|
|
safe_delay(delay);
|
|
|
|
|
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
|
|
|
|
|
detach();
|
|
|
|
|
#endif
|
|
|
|
|