Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.2 KiB

  1. /*
  2. DEBUG MODULE
  3. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #include <stdio.h>
  6. #include <stdarg.h>
  7. #ifdef DEBUG_UDP_IP
  8. #include <WiFiUdp.h>
  9. WiFiUDP udpDebug;
  10. #endif
  11. void debugSend(const char * format, ...) {
  12. char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
  13. va_list args;
  14. va_start(args, format);
  15. ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, format, args);
  16. va_end(args);
  17. #ifdef DEBUG_PORT
  18. DEBUG_PORT.printf(buffer);
  19. #endif
  20. #ifdef DEBUG_UDP_IP
  21. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  22. udpDebug.write(buffer);
  23. udpDebug.endPacket();
  24. #endif
  25. }
  26. void debugSend_P(PGM_P format, ...) {
  27. char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
  28. char f[DEBUG_MESSAGE_MAX_LENGTH+1];
  29. memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH);
  30. va_list args;
  31. va_start(args, format);
  32. ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args);
  33. va_end(args);
  34. #ifdef DEBUG_PORT
  35. DEBUG_PORT.printf(buffer);
  36. #endif
  37. #ifdef DEBUG_UDP_IP
  38. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  39. udpDebug.write(buffer);
  40. udpDebug.endPacket();
  41. #endif
  42. }