Переглянути джерело

Move endstop debug to Endstops

Scott Lahteine 7 роки тому
джерело
коміт
2e20c53c9d

+ 0
- 2
Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h Переглянути файл

@@ -30,8 +30,6 @@ void HAL_analog_pin_state(char buffer[], int8_t pin) {
30 30
   sprintf(buffer, "Analog in =% 5d", analogRead(pin - analogInputToDigitalPin(0)));
31 31
 }
32 32
 
33
-bool endstop_monitor_flag = false;
34
-
35 33
 #define NAME_FORMAT "%-35s"   // one place to specify the format of all the sources of names
36 34
                                // "-" left justify, "28" minimum width of name, pad with blanks
37 35
 

+ 0
- 12
Marlin/src/core/enum.h Переглянути файл

@@ -69,18 +69,6 @@ typedef enum {
69 69
   TEMPUNIT_F
70 70
 } TempUnit;
71 71
 
72
-enum EndstopEnum {
73
-  X_MIN,
74
-  Y_MIN,
75
-  Z_MIN,
76
-  Z_MIN_PROBE,
77
-  X_MAX,
78
-  Y_MAX,
79
-  Z_MAX,
80
-  Z2_MIN,
81
-  Z2_MAX
82
-};
83
-
84 72
 #if ENABLED(EMERGENCY_PARSER)
85 73
   enum e_parser_state {
86 74
     state_RESET,

+ 2
- 2
Marlin/src/gcode/config/M43.cpp Переглянути файл

@@ -245,9 +245,9 @@ void GcodeSuite::M43() {
245 245
 
246 246
   // Enable or disable endstop monitoring
247 247
   if (parser.seen('E')) {
248
-    endstop_monitor_flag = parser.value_bool();
248
+    endstops.monitor_flag = parser.value_bool();
249 249
     SERIAL_PROTOCOLPGM("endstop monitor ");
250
-    serialprintPGM(endstop_monitor_flag ? PSTR("en") : PSTR("dis"));
250
+    serialprintPGM(endstops.monitor_flag ? PSTR("en") : PSTR("dis"));
251 251
     SERIAL_PROTOCOLLNPGM("abled");
252 252
     return;
253 253
   }

+ 87
- 0
Marlin/src/module/endstops.cpp Переглянути файл

@@ -450,3 +450,90 @@ void Endstops::update() {
450 450
   old_endstop_bits = current_endstop_bits;
451 451
 
452 452
 } // Endstops::update()
453
+
454
+#if ENABLED(PINS_DEBUGGING)
455
+
456
+  bool Endstops::monitor_flag = false;
457
+
458
+  /**
459
+   * monitors endstops & Z probe for changes
460
+   *
461
+   * If a change is detected then the LED is toggled and
462
+   * a message is sent out the serial port
463
+   *
464
+   * Yes, we could miss a rapid back & forth change but
465
+   * that won't matter because this is all manual.
466
+   *
467
+   */
468
+  void Endstops::monitor() {
469
+
470
+    static uint16_t old_endstop_bits_local = 0;
471
+    static uint8_t local_LED_status = 0;
472
+    uint16_t current_endstop_bits_local = 0;
473
+
474
+    #if HAS_X_MIN
475
+      if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN);
476
+    #endif
477
+    #if HAS_X_MAX
478
+      if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX);
479
+    #endif
480
+    #if HAS_Y_MIN
481
+      if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN);
482
+    #endif
483
+    #if HAS_Y_MAX
484
+      if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX);
485
+    #endif
486
+    #if HAS_Z_MIN
487
+      if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN);
488
+    #endif
489
+    #if HAS_Z_MAX
490
+      if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX);
491
+    #endif
492
+    #if HAS_Z_MIN_PROBE_PIN
493
+      if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE);
494
+    #endif
495
+    #if HAS_Z2_MIN
496
+      if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN);
497
+    #endif
498
+    #if HAS_Z2_MAX
499
+      if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX);
500
+    #endif
501
+
502
+    uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local;
503
+
504
+    if (endstop_change) {
505
+      #if HAS_X_MIN
506
+        if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR("  X_MIN:", !!TEST(current_endstop_bits_local, X_MIN));
507
+      #endif
508
+      #if HAS_X_MAX
509
+        if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR("  X_MAX:", !!TEST(current_endstop_bits_local, X_MAX));
510
+      #endif
511
+      #if HAS_Y_MIN
512
+        if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR("  Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN));
513
+      #endif
514
+      #if HAS_Y_MAX
515
+        if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR("  Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX));
516
+      #endif
517
+      #if HAS_Z_MIN
518
+        if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR("  Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN));
519
+      #endif
520
+      #if HAS_Z_MAX
521
+        if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR("  Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX));
522
+      #endif
523
+      #if HAS_Z_MIN_PROBE_PIN
524
+        if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR("  PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE));
525
+      #endif
526
+      #if HAS_Z2_MIN
527
+        if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR("  Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN));
528
+      #endif
529
+      #if HAS_Z2_MAX
530
+        if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR("  Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX));
531
+      #endif
532
+      SERIAL_PROTOCOLPGM("\n\n");
533
+      analogWrite(LED_PIN, local_LED_status);
534
+      local_LED_status ^= 255;
535
+      old_endstop_bits_local = current_endstop_bits_local;
536
+    }
537
+  }
538
+
539
+#endif // PINS_DEBUGGING

+ 35
- 8
Marlin/src/module/endstops.h Переглянути файл

@@ -24,10 +24,23 @@
24 24
  *  endstops.h - manages endstops
25 25
  */
26 26
 
27
-#ifndef ENDSTOPS_H
28
-#define ENDSTOPS_H
29
-
30
-#include "../core/enum.h"
27
+#ifndef __ENDSTOPS_H__
28
+#define __ENDSTOPS_H__
29
+
30
+#include "../inc/MarlinConfig.h"
31
+#include <stdint.h>
32
+
33
+enum EndstopEnum {
34
+  X_MIN,
35
+  Y_MIN,
36
+  Z_MIN,
37
+  Z_MIN_PROBE,
38
+  X_MAX,
39
+  Y_MAX,
40
+  Z_MAX,
41
+  Z2_MIN,
42
+  Z2_MAX
43
+};
31 44
 
32 45
 class Endstops {
33 46
 
@@ -37,11 +50,12 @@ class Endstops {
37 50
     static volatile char endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
38 51
 
39 52
     #if ENABLED(Z_DUAL_ENDSTOPS)
40
-      static uint16_t
53
+      typedef uint16_t esbits_t;
41 54
     #else
42
-      static byte
55
+      typedef byte esbits_t;
43 56
     #endif
44
-        current_endstop_bits, old_endstop_bits;
57
+
58
+    static esbits_t current_endstop_bits, old_endstop_bits;
45 59
 
46 60
     Endstops() {};
47 61
 
@@ -83,6 +97,19 @@ class Endstops {
83 97
       static void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
84 98
     #endif
85 99
 
100
+    // Debugging of endstops
101
+    #if ENABLED(PINS_DEBUGGING)
102
+      static bool monitor_flag;
103
+      static void monitor();
104
+      FORCE_INLINE static void run_monitor() {
105
+        if (!monitor_flag) return;
106
+        static uint8_t monitor_count = 16;  // offset this check from the others
107
+        monitor_count += _BV(1);            //  15 Hz
108
+        monitor_count &= 0x7F;
109
+        if (!monitor_count) monitor();      // report changes in endstop status
110
+      }
111
+    #endif
112
+
86 113
   private:
87 114
 
88 115
     #if ENABLED(Z_DUAL_ENDSTOPS)
@@ -99,4 +126,4 @@ extern Endstops endstops;
99 126
 #endif
100 127
 
101 128
 
102
-#endif // ENDSTOPS_H
129
+#endif // __ENDSTOPS_H__

+ 2
- 90
Marlin/src/module/temperature.cpp Переглянути файл

@@ -39,7 +39,7 @@
39 39
   #include "stepper.h"
40 40
 #endif
41 41
 
42
-#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
42
+#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(PINS_DEBUGGING)
43 43
   #include "endstops.h"
44 44
 #endif
45 45
 
@@ -1561,87 +1561,6 @@ void Temperature::set_current_temp_raw() {
1561 1561
   temp_meas_ready = true;
1562 1562
 }
1563 1563
 
1564
-#if ENABLED(PINS_DEBUGGING)
1565
-  /**
1566
-   * monitors endstops & Z probe for changes
1567
-   *
1568
-   * If a change is detected then the LED is toggled and
1569
-   * a message is sent out the serial port
1570
-   *
1571
-   * Yes, we could miss a rapid back & forth change but
1572
-   * that won't matter because this is all manual.
1573
-   *
1574
-   */
1575
-  void endstop_monitor() {
1576
-    static uint16_t old_endstop_bits_local = 0;
1577
-    static uint8_t local_LED_status = 0;
1578
-    uint16_t current_endstop_bits_local = 0;
1579
-    #if HAS_X_MIN
1580
-      if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN);
1581
-    #endif
1582
-    #if HAS_X_MAX
1583
-      if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX);
1584
-    #endif
1585
-    #if HAS_Y_MIN
1586
-      if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN);
1587
-    #endif
1588
-    #if HAS_Y_MAX
1589
-      if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX);
1590
-    #endif
1591
-    #if HAS_Z_MIN
1592
-      if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN);
1593
-    #endif
1594
-    #if HAS_Z_MAX
1595
-      if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX);
1596
-    #endif
1597
-    #if HAS_Z_MIN_PROBE_PIN
1598
-      if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE);
1599
-    #endif
1600
-    #if HAS_Z2_MIN
1601
-      if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN);
1602
-    #endif
1603
-    #if HAS_Z2_MAX
1604
-      if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX);
1605
-    #endif
1606
-
1607
-    uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local;
1608
-
1609
-    if (endstop_change) {
1610
-      #if HAS_X_MIN
1611
-        if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR("  X_MIN:", !!TEST(current_endstop_bits_local, X_MIN));
1612
-      #endif
1613
-      #if HAS_X_MAX
1614
-        if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR("  X_MAX:", !!TEST(current_endstop_bits_local, X_MAX));
1615
-      #endif
1616
-      #if HAS_Y_MIN
1617
-        if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR("  Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN));
1618
-      #endif
1619
-      #if HAS_Y_MAX
1620
-        if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR("  Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX));
1621
-      #endif
1622
-      #if HAS_Z_MIN
1623
-        if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR("  Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN));
1624
-      #endif
1625
-      #if HAS_Z_MAX
1626
-        if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR("  Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX));
1627
-      #endif
1628
-      #if HAS_Z_MIN_PROBE_PIN
1629
-        if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR("  PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE));
1630
-      #endif
1631
-      #if HAS_Z2_MIN
1632
-        if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR("  Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN));
1633
-      #endif
1634
-      #if HAS_Z2_MAX
1635
-        if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR("  Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX));
1636
-      #endif
1637
-      SERIAL_PROTOCOLPGM("\n\n");
1638
-      analogWrite(LED_PIN, local_LED_status);
1639
-      local_LED_status ^= 255;
1640
-      old_endstop_bits_local = current_endstop_bits_local;
1641
-    }
1642
-  }
1643
-#endif // PINS_DEBUGGING
1644
-
1645 1564
 /**
1646 1565
  * Timer 0 is shared with millies so don't change the prescaler.
1647 1566
  *
@@ -2157,14 +2076,7 @@ void Temperature::isr() {
2157 2076
   #endif // BABYSTEPPING
2158 2077
 
2159 2078
   #if ENABLED(PINS_DEBUGGING)
2160
-    extern bool endstop_monitor_flag;
2161
-    // run the endstop monitor at 15Hz
2162
-    static uint8_t endstop_monitor_count = 16;  // offset this check from the others
2163
-    if (endstop_monitor_flag) {
2164
-      endstop_monitor_count += _BV(1);  //  15 Hz
2165
-      endstop_monitor_count &= 0x7F;
2166
-      if (!endstop_monitor_count) endstop_monitor();  // report changes in endstop status
2167
-    }
2079
+    endstops.run_monitor();  // report changes in endstop status
2168 2080
   #endif
2169 2081
 
2170 2082
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)

+ 0
- 2
Marlin/src/pins/pinsDebug.h Переглянути файл

@@ -20,8 +20,6 @@
20 20
  *
21 21
  */
22 22
 
23
-bool endstop_monitor_flag = false;
24
-
25 23
 #define MAX_NAME_LENGTH  35    // one place to specify the format of all the sources of names
26 24
                                // "-" left justify, "35" minimum width of name, pad with blanks
27 25
 

Завантаження…
Відмінити
Зберегти