Add M42 M, improve M43 (#17173)

This commit is contained in:
InsanityAutomation
2020-03-18 17:12:51 -04:00
committed by GitHub
parent de45ac41ad
commit 84dec5da10
2 changed files with 22 additions and 5 deletions

View File

@ -37,16 +37,33 @@
*
* S<byte> Pin status from 0 - 255
* I Flag to ignore Marlin's pin protection
*
* M<mode> Pin mode: 0=INPUT 1=OUTPUT 2=INPUT_PULLUP 3=INPUT_PULLDOWN
*/
void GcodeSuite::M42() {
if (!parser.seenval('S')) return;
const byte pin_status = parser.value_byte();
const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
if (pin_index < 0) return;
const pin_t pin = GET_PIN_MAP_PIN(pin_index);
if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
if (parser.seenval('M')) {
switch (parser.value_byte()) {
case 0: pinMode(pin, INPUT); break;
case 1: pinMode(pin, OUTPUT); break;
case 2: pinMode(pin, INPUT_PULLUP); break;
#ifdef INPUT_PULLDOWN
case 3: pinMode(pin, INPUT_PULLDOWN); break;
#endif
default: SERIAL_ECHOLNPGM("Invalid Pin Mode");
}
return;
}
if (!parser.seenval('S')) return;
const byte pin_status = parser.value_byte();
#if FAN_COUNT > 0
switch (pin) {
#if HAS_FAN0
@ -76,8 +93,6 @@ void GcodeSuite::M42() {
}
#endif
if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
pinMode(pin, OUTPUT);
extDigitalWrite(pin, pin_status);
analogWrite(pin, pin_status);