Refactor CheckFINDAvsEEPROM and setup2
parent
98daf765af
commit
b6c3cba396
|
|
@ -2,12 +2,21 @@
|
||||||
#include "start_up.h"
|
#include "start_up.h"
|
||||||
#include "../modules/buttons.h"
|
#include "../modules/buttons.h"
|
||||||
#include "../modules/finda.h"
|
#include "../modules/finda.h"
|
||||||
|
#include "../modules/globals.h"
|
||||||
#include "../modules/user_input.h"
|
#include "../modules/user_input.h"
|
||||||
|
|
||||||
namespace logic {
|
namespace logic {
|
||||||
|
|
||||||
StartUp startUp;
|
StartUp startUp;
|
||||||
|
|
||||||
|
bool StartUp::Reset(uint8_t) {
|
||||||
|
if (!CheckFINDAvsEEPROM()) {
|
||||||
|
SetInitError(ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool StartUp::StepInner() {
|
bool StartUp::StepInner() {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case ProgressCode::OK:
|
case ProgressCode::OK:
|
||||||
|
|
@ -20,7 +29,7 @@ bool StartUp::StepInner() {
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case ErrorCode::FINDA_VS_EEPROM_DISREPANCY:
|
case ErrorCode::FINDA_VS_EEPROM_DISREPANCY:
|
||||||
// Retry
|
// Retry
|
||||||
if (!mf::finda.CheckFINDAvsEEPROM()) {
|
if (!CheckFINDAvsEEPROM()) {
|
||||||
error = ErrorCode::FINDA_VS_EEPROM_DISREPANCY;
|
error = ErrorCode::FINDA_VS_EEPROM_DISREPANCY;
|
||||||
state = ProgressCode::ERRWaitingForUser;
|
state = ProgressCode::ERRWaitingForUser;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -43,4 +52,25 @@ bool StartUp::StepInner() {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StartUp::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);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace logic
|
} // namespace logic
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ public:
|
||||||
: CommandBase() {}
|
: CommandBase() {}
|
||||||
|
|
||||||
/// Restart the automaton
|
/// Restart the automaton
|
||||||
bool Reset(uint8_t /*param*/) override { return true; }
|
bool Reset(uint8_t /*param*/) override;
|
||||||
|
|
||||||
/// @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;
|
bool StepInner() override;
|
||||||
|
|
@ -24,6 +24,10 @@ public:
|
||||||
error = ec;
|
error = ec;
|
||||||
state = ProgressCode::ERRWaitingForUser;
|
state = ProgressCode::ERRWaitingForUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// @returns true if there is no discrepency, false otherwise
|
||||||
|
static bool CheckFINDAvsEEPROM();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The one and only instance of StartUp state machine in the FW
|
/// The one and only instance of StartUp state machine in the FW
|
||||||
|
|
|
||||||
11
src/main.cpp
11
src/main.cpp
|
|
@ -90,11 +90,7 @@ 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.CheckFINDAvsEEPROM()) {
|
// Turn off all leds
|
||||||
logic::startUp.SetInitError(ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Turn off all leds
|
|
||||||
for (uint8_t i = 0; i < config::toolCount; i++) {
|
for (uint8_t i = 0; i < config::toolCount; i++) {
|
||||||
ml::leds.SetMode(i, ml::green, ml::off);
|
ml::leds.SetMode(i, ml::green, ml::off);
|
||||||
ml::leds.SetMode(i, ml::red, ml::off);
|
ml::leds.SetMode(i, ml::red, ml::off);
|
||||||
|
|
@ -103,7 +99,7 @@ static void setup2() {
|
||||||
|
|
||||||
// Prep hardware sanity:
|
// Prep hardware sanity:
|
||||||
logic::hwSanity.Reset(0);
|
logic::hwSanity.Reset(0);
|
||||||
|
// Process HW sanity checks exclusively
|
||||||
while (!logic::hwSanity.StepInner()) {
|
while (!logic::hwSanity.StepInner()) {
|
||||||
ml::leds.Step();
|
ml::leds.Step();
|
||||||
}
|
}
|
||||||
|
|
@ -112,6 +108,9 @@ static void setup2() {
|
||||||
// forward the issue to the logic startup handler.
|
// forward the issue to the logic startup handler.
|
||||||
logic::startUp.SetInitError(logic::hwSanity.Error());
|
logic::startUp.SetInitError(logic::hwSanity.Error());
|
||||||
} else {
|
} else {
|
||||||
|
// When HW is sane, activate sequence of start up checks and let it run asynchronnously
|
||||||
|
logic::startUp.Reset(0);
|
||||||
|
|
||||||
// Idler and Selector decide whether homing is possible/safe
|
// Idler and Selector decide whether homing is possible/safe
|
||||||
mi::idler.Init();
|
mi::idler.Init();
|
||||||
ms::selector.Init();
|
ms::selector.Init();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
/// @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"
|
||||||
|
|
@ -22,25 +21,5 @@ 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);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace finda
|
} // namespace finda
|
||||||
} // namespace modules
|
} // namespace modules
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,6 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue