fix Servo detach issue

This commit is contained in:
hathach committed 2019-01-21 15:23:30 +07:00
1 parent c84672a7cd
commit 269d168f96
1 file changed
+7 -3
+7 -3
View File
@@ -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;