mwx::stream
input-output stream
Upper-level class that handles input/output streams.
Interfaces to several classes (
Serial, Wire, SPI, smplbuf
) by polymorphism using CRTP (Curiously Recurring Template Pattern) method.In CRTP, lower classes are defined as
template class Derived : public stream<Derived>;
and methods of lower classes are referenced from upper classes.
This class defines common processing such as
print
method,<<
operator, etc., and callswrite()
method, etc. implemented in lower classes, which is similar to using virtual functions.
Interfaces (implemented in lower classes)
Lower classes implement the functions listed below.
available()
Returns 1 if the input exists, 0 if it does not.
Return value int
0: no data 1: data present
The return value of this implementation is not the buffer length.
flush()
Flush output (wait for output to complete).
read()
Inputs 1-byte data from the stream. If the data does not exist, return -1
.
write()
Outputs 1 byte to the stream.
n
The character you want to output.
Return value size_t
1 if output succeeds, 0 if it fails.
vOutput()
This is a static function that produces a single byte output. Since this is not a class method, member variables and other information are not available. Instead, a pointer to the class instance is passed to vp, which is passed as a parameter.
This static function is used internally and the function pointer is passed as a one-byte output function of fctprintf()
. This is used to implement the print
method, etc.
out
the character to output
vp
pointer to a class instance Usually, cast to the original class and call the write() method
Interface
putchar()
Output a single byte.
print(), println()
Performs various types of formatted output.
val
Integer powerups
base
power form BIN binary / OCT 8 math / DEC 10 math / HEX 16 math
place
Number of decimals below the decimal point
back size_t
the number of booklets
printfmt()
Prints output in printf format.
TWESDK/TWENET/current/src/printf/README.md 参照
operator <<
char
1-byte output (not formatted as a number)
1-byte output (not formatted as a number)
double
numeric output (printf's "%.2f")
uint8_t
output 1 byte (same as char type)
uint16_t
output 2 bytes (big-endian order)
uint32_t
output 4 bytes (big-endian order)
const char*
uint8_t*
const char[S]
Output up to the terminating character. Output does not include the terminating character. >(S
specifies the size of the fixed array)
uint8_t[S]
Output the array size S
bytes as is. (S
is the fixed array size specification)
format()
output in printf format
mwx::crlf
output of newline CRLF
mwx::flush
flush output
bigendian()
output numeric types in big-endian order. (right-hand side value)
std::pair<T*, T*>
A pair containing begin(), end()
pointers of byte type. Can be created by make_pair
. Tis assumed to be of type
uint8_t`. (right-hand side value)
output byte string using bytelist()
std::initializer_list
.
smplbuf<uint8_t,AL>&
Output the contents of an array class of type uint8_t
. ALC
is memory allocation method.
smplbuf<uint8_t, AL>::to_stream()
Outputs data of smplbuf<T>
T
is of type uint8_t
, AL
is a memory allocation method.
When outputting as a byte string, cast to uint8_t, uint16_t, uint32_t
type. When outputting numerical values as strings, explicitly cast to int
type.
Single-byte types are handled differently depending on the type name. Usually, use the size-conscious uint8_t[S]
type.
set_timeout(), get_error_status(), clear_error_status()
Manages input timeouts and errors using the >>
operator.
The timeout period is specified by set_timeout()
, and input is processed using the >>
operator. If no input is received within the given timeout period, the error value can be read out with get_error_status()
. The error status is cleared by clear_error_status()
.
centisec
Sets the timeout period in units of 1/10 second. If 0xff
is specified, timeout is disabled.
Error Value
0
No Error
1
Error Status
operator >>
Input processing.
Cannot be executed within
setup()
.Because it waits for polling, depending on the timeout time setting (e.g. no timeout), the watchdog timer may be triggered and reset.
Normally, the following readout is performed during loop()
.
The following is a list of types that can be read and stored.
1-byte input (big-endian order)
2-byte input (big-endian order)
uint32_t
4-byte input (big-endian order)
uint8_t[S]
input for S
bytes (S
specifies fixed array size)
null_stream(int n)
read n
bytes away
最終更新