2018-11-16 03:32:01 -06: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/>.
*
*/
/**
2019-01-31 05:25:28 -06:00
* endstops . h - manages endstops
2018-11-16 03:32:01 -06:00
*/
2019-01-31 05:25:28 -06:00
# ifndef ENDSTOPS_H
# define ENDSTOPS_H
2018-11-16 03:32:01 -06:00
2019-01-31 05:25:28 -06:00
# include "enum.h"
2018-11-16 03:32:01 -06:00
# include "MarlinConfig.h"
class Endstops {
public :
static bool enabled , enabled_globally ;
2019-01-31 05:25:28 -06:00
static volatile char endstop_hit_bits ; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
2018-11-16 03:32:01 -06:00
# if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
2019-01-31 05:25:28 -06:00
static uint16_t
2018-11-16 03:32:01 -06:00
# else
2019-01-31 05:25:28 -06:00
static byte
2018-11-16 03:32:01 -06:00
# endif
2019-01-31 05:25:28 -06:00
current_endstop_bits , old_endstop_bits ;
2018-11-16 03:32:01 -06:00
2019-01-31 05:25:28 -06:00
Endstops ( ) {
enable_globally (
# if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
true
# else
false
2018-11-16 03:32:01 -06:00
# endif
) ;
2019-01-31 05:25:28 -06:00
} ;
2018-11-16 03:32:01 -06:00
/**
2019-01-31 05:25:28 -06:00
* Initialize the endstop pins
2018-11-16 03:32:01 -06:00
*/
2019-01-31 05:25:28 -06:00
void init ( ) ;
2018-11-16 03:32:01 -06:00
/**
2019-01-31 05:25:28 -06:00
* Update the endstops bits from the pins
2018-11-16 03:32:01 -06:00
*/
static void update ( ) ;
/**
2019-01-31 05:25:28 -06:00
* Print an error message reporting the position when the endstops were last hit .
2018-11-16 03:32:01 -06:00
*/
2019-01-31 05:25:28 -06: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
2018-11-16 03:32:01 -06:00
/**
* Report endstop positions in response to M119
*/
static void M119 ( ) ;
// Enable / disable endstop checking globally
2019-01-31 05:25:28 -06:00
static void enable_globally ( bool onoff = true ) { enabled_globally = enabled = onoff ; }
2018-11-16 03:32:01 -06:00
// Enable / disable endstop checking
2019-01-31 05:25:28 -06:00
static void enable ( bool onoff = true ) { enabled = onoff ; }
2018-11-16 03:32:01 -06:00
// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
2019-01-31 05:25:28 -06:00
static void not_homing ( ) { enabled = enabled_globally ; }
2018-11-16 03:32:01 -06:00
// Clear endstops (i.e., they were hit intentionally) to suppress the report
2019-01-31 05:25:28 -06:00
static void hit_on_purpose ( ) { endstop_hit_bits = 0 ; }
2018-11-16 03:32:01 -06:00
// Enable / disable endstop z-probe checking
# if HAS_BED_PROBE
static volatile bool z_probe_enabled ;
2019-01-31 05:25:28 -06:00
static void enable_z_probe ( bool onoff = true ) { z_probe_enabled = onoff ; }
2018-11-16 03:32:01 -06:00
# endif
2019-01-31 05:25:28 -06:00
private :
# 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
# if ENABLED(Z_DUAL_ENDSTOPS)
static void test_dual_z_endstops ( const EndstopEnum es1 , const EndstopEnum es2 ) ;
2018-11-16 03:32:01 -06:00
# endif
} ;
extern Endstops endstops ;
2019-01-31 05:25:28 -06:00
# if HAS_BED_PROBE
# define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled)
# else
# define ENDSTOPS_ENABLED endstops.enabled
# endif
# endif // ENDSTOPS_H