diff --git a/src/logic/command_base.cpp b/src/logic/command_base.cpp index 8075b8d..021a304 100644 --- a/src/logic/command_base.cpp +++ b/src/logic/command_base.cpp @@ -137,8 +137,7 @@ void CommandBase::ErrDisengagingIdler() { void CommandBase::GoToErrDisengagingIdler(ErrorCode ec) { state = ProgressCode::ERRDisengagingIdler; error = ec; - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::blink0); mi::idler.Disengage(); } diff --git a/src/logic/cut_filament.cpp b/src/logic/cut_filament.cpp index f1c4e3c..cd6c1e6 100644 --- a/src/logic/cut_filament.cpp +++ b/src/logic/cut_filament.cpp @@ -33,8 +33,7 @@ void CutFilament::SelectFilamentSlot() { state = ProgressCode::SelectingFilamentSlot; mi::idler.Engage(cutSlot); ms::selector.MoveToSlot(cutSlot); - ml::leds.SetMode(cutSlot, ml::green, ml::blink0); - ml::leds.SetMode(cutSlot, ml::red, ml::off); + ml::leds.SetPairButOffOthers(cutSlot, ml::blink0, ml::off); } 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 state = ProgressCode::OK; error = ErrorCode::OK; - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::on, ml::off); feed.Reset(true); } break; diff --git a/src/logic/feed_to_finda.cpp b/src/logic/feed_to_finda.cpp index 0e40965..6192ae8 100644 --- a/src/logic/feed_to_finda.cpp +++ b/src/logic/feed_to_finda.cpp @@ -15,7 +15,7 @@ void FeedToFinda::Reset(bool feedPhaseLimited) { dbg_logic_P(PSTR("\nFeed to FINDA\n\n")); state = EngagingIdler; 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()); // 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()); @@ -48,8 +48,7 @@ bool FeedToFinda::Step() { state = OK; } else if (mm::motion.QueueEmpty()) { // all moves have been finished and FINDA didn't switch on state = Failed; - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::blink0); } } return false; diff --git a/src/logic/load_filament.cpp b/src/logic/load_filament.cpp index a3ca344..e9765a9 100644 --- a/src/logic/load_filament.cpp +++ b/src/logic/load_filament.cpp @@ -27,13 +27,11 @@ void logic::LoadFilament::Reset2() { state = ProgressCode::FeedingToFinda; error = ErrorCode::RUNNING; feed.Reset(true); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off); } void logic::LoadFilament::GoToRetractingFromFinda() { - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off); state = ProgressCode::RetractingFromFinda; error = ErrorCode::RUNNING; retract.Reset(); @@ -42,8 +40,7 @@ void logic::LoadFilament::GoToRetractingFromFinda() { void logic::LoadFilament::FinishedCorrectly() { state = ProgressCode::OK; error = ErrorCode::OK; - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off); mm::motion.Disable(mm::Pulley); } diff --git a/src/logic/retract_from_finda.cpp b/src/logic/retract_from_finda.cpp index 89dbcd9..5d321ca 100644 --- a/src/logic/retract_from_finda.cpp +++ b/src/logic/retract_from_finda.cpp @@ -35,8 +35,7 @@ bool RetractFromFinda::Step() { ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); } else { // FINDA didn't switch off state = Failed; - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::blink0); } } return false; diff --git a/src/logic/tool_change.cpp b/src/logic/tool_change.cpp index cc5a854..76eb82b 100644 --- a/src/logic/tool_change.cpp +++ b/src/logic/tool_change.cpp @@ -45,16 +45,14 @@ void ToolChange::Reset(uint8_t param) { } void logic::ToolChange::GoToFeedingToBondtech() { - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::blink0, ml::off); james.Reset(3); state = ProgressCode::FeedingToBondtech; error = ErrorCode::RUNNING; } void logic::ToolChange::FinishedCorrectly() { - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::on, ml::off); state = ProgressCode::OK; error = ErrorCode::OK; } diff --git a/src/logic/unload_filament.cpp b/src/logic/unload_filament.cpp index a80e421..df71340 100644 --- a/src/logic/unload_filament.cpp +++ b/src/logic/unload_filament.cpp @@ -28,8 +28,7 @@ void UnloadFilament::Reset(uint8_t /*param*/) { state = ProgressCode::UnloadingToFinda; error = ErrorCode::RUNNING; unl.Reset(maxRetries); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off); } void logic::UnloadFilament::FinishedCorrectly() { @@ -37,8 +36,7 @@ void logic::UnloadFilament::FinishedCorrectly() { error = ErrorCode::OK; mm::motion.Disable(mm::Pulley); mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::AtPulley); // filament unloaded - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off); - ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::off); + ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off); } bool UnloadFilament::StepInner() { diff --git a/src/modules/leds.cpp b/src/modules/leds.cpp index 5d58415..1afafcf 100644 --- a/src/modules/leds.cpp +++ b/src/modules/leds.cpp @@ -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 modules diff --git a/src/modules/leds.h b/src/modules/leds.h index c2afcb0..90cbca8 100644 --- a/src/modules/leds.h +++ b/src/modules/leds.h @@ -116,6 +116,9 @@ public: 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: constexpr static const uint8_t ledPairs = config::toolCount; /// pairs of LEDs: