Browse Source

Add M42 M, improve M43 (#17173)

InsanityAutomation 5 years ago
parent
commit
84dec5da10
No account linked to committer's email address
2 changed files with 22 additions and 5 deletions
  1. 2
    0
      Marlin/src/gcode/config/M43.cpp
  2. 20
    5
      Marlin/src/gcode/control/M42.cpp

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

67
     else {
67
     else {
68
       watchdog_refresh();
68
       watchdog_refresh();
69
       report_pin_state_extended(pin, ignore_protection, true, PSTR("Pulsing   "));
69
       report_pin_state_extended(pin, ignore_protection, true, PSTR("Pulsing   "));
70
+      const bool prior_mode = GET_PINMODE(pin);
70
       #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
71
       #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
71
         if (pin == TEENSY_E2) {
72
         if (pin == TEENSY_E2) {
72
           SET_OUTPUT(TEENSY_E2);
73
           SET_OUTPUT(TEENSY_E2);
95
           watchdog_refresh();
96
           watchdog_refresh();
96
         }
97
         }
97
       }
98
       }
99
+      pinMode(pin, prior_mode);
98
     }
100
     }
99
     SERIAL_EOL();
101
     SERIAL_EOL();
100
   }
102
   }

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

37
  *
37
  *
38
  *  S<byte> Pin status from 0 - 255
38
  *  S<byte> Pin status from 0 - 255
39
  *  I       Flag to ignore Marlin's pin protection
39
  *  I       Flag to ignore Marlin's pin protection
40
+ *
41
+ *  M<mode> Pin mode: 0=INPUT  1=OUTPUT  2=INPUT_PULLUP  3=INPUT_PULLDOWN
40
  */
42
  */
41
 void GcodeSuite::M42() {
43
 void GcodeSuite::M42() {
42
-  if (!parser.seenval('S')) return;
43
-  const byte pin_status = parser.value_byte();
44
-
45
   const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
44
   const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
46
   if (pin_index < 0) return;
45
   if (pin_index < 0) return;
47
 
46
 
48
   const pin_t pin = GET_PIN_MAP_PIN(pin_index);
47
   const pin_t pin = GET_PIN_MAP_PIN(pin_index);
49
 
48
 
49
+  if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
50
+
51
+  if (parser.seenval('M')) {
52
+    switch (parser.value_byte()) {
53
+      case 0: pinMode(pin, INPUT); break;
54
+      case 1: pinMode(pin, OUTPUT); break;
55
+      case 2: pinMode(pin, INPUT_PULLUP); break;
56
+      #ifdef INPUT_PULLDOWN
57
+        case 3: pinMode(pin, INPUT_PULLDOWN); break;
58
+      #endif
59
+      default: SERIAL_ECHOLNPGM("Invalid Pin Mode");
60
+    }
61
+    return;
62
+  }
63
+
64
+  if (!parser.seenval('S')) return;
65
+  const byte pin_status = parser.value_byte();
66
+
50
   #if FAN_COUNT > 0
67
   #if FAN_COUNT > 0
51
     switch (pin) {
68
     switch (pin) {
52
       #if HAS_FAN0
69
       #if HAS_FAN0
76
     }
93
     }
77
   #endif
94
   #endif
78
 
95
 
79
-  if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
80
-
81
   pinMode(pin, OUTPUT);
96
   pinMode(pin, OUTPUT);
82
   extDigitalWrite(pin, pin_status);
97
   extDigitalWrite(pin, pin_status);
83
   analogWrite(pin, pin_status);
98
   analogWrite(pin, pin_status);

Loading…
Cancel
Save