浏览代码

Tweaks to Servo classes

Scott Lahteine 7 年前
父节点
当前提交
0cb4d25431

+ 5
- 5
Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp 查看文件

89
     this->servoIndex = INVALID_SERVO;  // too many servos
89
     this->servoIndex = INVALID_SERVO;  // too many servos
90
   }
90
   }
91
 
91
 
92
-  int8_t Servo::attach(int pin) {
92
+  int8_t Servo::attach(const int pin) {
93
     return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
93
     return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
94
   }
94
   }
95
 
95
 
96
-  int8_t Servo::attach(int pin, int min, int max) {
96
+  int8_t Servo::attach(const int pin, const int min, const int max) {
97
 
97
 
98
     if (this->servoIndex >= MAX_SERVOS) return -1;
98
     if (this->servoIndex >= MAX_SERVOS) return -1;
99
 
99
 
113
     servo_info[this->servoIndex].Pin.isActive = false;
113
     servo_info[this->servoIndex].Pin.isActive = false;
114
   }
114
   }
115
 
115
 
116
-  void Servo::write(int value) {
116
+  void Servo::write(const int value) {
117
     if (value < MIN_PULSE_WIDTH) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
117
     if (value < MIN_PULSE_WIDTH) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
118
       value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX());
118
       value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(), SERVO_MAX());
119
         // odd - this sets zero degrees to 544 and 180 degrees to 2400 microseconds but the literature says
119
         // odd - this sets zero degrees to 544 and 180 degrees to 2400 microseconds but the literature says
122
     this->writeMicroseconds(value);
122
     this->writeMicroseconds(value);
123
   }
123
   }
124
 
124
 
125
-  void Servo::writeMicroseconds(int value) {
125
+  void Servo::writeMicroseconds(const int value) {
126
     // calculate and store the values for the given channel
126
     // calculate and store the values for the given channel
127
     byte channel = this->servoIndex;
127
     byte channel = this->servoIndex;
128
     if (channel < MAX_SERVOS) {  // ensure channel is valid
128
     if (channel < MAX_SERVOS) {  // ensure channel is valid
146
 
146
 
147
   bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
147
   bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
148
 
148
 
149
-  void Servo::move(int value) {
149
+  void Servo::move(const int value) {
150
     if (this->attach(0) >= 0) {    // notice the pin number is zero here
150
     if (this->attach(0) >= 0) {    // notice the pin number is zero here
151
       this->write(value);
151
       this->write(value);
152
       delay(SERVO_DELAY);
152
       delay(SERVO_DELAY);

+ 5
- 5
Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.h 查看文件

39
   class Servo {
39
   class Servo {
40
     public:
40
     public:
41
       Servo();
41
       Servo();
42
-      int8_t attach(int pin);            // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
43
-      int8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
42
+      int8_t attach(const int pin);            // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
43
+      int8_t attach(const int pin, const int min, const int max); // as above but also sets min and max values for writes.
44
       void detach();
44
       void detach();
45
-      void write(int value);             // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
46
-      void writeMicroseconds(int value); // write pulse width in microseconds
47
-      void move(int value);              // attach the servo, then move to value
45
+      void write(const int value);             // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
46
+      void writeMicroseconds(const int value); // write pulse width in microseconds
47
+      void move(const int value);              // attach the servo, then move to value
48
                                          // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
48
                                          // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
49
                                          // if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach
49
                                          // if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach
50
       int read();                        // returns current pulse width as an angle between 0 and 180 degrees
50
       int read();                        // returns current pulse width as an angle between 0 and 180 degrees

+ 7
- 10
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp 查看文件

1
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
1
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2
 
2
 
3
-
4
 #include "HAL_Servo_Teensy.h"
3
 #include "HAL_Servo_Teensy.h"
5
 #include "../../inc/MarlinConfig.h"
4
 #include "../../inc/MarlinConfig.h"
6
 
5
 
7
-
8
-int8_t libServo::attach(int pin) {
9
-	if (this->servoIndex >= MAX_SERVOS) return -1;
10
-	return Servo::attach(pin);
6
+int8_t libServo::attach(const int pin) {
7
+  if (this->servoIndex >= MAX_SERVOS) return -1;
8
+  return Servo::attach(pin);
11
 }
9
 }
12
 
10
 
13
-int8_t libServo::attach(int pin, int min, int max) {
14
-	return Servo::attach(pin, min, max);
11
+int8_t libServo::attach(const int pin, const int min, const int max) {
12
+  return Servo::attach(pin, min, max);
15
 }
13
 }
16
 
14
 
17
-void libServo::move(int value) {
15
+void libServo::move(const int value) {
18
   if (this->attach(0) >= 0) {
16
   if (this->attach(0) >= 0) {
19
     this->write(value);
17
     this->write(value);
20
     delay(SERVO_DELAY);
18
     delay(SERVO_DELAY);
24
   }
22
   }
25
 }
23
 }
26
 
24
 
27
-
28
-#endif
25
+#endif // __MK64FX512__ || __MK66FX1M0__

+ 4
- 4
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.h 查看文件

6
 // Inherit and expand on the official library
6
 // Inherit and expand on the official library
7
 class libServo : public Servo {
7
 class libServo : public Servo {
8
 	public:
8
 	public:
9
-		int8_t attach(int pin);
10
-		int8_t attach(int pin, int min, int max);
11
-		void move(int value);
9
+		int8_t attach(const int pin);
10
+		int8_t attach(const int pin, const int min, const int max);
11
+		void move(const int value);
12
 	private:
12
 	private:
13
 	   uint16_t min_ticks;
13
 	   uint16_t min_ticks;
14
 	   uint16_t max_ticks;
14
 	   uint16_t max_ticks;
15
 	   uint8_t servoIndex;               // index into the channel data for this servo
15
 	   uint8_t servoIndex;               // index into the channel data for this servo
16
 };
16
 };
17
 
17
 
18
-#endif
18
+#endif // HAL_Servo_Teensy_h

正在加载...
取消
保存