Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert files but pause/G27.cpp
Browse files Browse the repository at this point in the history
classicrocker883 committed Apr 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4e3ba2d commit 05d0659
Showing 9 changed files with 161 additions and 166 deletions.
136 changes: 68 additions & 68 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
@@ -134,71 +134,6 @@

#endif

//
// Primitives supporting precompiler REPEAT
//
#define FIRST(a,...) a
#define SECOND(a,b,...) b
#define THIRD(a,b,c,...) c

// Concatenate symbol names, without or with pre-expansion
#define _CAT(a,V...) a##V
#define CAT(a,V...) _CAT(a,V)

// Defer expansion
#define EMPTY()
#define DEFER(M) M EMPTY()
#define DEFER2(M) M EMPTY EMPTY()()
#define DEFER3(M) M EMPTY EMPTY EMPTY()()()
#define DEFER4(M) M EMPTY EMPTY EMPTY EMPTY()()()()

// Force define expansion
#define EVAL EVAL16
#define EVAL1(V...) V
#define EVAL2(V...) EVAL1(EVAL1(V))
#define EVAL4(V...) EVAL2(EVAL2(V))
#define EVAL8(V...) EVAL4(EVAL4(V))
#define EVAL16(V...) EVAL8(EVAL8(V))
#define EVAL32(V...) EVAL16(EVAL16(V))
#define EVAL64(V...) EVAL32(EVAL32(V))
#define EVAL128(V...) EVAL64(EVAL64(V))
#define EVAL256(V...) EVAL128(EVAL128(V))
#define EVAL512(V...) EVAL256(EVAL256(V))
#define EVAL1024(V...) EVAL512(EVAL512(V))
#define EVAL2048(V...) EVAL1024(EVAL1024(V))
#define EVAL4096(V...) EVAL2048(EVAL2048(V))

#define IS_PROBE(V...) SECOND(V, 0) // Get the second item passed, or 0
#define PROBE() ~, 1 // Second item will be 1 if this is passed
#define _NOT_0 PROBE()
#define NOT(x) IS_PROBE(_CAT(_NOT_, x)) // NOT('0') gets '1'. Anything else gets '0'.
#define _BOOL(x) NOT(NOT(x)) // _BOOL('0') gets '0'. Anything else gets '1'.

#define _IF_ELSE(TF) _CAT(_IF_, TF)
#define IF_ELSE(TF) _IF_ELSE(_BOOL(TF))

#define _IF_1(V...) V _IF_1_ELSE
#define _IF_0(...) _IF_0_ELSE

#define _IF_1_ELSE(...)
#define _IF_0_ELSE(V...) V

// Simple Inline IF Macros, friendly to use in other macro definitions
#define IF(O, A, B) ((O) ? (A) : (B))
#define IF_0(O, A) IF(O, A, 0)
#define IF_1(O, A) IF(O, A, 1)

#define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)())
#define _END_OF_ARGUMENTS_() 0

// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
#define _NUM_ARGS(_,n,m,l,k,j,i,h,g,f,e,d,c,b,a,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
#define NUM_ARGS(V...) _NUM_ARGS(0,V,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)

// Use TWO_ARGS(__VA_ARGS__) to get whether there are 1, 2, or >2 arguments
#define _TWO_ARGS(_,n,m,l,k,j,i,h,g,f,e,d,c,b,a,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
#define TWO_ARGS(V...) _TWO_ARGS(0,V,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,1,0)

// Macros to chain up to 40 conditions
#define _DO_1(W,C,A) (_##W##_1(A))
#define _DO_2(W,C,A,B) (_##W##_1(A) C _##W##_1(B))
@@ -244,6 +179,10 @@
#define _DO_N(W,C,N,V...) __DO_N(W,C,N,V)
#define DO(W,C,V...) (_DO_N(W,C,NUM_ARGS(V),V))

// Concatenate symbol names, without or with pre-expansion
#define _CAT(a,V...) a##V
#define CAT(a,V...) _CAT(a,V)

// Recognize "true" values: blank, 1, 0x1, true
#define _ISENA_ ~,1
#define _ISENA_1 ~,1
@@ -263,13 +202,13 @@
#define MANY(V...) (COUNT_ENABLED(V) > 1)

// Ternary pre-compiler macros conceal non-emitted content from the compiler
#define ___TERN(P,V...) THIRD(P,V) // If first argument has a comma, A. Else B.
#define __TERN(T,V...) ___TERN(_CAT(_NO,T),V) // Prepend '_NO' to get '_NOT_0' or '_NOT_1'
#define _TERN(E,V...) __TERN(_CAT(T_,E),V) // Prepend 'T_' to get 'T_0' or 'T_1'
#define TERN(O,A,B) _TERN(_ENA_1(O),B,A) // OPTION ? 'A' : 'B'
#define TERN0(O,A) _TERN(_ENA_1(O),0,A) // OPTION ? 'A' : '0'
#define TERN1(O,A) _TERN(_ENA_1(O),1,A) // OPTION ? 'A' : '1'
#define TERN_(O,A) _TERN(_ENA_1(O),,A) // OPTION ? 'A' : '<nul>'
#define _TERN(E,V...) __TERN(_CAT(T_,E),V) // Prepend 'T_' to get 'T_0' or 'T_1'
#define __TERN(T,V...) ___TERN(_CAT(_NO,T),V) // Prepend '_NO' to get '_NOT_0' or '_NOT_1'
#define ___TERN(P,V...) THIRD(P,V) // If first argument has a comma, A. Else B.
#define IF_DISABLED(O,A) TERN(O,,A)

// Macros to conditionally emit array items and function arguments
@@ -433,6 +372,14 @@
#define FMOD(x, y) fmodf(x, y)
#define HYPOT(x,y) SQRT(HYPOT2(x,y))

// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
#define _NUM_ARGS(_,n,m,l,k,j,i,h,g,f,e,d,c,b,a,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
#define NUM_ARGS(V...) _NUM_ARGS(0,V,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)

// Use TWO_ARGS(__VA_ARGS__) to get whether there are 1, 2, or >2 arguments
#define _TWO_ARGS(_,n,m,l,k,j,i,h,g,f,e,d,c,b,a,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
#define TWO_ARGS(V...) _TWO_ARGS(0,V,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,1,0)

#ifdef __cplusplus

#ifndef _MINMAX_H_
@@ -667,6 +614,59 @@
#define SUB9(N) SUB4(SUB5(N))
#define SUB10(N) SUB5(SUB5(N))

//
// Primitives supporting precompiler REPEAT
//
#define FIRST(a,...) a
#define SECOND(a,b,...) b
#define THIRD(a,b,c,...) c

// Defer expansion
#define EMPTY()
#define DEFER(M) M EMPTY()
#define DEFER2(M) M EMPTY EMPTY()()
#define DEFER3(M) M EMPTY EMPTY EMPTY()()()
#define DEFER4(M) M EMPTY EMPTY EMPTY EMPTY()()()()

// Force define expansion
#define EVAL EVAL16
#define EVAL4096(V...) EVAL2048(EVAL2048(V))
#define EVAL2048(V...) EVAL1024(EVAL1024(V))
#define EVAL1024(V...) EVAL512(EVAL512(V))
#define EVAL512(V...) EVAL256(EVAL256(V))
#define EVAL256(V...) EVAL128(EVAL128(V))
#define EVAL128(V...) EVAL64(EVAL64(V))
#define EVAL64(V...) EVAL32(EVAL32(V))
#define EVAL32(V...) EVAL16(EVAL16(V))
#define EVAL16(V...) EVAL8(EVAL8(V))
#define EVAL8(V...) EVAL4(EVAL4(V))
#define EVAL4(V...) EVAL2(EVAL2(V))
#define EVAL2(V...) EVAL1(EVAL1(V))
#define EVAL1(V...) V

#define IS_PROBE(V...) SECOND(V, 0) // Get the second item passed, or 0
#define PROBE() ~, 1 // Second item will be 1 if this is passed
#define _NOT_0 PROBE()
#define NOT(x) IS_PROBE(_CAT(_NOT_, x)) // NOT('0') gets '1'. Anything else gets '0'.
#define _BOOL(x) NOT(NOT(x)) // _BOOL('0') gets '0'. Anything else gets '1'.

#define IF_ELSE(TF) _IF_ELSE(_BOOL(TF))
#define _IF_ELSE(TF) _CAT(_IF_, TF)

#define _IF_1(V...) V _IF_1_ELSE
#define _IF_0(...) _IF_0_ELSE

#define _IF_1_ELSE(...)
#define _IF_0_ELSE(V...) V

#define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)())
#define _END_OF_ARGUMENTS_() 0

// Simple Inline IF Macros, friendly to use in other macro definitions
#define IF(O, A, B) ((O) ? (A) : (B))
#define IF_0(O, A) IF(O, A, 0)
#define IF_1(O, A) IF(O, A, 1)

//
// REPEAT core macros. Recurse N times with ascending I.
//
97 changes: 49 additions & 48 deletions Marlin/src/feature/bltouch.cpp
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@

BLTouch bltouch;

bool BLTouch::od_5v_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
bool BLTouch::od_5v_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
#if HAS_BLTOUCH_HS_MODE
bool BLTouch::high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed
bool BLTouch::high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed
#else
constexpr bool BLTouch::high_speed_mode;
#endif
@@ -44,7 +44,6 @@ bool BLTouch::od_5v_mode; // Initialized by settings.load, 0 = Open Drain
bool BLTouch::command(const BLTCommand cmd, const millis_t &ms) {
const BLTCommand current = servo[Z_PROBE_SERVO_NR].read();
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("BLTouch from ", current, " to ", cmd);

// If the new command is the same, skip it (and the delay).
// The previous write should've already delayed to detect the alarm.
if (cmd != current) {
@@ -56,21 +55,22 @@ bool BLTouch::command(const BLTCommand cmd, const millis_t &ms) {

// Init the class and device. Call from setup().
void BLTouch::init(const bool set_voltage/*=false*/) {
/**
* Voltage Setting (if enabled). At every Marlin initialization:
* BLTOUCH < V3.0 and clones: This will be ignored by the probe
* BLTOUCH V3.0: SET_5V_MODE or SET_OD_MODE (if enabled).
* OD_MODE is the default on power on, but setting it does not hurt
* This mode will stay active until manual SET_OD_MODE or power cycle
* BLTOUCH V3.1: SET_5V_MODE or SET_OD_MODE (if enabled).
* At power on, the probe will default to the eeprom settings configured by the user
*/
// Voltage Setting (if enabled). At every Marlin initialization:
// BLTOUCH < V3.0 and clones: This will be ignored by the probe
// BLTOUCH V3.0: SET_5V_MODE or SET_OD_MODE (if enabled).
// OD_MODE is the default on power on, but setting it does not hurt
// This mode will stay active until manual SET_OD_MODE or power cycle
// BLTOUCH V3.1: SET_5V_MODE or SET_OD_MODE (if enabled).
// At power on, the probe will default to the eeprom settings configured by the user
_reset();
_stow();

#if ENABLED(BLTOUCH_FORCE_MODE_SET)

constexpr bool should_set = true;

#else

#ifdef DEBUG_OUT
if (DEBUGGING(LEVELING)) {
PGMSTR(mode0, "OD");
@@ -80,102 +80,104 @@ void BLTouch::init(const bool set_voltage/*=false*/) {
DEBUG_ECHOLNPGM(" (Default " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD") ")");
}
#endif

const bool should_set = od_5v_mode != ENABLED(BLTOUCH_SET_5V_MODE);

#endif

if (should_set && set_voltage)
mode_conv_proc(ENABLED(BLTOUCH_SET_5V_MODE));
}

void BLTouch::clear() {
_reset(); // RESET or RESET_SW will clear an alarm condition but...
// ...it will not clear a triggered condition in SW mode when the pin is currently up
// ANTClabs <-- CODE ERROR
_stow(); // STOW will pull up the pin and clear any triggered condition unless it fails, don't care
_deploy(); // DEPLOY to test the probe. Could fail, don't care
_stow(); // STOW to be ready for meaningful work. Could fail, don't care
_reset(); // RESET or RESET_SW will clear an alarm condition but...
// ...it will not clear a triggered condition in SW mode when the pin is currently up
// ANTClabs <-- CODE ERROR
_stow(); // STOW will pull up the pin and clear any triggered condition unless it fails, don't care
_deploy(); // DEPLOY to test the probe. Could fail, don't care
_stow(); // STOW to be ready for meaningful work. Could fail, don't care
}

bool BLTouch::triggered() { return PROBE_TRIGGERED(); }

// Do a DEPLOY
bool BLTouch::deploy_proc() {
// Do a DEPLOY
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch DEPLOY requested");

// Attempt to DEPLOY, wait for DEPLOY_DELAY or ALARM
if (_deploy_query_alarm()) {
// The deploy might have failed or the probe is already triggered (nozzle too low?)
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch ALARM or TRIGGER after DEPLOY, recovering");

clear(); // Get the probe into start condition
clear(); // Get the probe into start condition

// Last attempt to DEPLOY
if (_deploy_query_alarm()) {
// The deploy might have failed or the probe is actually triggered (nozzle too low?) again
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Deploy Failed");

probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
}
}

// One of the recommended ANTClabs ways to probe, using SW MODE
TERN_(BLTOUCH_FORCE_SW_MODE, _set_SW_mode());
/**
* Now the probe is ready to issue a 10ms pulse when the pin goes up.
* The trigger STOW (see motion.cpp for example) will pull up the probes pin as soon as the pulse
* is registered.
*/

// Now the probe is ready to issue a 10ms pulse when the pin goes up.
// The trigger STOW (see motion.cpp for example) will pull up the probes pin as soon as the pulse
// is registered.

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("bltouch.deploy_proc() end");

return false; // Report success to caller
return false; // report success to caller
}

// Do a STOW
bool BLTouch::stow_proc() {
/**
* A STOW will clear a triggered condition in the probe (10ms pulse).
* At the moment that we come in here, we might (pulse) or will (SW mode) see the trigger on the pin.
* So even though we know a STOW will be ignored if an ALARM condition is active, we will STOW.
* NOTE: If the probe is deployed AND in an ALARM condition, this STOW will not pull up the pin
* and the ALARM condition will still be there. --> ANTClabs should change this behavior maybe
*/
// Do a STOW
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch STOW requested");

// A STOW will clear a triggered condition in the probe (10ms pulse).
// At the moment that we come in here, we might (pulse) or will (SW mode) see the trigger on the pin.
// So even though we know a STOW will be ignored if an ALARM condition is active, we will STOW.
// Note: If the probe is deployed AND in an ALARM condition, this STOW will not pull up the pin
// and the ALARM condition will still be there. --> ANTClabs should change this behavior maybe

// Attempt to STOW, wait for STOW_DELAY or ALARM
if (_stow_query_alarm()) {
// The stow might have failed
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch ALARM or TRIGGER after STOW, recovering");

_reset(); // This RESET will then also pull up the pin. If it doesn't
// work and the pin is still down, there will no longer be
// an ALARM condition though.
// But one more STOW will catch that
_reset(); // This RESET will then also pull up the pin. If it doesn't
// work and the pin is still down, there will no longer be
// an ALARM condition though.
// But one more STOW will catch that
// Last attempt to STOW
if (_stow_query_alarm()) { // So if there is now STILL an ALARM condition:
if (_stow_query_alarm()) { // so if there is now STILL an ALARM condition:
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Stow Failed");

probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
}
}

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("bltouch.stow_proc() end");

return false; // Report success to caller
return false; // report success to caller
}

bool BLTouch::status_proc() {
/**
* Return a TRUE for "YES, it is DEPLOYED"
* This function will ensure switch state is reset after execution
*/

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch STATUS requested");

_set_SW_mode(); // Incidentally, _set_SW_mode() will also RESET any active alarm
const bool tr = triggered(); // If triggered in SW mode, the pin is up, it is STOWED

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch is ", tr);

if (tr) _stow(); else _deploy(); // Turn off SW mode, reset any trigger, honor pin state
if (tr) _stow(); else _deploy(); // Turn off SW mode, reset any trigger, honor pin state
return !tr;
}

@@ -186,7 +188,6 @@ void BLTouch::mode_conv_proc(const bool M5V) {
* BLTOUCH V3.1: This will set the mode and store it in the eeprom. The STOW is not needed but does not hurt
*/
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Set Mode - ", M5V);

_deploy();
if (M5V) _set_5V_mode(); else _set_OD_mode();
_mode_store();
Loading

0 comments on commit 05d0659

Please sign in to comment.