2019-03-17 05:57:25 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-03-17 05:57:25 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-03-17 05:57:25 -05:00
|
|
|
*
|
|
|
|
* 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
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-03-17 05:57:25 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-12-23 00:10:56 -06:00
|
|
|
#if DISABLED(BLTOUCH_HS_MODE)
|
|
|
|
#define BLTOUCH_SLOW_MODE 1
|
|
|
|
#endif
|
|
|
|
|
2019-03-17 05:57:25 -05:00
|
|
|
// BLTouch commands are sent as servo angles
|
|
|
|
typedef unsigned char BLTCommand;
|
|
|
|
|
2020-12-27 16:15:15 -06:00
|
|
|
#define STOW_ALARM true
|
|
|
|
#define BLTOUCH_DEPLOY 10
|
|
|
|
#define BLTOUCH_STOW 90
|
2019-05-07 21:25:54 -05:00
|
|
|
#define BLTOUCH_SW_MODE 60
|
|
|
|
#define BLTOUCH_SELFTEST 120
|
2019-05-17 19:10:18 -05:00
|
|
|
#define BLTOUCH_MODE_STORE 130
|
2019-05-07 21:25:54 -05:00
|
|
|
#define BLTOUCH_5V_MODE 140
|
|
|
|
#define BLTOUCH_OD_MODE 150
|
|
|
|
#define BLTOUCH_RESET 160
|
|
|
|
|
|
|
|
/**
|
2019-06-22 17:20:19 -05:00
|
|
|
* The following commands require different minimum delays.
|
2019-05-07 21:25:54 -05:00
|
|
|
*
|
2019-06-22 17:20:19 -05:00
|
|
|
* 500ms required for a reliable Reset.
|
2019-05-07 21:25:54 -05:00
|
|
|
*
|
2019-06-22 17:20:19 -05:00
|
|
|
* 750ms required for Deploy/Stow, otherwise the alarm state
|
|
|
|
* will not be seen until the following move command.
|
2019-05-07 21:25:54 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLTOUCH_SET5V_DELAY
|
2019-06-22 17:20:19 -05:00
|
|
|
#define BLTOUCH_SET5V_DELAY 150
|
2019-05-07 21:25:54 -05:00
|
|
|
#endif
|
|
|
|
#ifndef BLTOUCH_SETOD_DELAY
|
2019-06-22 17:20:19 -05:00
|
|
|
#define BLTOUCH_SETOD_DELAY 150
|
2019-05-07 21:25:54 -05:00
|
|
|
#endif
|
2019-05-17 19:10:18 -05:00
|
|
|
#ifndef BLTOUCH_MODE_STORE_DELAY
|
2019-06-22 17:20:19 -05:00
|
|
|
#define BLTOUCH_MODE_STORE_DELAY 150
|
2019-05-17 19:10:18 -05:00
|
|
|
#endif
|
2019-05-07 21:25:54 -05:00
|
|
|
#ifndef BLTOUCH_DEPLOY_DELAY
|
|
|
|
#define BLTOUCH_DEPLOY_DELAY 750
|
|
|
|
#endif
|
|
|
|
#ifndef BLTOUCH_STOW_DELAY
|
|
|
|
#define BLTOUCH_STOW_DELAY 750
|
|
|
|
#endif
|
|
|
|
#ifndef BLTOUCH_RESET_DELAY
|
2019-06-22 17:20:19 -05:00
|
|
|
#define BLTOUCH_RESET_DELAY 500
|
2019-05-07 21:25:54 -05:00
|
|
|
#endif
|
2019-03-17 05:57:25 -05:00
|
|
|
|
|
|
|
class BLTouch {
|
|
|
|
public:
|
2019-05-25 21:56:47 -05:00
|
|
|
static void init(const bool set_voltage=false);
|
|
|
|
static bool last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
|
2019-03-17 05:57:25 -05:00
|
|
|
|
2019-05-07 21:25:54 -05:00
|
|
|
// DEPLOY and STOW are wrapped for error handling - these are used by homing and by probing
|
|
|
|
FORCE_INLINE static bool deploy() { return deploy_proc(); }
|
|
|
|
FORCE_INLINE static bool stow() { return stow_proc(); }
|
|
|
|
FORCE_INLINE static bool status() { return status_proc(); }
|
2019-03-17 05:57:25 -05:00
|
|
|
|
2019-05-07 21:25:54 -05:00
|
|
|
// Native BLTouch commands ("Underscore"...), used in lcd menus and internally
|
|
|
|
FORCE_INLINE static void _reset() { command(BLTOUCH_RESET, BLTOUCH_RESET_DELAY); }
|
2019-03-23 23:28:15 -05:00
|
|
|
|
2019-05-07 21:25:54 -05:00
|
|
|
FORCE_INLINE static void _selftest() { command(BLTOUCH_SELFTEST, BLTOUCH_DELAY); }
|
2019-03-17 05:57:25 -05:00
|
|
|
|
2019-05-07 21:25:54 -05:00
|
|
|
FORCE_INLINE static void _set_SW_mode() { command(BLTOUCH_SW_MODE, BLTOUCH_DELAY); }
|
2019-05-17 19:10:18 -05:00
|
|
|
FORCE_INLINE static void _reset_SW_mode() { if (triggered()) _stow(); else _deploy(); }
|
|
|
|
|
2019-05-07 21:25:54 -05:00
|
|
|
FORCE_INLINE static void _set_5V_mode() { command(BLTOUCH_5V_MODE, BLTOUCH_SET5V_DELAY); }
|
|
|
|
FORCE_INLINE static void _set_OD_mode() { command(BLTOUCH_OD_MODE, BLTOUCH_SETOD_DELAY); }
|
2019-05-17 19:10:18 -05:00
|
|
|
FORCE_INLINE static void _mode_store() { command(BLTOUCH_MODE_STORE, BLTOUCH_MODE_STORE_DELAY); }
|
2019-05-07 21:25:54 -05:00
|
|
|
|
|
|
|
FORCE_INLINE static void _deploy() { command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
|
|
|
|
FORCE_INLINE static void _stow() { command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
|
2019-03-23 22:58:34 -05:00
|
|
|
|
2019-05-25 21:56:47 -05:00
|
|
|
FORCE_INLINE static void mode_conv_5V() { mode_conv_proc(true); }
|
|
|
|
FORCE_INLINE static void mode_conv_OD() { mode_conv_proc(false); }
|
|
|
|
|
2020-02-09 07:46:38 -06:00
|
|
|
static bool triggered();
|
|
|
|
|
2019-03-23 22:58:34 -05:00
|
|
|
private:
|
2019-05-07 21:25:54 -05:00
|
|
|
FORCE_INLINE static bool _deploy_query_alarm() { return command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
|
2020-06-16 01:45:27 -05:00
|
|
|
FORCE_INLINE static bool _stow_query_alarm() { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY) == STOW_ALARM; }
|
2019-05-07 21:25:54 -05:00
|
|
|
|
|
|
|
static void clear();
|
|
|
|
static bool command(const BLTCommand cmd, const millis_t &ms);
|
|
|
|
static bool deploy_proc();
|
|
|
|
static bool stow_proc();
|
|
|
|
static bool status_proc();
|
2019-05-25 21:56:47 -05:00
|
|
|
static void mode_conv_proc(const bool M5V);
|
2019-03-17 05:57:25 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
extern BLTouch bltouch;
|