extend power statemachine

This commit is contained in:
2022-01-02 18:50:22 +01:00
parent 7509858aa4
commit c340ab9d2a
8 changed files with 178 additions and 39 deletions

View File

@@ -3,8 +3,28 @@
CRGB leds[NUM_LEDS];
bool ledstate = false;
bool blinkState = false;
CRGB ledcolor = CRGB::Black;
uint32_t lastLedTime = 0;
void setLedBlink(bool blink)
{
blinkState = blink;
}
void SetLedColor(CRGB color)
{
ledcolor = color;
setLedBlink(false);
}
void SetLedColor(CRGB color, bool blink)
{
SetLedColor(color);
setLedBlink(blink);
}
void initLed(void)
{
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
@@ -16,42 +36,58 @@ void handleLed(void)
uint32_t timeNow = millis();
if (timeNow - lastLedTime > LEDTIMEOUT)
{
if (ledstate)
if (blinkState)
{
if (getPowerState() == POWERSTATES::on)
if (!ledstate)
{
if(getAudioState())
{
leds[0] = CRGB::Purple;
}
else if( getRFIDlastUID() != "")
{
leds[0] = CRGB::Yellow;
}
else
{
leds[0] = CRGB::Green;
}
}
else if (getPowerState() == POWERSTATES::poweringOn2)
{
leds[0] = CRGB::Blue;
}
else if (getPowerState() == POWERSTATES::poweringOff2)
{
leds[0] = CRGB::Orange;
leds[0] = CRGB::Black;
}
else
{
leds[0] = CRGB::Red;
leds[0] = ledcolor;
}
ledstate = !ledstate;
}
else
{
leds[0] = CRGB::Black;
leds[0] = ledcolor;
}
// if (ledstate)
// {
// if (getPowerState() == POWERSTATES::on)
// {
// if(getAudioState())
// {
// leds[0] = CRGB::Purple;
// }
// else if( getRFIDlastUID() != "")
// {
// leds[0] = CRGB::Yellow;
// }
// else
// {
// leds[0] = CRGB::Green;
// }
// }
// else if (getPowerState() == POWERSTATES::poweringOn2)
// {
// leds[0] = CRGB::Blue;
// }
// else if (getPowerState() == POWERSTATES::poweringOff2)
// {
// leds[0] = CRGB::Orange;
// }
// else
// {
// leds[0] = CRGB::Red;
// }
// }
// else
// {
// leds[0] = CRGB::Black;
// }
FastLED.show();
ledstate = !ledstate;
lastLedTime = timeNow;
}
}