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 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../../inc/MarlinConfig.h"
  24. #include "../../core/serial_hook.h"
  25. #include <Stream.h>
  26. #ifndef TX_BUFFER_SIZE
  27. #define TX_BUFFER_SIZE 32
  28. #endif
  29. #if ENABLED(WIFISUPPORT)
  30. #ifndef RX_BUFFER_SIZE
  31. #define RX_BUFFER_SIZE 128
  32. #endif
  33. #if TX_BUFFER_SIZE <= 0
  34. #error "TX_BUFFER_SIZE is required for the WebSocket."
  35. #endif
  36. #endif
  37. typedef uint16_t ring_buffer_pos_t;
  38. class RingBuffer {
  39. uint8_t *data;
  40. ring_buffer_pos_t size, read_index, write_index;
  41. public:
  42. RingBuffer(ring_buffer_pos_t size);
  43. ~RingBuffer();
  44. int available();
  45. int peek();
  46. int read();
  47. ring_buffer_pos_t read(uint8_t *buffer);
  48. void flush();
  49. ring_buffer_pos_t write(const uint8_t c);
  50. ring_buffer_pos_t write(const uint8_t* buffer, ring_buffer_pos_t size);
  51. };
  52. class WebSocketSerial: public Stream {
  53. RingBuffer rx_buffer;
  54. RingBuffer tx_buffer;
  55. public:
  56. WebSocketSerial();
  57. void begin(const long);
  58. void end();
  59. int available();
  60. int peek();
  61. int read();
  62. void flush();
  63. size_t write(const uint8_t c);
  64. size_t write(const uint8_t* buffer, size_t size);
  65. #if ENABLED(SERIAL_STATS_DROPPED_RX)
  66. FORCE_INLINE uint32_t dropped() { return 0; }
  67. #endif
  68. #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
  69. FORCE_INLINE int rxMaxEnqueued() { return 0; }
  70. #endif
  71. };
  72. typedef Serial1Class<WebSocketSerial> MSerialT;
  73. extern MSerialT webSocketSerial;