44
55NetworkDebugPrinter NetDebug;
66
7- void NetworkDebugPrinter::printchar (char s) {
8- debugUdp.write (s);
9- }
7+ void NetworkDebugPrinter::print (const char *s, bool newline) {
8+ if (!WLED_CONNECTED || !udpConnected || s == nullptr ) return ;
109
11- void NetworkDebugPrinter::print (const char *s) {
12- if (!WLED_CONNECTED || s == nullptr ) {
13- return ;
14- }
15- IPAddress debugPrintHostIP;
16- if (!debugPrintHostIP.fromString (netDebugPrintHost)) {
10+ if (!debugPrintHostIP && !debugPrintHostIP.fromString (netDebugPrintHost)) {
1711 #ifdef ESP8266
1812 WiFi.hostByName (netDebugPrintHost, debugPrintHostIP, 750 );
1913 #else
@@ -24,49 +18,49 @@ void NetworkDebugPrinter::print(const char *s) {
2418 #endif
2519 #endif
2620 }
21+
22+ WiFiUDP debugUdp;
2723 debugUdp.beginPacket (debugPrintHostIP, netDebugPrintPort);
28- // for (size_t i=0; i<strlen(s); i++) printchar(s[i]);
2924 debugUdp.write (reinterpret_cast <const uint8_t *>(s), strlen (s));
25+ if (newline) debugUdp.write (' \n ' );
3026 debugUdp.endPacket ();
3127}
3228
33- void NetworkDebugPrinter::print (const __FlashStringHelper* s) {
34- print (reinterpret_cast <const char *>(s));
29+ void NetworkDebugPrinter::print (const __FlashStringHelper* s, bool newline) {
30+ char buf[512 ];
31+ strncpy_P (buf, (PGM_P)s, 512 );
32+ print (buf, newline);
3533}
3634
3735void NetworkDebugPrinter::print (String s) {
3836 print (s.c_str ());
3937}
4038
41- void NetworkDebugPrinter::print (unsigned int n) {
39+ void NetworkDebugPrinter::print (unsigned int n, bool newline ) {
4240 char s[10 ];
4341 snprintf_P (s, sizeof (s), PSTR (" %d" ), n);
4442 s[9 ] = ' \0 ' ;
45- print (s);
43+ print (s, newline );
4644}
4745
4846void NetworkDebugPrinter::println () {
49- print (" \n " );
47+ print (" " , true );
5048}
5149
5250void NetworkDebugPrinter::println (const char *s) {
53- print (s);
54- print (" \n " );
51+ print (s, true );
5552}
5653
5754void NetworkDebugPrinter::println (const __FlashStringHelper* s) {
58- print (s);
59- print (" \n " );
55+ print (s, true );
6056}
6157
6258void NetworkDebugPrinter::println (String s) {
63- print (s);
64- print (" \n " );
59+ print (s.c_str (), true );
6560}
6661
6762void NetworkDebugPrinter::println (unsigned int n) {
68- print (n);
69- print (" \n " );
63+ print (n, true );
7064}
7165
7266void NetworkDebugPrinter::printf (const char *fmt...) {
0 commit comments