@@ -179,12 +179,32 @@ const int pwmMax = pow(2,pwmresolution)-1;
179179// will be returned for all http requests
180180String critERR = " " ;
181181
182- // Debug Data for stream and capture
183- #if defined(DEBUG_DEFAULT_ON)
184- bool debugData = true ;
185- #else
186- bool debugData = false ;
187- #endif
182+ // Debug flag for stream and capture data
183+ bool debugData;
184+
185+ void debugOn () {
186+ debugData = true ;
187+ Serial.println (" Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)" );
188+ }
189+
190+ void debugOff () {
191+ debugData = false ;
192+ Serial.println (" Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)" );
193+ }
194+
195+ // Serial input (debugging controls)
196+ void handleSerial () {
197+ if (Serial.available ()) {
198+ char cmd = Serial.read ();
199+ if (cmd == ' d' ) {
200+ serialDump ();
201+ } else {
202+ if (debugData) debugOff ();
203+ else debugOn ();
204+ }
205+ }
206+ while (Serial.available ()) Serial.read (); // chomp the buffer
207+ }
188208
189209// Notification LED
190210void flashLED (int flashtime) {
@@ -601,8 +621,11 @@ void setup() {
601621 Serial.printf (" \n Camera Ready!\n Use '%s' to connect\n " , httpURL);
602622 Serial.printf (" Stream viewer available at '%sview'\n " , streamURL);
603623 Serial.printf (" Raw stream URL is '%s'\n " , streamURL);
604- if (debugData) Serial.println (" Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)" );
605- else Serial.println (" Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)" );
624+ #if defined(DEBUG_DEFAULT_ON)
625+ debugOn ();
626+ #else
627+ debugOff ();
628+ #endif
606629 } else {
607630 Serial.printf (" \n Camera unavailable due to initialisation errors.\n\n " );
608631 }
@@ -621,9 +644,11 @@ void loop() {
621644 */
622645 if (accesspoint) {
623646 // Accespoint is permanently up, so just loop, servicing the captive portal as needed
647+ // Rather than loop forever, follow the watchdog, in case we later add auto re-scan.
624648 unsigned long start = millis ();
625649 while (millis () - start < WIFI_WATCHDOG ) {
626650 delay (100 );
651+ handleSerial ();
627652 if (captivePortal) dnsServer.processNextRequest ();
628653 }
629654 } else {
@@ -640,21 +665,7 @@ void loop() {
640665 unsigned long start = millis ();
641666 while (millis () - start < WIFI_WATCHDOG ) {
642667 delay (100 );
643- if (Serial.available ()) {
644- if (Serial.read () == ' d' ) {
645- serialDump ();
646- } else {
647- // Toggle debug output on serial input
648- if (debugData) {
649- debugData = false ;
650- Serial.println (" Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)" );
651- } else {
652- debugData = true ;
653- Serial.println (" Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)" );
654- }
655- }
656- }
657- while (Serial.available ()) Serial.read (); // chomp the buffer
668+ handleSerial ();
658669 }
659670 } else {
660671 // disconnected; attempt to reconnect
0 commit comments