Browse Source

Protected pin err for M226

Scott Lahteine 7 years ago
parent
commit
968a5d2e63

+ 5
- 0
Marlin/src/Marlin.cpp View File

@@ -264,6 +264,11 @@ bool pin_is_protected(const pin_t pin) {
264 264
   return false;
265 265
 }
266 266
 
267
+void protected_pin_err() {
268
+  SERIAL_ERROR_START();
269
+  SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);
270
+}
271
+
267 272
 void quickstop_stepper() {
268 273
   planner.quick_stop();
269 274
   planner.synchronize();

+ 1
- 0
Marlin/src/Marlin.h View File

@@ -219,6 +219,7 @@ extern millis_t max_inactive_time, stepper_inactive_time;
219 219
 #endif
220 220
 
221 221
 bool pin_is_protected(const pin_t pin);
222
+void protected_pin_err();
222 223
 
223 224
 #if HAS_SUICIDE
224 225
   inline void suicide() { OUT_WRITE(SUICIDE_PIN, LOW); }

+ 7
- 7
Marlin/src/gcode/config/M43.cpp View File

@@ -35,7 +35,7 @@
35 35
 #endif
36 36
 
37 37
 inline void toggle_pins() {
38
-  const bool I_flag = parser.boolval('I');
38
+  const bool ignore_protection = parser.boolval('I');
39 39
   const int repeat = parser.intval('R', 1),
40 40
             start = PARSED_PIN_INDEX('S', 0),
41 41
             end = PARSED_PIN_INDEX('E', NUM_DIGITAL_PINS - 1),
@@ -43,14 +43,14 @@ inline void toggle_pins() {
43 43
 
44 44
   for (uint8_t i = start; i <= end; i++) {
45 45
     pin_t pin = GET_PIN_MAP_PIN(i);
46
-    //report_pin_state_extended(pin, I_flag, false);
46
+    //report_pin_state_extended(pin, ignore_protection, false);
47 47
     if (!VALID_PIN(pin)) continue;
48
-    if (!I_flag && pin_is_protected(pin)) {
49
-      report_pin_state_extended(pin, I_flag, true, "Untouched ");
48
+    if (!ignore_protection && pin_is_protected(pin)) {
49
+      report_pin_state_extended(pin, ignore_protection, true, "Untouched ");
50 50
       SERIAL_EOL();
51 51
     }
52 52
     else {
53
-      report_pin_state_extended(pin, I_flag, true, "Pulsing   ");
53
+      report_pin_state_extended(pin, ignore_protection, true, "Pulsing   ");
54 54
       #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
55 55
         if (pin == TEENSY_E2) {
56 56
           SET_OUTPUT(TEENSY_E2);
@@ -275,7 +275,7 @@ void GcodeSuite::M43() {
275 275
     for (uint8_t i = first_pin; i <= last_pin; i++) {
276 276
       pin_t pin = GET_PIN_MAP_PIN(i);
277 277
       if (!VALID_PIN(pin)) continue;
278
-      if (pin_is_protected(pin) && !ignore_protection) continue;
278
+      if (!ignore_protection && pin_is_protected(pin)) continue;
279 279
       pinMode(pin, INPUT_PULLUP);
280 280
       delay(1);
281 281
       /*
@@ -295,7 +295,7 @@ void GcodeSuite::M43() {
295 295
       for (uint8_t i = first_pin; i <= last_pin; i++) {
296 296
         pin_t pin = GET_PIN_MAP_PIN(i);
297 297
         if (!VALID_PIN(pin)) continue;
298
-        if (pin_is_protected(pin) && !ignore_protection) continue;
298
+        if (!ignore_protection && pin_is_protected(pin)) continue;
299 299
         const byte val =
300 300
           /*
301 301
             IS_ANALOG(pin)

+ 13
- 20
Marlin/src/gcode/control/M226.cpp View File

@@ -33,27 +33,20 @@ void GcodeSuite::M226() {
33 33
               pin_state = parser.intval('S', -1); // required pin state - default is inverted
34 34
     const pin_t pin = GET_PIN_MAP_PIN(pin_number);
35 35
 
36
-    if (WITHIN(pin_state, -1, 1) && pin > -1 && !pin_is_protected(pin)) {
37
-
38
-      int target = LOW;
39
-
40
-      planner.synchronize();
41
-
42
-      pinMode(pin, INPUT);
43
-      switch (pin_state) {
44
-        case 1:
45
-          target = HIGH;
46
-          break;
47
-        case 0:
48
-          target = LOW;
49
-          break;
50
-        case -1:
51
-          target = !digitalRead(pin);
52
-          break;
36
+    if (WITHIN(pin_state, -1, 1) && pin > -1) {
37
+      if (pin_is_protected(pin))
38
+        protected_pin_err();
39
+      else {
40
+        int target = LOW;
41
+        planner.synchronize();
42
+        pinMode(pin, INPUT);
43
+        switch (pin_state) {
44
+          case 1: target = HIGH; break;
45
+          case 0: target = LOW; break;
46
+          case -1: target = !digitalRead(pin); break;
47
+        }
48
+        while (digitalRead(pin) != target) idle();
53 49
       }
54
-
55
-      while (digitalRead(pin) != target) idle();
56
-
57 50
     } // pin_state -1 0 1 && pin > -1
58 51
   } // parser.seen('P')
59 52
 }

+ 2
- 5
Marlin/src/gcode/control/M42.cpp View File

@@ -41,11 +41,8 @@ void GcodeSuite::M42() {
41 41
   if (pin_index < 0) return;
42 42
 
43 43
   const pin_t pin = GET_PIN_MAP_PIN(pin_index);
44
-  if (pin_is_protected(pin)) {
45
-    SERIAL_ERROR_START();
46
-    SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);
47
-    return;
48
-  }
44
+
45
+  if (pin_is_protected(pin_number)) return protected_pin_err();
49 46
 
50 47
   pinMode(pin, OUTPUT);
51 48
   digitalWrite(pin, pin_status);

Loading…
Cancel
Save