From 8504992e9f5e91ac61987b8dfd60a4b2bb1b1d64 Mon Sep 17 00:00:00 2001 From: AnHardt Date: Sun, 12 Jul 2015 22:16:46 +0200 Subject: [PATCH 1/2] Remove the additional pin variable in Servo.cpp as sugested by @c-born inhttps://github.com/MarlinFirmware/Marlin/issues/1885#issuecomment-92618240 --- Marlin/servo.cpp | 5 ++--- Marlin/servo.h | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Marlin/servo.cpp b/Marlin/servo.cpp index 21f5e04872..a7e9b867f7 100644 --- a/Marlin/servo.cpp +++ b/Marlin/servo.cpp @@ -244,9 +244,8 @@ uint8_t Servo::attach(int pin) { uint8_t Servo::attach(int pin, int min, int max) { if (this->servoIndex < MAX_SERVOS ) { - #if defined(ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0) - if (pin > 0) this->pin = pin; else pin = this->pin; - #endif + if(pin == 0) + pin = servos[this->servoIndex].Pin.nbr; pinMode(pin, OUTPUT); // set servo pin to output servos[this->servoIndex].Pin.nbr = pin; // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128 diff --git a/Marlin/servo.h b/Marlin/servo.h index 9a78643774..b370003933 100644 --- a/Marlin/servo.h +++ b/Marlin/servo.h @@ -128,9 +128,7 @@ class Servo { int read(); // returns current pulse width as an angle between 0 and 180 degrees int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) bool attached(); // return true if this servo is attached, otherwise false - #if defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0 - int pin; // store the hardware pin of the servo - #endif + private: uint8_t servoIndex; // index into the channel data for this servo int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH From a6628f12cc8fa255544b14cb8cc41ed8e7eb71ff Mon Sep 17 00:00:00 2001 From: AnHardt Date: Wed, 15 Jul 2015 12:11:42 +0200 Subject: [PATCH 2/2] Eliminate the further use of the pin-parameter --- Marlin/servo.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Marlin/servo.cpp b/Marlin/servo.cpp index a7e9b867f7..97def9ea03 100644 --- a/Marlin/servo.cpp +++ b/Marlin/servo.cpp @@ -244,10 +244,9 @@ uint8_t Servo::attach(int pin) { uint8_t Servo::attach(int pin, int min, int max) { if (this->servoIndex < MAX_SERVOS ) { - if(pin == 0) - pin = servos[this->servoIndex].Pin.nbr; - pinMode(pin, OUTPUT); // set servo pin to output - servos[this->servoIndex].Pin.nbr = pin; + if(pin > 0) + servos[this->servoIndex].Pin.nbr = pin; + pinMode(servos[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128 this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS this->max = (MAX_PULSE_WIDTH - max) / 4;