PFW-1423 add Retry handling in NoCommand for init error
parent
3988a9aff0
commit
4d38d1f620
|
|
@ -1,8 +1,42 @@
|
|||
/// @file no_command.cpp
|
||||
#include "no_command.h"
|
||||
#include "../modules/buttons.h"
|
||||
#include "../modules/finda.h"
|
||||
#include "../modules/user_input.h"
|
||||
|
||||
namespace logic {
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -15,12 +15,15 @@ public:
|
|||
bool Reset(uint8_t /*param*/) override { return true; }
|
||||
|
||||
/// @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).
|
||||
/// 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.
|
||||
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
|
||||
|
|
|
|||
14
src/main.cpp
14
src/main.cpp
|
|
@ -90,20 +90,8 @@ static void setup2() {
|
|||
// which is abused to let the LEDs shine for ~100ms
|
||||
mf::finda.BlockingInit();
|
||||
|
||||
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);
|
||||
if (!mf::finda.CheckFINDAvsEEPROM()) {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/// @file finda.cpp
|
||||
#include "finda.h"
|
||||
#include "globals.h"
|
||||
#include "timebase.h"
|
||||
#include "../hal/gpio.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 modules
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ public:
|
|||
/// to set correct FINDA state at startup
|
||||
void BlockingInit();
|
||||
|
||||
/// @returns true if there is no discrepency, false otherwise
|
||||
bool CheckFINDAvsEEPROM();
|
||||
|
||||
using debounce::Debouncer::Pressed;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue