M5Unit-RS485 0.2.0 git rev:0956c20
Loading...
Searching...
No Matches
unit_SP485_stream.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_RS485_UNIT_SP485_STREAM_HPP
11#define M5_UNIT_RS485_UNIT_SP485_STREAM_HPP
12
13#if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
14#include "rs485_component.hpp"
15#include <Stream.h>
16
17namespace m5 {
18namespace unit {
19
27class UnitSP485Stream final : public Stream {
28public:
34 {
35 }
36
41 int available() override
42 {
43 return _unit.available();
44 }
49 int read() override
50 {
51 return _unit.read();
52 }
57 int peek() override
58 {
59 return _unit.peek();
60 }
66 size_t write(const uint8_t b) override
67 {
68 return _unit.write(b);
69 }
76 size_t write(const uint8_t* buffer, size_t size) override
77 {
78 return _unit.write(buffer, size);
79 }
83 void flush() override
84 {
85 _unit.flush();
86 }
87
92 int availableForWrite() override
93 {
94 return _unit.availableForWrite();
95 }
96
97 using Print::write;
98
99private:
100 RS485Component& _unit;
101};
102
103} // namespace unit
104} // namespace m5
105#endif
106#endif
Non-instantiable base class for RS-485 transceiver units.
Definition rs485_component.hpp:37
int available()
Returns the number of available bytes to read.
Definition rs485_component.hpp:148
size_t write(const uint8_t d)
Writes one byte.
Definition rs485_component.cpp:179
int peek()
Peeks the next incoming byte without removing it.
Definition rs485_component.hpp:164
int read()
Reads one byte.
Definition rs485_component.hpp:172
void flush()
Flushes the serial port.
Definition rs485_component.hpp:243
int availableForWrite()
Returns the number of bytes that can be written without blocking.
Definition rs485_component.hpp:156
Thin Arduino Stream/Print adapter for any RS485Component (UnitSP485 / UnitSIT3088 / ....
Definition unit_SP485_stream.hpp:27
void flush() override
Flushes the serial port.
Definition unit_SP485_stream.hpp:83
int peek() override
Peeks the next incoming byte without removing it.
Definition unit_SP485_stream.hpp:57
size_t write(const uint8_t *buffer, size_t size) override
Writes bytes from buffer.
Definition unit_SP485_stream.hpp:76
UnitSP485Stream(RS485Component &unit)
Constructs a Stream adapter for any RS485Component-derived unit.
Definition unit_SP485_stream.hpp:33
int read() override
Reads one byte.
Definition unit_SP485_stream.hpp:49
int available() override
Returns the number of bytes available to read.
Definition unit_SP485_stream.hpp:41
int availableForWrite() override
Returns available buffer space for write.
Definition unit_SP485_stream.hpp:92
size_t write(const uint8_t b) override
Writes one byte.
Definition unit_SP485_stream.hpp:66
Top level namespace of M5Stack.
Unit-related namespace.
Common base for RS-485 transceiver units in M5UnitUnified.