Update servo.* for parity with 2.0.x

This commit is contained in:
Scott Lahteine
2018-03-08 19:27:15 -06:00
parent e5e3c3ff35
commit ba1c2a9819
2 changed files with 54 additions and 56 deletions

View File

@@ -236,7 +236,6 @@ static bool isTimerActive(timer16_Sequence_t timer) {
return false;
}
/****************** end of static functions ******************************/
Servo::Servo() {
@@ -248,11 +247,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;
@@ -307,16 +306,16 @@ 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
}
}
#endif
#endif // HAS_SERVOS