diff --git a/docs/users_guide/examples/hw_voltage.md b/docs/users_guide/examples/hw_voltage.md index 92925732e..42ac30600 100644 --- a/docs/users_guide/examples/hw_voltage.md +++ b/docs/users_guide/examples/hw_voltage.md @@ -21,46 +21,46 @@ of an offset. First we include all the dependencies: ```cpp title="hw_voltage.cpp" linenums="1" ---8<-- "example/hw_voltage.cpp:28:43" +--8<-- "example/hw_voltage.cpp:28:44" ``` Next, we specify the real measurement voltage range to be in the range of [-10, 10]: -```cpp title="hw_voltage.cpp" linenums="17" ---8<-- "example/hw_voltage.cpp:45:48" +```cpp title="hw_voltage.cpp" linenums="18" +--8<-- "example/hw_voltage.cpp:46:49" ``` and provide a storage type and special values for the hardware representation: -```cpp title="hw_voltage.cpp" linenums="21" ---8<-- "example/hw_voltage.cpp:50:56" +```cpp title="hw_voltage.cpp" linenums="22" +--8<-- "example/hw_voltage.cpp:51:57" ``` Finally, we define a quantity point origin, an offset unit that scales the value and uses this origin to offset the zero of the sale, and a dedicated quantity point alias using those: -```cpp title="hw_voltage.cpp" linenums="28" ---8<-- "example/hw_voltage.cpp:60:66" +```cpp title="hw_voltage.cpp" linenums="29" +--8<-- "example/hw_voltage.cpp:61:67" ``` Now, when everything is ready, we can simulate mapping of our hardware register, and provide a helper function that will read the value and construct a quantity point from the obtained copy: -```cpp title="hw_voltage.cpp" linenums="35" ---8<-- "example/hw_voltage.cpp:69:77" +```cpp title="hw_voltage.cpp" linenums="36" +--8<-- "example/hw_voltage.cpp:70:78" ``` We also provide a simple print helper for our quantity points: -```cpp title="hw_voltage.cpp" linenums="44" ---8<-- "example/hw_voltage.cpp:79:82" +```cpp title="hw_voltage.cpp" linenums="45" +--8<-- "example/hw_voltage.cpp:80:84" ``` In the main function we simulate setting of 3 values by our hardware. Each of them is read and printed in the voltage unit used on the hardware as well as in the standard SI unit: -```cpp title="hw_voltage.cpp" linenums="48" ---8<-- "example/hw_voltage.cpp:84:" +```cpp title="hw_voltage.cpp" linenums="50" +--8<-- "example/hw_voltage.cpp:86:" ``` The above program results with the following text output: diff --git a/example/hw_voltage.cpp b/example/hw_voltage.cpp index 8eef10858..f04c6489f 100644 --- a/example/hw_voltage.cpp +++ b/example/hw_voltage.cpp @@ -26,11 +26,12 @@ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #include +#include #ifdef MP_UNITS_IMPORT_STD import std; #else +#include #include -#include #endif #ifdef MP_UNITS_MODULES import mp_units; @@ -78,7 +79,8 @@ std::optional read_hw_voltage() void print(QuantityPoint auto qp) { - std::println("{:10} ({:5})", qp.quantity_from_zero(), value_cast(qp).quantity_from_zero()); + std::cout << MP_UNITS_STD_FMT::format("{:10} ({:5})", qp.quantity_from_zero(), + value_cast(qp).quantity_from_zero()); } int main()