PFW-1423 add Retry handling in NoCommand for init error

pull/247/head
Guðni Már Gilbert 2022-12-04 11:14:24 +00:00
parent 7fe81be707
commit 496917ba8d
5 changed files with 65 additions and 15 deletions

View File

@ -1,8 +1,42 @@
/// @file no_command.cpp /// @file no_command.cpp
#include "no_command.h" #include "no_command.h"
#include "../modules/buttons.h"
#include "../modules/finda.h"
#include "../modules/user_input.h"
namespace logic { namespace logic {
NoCommand noCommand; NoCommand noCommand;
bool NoCommand::StepInner() {
switch (state) {
case ProgressCode::OK:
return true;
case ProgressCode::ERRWaitingForUser: {
// waiting for user buttons and/or a command from the printer
mui::Event ev = mui::userInput.ConsumeEvent();
switch (ev) {
case mui::Event::Middle:
switch (error) {
case ErrorCode::FINDA_VS_EEPROM_DISREPANCY:
// Retry
if (!mf::finda.CheckFINDAvsEEPROM()) {
error = ErrorCode::FINDA_VS_EEPROM_DISREPANCY;
state = ProgressCode::ERRWaitingForUser;
} else {
error = ErrorCode::OK;
state = ProgressCode::OK;
}
break;
}
break; // mui::Event::Middle
}
break; // ProgressCode::ERRWaitingForUser
}
default:
// Do nothing
break;
}
return false;
}
} // namespace logic } // namespace logic

View File

@ -15,12 +15,15 @@ public:
bool Reset(uint8_t /*param*/) override { return true; } bool Reset(uint8_t /*param*/) override { return true; }
/// @returns true if the state machine finished its job, false otherwise /// @returns true if the state machine finished its job, false otherwise
bool StepInner() override { return true; } bool StepInner() override;
/// Used to report initialization errors (which can be reported if the UART started up). /// Used to report initialization errors (which can be reported if the UART started up).
/// Intentionally only available in the "noCommand" operation /// Intentionally only available in the "noCommand" operation
/// which is only active when the MMU starts and before it gets any other command from the printer. /// which is only active when the MMU starts and before it gets any other command from the printer.
inline void SetInitError(ErrorCode ec) { error = ec; } inline void SetInitError(ErrorCode ec) {
error = ec;
state = ProgressCode::ERRWaitingForUser;
}
}; };
/// The one and only instance of NoCommand state machine in the FW /// The one and only instance of NoCommand state machine in the FW

View File

@ -90,20 +90,8 @@ static void setup2() {
// which is abused to let the LEDs shine for ~100ms // which is abused to let the LEDs shine for ~100ms
mf::finda.BlockingInit(); mf::finda.BlockingInit();
if (mf::finda.Pressed() && mg::globals.FilamentLoaded() < mg::InFSensor) { if (!mf::finda.CheckFINDAvsEEPROM()) {
// This is a tricky situation - EEPROM doesn't have a record about loaded filament (blocking the Selector)
// To be on the safe side, we have to override the EEPROM information about filament position - at least InFSensor
// Moreover - we need to override the active slot position as well, because we cannot know where the Selector is.
// For this we speculatively set the active slot to 2 (in the middle ;) )
// Ideally this should be signalled as an error state and displayed on the printer and recovered properly.
mg::globals.SetFilamentLoaded(2, mg::InFSensor);
logic::noCommand.SetInitError(ErrorCode::FINDA_VS_EEPROM_DISREPANCY); logic::noCommand.SetInitError(ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
} else if (!mf::finda.Pressed() && mg::globals.FilamentLoaded() >= mg::InSelector) {
// Opposite situation - not so dangerous, but definitely confusing to users.
// FINDA is not pressed but we have a record in the EEPROM.
// It has been decided, that we shall clear such a record from EEPROM automagically
// and presume there is no filament at all (requires working FINDA)
mg::globals.SetFilamentLoaded(config::toolCount, mg::AtPulley);
} }
/// Turn off all leds /// Turn off all leds

View File

@ -1,5 +1,6 @@
/// @file finda.cpp /// @file finda.cpp
#include "finda.h" #include "finda.h"
#include "globals.h"
#include "timebase.h" #include "timebase.h"
#include "../hal/gpio.h" #include "../hal/gpio.h"
#include "../pins.h" #include "../pins.h"
@ -21,5 +22,26 @@ void FINDA::BlockingInit() {
} }
} }
bool FINDA::CheckFINDAvsEEPROM() {
bool ret = true;
if (mf::finda.Pressed() && mg::globals.FilamentLoaded() < mg::InFSensor) {
// This is a tricky situation - EEPROM doesn't have a record about loaded filament (blocking the Selector)
// To be on the safe side, we have to override the EEPROM information about filament position - at least InFSensor
// Moreover - we need to override the active slot position as well, because we cannot know where the Selector is.
// For this we speculatively set the active slot to 2 (in the middle ;) )
// Ideally this should be signalled as an error state and displayed on the printer and recovered properly.
//mg::globals.SetFilamentLoaded(2, mg::InFSensor);
ret = false;
} else if (!mf::finda.Pressed() && mg::globals.FilamentLoaded() >= mg::InSelector) {
// Opposite situation - not so dangerous, but definitely confusing to users.
// FINDA is not pressed but we have a record in the EEPROM.
// It has been decided, that we shall clear such a record from EEPROM automagically
// and presume there is no filament at all (requires working FINDA)
//mg::globals.SetFilamentLoaded(config::toolCount, mg::AtPulley);
ret = false;
}
return ret;
}
} // namespace finda } // namespace finda
} // namespace modules } // namespace modules

View File

@ -22,6 +22,9 @@ public:
/// to set correct FINDA state at startup /// to set correct FINDA state at startup
void BlockingInit(); void BlockingInit();
/// @returns true if there is no discrepency, false otherwise
bool CheckFINDAvsEEPROM();
using debounce::Debouncer::Pressed; using debounce::Debouncer::Pressed;
}; };