Subversion Repositories MK-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
/**
2
 * Marlin 3D Printer Firmware
3
 * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
 *
5
 * Based on Sprinter and grbl.
6
 * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
 
23
/**
24
 * endstops.h - manages endstops
25
 */
26
 
27
#ifndef __ENDSTOPS_H__
28
#define __ENDSTOPS_H__
29
 
30
#include "MarlinConfig.h"
31
 
32
#define VALIDATE_HOMING_ENDSTOPS
33
 
34
enum EndstopEnum : char {
35
  X_MIN,
36
  Y_MIN,
37
  Z_MIN,
38
  Z_MIN_PROBE,
39
  X_MAX,
40
  Y_MAX,
41
  Z_MAX,
42
  X2_MIN,
43
  X2_MAX,
44
  Y2_MIN,
45
  Y2_MAX,
46
  Z2_MIN,
47
  Z2_MAX
48
};
49
 
50
class Endstops {
51
 
52
  public:
53
 
54
    static bool enabled, enabled_globally;
55
 
56
    #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
57
      typedef uint16_t esbits_t;
58
      #if ENABLED(X_DUAL_ENDSTOPS)
59
        static float x_endstop_adj;
60
      #endif
61
      #if ENABLED(Y_DUAL_ENDSTOPS)
62
        static float y_endstop_adj;
63
      #endif
64
      #if ENABLED(Z_DUAL_ENDSTOPS)
65
        static float z_endstop_adj;
66
      #endif
67
    #else
68
      typedef uint8_t esbits_t;
69
    #endif
70
 
71
  private:
72
    static esbits_t live_state;
73
    static volatile uint8_t hit_state;      // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index
74
 
75
    #if ENABLED(ENDSTOP_NOISE_FILTER)
76
      static esbits_t validated_live_state;
77
      static uint8_t endstop_poll_count;    // Countdown from threshold for polling
78
    #endif
79
 
80
  public:
81
    Endstops() {};
82
 
83
    /**
84
     * Initialize the endstop pins
85
     */
86
    static void init();
87
 
88
    /**
89
     * Are endstops or the probe set to abort the move?
90
     */
91
    FORCE_INLINE static bool abort_enabled() {
92
      return (enabled
93
        #if HAS_BED_PROBE
94
          || z_probe_enabled
95
        #endif
96
      );
97
    }
98
 
99
    /**
100
     * Periodic call to poll endstops if required. Called from temperature ISR
101
     */
102
    static void poll();
103
 
104
    /**
105
     * Update endstops bits from the pins. Apply filtering to get a verified state.
106
     * If abort_enabled() and moving towards a triggered switch, abort the current move.
107
     * Called from ISR contexts.
108
     */
109
    static void update();
110
 
111
    /**
112
     * Get Endstop hit state.
113
     */
114
    FORCE_INLINE static uint8_t trigger_state() { return hit_state; }
115
 
116
    /**
117
     * Get current endstops state
118
     */
119
    FORCE_INLINE static esbits_t state() {
120
      return
121
        #if ENABLED(ENDSTOP_NOISE_FILTER)
122
          validated_live_state
123
        #else
124
          live_state
125
        #endif
126
      ;
127
    }
128
 
129
    /**
130
     * Report endstop hits to serial. Called from loop().
131
     */
132
    static void event_handler();
133
 
134
    /**
135
     * Report endstop positions in response to M119
136
     */
137
    static void M119();
138
 
139
    // Enable / disable endstop checking globally
140
    static void enable_globally(const bool onoff=true);
141
 
142
    // Enable / disable endstop checking
143
    static void enable(const bool onoff=true);
144
 
145
    // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
146
    static void not_homing();
147
 
148
    #if ENABLED(VALIDATE_HOMING_ENDSTOPS)
149
      // If the last move failed to trigger an endstop, call kill
150
      static void validate_homing_move();
151
    #else
152
      FORCE_INLINE static void validate_homing_move() { hit_on_purpose(); }
153
    #endif
154
 
155
    // Clear endstops (i.e., they were hit intentionally) to suppress the report
156
    FORCE_INLINE static void hit_on_purpose() { hit_state = 0; }
157
 
158
    // Enable / disable endstop z-probe checking
159
    #if HAS_BED_PROBE
160
      static volatile bool z_probe_enabled;
161
      static void enable_z_probe(const bool onoff=true);
162
    #endif
163
 
164
    // Debugging of endstops
165
    #if ENABLED(PINS_DEBUGGING)
166
      static bool monitor_flag;
167
      static void monitor();
168
      static void run_monitor();
169
    #endif
170
};
171
 
172
extern Endstops endstops;
173
 
174
#endif // __ENDSTOPS_H__