From 269d168f966028c2f3236a99ed5c2965708db408 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 21 Jan 2019 15:23:30 +0700 Subject: [PATCH] fix Servo detach issue --- libraries/Servo/src/nrf52/Servo.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/Servo/src/nrf52/Servo.cpp b/libraries/Servo/src/nrf52/Servo.cpp index 664fc5f8..c9a0375a 100644 --- a/libraries/Servo/src/nrf52/Servo.cpp +++ b/libraries/Servo/src/nrf52/Servo.cpp @@ -47,7 +47,7 @@ uint8_t Servo::attach(int pin, int min, int max) pinMode(pin, OUTPUT); // set servo pin to output servos[this->servoIndex].Pin.nbr = pin; - if(min < MIN_PULSE_WIDTH) min = MIN_PULSE_WIDTH; + if (min < MIN_PULSE_WIDTH) min = MIN_PULSE_WIDTH; if (max > MAX_PULSE_WIDTH) max = MAX_PULSE_WIDTH; //fix min if conversion to pulse cycle value is too low @@ -77,8 +77,12 @@ uint8_t Servo::attach(int pin, int min, int max) void Servo::detach() { + uint8_t const pin = servos[this->servoIndex].Pin.nbr; + servos[this->servoIndex].Pin.isActive = false; - // TODO Adafruit remove pin from HW PWM + + // remove pin from HW PWM + this->pwm->removePin(pin); } @@ -108,7 +112,7 @@ int Servo::read() // return the value as degrees int Servo::readMicroseconds() { - uint8_t pin=servos[this->servoIndex].Pin.nbr; + uint8_t pin = servos[this->servoIndex].Pin.nbr; if ( this->pwm ) return this->pwm->readPin(pin)*DUTY_CYCLE_RESOLUTION;