|
@@ -37,16 +37,33 @@
|
37
|
37
|
*
|
38
|
38
|
* S<byte> Pin status from 0 - 255
|
39
|
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
|
43
|
void GcodeSuite::M42() {
|
42
|
|
- if (!parser.seenval('S')) return;
|
43
|
|
- const byte pin_status = parser.value_byte();
|
44
|
|
-
|
45
|
44
|
const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
|
46
|
45
|
if (pin_index < 0) return;
|
47
|
46
|
|
48
|
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
|
67
|
#if FAN_COUNT > 0
|
51
|
68
|
switch (pin) {
|
52
|
69
|
#if HAS_FAN0
|
|
@@ -76,8 +93,6 @@ void GcodeSuite::M42() {
|
76
|
93
|
}
|
77
|
94
|
#endif
|
78
|
95
|
|
79
|
|
- if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
|
80
|
|
-
|
81
|
96
|
pinMode(pin, OUTPUT);
|
82
|
97
|
extDigitalWrite(pin, pin_status);
|
83
|
98
|
analogWrite(pin, pin_status);
|