Enter printf format in mwx::stream
Helper class for writing format format to the << operator of mwx::stream
. In the library, it is alias defined as Using format=mwx::mwx_format;
.
The maximum number of arguments that can be registered in the variable number argument list is 8. 64-bit parameters such as double and uint64_t type are limited in number. If the limit is exceeded, a compile error will result due to static↵_assert.
Store the argument list received in the constructor in a variable internal to the class using the expand function of the parameter pack.
Call fctprintf()
at the point operator <<
is called to write data to the stream
The constructor stores the format pointer and parameters. The subsequent call with the <<
operator interprets the format and processes the output.
Parameters | Description |
---|---|
The fmt
must remain accessible until this object is destroyed.
fmt
Format format. See TWESDK/TWENET/current/src/printf/README.md
...
Parameters according to the format format. * The maximum number of parameters is 4. 5 or more parameters will result in a compile error. * Since consistency with the format is not checked, it is not safe for inconsistent input.
Flush buffered output to twe::stream.
Flush the output buffer of mwx::stream
. Instance to a helper class that calls the flush()
method.
For serial ports, wait polling until output completes.
For mwx::simpbuf
buffers, output 0x00
at the end (size is not changed)
twe::stream に改行コードを出力する
Instance of a helper class to output a newline code (CR LF) for the <<
operator of mwx::stream
.
stream_helper is a helper object that grants the mwx::stream
interface. It creates a helper object that references a data class and performs data input/output via the helper object.
The following creates a helper object bs
from an array b
of smplbufs and inputs data using the mwx::stream::operator <<()
operator.
stream_helper behaves as if the data array were a stream.
Internally, it holds read/write positions in the data array. It behaves as follows.
After the last data is read or written, it moves to the next read/write position.
After the last data is read or data is appended to the end, the read/write position becomes the end.
If the read/write position is the end of the line, then
available()
becomes false
.
Read cannot be performed.
Writing is appended if it is within the writable range.
stream_helper is a data class (smplbuf, EEPROM) member functions.
Moves the read/write position to the beginning.
Set the read/write position.
Returns the read/write position. Returns -1
for the end position.
Returns 0
if the read/write position is the end. If it is not the end, it returns any other value.
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 calls write()
method, etc. implemented in lower classes, which is similar to using virtual functions.
Lower classes implement the functions listed below.
Returns 1 if the input exists, 0 if it does not.
Parameters | Description |
---|---|
The return value of this implementation is not the buffer length.
Flush output (wait for output to complete).
Inputs 1-byte data from the stream. If the data does not exist, return -1
.
Outputs 1 byte to the stream.
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.
Output a single byte.
Performs various types of formatted output.
Prints output in printf format.
TWESDK/TWENET/current/src/printf/README.md 参照
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.
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()
.
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.
whence | Set the location |
---|---|
Parameters | Description |
---|---|
Parameters | Description |
---|---|
Paramita | Explanation |
---|---|
Argument type | Explanation |
---|---|
Argument type | Description |
---|---|
Value | Meaning |
---|---|
Argument type | Explanation |
---|---|
v
a value of type uint16_t
or uint32_t
MWX_SEEK_SET
set from the leading position. If offset
is 0
, it means the same as rewind()
.
MWX_SEEK_CUR
Move by offset
with respect to the current position.
MWX_SEEK_END
end position. Setting offset
to 0
sets the end position. If -1
is set, it moves to the last character.
Return value int
0: no data 1: data present
n
The character you want to output.
Return value size_t
1 if output succeeds, 0 if it fails.
out
the character to output
vp
pointer to a class instance Usually, cast to the original class and call the write() method
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
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.
centisec
Sets the timeout period in units of 1/10 second. If 0xff
is specified, timeout is disabled.
0
No Error
1
Error Status
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