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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <Stream.h>
  25. #ifndef TX_BUFFER_SIZE
  26. #define TX_BUFFER_SIZE 32
  27. #endif
  28. #if ENABLED(WIFISUPPORT)
  29. #ifndef RX_BUFFER_SIZE
  30. #define RX_BUFFER_SIZE 128
  31. #endif
  32. #if TX_BUFFER_SIZE <= 0
  33. #error "TX_BUFFER_SIZE is required for the WebSocket."
  34. #endif
  35. #endif
  36. typedef uint16_t ring_buffer_pos_t;
  37. class RingBuffer {
  38. uint8_t *data;
  39. ring_buffer_pos_t size, read_index, write_index;
  40. public:
  41. RingBuffer(ring_buffer_pos_t size);
  42. ~RingBuffer();
  43. int available();
  44. int peek();
  45. int read();
  46. ring_buffer_pos_t read(uint8_t *buffer);
  47. void flush();
  48. ring_buffer_pos_t write(const uint8_t c);
  49. ring_buffer_pos_t write(const uint8_t* buffer, ring_buffer_pos_t size);
  50. };
  51. class WebSocketSerial: public Stream {
  52. RingBuffer rx_buffer;
  53. RingBuffer tx_buffer;
  54. public:
  55. WebSocketSerial();
  56. void begin(const long);
  57. void end();
  58. int available();
  59. int peek();
  60. int read();
  61. void flush();
  62. void flushTX();
  63. size_t write(const uint8_t c);
  64. size_t write(const uint8_t* buffer, size_t size);
  65. operator bool() { return true; }
  66. #if ENABLED(SERIAL_STATS_DROPPED_RX)
  67. FORCE_INLINE uint32_t dropped() { return 0; }
  68. #endif
  69. #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
  70. FORCE_INLINE int rxMaxEnqueued() { return 0; }
  71. #endif
  72. };
  73. extern WebSocketSerial webSocketSerial;