|
roo_quantity
API Documentation for roo_quantity
|
Mixing up units of measurement (milliseconds vs microseconds), or different quantities to begin with (e.g., time vs temperature vs voltage), can lead to very frustrating and hard-to-find bugs. This library aims to make your life as a programmer a little bit safer, by making it much harder to make such mistakes. It represents physical quantities as strongly-typed, salf-aware wrappers.
The library is meant for physical quantities that are measured by your micro-controller, such as: temperature, elapsed time, voltage, current, capacitance, velocity, work, pressure, etc. Internally, it represents a measured quantity as a float, using a default unit of measure (generally, base SI unit). It provides functions to convert between various units of measure easily, and to print out quantities in a human-friendly format, with the automatically chosen unit of measure. For example:
Output:
You can perform basic transformations directly on the quantities, treating them as numbers, as long as it makes physical sense. Let's look at an example that uses the Ohm's law, and formula for electric power:
Output:
Note how the library selects human-friendly units when pretty-printing the output.
Everything is inlined: the generated code will look as if you simply used float variables. Pretty-printing will have some small overhead, but only if you actually use it.
In particular, quantity classes are not virtual. (If they were, we could avoid needing to explicitly call asArduinoString() when writing to Serial, but at a cost of adding vtable pointer to each quantity representation.)