Reuse FSensor runout blocking impl. throughout the whole FW

This commit is contained in:
D.R.racer 2022-05-31 09:20:51 +02:00
parent eed816d9de
commit 0e75a03c8c
7 changed files with 104 additions and 135 deletions

View File

@ -11,13 +11,29 @@
#include "ultralcd.h"
#ifdef FILAMENT_SENSOR
#if FILAMENT_SENSOR_TYPE == FSENSOR_IR
FSensorBlockRunout::FSensorBlockRunout() {
fsensor.setRunoutEnabled(false); //suppress filament runouts while loading filament.
fsensor.setAutoLoadEnabled(false); //suppress filament autoloads while loading filament.
#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.setJamDetectionEnabled(false); //suppress filament jam detection while loading filament.
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
}
FSensorBlockRunout::~FSensorBlockRunout() {
fsensor.settings_init(); // restore filament runout state.
}
# if FILAMENT_SENSOR_TYPE == FSENSOR_IR
IR_sensor fsensor;
#elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
# elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
IR_sensor_analog fsensor;
#elif FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
# elif FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
PAT9125_sensor fsensor;
#endif
# endif
#else // FILAMENT_SENSOR
FSensorBlockRunout::FSensorBlockRunout() { }
FSensorBlockRunout::~FSensorBlockRunout() { }
#endif // FILAMENT_SENSOR
void Filament_sensor::setEnabled(bool enabled) {

View File

@ -11,6 +11,15 @@
#define FSENSOR_IR_ANALOG 2
#define FSENSOR_PAT9125 3
/// Can be used to block printer's filament sensor handling - to avoid errorneous injecting of M600
/// while doing a toolchange with the MMU
/// In case of "no filament sensor" these methods default to an empty implementation
class FSensorBlockRunout {
public:
FSensorBlockRunout();
~FSensorBlockRunout();
};
#ifdef FILAMENT_SENSOR
class Filament_sensor {
public:

View File

@ -3573,101 +3573,86 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
else
unload_filament(true); // unload filament for single material (used also in M702)
st_synchronize(); // finish moves
#ifdef FILAMENT_SENSOR
fsensor.setRunoutEnabled(false); //suppress filament runouts while loading filament.
fsensor.setAutoLoadEnabled(false); //suppress filament autoloads while loading filament.
#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.setJamDetectionEnabled(false); //suppress filament jam detection while loading filament.
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
#endif
if (!MMU2::mmu2.Enabled()) {
KEEPALIVE_STATE(PAUSED_FOR_USER);
lcd_change_fil_state =
lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Was filament unload successful?"), false, LCD_LEFT_BUTTON_CHOICE); ////MSG_UNLOAD_SUCCESSFUL c=20 r=2
if (lcd_change_fil_state == LCD_MIDDLE_BUTTON_CHOICE) {
lcd_clear();
lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
current_position[X_AXIS] -= 100;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_XYFEED);
st_synchronize();
lcd_show_fullscreen_message_and_wait_P(_i("Please open idler and remove filament manually.")); ////MSG_CHECK_IDLER c=20 r=5
}
}
if (MMU2::mmu2.Enabled()) {
if (!automatic) {
if (saved_printing){
// if M600 was invoked by filament senzor (FINDA) eject filament so user can easily remove it
MMU2::mmu2.eject_filament(MMU2::mmu2.get_current_tool(), false);
}
mmu_M600_wait_and_beep();
if (saved_printing) {
{
FSensorBlockRunout fsBlockRunout;
if (!MMU2::mmu2.Enabled()) {
KEEPALIVE_STATE(PAUSED_FOR_USER);
lcd_change_fil_state =
lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Was filament unload successful?"), false, LCD_LEFT_BUTTON_CHOICE); ////MSG_UNLOAD_SUCCESSFUL c=20 r=2
if (lcd_change_fil_state == LCD_MIDDLE_BUTTON_CHOICE) {
lcd_clear();
lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
//@@TODO mmu_command(MmuCmd::R0);
// manage_response(false, false);
current_position[X_AXIS] -= 100;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_XYFEED);
st_synchronize();
lcd_show_fullscreen_message_and_wait_P(_i("Please open idler and remove filament manually.")); ////MSG_CHECK_IDLER c=20 r=5
}
}
mmu_M600_load_filament(automatic, HotendTempBckp);
} else
M600_load_filament();
if (!automatic)
M600_check_state(HotendTempBckp);
lcd_update_enable(true);
// Not let's go back to print
fanSpeed = fanSpeedBckp;
// Feed a little of filament to stabilize pressure
if (!automatic) {
current_position[E_AXIS] += FILAMENTCHANGE_RECFEED;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_EXFEED);
if (MMU2::mmu2.Enabled()) {
if (!automatic) {
if (saved_printing){
// if M600 was invoked by filament senzor (FINDA) eject filament so user can easily remove it
MMU2::mmu2.eject_filament(MMU2::mmu2.get_current_tool(), false);
}
mmu_M600_wait_and_beep();
if (saved_printing) {
lcd_clear();
lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
//@@TODO mmu_command(MmuCmd::R0);
// manage_response(false, false);
}
}
mmu_M600_load_filament(automatic, HotendTempBckp);
} else
M600_load_filament();
if (!automatic)
M600_check_state(HotendTempBckp);
lcd_update_enable(true);
// Not let's go back to print
fanSpeed = fanSpeedBckp;
// Feed a little of filament to stabilize pressure
if (!automatic) {
current_position[E_AXIS] += FILAMENTCHANGE_RECFEED;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_EXFEED);
}
// Move XY back
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_XYFEED, active_extruder);
st_synchronize();
// Move Z back
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_ZFEED, active_extruder);
st_synchronize();
// Set E position to original
plan_set_e_position(lastpos[E_AXIS]);
memcpy(current_position, lastpos, sizeof(lastpos));
set_destination_to_current();
// Recover feed rate
feedmultiply = feedmultiplyBckp;
char cmd[9];
sprintf_P(cmd, PSTR("M220 S%i"), feedmultiplyBckp);
enquecommand(cmd);
}
// Move XY back
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_XYFEED, active_extruder);
st_synchronize();
// Move Z back
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_ZFEED, active_extruder);
st_synchronize();
// Set E position to original
plan_set_e_position(lastpos[E_AXIS]);
memcpy(current_position, lastpos, sizeof(lastpos));
set_destination_to_current();
// Recover feed rate
feedmultiply = feedmultiplyBckp;
char cmd[9];
sprintf_P(cmd, PSTR("M220 S%i"), feedmultiplyBckp);
enquecommand(cmd);
#ifdef FILAMENT_SENSOR
fsensor.settings_init();
#endif
lcd_setstatuspgm(MSG_WELCOME);
custom_message_type = CustomMsg::Status;
}
void gcode_M701(uint8_t mmuSlotIndex){
printf_P(PSTR("gcode_M701 begin\n"));
#ifdef FILAMENT_SENSOR
fsensor.setRunoutEnabled(false); // suppress filament runouts while loading filament.
fsensor.setAutoLoadEnabled(false); // suppress filament autoloads while loading filament.
#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.setJamDetectionEnabled(false); // suppress filament jam detection while loading filament.
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
#endif
prusa_statistics(22);
}
FSensorBlockRunout fsBlockRunout;
prusa_statistics(22);
if (MMU2::mmu2.Enabled() && mmuSlotIndex < MMU_FILAMENT_COUNT) {
MMU2::mmu2.load_filament(mmuSlotIndex); // loads current extruder
@ -3705,10 +3690,6 @@ void gcode_M701(uint8_t mmuSlotIndex){
}
eFilamentAction = FilamentAction::None;
#ifdef FILAMENT_SENSOR
fsensor.settings_init(); // restore filament runout state.
#endif
}
/**
* @brief Get serial number from 32U2 processor

View File

@ -198,7 +198,7 @@ bool MMU2::tool_change(uint8_t index) {
if (index != extruder) {
ReportingRAII rep(CommandInProgress::ToolChange);
BlockRunoutRAII blockRunout;
FSensorBlockRunout blockRunout;
st_synchronize();
@ -227,7 +227,7 @@ bool MMU2::tool_change(char code, uint8_t slot) {
if( ! WaitForMMUReady())
return false;
BlockRunoutRAII blockRunout;
FSensorBlockRunout blockRunout;
switch (code) {
case '?': {
@ -333,7 +333,7 @@ bool MMU2::load_filament_to_nozzle(uint8_t index) {
{
// used for MMU-menu operation "Load to Nozzle"
ReportingRAII rep(CommandInProgress::ToolChange);
BlockRunoutRAII blockRunout;
FSensorBlockRunout blockRunout;
if( extruder != MMU2_NO_TOOL ){ // we already have some filament loaded - free it + shape its tip properly
filament_ramming();

View File

@ -7,21 +7,4 @@ FilamentState WhereIsFilament(){
return fsensor.getFilamentPresent() ? FilamentState::AT_FSENSOR : FilamentState::NOT_PRESENT;
}
BlockRunoutRAII::BlockRunoutRAII() {
#ifdef FILAMENT_SENSOR
fsensor.setRunoutEnabled(false); //suppress filament runouts while loading filament.
fsensor.setAutoLoadEnabled(false); //suppress filament autoloads while loading filament.
#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.setJamDetectionEnabled(false); //suppress filament jam detection while loading filament.
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
#endif
}
BlockRunoutRAII::~BlockRunoutRAII() {
#ifdef FILAMENT_SENSOR
fsensor.settings_init(); // restore filament runout state.
#endif
}
} // namespace MMU2

View File

@ -1,5 +1,6 @@
#pragma once
#include <stdint.h>
#include "Filament_sensor.h"
namespace MMU2 {
@ -13,12 +14,4 @@ enum class FilamentState : uint_fast8_t {
FilamentState WhereIsFilament();
/// Can be used to block printer's filament sensor handling - to avoid errorneous injecting of M600
/// while doing a toolchange with the MMU
class BlockRunoutRAII {
public:
BlockRunoutRAII();
~BlockRunoutRAII();
};
} // namespace MMU2

View File

@ -5196,14 +5196,7 @@ void unload_filament(bool automatic)
custom_message_type = CustomMsg::FilamentLoading;
lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
#ifdef FILAMENT_SENSOR
fsensor.setRunoutEnabled(false); //suppress filament runouts while loading filament.
fsensor.setAutoLoadEnabled(false); //suppress filament autoloads while loading filament.
#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.setJamDetectionEnabled(false); //suppress filament jam detection while loading filament.
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
#endif
FSensorBlockRunout fsBlockRunout;
raise_z_above(automatic? MIN_Z_FOR_SWAP: MIN_Z_FOR_UNLOAD);
// extr_unload2();
@ -5241,10 +5234,6 @@ void unload_filament(bool automatic)
custom_message_type = CustomMsg::Status;
eFilamentAction = FilamentAction::None;
#ifdef FILAMENT_SENSOR
fsensor.settings_init(); //restore filament runout state.
#endif
}
#include "xflash.h"
@ -6209,8 +6198,7 @@ void printf_IRSensorAnalogBoardChange(){
static bool lcd_selftest_IRsensor(bool bStandalone)
{
bool ret = false;
fsensor.setAutoLoadEnabled(false);
fsensor.setRunoutEnabled(false);
FSensorBlockRunout fsBlockRunout;
IR_sensor_analog::SensorRevision oldSensorRevision = fsensor.getSensorRevision();
IR_sensor_analog::SensorRevision newSensorRevision;
uint16_t volt_IR_int = fsensor.getVoltRaw();
@ -6236,7 +6224,6 @@ static bool lcd_selftest_IRsensor(bool bStandalone)
}
ret = true;
exit:
fsensor.settings_init();
return ret;
}