roo_quantity
API Documentation for roo_quantity
Loading...
Searching...
No Matches
charge.cpp
Go to the documentation of this file.
2
3#include "roo_quantity/si.h"
4
5namespace roo_quantity {
6namespace {
7
8void ChargeToString(const Charge& val, char* out, int maxlen) {
9 FormatSimpleSiValue(val.inCoulombs(), "C", out, maxlen);
10}
11
12} // namespace
13
14#if defined(ESP32) || defined(ESP8266) || defined(__linux__)
15
16std::string Charge::asString() const {
17 char out[16];
18 ChargeToString(*this, out, 16);
19 return out;
20}
21
22#endif
23
24#if defined(ARDUINO)
25
26String Charge::asArduinoString() const {
27 char out[16];
28 ChargeToString(*this, out, 16);
29 return out;
30}
31
32#endif
33
34roo_logging::Stream& operator<<(roo_logging::Stream& os, const Charge& val) {
35 char out[16];
36 ChargeToString(val, out, 16);
37 os << out;
38 return os;
39}
40
41} // namespace roo_quantity
Representation of charge, internally stored as floating-point Coulombs.
Definition charge.h:19
For convenience conversion from roo_time::Duration.
Definition area.cpp:3
roo_logging::Stream & operator<<(roo_logging::Stream &os, const Area &val)
Definition area.cpp:57
void FormatSimpleSiValue(float val, const char *base_unit, char *out, int maxlen)
Formats a value with an SI prefix and base unit.
Definition si.cpp:8