From 38b0082bf2ef262e93e4fedbf83eabf26d579b8b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 6 Mar 2016 02:20:03 -0800 Subject: [PATCH] Additional tweaks to M42 exit conditions --- Marlin/Marlin_main.cpp | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 3843a379d..bd66e3723 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3584,39 +3584,39 @@ inline void gcode_M31() { /** * M42: Change pin status via GCode + * + * P Pin number (LED if omitted) + * S Pin status from 0 - 255 */ inline void gcode_M42() { if (code_seen('S')) { - int pin_status = code_value_short(), - pin_number = LED_PIN; - - if (code_seen('P') && pin_status >= 0 && pin_status <= 255) - pin_number = code_value_short(); + int pin_status = code_value_short(); + if (pin_status < 0 || pin_status > 255) return; - for (uint8_t i = 0; i < COUNT(sensitive_pins); i++) { - if (sensitive_pins[i] == pin_number) { - pin_number = -1; - break; - } - } + int pin_number = code_seen('P') ? code_value_short() : LED_PIN; + if (pin_number < 0) return; - #if HAS_FAN0 - if (pin_number == FAN_PIN) fanSpeeds[0] = pin_status; - #endif + for (uint8_t i = 0; i < COUNT(sensitive_pins); i++) + if (pin_number == sensitive_pins[i]) return; - #if HAS_FAN1 - if (pin_number == FAN1_PIN) fanSpeeds[1] = pin_status; - #endif + pinMode(pin_number, OUTPUT); + digitalWrite(pin_number, pin_status); + analogWrite(pin_number, pin_status); - #if HAS_FAN2 - if (pin_number == FAN2_PIN) fanSpeeds[2] = pin_status; + #if FAN_COUNT > 0 + switch (pin_number) { + #if HAS_FAN0 + case FAN_PIN: fanSpeeds[0] = pin_status; break; + #endif + #if HAS_FAN1 + case FAN1_PIN: fanSpeeds[1] = pin_status; break; + #endif + #if HAS_FAN2 + case FAN2_PIN: fanSpeeds[2] = pin_status; break; + #endif + } #endif - if (pin_number > -1) { - pinMode(pin_number, OUTPUT); - digitalWrite(pin_number, pin_status); - analogWrite(pin_number, pin_status); - } } // code_seen('S') }