Better debug toggle and setup

This commit is contained in:
Owen 2021-05-09 14:59:18 +02:00
parent 658fe173dc
commit 10c2d7e841
1 changed files with 25 additions and 21 deletions

View File

@ -179,32 +179,33 @@ const int pwmMax = pow(2,pwmresolution)-1;
// will be returned for all http requests
String critERR = "";
// Debug Data for stream and capture
#if defined(DEBUG_DEFAULT_ON)
bool debugData = true;
#else
bool debugData = false;
#endif
// Debug flag for stream and capture data
bool debugData;
void debugToggle() {
void debugOn() {
debugData = true;
Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)");
}
void debugOff() {
debugData = false;
Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)");
}
// Serial input (debugging controls)
void handleSerial() {
if (Serial.available()) {
if (Serial.read() == 'd' ) {
char cmd = Serial.read();
if (cmd == 'd' ) {
serialDump();
} else {
// Toggle debug output on serial input
if (debugData) {
debugData = false;
Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)");
} else {
debugData = true;
Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)");
}
if (debugData) debugOff();
else debugOn();
}
}
while (Serial.available()) Serial.read(); // chomp the buffer
}
// Notification LED
void flashLED(int flashtime) {
#ifdef LED_PIN // If we have it; flash it.
@ -620,8 +621,11 @@ void setup() {
Serial.printf("\nCamera Ready!\nUse '%s' to connect\n", httpURL);
Serial.printf("Stream viewer available at '%sview'\n", streamURL);
Serial.printf("Raw stream URL is '%s'\n", streamURL);
if (debugData) Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)");
else Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)");
#if defined(DEBUG_DEFAULT_ON)
debugOn();
#else
debugOff();
#endif
} else {
Serial.printf("\nCamera unavailable due to initialisation errors.\n\n");
}
@ -644,7 +648,7 @@ void loop() {
unsigned long start = millis();
while (millis() - start < WIFI_WATCHDOG ) {
delay(100);
debugToggle();
handleSerial();
if (captivePortal) dnsServer.processNextRequest();
}
} else {
@ -661,7 +665,7 @@ void loop() {
unsigned long start = millis();
while (millis() - start < WIFI_WATCHDOG ) {
delay(100);
debugToggle();
handleSerial();
}
} else {
// disconnected; attempt to reconnect