Turn off other LEDs when appropriate

Solves an interesting tiny issue introduced in the previous commits.
When we start with the filament in selector, the corresponding LED
is set to ON. However, all of the logic state machines only operated
on the LED pair of the active slot -> the starting LED may have been
left ON in some edge cases.

Now, this is resolved by clearing all other LEDs except for the active
slot where appropriate.
pull/148/head
D.R.racer 2021-11-25 11:07:02 +01:00 committed by DRracer
parent f2f82c620a
commit 662e05b813
9 changed files with 25 additions and 25 deletions

View File

@ -137,8 +137,7 @@ void CommandBase::ErrDisengagingIdler() {
void CommandBase::GoToErrDisengagingIdler(ErrorCode ec) { void CommandBase::GoToErrDisengagingIdler(ErrorCode ec) {
state = ProgressCode::ERRDisengagingIdler; state = ProgressCode::ERRDisengagingIdler;
error = ec; error = ec;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::blink0);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0);
mi::idler.Disengage(); mi::idler.Disengage();
} }

View File

@ -33,8 +33,7 @@ void CutFilament::SelectFilamentSlot() {
state = ProgressCode::SelectingFilamentSlot; state = ProgressCode::SelectingFilamentSlot;
mi::idler.Engage(cutSlot); mi::idler.Engage(cutSlot);
ms::selector.MoveToSlot(cutSlot); ms::selector.MoveToSlot(cutSlot);
ml::leds.SetMode(cutSlot, ml::green, ml::blink0); ml::leds.SetPairButOffOthers(cutSlot, ml::blink0, ml::off);
ml::leds.SetMode(cutSlot, ml::red, ml::off);
} }
bool CutFilament::StepInner() { bool CutFilament::StepInner() {
@ -94,8 +93,7 @@ bool CutFilament::StepInner() {
if (ms::selector.Slot() == 5) { // selector returned to position, feed the filament back to FINDA if (ms::selector.Slot() == 5) { // selector returned to position, feed the filament back to FINDA
state = ProgressCode::OK; state = ProgressCode::OK;
error = ErrorCode::OK; error = ErrorCode::OK;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::on, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off);
feed.Reset(true); feed.Reset(true);
} }
break; break;

View File

@ -15,7 +15,7 @@ void FeedToFinda::Reset(bool feedPhaseLimited) {
dbg_logic_P(PSTR("\nFeed to FINDA\n\n")); dbg_logic_P(PSTR("\nFeed to FINDA\n\n"));
state = EngagingIdler; state = EngagingIdler;
this->feedPhaseLimited = feedPhaseLimited; this->feedPhaseLimited = feedPhaseLimited;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off);
mi::idler.Engage(mg::globals.ActiveSlot()); mi::idler.Engage(mg::globals.ActiveSlot());
// We can't get any FINDA readings if the selector is at the wrong spot - move it accordingly if necessary // We can't get any FINDA readings if the selector is at the wrong spot - move it accordingly if necessary
ms::selector.MoveToSlot(mg::globals.ActiveSlot()); ms::selector.MoveToSlot(mg::globals.ActiveSlot());
@ -48,8 +48,7 @@ bool FeedToFinda::Step() {
state = OK; state = OK;
} else if (mm::motion.QueueEmpty()) { // all moves have been finished and FINDA didn't switch on } else if (mm::motion.QueueEmpty()) { // all moves have been finished and FINDA didn't switch on
state = Failed; state = Failed;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::blink0);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0);
} }
} }
return false; return false;

View File

@ -27,13 +27,11 @@ void logic::LoadFilament::Reset2() {
state = ProgressCode::FeedingToFinda; state = ProgressCode::FeedingToFinda;
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
feed.Reset(true); feed.Reset(true);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off);
} }
void logic::LoadFilament::GoToRetractingFromFinda() { void logic::LoadFilament::GoToRetractingFromFinda() {
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0);
state = ProgressCode::RetractingFromFinda; state = ProgressCode::RetractingFromFinda;
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
retract.Reset(); retract.Reset();
@ -42,8 +40,7 @@ void logic::LoadFilament::GoToRetractingFromFinda() {
void logic::LoadFilament::FinishedCorrectly() { void logic::LoadFilament::FinishedCorrectly() {
state = ProgressCode::OK; state = ProgressCode::OK;
error = ErrorCode::OK; error = ErrorCode::OK;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
mm::motion.Disable(mm::Pulley); mm::motion.Disable(mm::Pulley);
} }

View File

@ -35,8 +35,7 @@ bool RetractFromFinda::Step() {
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
} else { // FINDA didn't switch off } else { // FINDA didn't switch off
state = Failed; state = Failed;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::blink0);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0);
} }
} }
return false; return false;

View File

@ -45,16 +45,14 @@ void ToolChange::Reset(uint8_t param) {
} }
void logic::ToolChange::GoToFeedingToBondtech() { void logic::ToolChange::GoToFeedingToBondtech() {
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0);
james.Reset(3); james.Reset(3);
state = ProgressCode::FeedingToBondtech; state = ProgressCode::FeedingToBondtech;
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
} }
void logic::ToolChange::FinishedCorrectly() { void logic::ToolChange::FinishedCorrectly() {
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::on, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on);
state = ProgressCode::OK; state = ProgressCode::OK;
error = ErrorCode::OK; error = ErrorCode::OK;
} }

View File

@ -28,8 +28,7 @@ void UnloadFilament::Reset(uint8_t /*param*/) {
state = ProgressCode::UnloadingToFinda; state = ProgressCode::UnloadingToFinda;
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
unl.Reset(maxRetries); unl.Reset(maxRetries);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off);
} }
void logic::UnloadFilament::FinishedCorrectly() { void logic::UnloadFilament::FinishedCorrectly() {
@ -37,8 +36,7 @@ void logic::UnloadFilament::FinishedCorrectly() {
error = ErrorCode::OK; error = ErrorCode::OK;
mm::motion.Disable(mm::Pulley); mm::motion.Disable(mm::Pulley);
mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::AtPulley); // filament unloaded mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::AtPulley); // filament unloaded
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off);
} }
bool UnloadFilament::StepInner() { bool UnloadFilament::StepInner() {

View File

@ -55,5 +55,14 @@ void LEDs::Step() {
} }
} }
void LEDs::SetPairButOffOthers(uint8_t activeSlot, ml::Mode greenMode, ml::Mode redMode) {
for (uint8_t i = 0; i < ledPairs; ++i) {
SetMode(i, ml::green, ml::off);
SetMode(i, ml::red, ml::off);
}
SetMode(activeSlot, ml::green, greenMode);
SetMode(activeSlot, ml::red, redMode);
}
} // namespace leds } // namespace leds
} // namespace modules } // namespace modules

View File

@ -116,6 +116,9 @@ public:
return leds[slot * 2 + color].On(); return leds[slot * 2 + color].On();
} }
/// Sets active slot LEDs to some mode and turns off all the others
void SetPairButOffOthers(uint8_t activeSlot, modules::leds::Mode greenMode, modules::leds::Mode redMode);
private: private:
constexpr static const uint8_t ledPairs = config::toolCount; constexpr static const uint8_t ledPairs = config::toolCount;
/// pairs of LEDs: /// pairs of LEDs: