3-phase PV router
Loading...
Searching...
No Matches
SerialOutput Namespace Reference

Classes

struct  DecimalsTable
 The values of a float array, as integers with the given number of decimals. More...
 

Typedefs

using Step = bool (*)(Print& out, uint8_t step)
 One step of an output.
 

Functions

void beginStartupText ()
 Serial settings for the startup text: 9600 baud 8N1, the default of serial monitors.
 
bool busy ()
 Whether an output is still in progress.
 
void complete ()
 Write whatever is left of the current output to Serial, waiting like a plain print.
 
template<bool IOT>
void endStartupText ()
 Serial settings after the startup text: 7E1 for the IoT telemetry frames, as the mk2Wifi module expects; unchanged for the other outputs.
 
void poll (Print &out=Serial)
 Write as many steps as the transmit buffer can take, without waiting.
 
void printDecimals (Print &out, int32_t value, uint8_t decimals)
 Print a value given as an integer with a fixed number of decimals (see toDecimals())
 
void printHundredths (Print &out, int16_t value_x100)
 Print a value given in hundredths, in its shortest decimal form.
 
void runStep (Print &out)
 Run the next step of the current output.
 
bool start (Step step)
 Start an output, written by later calls to poll()
 
template<uint8_t N>
constexpr DecimalsTable< N > toDecimals (const float(&values)[N], uint8_t decimals)
 A float array constant as integers with the given number of decimals, rounded.
 
constexpr int32_t toDecimals (float value, uint8_t decimals)
 A float constant as an integer with the given number of decimals, rounded.
 

Variables

constexpr uint32_t BAUD_RATE { 9600 }
 
Step current { nullptr }
 
constexpr uint8_t MAX_STEP_LENGTH { 32 }
 
uint8_t nextStep { 0 }
 

Typedef Documentation

◆ Step

using SerialOutput::Step = bool (*)(Print& out, uint8_t step)

One step of an output.

Parameters
outwhere to write, at most MAX_STEP_LENGTH characters
stepindex of the step, from 0
Returns
false if this was the last step

Definition at line 41 of file serial_output.h.

Function Documentation

◆ beginStartupText()

void SerialOutput::beginStartupText ( )
inline

Serial settings for the startup text: 9600 baud 8N1, the default of serial monitors.

Definition at line 229 of file serial_output.h.

Here is the caller graph for this function:

◆ busy()

bool SerialOutput::busy ( )
inlinenodiscard

Whether an output is still in progress.

Definition at line 49 of file serial_output.h.

Here is the caller graph for this function:

◆ complete()

void SerialOutput::complete ( )
inline

Write whatever is left of the current output to Serial, waiting like a plain print.

Note
Out of line and without parameters: it is called before every debug message, so each call site costs a plain call.

Definition at line 99 of file serial_output.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endStartupText()

template<bool IOT>
void SerialOutput::endStartupText ( )
inline

Serial settings after the startup text: 7E1 for the IoT telemetry frames, as the mk2Wifi module expects; unchanged for the other outputs.

Template Parameters
IOTwhether the output is IoT

Definition at line 241 of file serial_output.h.

Here is the caller graph for this function:

◆ poll()

void SerialOutput::poll ( Print & out = Serial)
inline

Write as many steps as the transmit buffer can take, without waiting.

Definition at line 85 of file serial_output.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printDecimals()

void SerialOutput::printDecimals ( Print & out,
int32_t value,
uint8_t decimals )
inline

Print a value given as an integer with a fixed number of decimals (see toDecimals())

printDecimals(out, 50000, 6) -> "0.050000", printDecimals(out, -5, 2) -> "-0.05". What Print::print(float, decimals) wrote, without its float code.

Parameters
outwhere to write
valuethe value, times 10^decimals
decimalsthe number of decimals

Definition at line 197 of file serial_output.h.

Here is the caller graph for this function:

◆ printHundredths()

void SerialOutput::printHundredths ( Print & out,
int16_t value_x100 )
inline

Print a value given in hundredths, in its shortest decimal form.

2137 -> "21.37", 2150 -> "21.5", 2100 -> "21", -5 -> "-0.05". What ArduinoJson wrote for the float value / 100, without its float noise (it wrote -9.969999 for -997).

Parameters
outwhere to write
value_x100the value, in hundredths

Definition at line 117 of file serial_output.h.

Here is the caller graph for this function:

◆ runStep()

void SerialOutput::runStep ( Print & out)
inline

Run the next step of the current output.

Definition at line 74 of file serial_output.h.

Here is the caller graph for this function:

◆ start()

bool SerialOutput::start ( Step step)
inline

Start an output, written by later calls to poll()

Parameters
stepthe output's step function
Returns
false if the previous output is still in progress (nothing started)

Definition at line 60 of file serial_output.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toDecimals() [1/2]

template<uint8_t N>
DecimalsTable< N > SerialOutput::toDecimals ( const float(&) values[N],
uint8_t decimals )
constexpr

A float array constant as integers with the given number of decimals, rounded.

Parameters
valuesthe float array constant
decimalsthe number of decimals
Returns
the values times 10^decimals, rounded

Definition at line 177 of file serial_output.h.

Here is the call graph for this function:

◆ toDecimals() [2/2]

int32_t SerialOutput::toDecimals ( float value,
uint8_t decimals )
constexpr

A float constant as an integer with the given number of decimals, rounded.

For compile time only (constexpr variables): Print::print(float) costs about 1 kB of float code, printDecimals() only integer divisions. toDecimals(0.05F, 6) -> 50000, printed by printDecimals(out, 50000, 6) as "0.050000".

Parameters
valuethe float constant
decimalsthe number of decimals
Returns
the value times 10^decimals, rounded

Definition at line 151 of file serial_output.h.

Here is the caller graph for this function:

Variable Documentation

◆ BAUD_RATE

uint32_t SerialOutput::BAUD_RATE { 9600 }
inlineconstexpr

Baud rate of every output mode: do NOT set it higher

Definition at line 224 of file serial_output.h.

◆ current

Step SerialOutput::current { nullptr }
inline

output in progress, nullptr if none

Definition at line 43 of file serial_output.h.

◆ MAX_STEP_LENGTH

uint8_t SerialOutput::MAX_STEP_LENGTH { 32 }
inlineconstexpr

a step never writes more characters than this

Definition at line 32 of file serial_output.h.

◆ nextStep

uint8_t SerialOutput::nextStep { 0 }
inline

index of its next step

Definition at line 44 of file serial_output.h.