Browse Source

Protected pin err for M226

Scott Lahteine 7 years ago
parent
commit
968a5d2e63

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

264
   return false;
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
 void quickstop_stepper() {
272
 void quickstop_stepper() {
268
   planner.quick_stop();
273
   planner.quick_stop();
269
   planner.synchronize();
274
   planner.synchronize();

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

219
 #endif
219
 #endif
220
 
220
 
221
 bool pin_is_protected(const pin_t pin);
221
 bool pin_is_protected(const pin_t pin);
222
+void protected_pin_err();
222
 
223
 
223
 #if HAS_SUICIDE
224
 #if HAS_SUICIDE
224
   inline void suicide() { OUT_WRITE(SUICIDE_PIN, LOW); }
225
   inline void suicide() { OUT_WRITE(SUICIDE_PIN, LOW); }

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

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

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

33
               pin_state = parser.intval('S', -1); // required pin state - default is inverted
33
               pin_state = parser.intval('S', -1); // required pin state - default is inverted
34
     const pin_t pin = GET_PIN_MAP_PIN(pin_number);
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
     } // pin_state -1 0 1 && pin > -1
50
     } // pin_state -1 0 1 && pin > -1
58
   } // parser.seen('P')
51
   } // parser.seen('P')
59
 }
52
 }

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

41
   if (pin_index < 0) return;
41
   if (pin_index < 0) return;
42
 
42
 
43
   const pin_t pin = GET_PIN_MAP_PIN(pin_index);
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
   pinMode(pin, OUTPUT);
47
   pinMode(pin, OUTPUT);
51
   digitalWrite(pin, pin_status);
48
   digitalWrite(pin, pin_status);

Loading…
Cancel
Save