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.1KB

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