Bläddra i källkod

Some cleanup to M43

Scott Lahteine 8 år sedan
förälder
incheckning
04a1fac029
1 ändrade filer med 30 tillägg och 18 borttagningar
  1. 30
    18
      Marlin/Marlin_main.cpp

+ 30
- 18
Marlin/Marlin_main.cpp Visa fil

@@ -4676,26 +4676,43 @@ inline void gcode_M42() {
4676 4676
   /**
4677 4677
    * M43: Pin report and debug
4678 4678
    *
4679
-   *      pin report if just M43 with no codes
4680
-   *      P<pin> Will read/watch a single pin
4681
-   *      W      Watch pins for changes until reboot
4682
-   *      E      toggles endstop monitor
4683
-   *               reports changes to endstops
4684
-   *               toggles LED when endstop changes
4685
-   *               background function (machine continues to operate as normal)
4679
+   *      E<bool> Enable / disable background endstop monitoring
4680
+   *               - Machine continues to operate
4681
+   *               - Reports changes to endstops
4682
+   *               - Toggles LED when an endstop changes
4683
+   *
4684
+   *   or
4685
+   *
4686
+   *      P<pin>  Pin to read or watch. If omitted, read/watch all pins.
4687
+   *      W<bool> Watch pins -reporting changes- until reset, click, or M108.
4688
+   *      I<bool> Flag to ignore Marlin's pin protection.
4686 4689
    *
4687 4690
    */
4688 4691
   inline void gcode_M43() {
4692
+
4693
+    // Enable or disable endstop monitoring
4694
+    if (code_seen('E')) {
4695
+      endstop_monitor_flag = code_value_bool();
4696
+      SERIAL_PROTOCOLPGM("endstop monitor ");
4697
+      SERIAL_PROTOCOL(endstop_monitor_flag ? "en" : "dis");
4698
+      SERIAL_PROTOCOLLNPGM("abled");
4699
+      return;
4700
+    }
4701
+
4702
+    // Get the range of pins to test or watch
4689 4703
     int first_pin = 0, last_pin = DIO_COUNT - 1;
4690 4704
     if (code_seen('P')) {
4691 4705
       first_pin = last_pin = code_value_byte();
4692 4706
       if (first_pin > DIO_COUNT - 1) return;
4693 4707
     }
4694 4708
 
4709
+    bool ignore_protection = code_seen('I') ? code_value_bool() : false;
4710
+
4711
+    // Watch until click, M108, or reset
4695 4712
     if (code_seen('W') && code_value_bool()) { // watch digital pins
4696 4713
       byte pin_state[last_pin - first_pin + 1];
4697 4714
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
4698
-        if (pin_is_protected(pin)) continue;
4715
+        if (pin_is_protected(pin) && !ignore_protection) continue;
4699 4716
         pinMode(pin, INPUT_PULLUP);
4700 4717
         // if (IS_ANALOG(pin))
4701 4718
         //   pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
@@ -4727,17 +4744,12 @@ inline void gcode_M42() {
4727 4744
 
4728 4745
         safe_delay(500);
4729 4746
       }
4747
+      return;
4730 4748
     }
4731
-    if ( !(code_seen('P') || code_seen('W') || code_seen('E')))   // single pins report
4732
-      for (uint8_t pin = first_pin; pin <= last_pin; pin++)
4733
-        report_pin_state_extended(pin, code_seen('I') );        // "hidden" option to ignore protected list
4734
-    
4735
-    if (code_seen('E')) {
4736
-      endstop_monitor_flag ^= true;
4737
-      SERIAL_PROTOCOLPGM("endstop monitor ");
4738
-      SERIAL_PROTOCOL(endstop_monitor_flag ? "en" : "dis");
4739
-      SERIAL_PROTOCOLLNPGM("abled");
4740
-    }    
4749
+
4750
+    // Report current state of selected pin(s)
4751
+    for (uint8_t pin = first_pin; pin <= last_pin; pin++)
4752
+      report_pin_state_extended(pin, ignore_protection);
4741 4753
   }
4742 4754
 
4743 4755
 #endif // PINS_DEBUGGING

Laddar…
Avbryt
Spara