mirror of
https://github.com/richardghirst/PiBits.git
synced 2025-02-26 19:54:16 +01:00
Fix special cases round setting widths of 0 and 100%
This commit is contained in:
parent
ab34d81e53
commit
1b78f9ad6b
@ -432,11 +432,26 @@ set_servo(int servo, int width)
|
|||||||
int i;
|
int i;
|
||||||
uint32_t mask = 1 << servo2gpio[servo];
|
uint32_t mask = 1 << servo2gpio[servo];
|
||||||
|
|
||||||
if (width == servowidth[servo])
|
/* If requested width is 0 just remove the 'turn-on' action and allow
|
||||||
return;
|
* the 'turn-off' action at the end of the current pulse to turn it
|
||||||
|
* off. Special case if current width is 100%; in that case there will
|
||||||
|
* be no 'turn-off' action, so we will need to force the output off
|
||||||
|
* here.
|
||||||
|
*/
|
||||||
if (width == 0) {
|
if (width == 0) {
|
||||||
ctl->turnon[servo] = 0;
|
ctl->turnon[servo] = 0;
|
||||||
|
if (servowidth[servo] == NUM_SAMPLES)
|
||||||
|
gpio_set(servo2gpio[servo], invert ? 1 : 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Requested width is non-zero, and it is the same as the last non-zero
|
||||||
|
* pulse width. In this case just make sure the 'turn-on' action is
|
||||||
|
* present, and reactivate the idle timer.
|
||||||
|
*/
|
||||||
|
if (width == servowidth[servo]) {
|
||||||
|
ctl->turnon[servo] = mask;
|
||||||
|
update_idle_time(servo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user