|
@@ -28,25 +28,30 @@
|
28
|
28
|
|
29
|
29
|
#include "Servo.h"
|
30
|
30
|
|
31
|
|
-uint8_t servoPin[MAX_SERVOS] = { 0 };
|
|
31
|
+static uint_fast8_t servoCount = 0;
|
|
32
|
+constexpr millis_t servoDelay[] = SERVO_DELAY;
|
|
33
|
+static_assert(COUNT(servoDelay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
|
|
34
|
+
|
|
35
|
+libServo::libServo()
|
|
36
|
+: delay(servoDelay[servoCount++])
|
|
37
|
+{}
|
32
|
38
|
|
33
|
39
|
int8_t libServo::attach(const int pin) {
|
34
|
|
- if (servoIndex >= MAX_SERVOS) return -1;
|
35
|
|
- if (pin > 0) servoPin[servoIndex] = pin;
|
36
|
|
- return super::attach(servoPin[servoIndex]);
|
|
40
|
+ if (servoCount >= MAX_SERVOS) return -1;
|
|
41
|
+ if (pin > 0) servo_pin = pin;
|
|
42
|
+ return super::attach(servo_pin);
|
37
|
43
|
}
|
38
|
44
|
|
39
|
45
|
int8_t libServo::attach(const int pin, const int min, const int max) {
|
40
|
|
- if (pin > 0) servoPin[servoIndex] = pin;
|
41
|
|
- return super::attach(servoPin[servoIndex], min, max);
|
|
46
|
+ if (servoCount >= MAX_SERVOS) return -1;
|
|
47
|
+ if (pin > 0) servo_pin = pin;
|
|
48
|
+ return super::attach(servo_pin, min, max);
|
42
|
49
|
}
|
43
|
50
|
|
44
|
51
|
void libServo::move(const int value) {
|
45
|
|
- constexpr uint16_t servo_delay[] = SERVO_DELAY;
|
46
|
|
- static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
|
47
|
52
|
if (attach(0) >= 0) {
|
48
|
53
|
write(value);
|
49
|
|
- safe_delay(servo_delay[servoIndex]);
|
|
54
|
+ safe_delay(delay);
|
50
|
55
|
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
|
51
|
56
|
detach();
|
52
|
57
|
#endif
|