enum LEDState
{
  Off,
  BlinkLow,
  BlinkHigh,
  On
};

bool ledAP = false;
LEDState ledWiFi = Off;
uint32_t blinkOnTime = 0;


void updateLED()
{
  uint8_t value = (currentTime - blinkOnTime >= 1000) ? LOW : HIGH;

  WiFiMode_t mode = WiFi.getMode();
  if (mode == WIFI_AP_STA || mode == WIFI_AP)
  {
    if (!ledAP)
    {
      digitalWrite(systemSettings->pinLEDAP(), HIGH);
      ledAP = true;
    }
  }
  else
  {
    if (ledAP)
    {
      digitalWrite(systemSettings->pinLEDAP(), LOW);
      ledAP = false;
    }
  }

  if (mode == WIFI_AP_STA || mode == WIFI_STA)
  {
    wl_status_t status = WiFi.status();

    if (status == WL_CONNECTED)
    {
      if (ledWiFi != On)
      {
        digitalWrite(systemSettings->pinLEDSTA(), HIGH);
        ledWiFi = On;
      }
    }
    else
    {
      LEDState expectedState = value == HIGH ? BlinkHigh : BlinkLow;
      if (ledWiFi != expectedState)
      {
        digitalWrite(systemSettings->pinLEDSTA(), value);
        ledWiFi = expectedState;
      }
    }
  }
  else
  {
    if (ledWiFi != Off)
    {
      digitalWrite(systemSettings->pinLEDSTA(), LOW);
      ledWiFi = Off;
    }
  }


  if (currentTime - blinkOnTime >= 2000)
    blinkOnTime = currentTime;
}