Allow load filament retry after button push unlimited times in case mmu_continue_loading() is in blocking mode.

This commit is contained in:
Marek Bel 2019-04-09 20:50:29 +02:00
parent 84cabd3836
commit c7d403733a
2 changed files with 92 additions and 57 deletions

View file

@ -1466,21 +1466,62 @@ static void load_more()
st_synchronize();
}
//! @par blocking
//! * true blocking
//! * false non-blocking
void mmu_continue_loading(bool blocking)
static void increment_load_fail()
{
if (ir_sensor_detected)
{
load_more();
if (PIN_GET(IR_SENSOR_PIN) != 0) {
uint8_t mmu_load_fail = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL);
uint16_t mmu_load_fail_tot = eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT);
if(mmu_load_fail < 255) eeprom_update_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL, mmu_load_fail + 1);
if(mmu_load_fail_tot < 65535) eeprom_update_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT, mmu_load_fail_tot + 1);
}
//! @brief continue loading filament
//! @par blocking
//! * true blocking - do not return until successful load
//! * false non-blocking - pause print and return on load failure
//!
//! @startuml
//! [*] --> [*] : !ir_sensor_detected /\n send MmuCmd::C0
//! [*] --> LoadMore
//! LoadMore --> [*] : filament \ndetected
//! LoadMore --> Retry : !filament detected /\n increment load fail
//! Retry --> [*] : filament \ndetected
//! Retry --> Unload : !filament \ndetected
//! Unload --> [*] : non-blocking
//! Unload --> Retry : button \nclicked
//!
//! Retry : Cut filament if enabled
//! Retry : repeat last T-code
//! Unload : unload filament
//! Unload : pause print
//! Unload : show error message
//!
//! @enduml
void mmu_continue_loading(bool blocking)
{
if (!ir_sensor_detected)
{
mmu_command(MmuCmd::C0);
return;
}
load_more();
enum class Ls : uint_least8_t
{
enter,
retry,
unload,
};
Ls state = Ls::enter;
while (PIN_GET(IR_SENSOR_PIN) != 0)
{
switch (state)
{
case Ls::enter:
increment_load_fail();
// no break
case Ls::retry:
#ifdef MMU_HAS_CUTTER
if (1 == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
{
@ -1488,14 +1529,12 @@ void mmu_continue_loading(bool blocking)
manage_response(true, true, MMU_UNLOAD_MOVE);
}
#endif //MMU_HAS_CUTTER
mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE);
load_more();
if (PIN_GET(IR_SENSOR_PIN) != 0)
{
//pause print, show error message and then repeat last T-code
state = Ls::unload;
break;
case Ls::unload:
stop_and_save_print_to_ram(0, 0);
//lift z
@ -1514,26 +1553,22 @@ void mmu_continue_loading(bool blocking)
manage_response(false, true, MMU_UNLOAD_MOVE);
setAllTargetHotends(0);
lcd_setstatuspgm(_i("MMU load failed "));////MSG_RECOVERING_PRINT c=20 r=1
lcd_setstatuspgm(_i("MMU load failed "));////c=20 r=1
if (blocking)
{
marlin_wait_for_click();
restore_print_from_ram_and_continue(0);
mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE);
load_more();
state = Ls::retry;
}
else
{
mmu_fil_loaded = false; //so we can retry same T-code again
isPrintPaused = true;
mmu_command(MmuCmd::W0);
return;
}
break;
}
}
}
else { //mmu_ir_sensor_detected == false
mmu_command(MmuCmd::C0);
}
}

View file

@ -58,7 +58,7 @@ enum class MmuCmd : uint_least8_t
K4,
R0,
S3,
W0,
W0, //!< Wait and signal load error
};
inline MmuCmd operator+ (MmuCmd cmd, uint8_t filament)