My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

WebSocketSerial.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../../inc/MarlinConfig.h"
  24. #include <WString.h>
  25. #define DEC 10
  26. #define HEX 16
  27. #define OCT 8
  28. #define BIN 2
  29. #ifndef RX_BUFFER_SIZE
  30. #define RX_BUFFER_SIZE 128
  31. #endif
  32. #ifndef TX_BUFFER_SIZE
  33. #define TX_BUFFER_SIZE 32
  34. #endif
  35. #if TX_BUFFER_SIZE <= 0
  36. #error "TX_BUFFER_SIZE is required for the WebSocket."
  37. #endif
  38. #if RX_BUFFER_SIZE > 256
  39. typedef uint16_t ring_buffer_pos_t;
  40. #else
  41. typedef uint8_t ring_buffer_pos_t;
  42. #endif
  43. class WebSocketSerial {
  44. public:
  45. WebSocketSerial() {};
  46. static void begin(const long);
  47. static void end();
  48. static int peek(void);
  49. static int read(void);
  50. static void flush(void);
  51. static void flushTx(void);
  52. static bool available(void);
  53. static void write(const uint8_t c);
  54. #if ENABLED(SERIAL_STATS_DROPPED_RX)
  55. FORCE_INLINE static uint32_t dropped() { return 0; }
  56. #endif
  57. #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
  58. FORCE_INLINE static int rxMaxEnqueued() { return 0; }
  59. #endif
  60. FORCE_INLINE static void write(const char* str) { while (*str) write(*str++); }
  61. FORCE_INLINE static void write(const uint8_t* buffer, size_t size) { while (size--) write(*buffer++); }
  62. FORCE_INLINE static void print(const String& s) { for (int i = 0; i < (int)s.length(); i++) write(s[i]); }
  63. FORCE_INLINE static void print(const char* str) { write(str); }
  64. static void print(char, int = 0);
  65. static void print(unsigned char, int = 0);
  66. static void print(int, int = DEC);
  67. static void print(unsigned int, int = DEC);
  68. static void print(long, int = DEC);
  69. static void print(unsigned long, int = DEC);
  70. static void print(double, int = 2);
  71. static void println(const String& s);
  72. static void println(const char[]);
  73. static void println(char, int = 0);
  74. static void println(unsigned char, int = 0);
  75. static void println(int, int = DEC);
  76. static void println(unsigned int, int = DEC);
  77. static void println(long, int = DEC);
  78. static void println(unsigned long, int = DEC);
  79. static void println(double, int = 2);
  80. static void println(void);
  81. operator bool() { return true; }
  82. private:
  83. static void printNumber(unsigned long, const uint8_t);
  84. static void printFloat(double, uint8_t);
  85. };
  86. extern WebSocketSerial webSocketSerial;