Sfoglia il codice sorgente

Cleanup of pins testing code

Scott Lahteine 8 anni fa
parent
commit
e97f1284c1
2 ha cambiato i file con 115 aggiunte e 75 eliminazioni
  1. 114
    70
      Marlin/Marlin_main.cpp
  2. 1
    5
      Marlin/pinsDebug.h

+ 114
- 70
Marlin/Marlin_main.cpp Vedi File

5806
   #include "pinsDebug.h"
5806
   #include "pinsDebug.h"
5807
 
5807
 
5808
   inline void toggle_pins() {
5808
   inline void toggle_pins() {
5809
-    int pin, j;
5809
+    const bool I_flag = code_seen('I') && code_value_bool();
5810
+    const int repeat = code_seen('R') ? code_value_int() : 1,
5811
+              start = code_seen('S') ? code_value_int() : 0,
5812
+              end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
5813
+              wait = code_seen('W') ? code_value_int() : 500;
5810
 
5814
 
5811
-    bool I_flag = code_seen('I') ? code_value_bool() : false;
5812
-
5813
-    int repeat = code_seen('R') ? code_value_int() : 1,
5814
-        start = code_seen('S') ? code_value_int() : 0,
5815
-        end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
5816
-        wait = code_seen('W') ? code_value_int() : 500;
5817
-
5818
-    for (pin = start; pin <= end; pin++) {
5819
-        if (!I_flag && pin_is_protected(pin)) {
5820
-          SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
5821
-          SERIAL_ECHOPGM(" untouched.\n");
5822
-        }
5823
-        else {
5824
-          SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
5825
-          pinMode(pin, OUTPUT);
5826
-          for(j = 0; j < repeat; j++) {
5827
-            digitalWrite(pin, 0);
5828
-            safe_delay(wait);
5829
-            digitalWrite(pin, 1);
5830
-            safe_delay(wait);
5831
-            digitalWrite(pin, 0);
5832
-            safe_delay(wait);
5833
-          }
5815
+    for (uint8_t pin = start; pin <= end; pin++) {
5816
+      if (!I_flag && pin_is_protected(pin)) {
5817
+        SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
5818
+        SERIAL_ECHOLNPGM(" untouched.");
5819
+      }
5820
+      else {
5821
+        SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
5822
+        pinMode(pin, OUTPUT);
5823
+        for (int16_t j = 0; j < repeat; j++) {
5824
+          digitalWrite(pin, 0);
5825
+          safe_delay(wait);
5826
+          digitalWrite(pin, 1);
5827
+          safe_delay(wait);
5828
+          digitalWrite(pin, 0);
5829
+          safe_delay(wait);
5834
         }
5830
         }
5835
-      SERIAL_ECHOPGM("\n");
5831
+      }
5832
+      SERIAL_CHAR('\n');
5836
     }
5833
     }
5837
-    SERIAL_ECHOPGM("Done\n");
5834
+    SERIAL_ECHOLNPGM("Done.");
5835
+
5838
   } // toggle_pins
5836
   } // toggle_pins
5839
 
5837
 
5840
-  inline void servo_probe_test(){
5841
-    #if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
5838
+  inline void servo_probe_test() {
5839
+    #if !(NUM_SERVOS > 0 && HAS_SERVO_0)
5840
+
5842
       SERIAL_ERROR_START;
5841
       SERIAL_ERROR_START;
5843
       SERIAL_ERRORLNPGM("SERVO not setup");
5842
       SERIAL_ERRORLNPGM("SERVO not setup");
5843
+
5844
     #elif !HAS_Z_SERVO_ENDSTOP
5844
     #elif !HAS_Z_SERVO_ENDSTOP
5845
+
5845
       SERIAL_ERROR_START;
5846
       SERIAL_ERROR_START;
5846
       SERIAL_ERRORLNPGM("Z_ENDSTOP_SERVO_NR not setup");
5847
       SERIAL_ERRORLNPGM("Z_ENDSTOP_SERVO_NR not setup");
5848
+
5847
     #else
5849
     #else
5848
-      uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
5850
+
5851
+      #if !defined(z_servo_angle)
5852
+        const int z_servo_angle[2] = Z_SERVO_ANGLES;
5853
+      #endif
5854
+
5855
+      const uint8_t probe_index = code_seen('P') ? code_value_byte() : Z_ENDSTOP_SERVO_NR;
5856
+
5849
       SERIAL_PROTOCOLLNPGM("Servo probe test");
5857
       SERIAL_PROTOCOLLNPGM("Servo probe test");
5850
       SERIAL_PROTOCOLLNPAIR(".  using index:  ", probe_index);
5858
       SERIAL_PROTOCOLLNPAIR(".  using index:  ", probe_index);
5851
       SERIAL_PROTOCOLLNPAIR(".  deploy angle: ", z_servo_angle[0]);
5859
       SERIAL_PROTOCOLLNPAIR(".  deploy angle: ", z_servo_angle[0]);
5852
       SERIAL_PROTOCOLLNPAIR(".  stow angle:   ", z_servo_angle[1]);
5860
       SERIAL_PROTOCOLLNPAIR(".  stow angle:   ", z_servo_angle[1]);
5861
+
5853
       bool probe_inverting;
5862
       bool probe_inverting;
5863
+
5854
       #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
5864
       #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
5865
+
5855
         #define PROBE_TEST_PIN Z_MIN_PIN
5866
         #define PROBE_TEST_PIN Z_MIN_PIN
5867
+
5856
         SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
5868
         SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
5857
         SERIAL_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
5869
         SERIAL_PROTOCOLLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
5858
         SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
5870
         SERIAL_PROTOCOLPGM(". Z_MIN_ENDSTOP_INVERTING: ");
5859
-        if (Z_MIN_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
5860
-        else  SERIAL_PROTOCOLLNPGM("false");
5871
+
5872
+        #if Z_MIN_ENDSTOP_INVERTING
5873
+          SERIAL_PROTOCOLLNPGM("true");
5874
+        #else
5875
+          SERIAL_PROTOCOLLNPGM("false");
5876
+        #endif
5877
+
5861
         probe_inverting = Z_MIN_ENDSTOP_INVERTING;
5878
         probe_inverting = Z_MIN_ENDSTOP_INVERTING;
5879
+
5862
       #elif ENABLED(Z_MIN_PROBE_ENDSTOP)
5880
       #elif ENABLED(Z_MIN_PROBE_ENDSTOP)
5881
+
5863
         #define PROBE_TEST_PIN Z_MIN_PROBE_PIN
5882
         #define PROBE_TEST_PIN Z_MIN_PROBE_PIN
5864
         SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
5883
         SERIAL_PROTOCOLLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
5865
         SERIAL_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
5884
         SERIAL_PROTOCOLLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
5866
         SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
5885
         SERIAL_PROTOCOLPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
5867
-        if (Z_MIN_PROBE_ENDSTOP_INVERTING) SERIAL_PROTOCOLLNPGM("true");
5868
-        else  SERIAL_PROTOCOLLNPGM("false");
5886
+
5887
+        #if Z_MIN_PROBE_ENDSTOP_INVERTING
5888
+          SERIAL_PROTOCOLLNPGM("true");
5889
+        #else
5890
+          SERIAL_PROTOCOLLNPGM("false");
5891
+        #endif
5892
+
5869
         probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
5893
         probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
5870
-      #else
5871
-        #error "ERROR - probe pin not defined - strange, SANITY_CHECK should have caught this"
5894
+
5872
       #endif
5895
       #endif
5896
+
5873
       SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
5897
       SERIAL_PROTOCOLLNPGM(". deploy & stow 4 times");
5874
       pinMode(PROBE_TEST_PIN, INPUT_PULLUP);
5898
       pinMode(PROBE_TEST_PIN, INPUT_PULLUP);
5875
       bool deploy_state;
5899
       bool deploy_state;
5883
         stow_state = digitalRead(PROBE_TEST_PIN);
5907
         stow_state = digitalRead(PROBE_TEST_PIN);
5884
       }
5908
       }
5885
       if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
5909
       if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
5910
+
5886
       refresh_cmd_timeout();
5911
       refresh_cmd_timeout();
5912
+
5887
       if (deploy_state != stow_state) {
5913
       if (deploy_state != stow_state) {
5888
         SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
5914
         SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
5889
         if (deploy_state) {
5915
         if (deploy_state) {
5900
 
5926
 
5901
       }
5927
       }
5902
       else {                                           // measure active signal length
5928
       else {                                           // measure active signal length
5903
-        servo[probe_index].move(z_servo_angle[0]); //deploy
5929
+        servo[probe_index].move(z_servo_angle[0]);     // deploy
5904
         safe_delay(500);
5930
         safe_delay(500);
5905
         SERIAL_PROTOCOLLNPGM("please trigger probe");
5931
         SERIAL_PROTOCOLLNPGM("please trigger probe");
5906
         uint16_t probe_counter = 0;
5932
         uint16_t probe_counter = 0;
5907
-        for (uint16_t j = 0; j < 500*30 && probe_counter == 0 ; j++) {   // allow 30 seconds max for operator to trigger probe
5933
+
5934
+        // Allow 30 seconds max for operator to trigger probe
5935
+        for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
5936
+
5908
           safe_delay(2);
5937
           safe_delay(2);
5909
-          if ( 0 == j%(500*1)) {refresh_cmd_timeout(); watchdog_reset();}  // beat the dog every 45 seconds
5910
-          if (deploy_state != digitalRead(PROBE_TEST_PIN)) {             // probe triggered
5911
-            for (probe_counter = 1; probe_counter < 50 && (deploy_state != digitalRead(PROBE_TEST_PIN)); probe_counter ++) {
5938
+
5939
+          if (0 == j % (500 * 1)) // keep cmd_timeout happy
5940
+            refresh_cmd_timeout();
5941
+
5942
+          if (deploy_state != digitalRead(PROBE_TEST_PIN)) { // probe triggered
5943
+
5944
+            for (probe_counter = 1; probe_counter < 50 && deploy_state != digitalRead(PROBE_TEST_PIN); ++probe_counter)
5912
               safe_delay(2);
5945
               safe_delay(2);
5913
-            }
5914
-            if (probe_counter == 50) {
5915
-              SERIAL_PROTOCOLLNPGM("Z Servo Probe detected");   // >= 100mS active time
5916
-            }
5917
-            else if (probe_counter >= 2 ) {
5918
-              SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2 );   // allow 4 - 100mS pulse
5919
-            }
5920
-            else {
5921
-              SERIAL_PROTOCOLLNPGM("noise detected - please re-run test");   // less than 2mS pulse
5922
-            }
5946
+
5947
+            if (probe_counter == 50)
5948
+              SERIAL_PROTOCOLLNPGM("Z Servo Probe detected"); // >= 100mS active time
5949
+            else if (probe_counter >= 2)
5950
+              SERIAL_PROTOCOLLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
5951
+            else
5952
+              SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
5953
+
5923
             servo[probe_index].move(z_servo_angle[1]); //stow
5954
             servo[probe_index].move(z_servo_angle[1]); //stow
5955
+
5924
           }  // pulse detected
5956
           }  // pulse detected
5925
-        }    // for loop waiting for trigger
5957
+
5958
+        } // for loop waiting for trigger
5959
+
5926
         if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
5960
         if (probe_counter == 0) SERIAL_PROTOCOLLNPGM("trigger not detected");
5927
-      }      // measure active signal length
5961
+
5962
+      } // measure active signal length
5963
+
5928
     #endif
5964
     #endif
5965
+
5929
   } // servo_probe_test
5966
   } // servo_probe_test
5930
 
5967
 
5931
   /**
5968
   /**
5977
     }
6014
     }
5978
 
6015
 
5979
     // Get the range of pins to test or watch
6016
     // Get the range of pins to test or watch
5980
-    int first_pin = 0, last_pin = NUM_DIGITAL_PINS - 1;
5981
-    if (code_seen('P')) {
5982
-      first_pin = last_pin = code_value_byte();
5983
-      if (first_pin > NUM_DIGITAL_PINS - 1) return;
5984
-    }
6017
+    const uint8_t first_pin = code_seen('P') ? code_value_byte() : 0,
6018
+                  last_pin = code_seen('P') ? first_pin : NUM_DIGITAL_PINS - 1;
5985
 
6019
 
5986
-    bool ignore_protection = code_seen('I') ? code_value_bool() : false;
6020
+    if (first_pin > last_pin) return;
6021
+
6022
+    const bool ignore_protection = code_seen('I') && code_value_bool();
5987
 
6023
 
5988
     // Watch until click, M108, or reset
6024
     // Watch until click, M108, or reset
5989
-    if (code_seen('W') && code_value_bool()) { // watch digital pins
6025
+    if (code_seen('W') && code_value_bool()) {
5990
       SERIAL_PROTOCOLLNPGM("Watching pins");
6026
       SERIAL_PROTOCOLLNPGM("Watching pins");
5991
       byte pin_state[last_pin - first_pin + 1];
6027
       byte pin_state[last_pin - first_pin + 1];
5992
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6028
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
5993
         if (pin_is_protected(pin) && !ignore_protection) continue;
6029
         if (pin_is_protected(pin) && !ignore_protection) continue;
5994
         pinMode(pin, INPUT_PULLUP);
6030
         pinMode(pin, INPUT_PULLUP);
5995
-        // if (IS_ANALOG(pin))
5996
-        //   pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
5997
-        // else
5998
-          pin_state[pin - first_pin] = digitalRead(pin);
6031
+        /*
6032
+          if (IS_ANALOG(pin))
6033
+            pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
6034
+          else
6035
+        //*/
6036
+            pin_state[pin - first_pin] = digitalRead(pin);
5999
       }
6037
       }
6000
 
6038
 
6001
       #if HAS_RESUME_CONTINUE
6039
       #if HAS_RESUME_CONTINUE
6002
         wait_for_user = true;
6040
         wait_for_user = true;
6041
+        KEEPALIVE_STATE(PAUSED_FOR_USER);
6003
       #endif
6042
       #endif
6004
 
6043
 
6005
-      for(;;) {
6044
+      for (;;) {
6006
         for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6045
         for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6007
           if (pin_is_protected(pin)) continue;
6046
           if (pin_is_protected(pin)) continue;
6008
-          byte val;
6009
-          // if (IS_ANALOG(pin))
6010
-          //   val = analogRead(pin - analogInputToDigitalPin(0)); // int16_t val
6011
-          // else
6012
-            val = digitalRead(pin);
6047
+          const byte val =
6048
+            /*
6049
+              IS_ANALOG(pin)
6050
+                ? analogRead(pin - analogInputToDigitalPin(0)) : // int16_t val
6051
+                :
6052
+            //*/
6053
+              digitalRead(pin);
6013
           if (val != pin_state[pin - first_pin]) {
6054
           if (val != pin_state[pin - first_pin]) {
6014
             report_pin_state(pin);
6055
             report_pin_state(pin);
6015
             pin_state[pin - first_pin] = val;
6056
             pin_state[pin - first_pin] = val;
6017
         }
6058
         }
6018
 
6059
 
6019
         #if HAS_RESUME_CONTINUE
6060
         #if HAS_RESUME_CONTINUE
6020
-          if (!wait_for_user) break;
6061
+          if (!wait_for_user) {
6062
+            KEEPALIVE_STATE(IN_HANDLER);
6063
+            break;
6064
+          }
6021
         #endif
6065
         #endif
6022
 
6066
 
6023
         safe_delay(500);
6067
         safe_delay(500);

+ 1
- 5
Marlin/pinsDebug.h Vedi File

255
   SERIAL_PROTOCOLPGM("   non-standard PWM mode");
255
   SERIAL_PROTOCOLPGM("   non-standard PWM mode");
256
 }
256
 }
257
 static void err_is_interrupt() {
257
 static void err_is_interrupt() {
258
-  SERIAL_PROTOCOLPGM("   compare interrupt enabled ");
258
+  SERIAL_PROTOCOLPGM("   compare interrupt enabled");
259
 }
259
 }
260
 static void err_prob_interrupt() {
260
 static void err_prob_interrupt() {
261
   SERIAL_PROTOCOLPGM("   overflow interrupt enabled");
261
   SERIAL_PROTOCOLPGM("   overflow interrupt enabled");
262
 }
262
 }
263
-static void can_be_used() { SERIAL_PROTOCOLPGM("   can be used as PWM   "); }
264
 
263
 
265
 void com_print(uint8_t N, uint8_t Z) {
264
 void com_print(uint8_t N, uint8_t Z) {
266
   uint8_t *TCCRA = (uint8_t*) TCCR_A(N);
265
   uint8_t *TCCRA = (uint8_t*) TCCR_A(N);
325
 }
324
 }
326
 
325
 
327
 static void pwm_details(uint8_t pin) {
326
 static void pwm_details(uint8_t pin) {
328
-  char buffer[20];   // for the sprintf statements
329
-  uint8_t WGM;
330
-
331
   switch(digitalPinToTimer(pin)) {
327
   switch(digitalPinToTimer(pin)) {
332
 
328
 
333
     #if defined(TCCR0A) && defined(COM0A1)
329
     #if defined(TCCR0A) && defined(COM0A1)

Loading…
Annulla
Salva