2016-04-27 14:15:20 +00:00
/**
* Marlin 3 D Printer Firmware
* Copyright ( C ) 2016 MarlinFirmware [ https : //github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl .
* Copyright ( C ) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*
*/
/**
2018-03-10 11:56:04 +00:00
* endstops . h - manages endstops
2016-04-27 14:15:20 +00:00
*/
2017-09-18 10:55:09 +00:00
# ifndef __ENDSTOPS_H__
# define __ENDSTOPS_H__
# include "../inc/MarlinConfig.h"
# include <stdint.h>
2018-03-07 04:35:22 +00:00
enum EndstopEnum : char {
2017-09-18 10:55:09 +00:00
X_MIN ,
Y_MIN ,
Z_MIN ,
Z_MIN_PROBE ,
X_MAX ,
Y_MAX ,
Z_MAX ,
2017-10-29 08:43:44 +00:00
X2_MIN ,
X2_MAX ,
Y2_MIN ,
Y2_MAX ,
2017-09-18 10:55:09 +00:00
Z2_MIN ,
Z2_MAX
} ;
2016-04-27 14:15:20 +00:00
class Endstops {
public :
2016-05-26 18:01:20 +00:00
static bool enabled , enabled_globally ;
2018-05-16 07:08:43 +00:00
static volatile uint8_t endstop_hit_bits ; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
2016-04-27 14:15:20 +00:00
2017-10-29 08:43:44 +00:00
# if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
2017-09-18 10:55:09 +00:00
typedef uint16_t esbits_t ;
2018-03-10 11:56:04 +00:00
# if ENABLED(X_DUAL_ENDSTOPS)
static float x_endstop_adj ;
# endif
# if ENABLED(Y_DUAL_ENDSTOPS)
static float y_endstop_adj ;
# endif
# if ENABLED(Z_DUAL_ENDSTOPS)
static float z_endstop_adj ;
# endif
2016-04-27 14:15:20 +00:00
# else
2017-09-18 10:55:09 +00:00
typedef byte esbits_t ;
2016-04-27 14:15:20 +00:00
# endif
2017-09-18 10:55:09 +00:00
2018-05-16 07:08:43 +00:00
static esbits_t current_endstop_bits ;
2016-07-19 13:31:09 +00:00
2018-05-16 07:08:43 +00:00
Endstops ( ) { } ;
2016-04-27 14:15:20 +00:00
/**
* Initialize the endstop pins
*/
2017-09-06 11:28:32 +00:00
static void init ( ) ;
2016-04-27 14:15:20 +00:00
2018-05-16 07:08:43 +00:00
/**
* A change was detected or presumed to be in endstops pins . Find out what
* changed , if anything . Called from ISR contexts
*/
static void check_possible_change ( ) ;
/**
* Periodic call to poll endstops if required . Called from temperature ISR
*/
static void poll ( ) ;
2016-04-27 14:15:20 +00:00
/**
* Update the endstops bits from the pins
*/
2016-05-26 18:01:20 +00:00
static void update ( ) ;
2016-04-27 14:15:20 +00:00
/**
* Print an error message reporting the position when the endstops were last hit .
*/
2016-05-26 18:01:20 +00:00
static void report_state ( ) ; //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
2016-04-27 14:15:20 +00:00
2016-04-27 21:46:24 +00:00
/**
* Report endstop positions in response to M119
*/
2016-05-26 18:01:20 +00:00
static void M119 ( ) ;
2016-04-27 21:46:24 +00:00
2016-04-27 14:15:20 +00:00
// Enable / disable endstop checking globally
2018-05-16 07:08:43 +00:00
static void enable_globally ( const bool onoff = true ) ;
2016-04-27 14:15:20 +00:00
// Enable / disable endstop checking
2018-05-16 07:08:43 +00:00
static void enable ( const bool onoff = true ) ;
2016-04-27 14:15:20 +00:00
// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
2018-05-16 07:08:43 +00:00
static void not_homing ( ) ;
2016-04-27 14:15:20 +00:00
// Clear endstops (i.e., they were hit intentionally) to suppress the report
2018-05-16 07:08:43 +00:00
static void hit_on_purpose ( ) ;
2016-04-27 14:15:20 +00:00
// Enable / disable endstop z-probe checking
2016-05-04 03:15:18 +00:00
# if HAS_BED_PROBE
2016-05-26 18:01:20 +00:00
static volatile bool z_probe_enabled ;
2018-05-16 07:08:43 +00:00
static void enable_z_probe ( bool onoff = true ) ;
2016-04-27 14:15:20 +00:00
# endif
2016-04-28 09:15:53 +00:00
2017-09-18 10:55:09 +00:00
// Debugging of endstops
# if ENABLED(PINS_DEBUGGING)
static bool monitor_flag ;
static void monitor ( ) ;
2018-05-16 07:08:43 +00:00
static void run_monitor ( ) ;
2017-09-18 10:55:09 +00:00
# endif
2016-04-28 09:15:53 +00:00
private :
2017-10-29 08:43:44 +00:00
# if ENABLED(X_DUAL_ENDSTOPS)
static void test_dual_x_endstops ( const EndstopEnum es1 , const EndstopEnum es2 ) ;
# endif
# if ENABLED(Y_DUAL_ENDSTOPS)
static void test_dual_y_endstops ( const EndstopEnum es1 , const EndstopEnum es2 ) ;
# endif
2016-04-28 09:15:53 +00:00
# if ENABLED(Z_DUAL_ENDSTOPS)
2016-10-29 21:01:27 +00:00
static void test_dual_z_endstops ( const EndstopEnum es1 , const EndstopEnum es2 ) ;
2016-04-28 09:15:53 +00:00
# endif
2016-04-27 14:15:20 +00:00
} ;
extern Endstops endstops ;
2017-09-18 10:55:09 +00:00
# endif // __ENDSTOPS_H__