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/275/head
Guðni Már Gilbert 2023-04-30 18:37:25 +00:00 committed by DRracer
parent c6c23e2c06
commit c096725674
6 changed files with 17 additions and 12 deletions

View File

@ -80,7 +80,7 @@ bool EjectFilament::StepInner() {
ResumeIdlerSelector(); ResumeIdlerSelector();
switch (error) { switch (error) {
case ErrorCode::FILAMENT_EJECTED: // the user clicked "Done", we can finish the Eject operation 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(); FinishedOK();
break; break;
case ErrorCode::FINDA_FLICKERS: case ErrorCode::FINDA_FLICKERS:

View File

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

View File

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

View File

@ -29,7 +29,7 @@ bool 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.SetPairButOffOthers(mg::globals.ActiveSlot(), ml::off, ml::off); ml::leds.SetAllOff();
return true; return true;
} }
@ -37,7 +37,7 @@ void UnloadFilament::UnloadFinishedCorrectly() {
FinishedOK(); FinishedOK();
mpu::pulley.Disable(); mpu::pulley.Disable();
mg::globals.SetFilamentLoaded(mg::globals.ActiveSlot(), mg::FilamentLoadState::AtPulley); // filament unloaded 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() { void UnloadFilament::GoToRetractingFromFinda() {

View File

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

View File

@ -119,6 +119,9 @@ public:
/// Sets active slot LEDs to some mode and turns off all the others /// 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); void SetPairButOffOthers(uint8_t activeSlot, modules::leds::Mode greenMode, modules::leds::Mode redMode);
/// Turn off all LEDs
void SetAllOff();
private: private:
constexpr static const uint8_t ledPairs = config::toolCount; constexpr static const uint8_t ledPairs = config::toolCount;
/// pairs of LEDs: /// pairs of LEDs: