Skip to content

Commit 8ba6e8a

Browse files
committed
🎨 Clean up tool change with tool sensor
1 parent e458aa4 commit 8ba6e8a

File tree

1 file changed

+48
-50
lines changed

1 file changed

+48
-50
lines changed

Marlin/src/module/tool_change.cpp

+48-50
Original file line numberDiff line numberDiff line change
@@ -385,65 +385,59 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.
385385

386386
#endif // PARKING_EXTRUDER
387387

388-
#if ENABLED(SWITCHING_TOOLHEAD)
388+
#if ENABLED(TOOL_SENSOR)
389+
390+
bool tool_sensor_disabled; // = false
389391

390392
// Return a bitmask of tool sensor states
391393
inline uint8_t poll_tool_sensor_pins() {
392394
return (0
393-
#if ENABLED(TOOL_SENSOR)
394-
#if PIN_EXISTS(TOOL_SENSOR1)
395-
| (READ(TOOL_SENSOR1_PIN) << 0)
396-
#endif
397-
#if PIN_EXISTS(TOOL_SENSOR2)
398-
| (READ(TOOL_SENSOR2_PIN) << 1)
399-
#endif
400-
#if PIN_EXISTS(TOOL_SENSOR3)
401-
| (READ(TOOL_SENSOR3_PIN) << 2)
402-
#endif
403-
#if PIN_EXISTS(TOOL_SENSOR4)
404-
| (READ(TOOL_SENSOR4_PIN) << 3)
405-
#endif
406-
#if PIN_EXISTS(TOOL_SENSOR5)
407-
| (READ(TOOL_SENSOR5_PIN) << 4)
408-
#endif
409-
#if PIN_EXISTS(TOOL_SENSOR6)
410-
| (READ(TOOL_SENSOR6_PIN) << 5)
411-
#endif
412-
#if PIN_EXISTS(TOOL_SENSOR7)
413-
| (READ(TOOL_SENSOR7_PIN) << 6)
414-
#endif
415-
#if PIN_EXISTS(TOOL_SENSOR8)
416-
| (READ(TOOL_SENSOR8_PIN) << 7)
417-
#endif
395+
#if PIN_EXISTS(TOOL_SENSOR1)
396+
| (READ(TOOL_SENSOR1_PIN) << 0)
397+
#endif
398+
#if PIN_EXISTS(TOOL_SENSOR2)
399+
| (READ(TOOL_SENSOR2_PIN) << 1)
400+
#endif
401+
#if PIN_EXISTS(TOOL_SENSOR3)
402+
| (READ(TOOL_SENSOR3_PIN) << 2)
403+
#endif
404+
#if PIN_EXISTS(TOOL_SENSOR4)
405+
| (READ(TOOL_SENSOR4_PIN) << 3)
406+
#endif
407+
#if PIN_EXISTS(TOOL_SENSOR5)
408+
| (READ(TOOL_SENSOR5_PIN) << 4)
409+
#endif
410+
#if PIN_EXISTS(TOOL_SENSOR6)
411+
| (READ(TOOL_SENSOR6_PIN) << 5)
412+
#endif
413+
#if PIN_EXISTS(TOOL_SENSOR7)
414+
| (READ(TOOL_SENSOR7_PIN) << 6)
415+
#endif
416+
#if PIN_EXISTS(TOOL_SENSOR8)
417+
| (READ(TOOL_SENSOR8_PIN) << 7)
418418
#endif
419419
);
420420
}
421421

422-
#if ENABLED(TOOL_SENSOR)
423-
424-
bool tool_sensor_disabled; // = false
425-
426-
uint8_t check_tool_sensor_stats(const uint8_t tool_index, const bool kill_on_error/*=false*/, const bool disable/*=false*/) {
427-
static uint8_t sensor_tries; // = 0
428-
for (;;) {
429-
if (poll_tool_sensor_pins() == _BV(tool_index)) {
430-
sensor_tries = 0;
431-
return tool_index;
432-
}
433-
else if (kill_on_error && (!tool_sensor_disabled || disable)) {
434-
sensor_tries++;
435-
if (sensor_tries > 10) kill(F("Tool Sensor error"));
436-
safe_delay(5);
437-
}
438-
else {
439-
sensor_tries++;
440-
if (sensor_tries > 10) return -1;
441-
safe_delay(5);
442-
}
422+
uint8_t check_tool_sensor_stats(const uint8_t tool_index, const bool kill_on_error/*=false*/, const bool disable/*=false*/) {
423+
static uint8_t sensor_tries; // = 0
424+
for (;;) {
425+
if (poll_tool_sensor_pins() == _BV(tool_index)) {
426+
sensor_tries = 0;
427+
return tool_index;
428+
}
429+
else if (kill_on_error && (!tool_sensor_disabled || disable)) {
430+
sensor_tries++;
431+
if (sensor_tries > 10) kill(F("Tool Sensor error"));
432+
safe_delay(5);
433+
}
434+
else {
435+
sensor_tries++;
436+
if (sensor_tries > 10) return -1;
437+
safe_delay(5);
443438
}
444439
}
445-
446-
#endif
440+
}
447441

448442
inline void switching_toolhead_lock(const bool locked) {
449443
#ifdef SWITCHING_TOOLHEAD_SERVO_ANGLES
@@ -496,9 +490,13 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.
496490
switching_toolhead_lock(true);
497491
}
498492
LCD_MESSAGE_F("TC Success");
499-
#endif
493+
#endif // TOOL_SENSOR
500494
}
501495

496+
#endif // TOOL_SENSOR
497+
498+
#if ENABLED(SWITCHING_TOOLHEAD)
499+
502500
inline void switching_toolhead_tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
503501
if (no_move) return;
504502

0 commit comments

Comments
 (0)