Patch servos code for move

- Have `Servo::attach` explicitly return -1 if it fails
- Check for -1 in `Servo::move` because `servoIndex` might be 0
- Make `attach` / `detach` calls conditional on `SERVO_LEVELING`
- Move `SERVO_LEVELING` define to `Conditionals.h`
This commit is contained in:
Scott Lahteine
2015-07-19 11:24:23 -07:00
parent 54ddc1d417
commit 3b23ccd366
4 changed files with 32 additions and 25 deletions

View File

@ -117,12 +117,12 @@ typedef struct {
class Servo {
public:
Servo();
uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
int8_t attach(int pin); // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
int8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
void detach();
void write(int value); // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
void writeMicroseconds(int value); // Write pulse width in microseconds
uint8_t move(int pin, int value); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure.
int8_t move(int pin, int value); // attach the given pin to the next free channel, set pinMode, return channel number (-1 if attach fails)
// if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds.
// if DEACTIVATE_SERVOS_AFTER_MOVE is defined waits SERVO_DEACTIVATION_DELAY, than detaches.
int read(); // returns current pulse width as an angle between 0 and 180 degrees