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.

47 lines
944 B

  1. // -----------------------------------------------------------------------------
  2. // printf-like debug methods
  3. // -----------------------------------------------------------------------------
  4. #pragma once
  5. void debugSendImpl(const char*);
  6. void _debugSend(const char * format, va_list args) {
  7. char temp[64];
  8. int len = ets_vsnprintf(temp, sizeof(temp), format, args);
  9. if (len < 64) { debugSendImpl(temp); return; }
  10. auto buffer = new char[len + 1];
  11. ets_vsnprintf(buffer, len + 1, format, args);
  12. debugSendImpl(buffer);
  13. delete[] buffer;
  14. }
  15. void debugSend(const char* format, ...) {
  16. va_list args;
  17. va_start(args, format);
  18. _debugSend(format, args);
  19. va_end(args);
  20. }
  21. void debugSend_P(PGM_P format_P, ...) {
  22. char format[strlen_P(format_P) + 1];
  23. memcpy_P(format, format_P, sizeof(format));
  24. va_list args;
  25. va_start(args, format_P);
  26. _debugSend(format, args);
  27. va_end(args);
  28. }