Less use of "this"
This commit is contained in:
@ -32,25 +32,25 @@
|
||||
int Servo::channel_next_free = 12;
|
||||
|
||||
Servo::Servo() {
|
||||
this->channel = channel_next_free++;
|
||||
channel = channel_next_free++;
|
||||
}
|
||||
|
||||
int8_t Servo::attach(const int pin) {
|
||||
if (this->channel >= CHANNEL_MAX_NUM) return -1;
|
||||
if (pin > 0) this->pin = pin;
|
||||
int8_t Servo::attach(const int inPin) {
|
||||
if (channel >= CHANNEL_MAX_NUM) return -1;
|
||||
if (pin > 0) pin = inPin;
|
||||
|
||||
ledcSetup(this->channel, 50, 16); // channel X, 50 Hz, 16-bit depth
|
||||
ledcAttachPin(this->pin, this->channel);
|
||||
ledcSetup(channel, 50, 16); // channel X, 50 Hz, 16-bit depth
|
||||
ledcAttachPin(pin, channel);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Servo::detach() { ledcDetachPin(this->pin); }
|
||||
void Servo::detach() { ledcDetachPin(pin); }
|
||||
|
||||
int Servo::read() { return this->degrees; }
|
||||
int Servo::read() { return degrees; }
|
||||
|
||||
void Servo::write(int inDegrees) {
|
||||
this->degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
|
||||
int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
|
||||
degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
|
||||
int us = map(degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
|
||||
int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
|
||||
ledcWrite(channel, duty);
|
||||
}
|
||||
@ -58,11 +58,11 @@ void Servo::write(int inDegrees) {
|
||||
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);
|
||||
safe_delay(servo_delay[this->channel]);
|
||||
if (attach(0) >= 0) {
|
||||
write(value);
|
||||
safe_delay(servo_delay[channel]);
|
||||
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
|
||||
this->detach();
|
||||
detach();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user