Browse Source

Additional tweaks to M42 exit conditions

Scott Lahteine 8 years ago
parent
commit
38b0082bf2
1 changed files with 24 additions and 24 deletions
  1. 24
    24
      Marlin/Marlin_main.cpp

+ 24
- 24
Marlin/Marlin_main.cpp View File

@@ -3584,39 +3584,39 @@ inline void gcode_M31() {
3584 3584
 
3585 3585
 /**
3586 3586
  * M42: Change pin status via GCode
3587
+ *
3588
+ *  P<pin>  Pin number (LED if omitted)
3589
+ *  S<byte> Pin status from 0 - 255
3587 3590
  */
3588 3591
 inline void gcode_M42() {
3589 3592
   if (code_seen('S')) {
3590
-    int pin_status = code_value_short(),
3591
-        pin_number = LED_PIN;
3592
-
3593
-    if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
3594
-      pin_number = code_value_short();
3593
+    int pin_status = code_value_short();
3594
+    if (pin_status < 0 || pin_status > 255) return;
3595 3595
 
3596
-    for (uint8_t i = 0; i < COUNT(sensitive_pins); i++) {
3597
-      if (sensitive_pins[i] == pin_number) {
3598
-        pin_number = -1;
3599
-        break;
3600
-      }
3601
-    }
3596
+    int pin_number = code_seen('P') ? code_value_short() : LED_PIN;
3597
+    if (pin_number < 0) return;
3602 3598
 
3603
-    #if HAS_FAN0
3604
-      if (pin_number == FAN_PIN)  fanSpeeds[0] = pin_status;
3605
-    #endif
3599
+    for (uint8_t i = 0; i < COUNT(sensitive_pins); i++)
3600
+      if (pin_number == sensitive_pins[i]) return;
3606 3601
 
3607
-    #if HAS_FAN1
3608
-      if (pin_number == FAN1_PIN) fanSpeeds[1] = pin_status;
3609
-    #endif
3602
+    pinMode(pin_number, OUTPUT);
3603
+    digitalWrite(pin_number, pin_status);
3604
+    analogWrite(pin_number, pin_status);
3610 3605
 
3611
-    #if HAS_FAN2
3612
-      if (pin_number == FAN2_PIN) fanSpeeds[2] = pin_status;
3606
+    #if FAN_COUNT > 0
3607
+      switch (pin_number) {
3608
+        #if HAS_FAN0
3609
+          case FAN_PIN: fanSpeeds[0] = pin_status; break;
3610
+        #endif
3611
+        #if HAS_FAN1
3612
+          case FAN1_PIN: fanSpeeds[1] = pin_status; break;
3613
+        #endif
3614
+        #if HAS_FAN2
3615
+          case FAN2_PIN: fanSpeeds[2] = pin_status; break;
3616
+        #endif
3617
+      }
3613 3618
     #endif
3614 3619
 
3615
-    if (pin_number > -1) {
3616
-      pinMode(pin_number, OUTPUT);
3617
-      digitalWrite(pin_number, pin_status);
3618
-      analogWrite(pin_number, pin_status);
3619
-    }
3620 3620
   } // code_seen('S')
3621 3621
 }
3622 3622
 

Loading…
Cancel
Save