Changed LED behaviour when in AP mode

This commit is contained in:
Gunnar Skjold
2024-04-04 19:53:44 +02:00
parent c22bca3130
commit 361d3a38ed
3 changed files with 34 additions and 31 deletions

View File

@@ -55,7 +55,7 @@ public:
bool ledOn(uint8_t color); bool ledOn(uint8_t color);
bool ledOff(uint8_t color); bool ledOff(uint8_t color);
bool ledBlink(uint8_t color, uint8_t blink); bool ledBlink(uint8_t color, uint8_t blink);
void setBootSuccessful(); void setBootSuccessful(bool value);
HwTools() {}; HwTools() {};
private: private:

View File

@@ -237,19 +237,7 @@ void HwTools::setup(GpioConfig* config) {
} }
if(config->ledDisablePin > 0 && config->ledDisablePin < 40) { if(config->ledDisablePin > 0 && config->ledDisablePin < 40) {
pinMode(config->ledDisablePin, OUTPUT_OPEN_DRAIN); pinMode(config->ledDisablePin, OUTPUT_OPEN_DRAIN);
switch(config->ledBehaviour) { setBootSuccessful(false);
case LED_BEHAVIOUR_ERROR_ONLY:
case LED_BEHAVIOUR_OFF:
digitalWrite(config->ledDisablePin, LOW);
break;
case LED_BEHAVIOUR_BOOT:
if(bootSuccessful) {
digitalWrite(config->ledDisablePin, LOW);
}
break;
default:
digitalWrite(config->ledDisablePin, HIGH);
}
} }
} }
@@ -538,11 +526,25 @@ int HwTools::getWifiRssi() {
return isnan(rssi) ? -100.0 : rssi; return isnan(rssi) ? -100.0 : rssi;
} }
void HwTools::setBootSuccessful() { void HwTools::setBootSuccessful(bool value) {
if(bootSuccessful) return; if(bootSuccessful && value) return;
bootSuccessful = true; bootSuccessful = value;
if(config->ledBehaviour != LED_BEHAVIOUR_DEFAULT) { if(config->ledDisablePin > 0 && config->ledDisablePin < 40) {
digitalWrite(config->ledDisablePin, LOW); switch(config->ledBehaviour) {
case LED_BEHAVIOUR_ERROR_ONLY:
case LED_BEHAVIOUR_OFF:
digitalWrite(config->ledDisablePin, LOW);
break;
case LED_BEHAVIOUR_BOOT:
if(bootSuccessful) {
digitalWrite(config->ledDisablePin, LOW);
} else {
digitalWrite(config->ledDisablePin, HIGH);
}
break;
default:
digitalWrite(config->ledDisablePin, HIGH);
}
} }
} }

View File

@@ -716,12 +716,6 @@ void loop() {
if(dnsServer != NULL) { if(dnsServer != NULL) {
dnsServer->processNextRequest(); dnsServer->processNextRequest();
} }
// Continously flash the LED when AP mode
if (now / 50 % 64 == 0) {
if(!hw.ledBlink(LED_YELLOW, 1)) {
hw.ledBlink(LED_INTERNAL, 1);
}
}
ws.loop(); ws.loop();
} }
@@ -811,7 +805,7 @@ void loop() {
} }
handleTemperature(now); handleTemperature(now);
handleSystem(now); handleSystem(now);
hw.setBootSuccessful(); hw.setBootSuccessful(true);
} else { } else {
end = millis(); end = millis();
if(end - start > 1000) { if(end - start > 1000) {
@@ -1092,6 +1086,7 @@ void errorBlink() {
if(lastError == 3) if(lastError == 3)
lastError = 0; lastError = 0;
lastErrorBlink = millis64(); lastErrorBlink = millis64();
if(setupMode) return;
while(lastError < 3) { while(lastError < 3) {
switch(lastError++) { switch(lastError++) {
case 0: case 0:
@@ -1207,6 +1202,11 @@ void toggleSetupMode() {
Debug.begin(F("192.168.4.1"), 23, RemoteDebug::VERBOSE); Debug.begin(F("192.168.4.1"), 23, RemoteDebug::VERBOSE);
#endif #endif
setupMode = true; setupMode = true;
hw.setBootSuccessful(false);
if(gpioConfig.ledDisablePin != 0xFF) {
digitalWrite(gpioConfig.ledDisablePin, LOW);
}
} else { } else {
if(Debug.isActive(RemoteDebug::INFO)) debugI_P(PSTR("Exiting setup mode")); if(Debug.isActive(RemoteDebug::INFO)) debugI_P(PSTR("Exiting setup mode"));
if(dnsServer != NULL) { if(dnsServer != NULL) {
@@ -1215,10 +1215,11 @@ void toggleSetupMode() {
} }
connectToNetwork(); connectToNetwork();
setupMode = false; setupMode = false;
} delay(500);
delay(500); if(!hw.ledOff(LED_YELLOW)) {
if(!hw.ledOff(LED_YELLOW)) { hw.ledOff(LED_INTERNAL);
hw.ledOff(LED_INTERNAL); }
hw.setBootSuccessful(true);
} }
} }
@@ -1258,7 +1259,7 @@ bool readHanPort() {
} }
void handleDataSuccess(AmsData* data) { void handleDataSuccess(AmsData* data) {
if(!hw.ledBlink(LED_GREEN, 1)) if(!setupMode && !hw.ledBlink(LED_GREEN, 1))
hw.ledBlink(LED_INTERNAL, 1); hw.ledBlink(LED_INTERNAL, 1);
if(mqttHandler != NULL) { if(mqttHandler != NULL) {