DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
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.

DebugLog.cpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
  3. *
  4. * This file is part of Giess-o-mat.
  5. *
  6. * Giess-o-mat is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Giess-o-mat is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Giess-o-mat. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include <Arduino.h>
  20. #ifdef PLATFORM_ESP
  21. #include "WifiStuff.h"
  22. #endif // PLATFORM_ESP
  23. #include "DebugLog.h"
  24. DebugLog debug;
  25. #ifdef PLATFORM_ESP
  26. String DebugLog::getBuffer(void) {
  27. String r;
  28. for (unsigned int i = 0; i < buffer.size(); i++) {
  29. r += buffer[i];
  30. }
  31. return r;
  32. }
  33. void DebugLog::addToBuffer(String s) {
  34. for (unsigned int i = 0; i < s.length(); i++) {
  35. buffer.push(s[i]);
  36. }
  37. }
  38. #endif // PLATFORM_ESP
  39. void DebugLog::sendToTargets(String s) {
  40. Serial.print(s);
  41. #ifdef PLATFORM_ESP
  42. s = "log:" + s;
  43. wifi_send_websocket(s);
  44. #endif // PLATFORM_ESP
  45. }
  46. void DebugLog::print(String s) {
  47. #ifdef PLATFORM_ESP
  48. addToBuffer(s);
  49. #endif // PLATFORM_ESP
  50. sendToTargets(s);
  51. }
  52. void DebugLog::print(int n) {
  53. print(String(n));
  54. }
  55. void DebugLog::println(void) {
  56. print(String(F("\r\n")));
  57. }
  58. void DebugLog::println(String s) {
  59. s += String(F("\r\n"));
  60. print(s);
  61. }
  62. void DebugLog::println(int n) {
  63. println(String(n));
  64. }