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.
Parameters | Description |
---|---|
Return value | 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.
Parameters | Description |
---|---|
| The character you want to output. |
Return value | 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.
Parameters | Description |
---|---|
| the character to output |
| 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.
Paramita | Explanation |
---|---|
| Integer powerups |
| power form BIN binary / OCT 8 math / DEC 10 math / HEX 16 math |
| Number of decimals below the decimal point |
back | the number of booklets |
printfmt()
Prints output in printf format.
TWESDK/TWENET/current/src/printf/README.md 参照
operator <<
Argument type | Explanation |
---|---|
| 1-byte output (not formatted as a number) |
1-byte output (not formatted as a number) | |
| numeric output (printf's "%.2f") |
| output 1 byte (same as char type) |
| output 2 bytes (big-endian order) |
| output 4 bytes (big-endian order) |
| Output up to the terminating character. Output does not include the terminating character. >( |
| Output the array size |
| output in printf format |
| output of newline CRLF |
| flush output |
| output numeric types in big-endian order. (right-hand side value) |
| A pair containing |
output byte string using |
|
| Output the contents of an array class of type |
| Outputs data of |
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()
.
Argument type | Description |
---|---|
| Sets the timeout period in units of 1/10 second. If |
Error Value
Value | Meaning |
---|---|
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.
Argument type | Explanation |
---|---|
1-byte input (big-endian order) | |
2-byte input (big-endian order) | |
| 4-byte input (big-endian order) |
| input for |
| read |
最終更新