25#ifndef SERIAL_OUTPUT_H
26#define SERIAL_OUTPUT_H
41using Step = bool (*)(Print& out, uint8_t step);
49[[nodiscard]]
inline bool busy()
85inline void poll(Print& out = Serial)
99__attribute__((noinline))
inline void complete()
119 const uint16_t magnitude{ value_x100 < 0 ? static_cast< uint16_t >(0U -
static_cast< uint16_t
>(value_x100))
120 :
static_cast< uint16_t
>(value_x100) };
125 out.print(magnitude / 100);
127 const uint8_t hundredths{
static_cast< uint8_t
>(magnitude % 100) };
133 out.print(hundredths / 10);
136 out.print(hundredths % 10);
153 for (uint8_t
i = 0;
i != decimals; ++
i)
157 return static_cast< int32_t
>(value < 0 ? value - 0.5F : value + 0.5F);
180 for (uint8_t
i = 0;
i != N; ++
i)
197__attribute__((noinline))
inline void printDecimals(Print& out, int32_t value, uint8_t decimals)
199 const uint32_t magnitude{ value < 0 ? 0U -
static_cast< uint32_t
>(value) :
static_cast< uint32_t
>(value) };
205 uint32_t divisor{ 1 };
206 for (uint8_t
i = 0;
i != decimals; ++
i)
210 out.print(magnitude / divisor);
217 while (divisor /= 10)
219 out.print(
static_cast< char >(
'0' + (magnitude / divisor) % 10));
bool(*)(Print &out, uint8_t step) Step
One step of an output.
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.
void complete()
Write whatever is left of the current output to Serial, waiting like a plain print.
constexpr int32_t toDecimals(float value, uint8_t decimals)
A float constant as an integer with the given number of decimals, rounded.
void beginStartupText()
Serial settings for the startup text: 9600 baud 8N1, the default of serial monitors.
constexpr uint8_t MAX_STEP_LENGTH
constexpr uint32_t BAUD_RATE
bool start(Step step)
Start an output, written by later calls to poll()
void endStartupText()
Serial settings after the startup text: 7E1 for the IoT telemetry frames, as the mk2Wifi module expec...
bool busy()
Whether an output is still in progress.
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())
The values of a float array, as integers with the given number of decimals.