Procházet zdrojové kódy

Apply const, safe_delay in servo.*

Scott Lahteine před 6 roky
rodič
revize
e297748b22
2 změnil soubory, kde provedl 7 přidání a 11 odebrání
  1. 4
    8
      Marlin/src/HAL/servo.cpp
  2. 3
    3
      Marlin/src/HAL/servo.h

+ 4
- 8
Marlin/src/HAL/servo.cpp Zobrazit soubor

@@ -54,19 +54,15 @@
54 54
 
55 55
 #include "../inc/MarlinConfig.h"
56 56
 
57
-#include "HAL.h"
58
-
59 57
 #if HAS_SERVOS && !(IS_32BIT_TEENSY || defined(TARGET_LPC1768))
60 58
 
61 59
 //#include <Arduino.h>
62
-
63 60
 #include "servo.h"
64 61
 #include "servo_private.h"
65 62
 
66 63
 ServoInfo_t servo_info[MAX_SERVOS];                  // static array of servo info structures
67 64
 uint8_t ServoCount = 0;                              // the total number of attached servos
68 65
 
69
-
70 66
 #define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4)  // minimum value in uS for this servo
71 67
 #define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4)  // maximum value in uS for this servo
72 68
 
@@ -92,11 +88,11 @@ Servo::Servo() {
92 88
     this->servoIndex = INVALID_SERVO;  // too many servos
93 89
 }
94 90
 
95
-int8_t Servo::attach(int pin) {
91
+int8_t Servo::attach(const int pin) {
96 92
   return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
97 93
 }
98 94
 
99
-int8_t Servo::attach(int pin, int min, int max) {
95
+int8_t Servo::attach(const int pin, const int min, const int max) {
100 96
 
101 97
   if (this->servoIndex >= MAX_SERVOS) return -1;
102 98
 
@@ -151,12 +147,12 @@ int Servo::readMicroseconds() {
151 147
 
152 148
 bool Servo::attached() { return servo_info[this->servoIndex].Pin.isActive; }
153 149
 
154
-void Servo::move(int value) {
150
+void Servo::move(const int value) {
155 151
   constexpr uint16_t servo_delay[] = SERVO_DELAY;
156 152
   static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
157 153
   if (this->attach(0) >= 0) {
158 154
     this->write(value);
159
-    delay(servo_delay[this->servoIndex]);
155
+    safe_delay(servo_delay[this->servoIndex]);
160 156
     #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
161 157
       this->detach();
162 158
     #endif

+ 3
- 3
Marlin/src/HAL/servo.h Zobrazit soubor

@@ -89,12 +89,12 @@
89 89
   class Servo {
90 90
     public:
91 91
       Servo();
92
-      int8_t attach(int pin);            // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
93
-      int8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
92
+      int8_t attach(const int pin);      // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
93
+      int8_t attach(const int pin, const int min, const int max); // as above but also sets min and max values for writes.
94 94
       void detach();
95 95
       void write(int value);             // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
96 96
       void writeMicroseconds(int value); // write pulse width in microseconds
97
-      void move(int value);              // attach the servo, then move to value
97
+      void move(const int value);        // attach the servo, then move to value
98 98
                                          // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
99 99
                                          // if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach
100 100
       int read();                        // returns current pulse width as an angle between 0 and 180 degrees

Loading…
Zrušit
Uložit