Revert LongTimers to uint32_t in mmu.cpp to fix issues with MMU2 fw 1.0.6

This commit is contained in:
3d-gussner 2023-01-13 11:20:49 +01:00
parent fdadc9314e
commit 6db58f09d0
3 changed files with 49 additions and 29 deletions

View File

@ -76,9 +76,12 @@ int16_t mmu_version = -1;
int16_t mmu_buildnr = -1;
LongTimer mmu_last_request;
LongTimer mmu_last_response;
LongTimer mmu_last_finda_response;
uint32_t mmu_last_request;
uint32_t mmu_last_response;
uint32_t mmu_last_finda_response;
//LongTimer mmu_last_request;
//LongTimer mmu_last_response;
//LongTimer mmu_last_finda_response;
MmuCmd mmu_last_cmd = MmuCmd::None;
uint16_t mmu_power_failures = 0;
@ -114,7 +117,8 @@ int mmu_puts_P(const char* str)
{
mmu_clr_rx_buf(); //clear rx buffer
int r = fputs_P(str, uart2io); //send command
mmu_last_request.start();
mmu_last_request = _millis();
//mmu_last_request.start();
return r;
}
@ -126,7 +130,8 @@ int mmu_printf_P(const char* format, ...)
mmu_clr_rx_buf(); //clear rx buffer
int r = vfprintf_P(uart2io, format, args); //send command
va_end(args);
mmu_last_request.start();
mmu_last_request = _millis();
//mmu_last_request.start();
return r;
}
@ -134,7 +139,8 @@ int mmu_printf_P(const char* format, ...)
int8_t mmu_rx_ok(void)
{
int8_t res = uart2_rx_str_P(PSTR("ok\n"));
if (res == 1) mmu_last_response.start();
if (res == 1) mmu_last_response = _millis();
//if (res == 1) mmu_last_response.start();
return res;
}
@ -142,7 +148,8 @@ int8_t mmu_rx_ok(void)
int8_t mmu_rx_start(void)
{
int8_t res = uart2_rx_str_P(PSTR("start\n"));
if (res == 1) mmu_last_response.start();
if (res == 1) mmu_last_response = _millis();
//if (res == 1) mmu_last_response.start();
return res;
}
@ -201,12 +208,12 @@ static bool activate_stealth_mode()
void mmu_loop(void)
{
static uint8_t mmu_attempt_nr = 0;
// printf_P(PSTR("MMU loop, state=%d\n"), mmu_state);
// printf_P(PSTR("MMU loop, state=%d\n"), (int)mmu_state);
switch (mmu_state)
{
case S::Disabled:
case S::Disabled: //state 0
return;
case S::Init:
case S::Init: //state 1
if (mmu_rx_start() > 0)
{
DEBUG_PUTS_P(PSTR("MMU => 'start'"));
@ -220,7 +227,7 @@ void mmu_loop(void)
mmu_state = S::Disabled;
}
return;
case S::GetVersion:
case S::GetVersion: //state 2
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%u"), &mmu_version); //scan version from buffer
@ -230,7 +237,7 @@ void mmu_loop(void)
mmu_state = S::GetBuildNr;
}
return;
case S::GetBuildNr:
case S::GetBuildNr: //state 3
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%u"), &mmu_buildnr); //scan buildnr from buffer
@ -254,7 +261,7 @@ void mmu_loop(void)
}
return;
case S::WaitStealthMode:
case S::WaitStealthMode: //state 4
if (mmu_rx_ok() > 0)
{
FDEBUG_PUTS_P(PSTR("MMU <= 'P0'"));
@ -262,11 +269,12 @@ void mmu_loop(void)
mmu_state = S::GetFindaInit;
}
return;
case S::GetFindaInit:
case S::GetFindaInit: //state 5
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer. MUST BE %hhu!!!
mmu_last_finda_response.start();
mmu_last_finda_response = _millis();
//mmu_last_finda_response.start();
FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda);
puts_P(PSTR("MMU - ENABLED"));
mmu_enabled = true;
@ -276,7 +284,7 @@ void mmu_loop(void)
mmu_state = S::Idle;
}
return;
case S::Idle:
case S::Idle: //state 6
if (mmu_cmd != MmuCmd::None) //command request ?
{
if ((mmu_cmd >= MmuCmd::T0) && (mmu_cmd <= MmuCmd::T4))
@ -351,7 +359,8 @@ void mmu_loop(void)
mmu_printf_P(PSTR("M%d\n"), SilentModeMenu_MMU);
mmu_state = S::SwitchMode;
}
else if (mmu_last_response.expired(300)) //request every 300ms
else if ((mmu_last_response + 300) < _millis()) //request every 300ms
//else if (mmu_last_response.expired(300)) //request every 300ms
{
#ifndef IR_SENSOR
if(check_for_ir_sensor()) ir_sensor_detected = true;
@ -360,8 +369,11 @@ void mmu_loop(void)
mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
mmu_state = S::GetFinda;
}
//printf_P(PSTR("MMU loop, state %d\n"), (int)mmu_state);
//printf_P(PSTR("mmu_last_response %lu\n"), mmu_last_response.elapsed());
//printf_P(PSTR("mmu_last_finda_response %lu\n"), mmu_last_finda_response.elapsed());
return;
case S::GetFinda: //response to command P0
case S::GetFinda: //response to command P0 state 7
if (mmu_idl_sens)
{
if (READ(IR_SENSOR_PIN) == 0 && mmu_loading_flag)
@ -379,7 +391,8 @@ void mmu_loop(void)
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer. MUST BE %hhu!!!
mmu_last_finda_response.start();
mmu_last_finda_response = _millis();
//mmu_last_finda_response.start();
FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda);
//printf_P(PSTR("Eact: %d\n"), int(e_active()));
if (!mmu_finda && CHECK_FSENSOR && fsensor_enabled) {
@ -399,12 +412,13 @@ void mmu_loop(void)
if (mmu_cmd == MmuCmd::None)
mmu_ready = true;
}
else if (mmu_last_request.expired(MMU_P0_TIMEOUT))
else if ((mmu_last_request + MMU_P0_TIMEOUT) < _millis())
//else if (mmu_last_request.expired(MMU_P0_TIMEOUT))
{ //resend request after timeout (30s)
mmu_state = S::Idle;
}
return;
case S::WaitCmd: //response to mmu commands
case S::WaitCmd: //response to mmu commands state 8
if (mmu_idl_sens)
{
if (READ(IR_SENSOR_PIN) == 0 && mmu_loading_flag)
@ -425,7 +439,8 @@ void mmu_loop(void)
mmu_ready = true;
mmu_state = S::Idle;
}
else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis())
//else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
{ //resend request after timeout (5 min)
if (mmu_last_cmd != MmuCmd::None)
{
@ -444,7 +459,7 @@ void mmu_loop(void)
mmu_state = S::Idle;
}
return;
case S::Pause:
case S::Pause: //state 9
if (mmu_rx_ok() > 0)
{
DEBUG_PRINTF_P(PSTR("MMU => 'ok', resume print\n"));
@ -459,7 +474,7 @@ void mmu_loop(void)
mmu_state = S::Idle;
}
return;
case S::GetDrvError:
case S::GetDrvError: //state 10
if (mmu_rx_ok() > 0)
{
fscanf_P(uart2io, PSTR("%d"), &mmu_power_failures); //scan power failures
@ -468,19 +483,21 @@ void mmu_loop(void)
mmu_ready = true;
mmu_state = S::Idle;
}
else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis())
//else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
{ //timeout 45 s
mmu_state = S::Idle;
}
return;
case S::SwitchMode:
case S::SwitchMode: //state 11
if (mmu_rx_ok() > 0)
{
DEBUG_PRINTF_P(PSTR("MMU => 'ok'\n"));
eeprom_update_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU);
mmu_state = S::Idle;
}
else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis())
//else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
{ //timeout 45 s
mmu_state = S::Idle;
}
@ -724,6 +741,7 @@ void manage_response(bool move_axes, bool turn_off_nozzle, uint8_t move)
screen++;
}
else { //screen 1
//printf_P(PSTR("active ex: %d deg: %d turn_off_nozzle: %d\n"),active_extruder ,degTargetHotend(active_extruder), (int)turn_off_nozzle);
if((degTargetHotend(active_extruder) == 0) && turn_off_nozzle) lcd_display_message_fullscreen_P(_i("Press the knob to resume nozzle temperature."));////MSG_RESUME_NOZZLE_TEMP c=20 r=4
else lcd_display_message_fullscreen_P(_i("Fix the issue and then press button on MMU unit."));////MSG_MMU_FIX_ISSUE c=20 r=4
screen=0;

View File

@ -15,7 +15,8 @@ extern uint8_t mmu_extruder;
extern uint8_t tmp_extruder;
extern int8_t mmu_finda;
extern LongTimer mmu_last_finda_response;
extern uint32_t mmu_last_finda_response;
//extern LongTimer mmu_last_finda_response;
extern bool ir_sensor_detected;
extern int16_t mmu_version;

View File

@ -3520,7 +3520,8 @@ static void lcd_show_sensors_state()
uint8_t idler_state = STATE_NA;
pinda_state = READ(Z_MIN_PIN);
if (mmu_enabled && !mmu_last_finda_response.expired(1000))
if (mmu_enabled && ((_millis() - mmu_last_finda_response) < 1000ul))
//if (mmu_enabled && !mmu_last_finda_response.expired(1000))
{
finda_state = mmu_finda;
}