modules: leds: Implement SetAllOff()

A helper function which turns of all LEDs
reduces code size :)

Change in memory:
Flash: -64 bytes
SRAM: 0 bytes
pull/272/head
Guðni Már Gilbert 2023-04-30 18:37:25 +00:00
parent 729a3a43da
commit 23ba16cdea
6 changed files with 17 additions and 12 deletions

View File

@ -80,7 +80,7 @@ bool EjectFilament::StepInner() {
ResumeIdlerSelector();
switch (error) {
case ErrorCode::FILAMENT_EJECTED: // the user clicked "Done", we can finish the Eject operation
ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off);
ml::leds.SetAllOff();
FinishedOK();
break;
case ErrorCode::FINDA_FLICKERS:

View File

@ -97,9 +97,7 @@ bool HWSanity::StepInner() {
} else {
state = ProgressCode::HWTestExec;
// display done, reset LEDs.
for (uint8_t i = 0; i < 6; i++) {
ml::leds.SetMode(i, ml::off);
}
ml::leds.SetAllOff();
}
[[fallthrough]];
case ProgressCode::HWTestExec: {
@ -163,7 +161,7 @@ bool HWSanity::StepInner() {
ml::leds.SetMode(4, ml::green, ml::off);
return true;
} else {
ml::leds.SetPairButOffOthers(0, ml::off, ml::off);
ml::leds.SetAllOff();
FinishedOK();
}
case ProgressCode::OK:

View File

@ -64,7 +64,7 @@ void logic::LoadFilament::GoToRetractingFromFinda() {
void logic::LoadFilament::LoadFinishedCorrectly() {
FinishedOK();
ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off);
ml::leds.SetAllOff();
mpu::pulley.Disable();
}

View File

@ -29,7 +29,7 @@ bool UnloadFilament::Reset(uint8_t /*param*/) {
state = ProgressCode::UnloadingToFinda;
error = ErrorCode::RUNNING;
unl.Reset(maxRetries);
ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off);
ml::leds.SetAllOff();
return true;
}
@ -37,7 +37,7 @@ void UnloadFilament::UnloadFinishedCorrectly() {
FinishedOK();
mpu::pulley.Disable();
mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::AtPulley); // filament unloaded
ml::leds.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off);
ml::leds.SetAllOff();
}
void UnloadFilament::GoToRetractingFromFinda() {

View File

@ -56,13 +56,17 @@ 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);
}
SetAllOff();
SetMode(activeSlot, ml::green, greenMode);
SetMode(activeSlot, ml::red, redMode);
}
void LEDs::SetAllOff() {
for (uint8_t i = 0; i < ledPairs; ++i) {
SetMode(i, ml::green, ml::off);
SetMode(i, ml::red, ml::off);
}
}
} // namespace leds
} // namespace modules

View File

@ -119,6 +119,9 @@ public:
/// 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);
/// Turn off all LEDs
void SetAllOff();
private:
constexpr static const uint8_t ledPairs = config::toolCount;
/// pairs of LEDs: