Browse Source

Add M42 M, improve M43 (#17173)

vanilla_fb_2.0.x
InsanityAutomation 5 years ago
committed by GitHub
parent
commit
84dec5da10
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Marlin/src/gcode/config/M43.cpp
  2. 25
      Marlin/src/gcode/control/M42.cpp

2
Marlin/src/gcode/config/M43.cpp

@ -67,6 +67,7 @@ inline void toggle_pins() {
else {
watchdog_refresh();
report_pin_state_extended(pin, ignore_protection, true, PSTR("Pulsing "));
const bool prior_mode = GET_PINMODE(pin);
#if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
if (pin == TEENSY_E2) {
SET_OUTPUT(TEENSY_E2);
@ -95,6 +96,7 @@ inline void toggle_pins() {
watchdog_refresh();
}
}
pinMode(pin, prior_mode);
}
SERIAL_EOL();
}

25
Marlin/src/gcode/control/M42.cpp

@ -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);

Loading…
Cancel
Save