@@ -16,8 +16,22 @@ Arduino library to help formatting data for printing.
1616The printHelpers library contains a number of functions that help to print
1717data in a way not possible in the standard print library of the Arduino.
1818
19+
20+ #### thread safety
21+
22+ Note the functions of this library all share an internal buffer, so the
23+ library is not thread safe. Therefore one should copy / print the data
24+ (returned pointer) as fast as possible.
25+
26+ Thread-safe versions of these print functions might be made in the future.
27+
28+
29+ ## Interface
30+
1931The following functions are implemented:
2032
33+ #### print64()
34+
2135- ** char \* print64(int64_t value, uint8_t base)** converts a 64 bit integer
2236number to a char array.
2337The plus sign is not printed, neither are leading zero's.
@@ -30,7 +44,7 @@ int number to a char array.
3044No sign is printed, neither are leading zero's.
3145Base 10 (DEC) and 16 (HEX) are supported and bases up to 36 can be used.
3246
33- ----
47+ #### sci() eng()
3448
3549- ** char \* sci(double value, uint8_t decimals)** converts a float or double to a
3650char array.
@@ -59,7 +73,7 @@ The usability of other values than 1 and 3 are not known.
5973Personally I like the multiple of 2 as I get 2 orders of magnitude in the
6074mantissa.
6175
62- ----
76+ #### toBytes()
6377
6478- ** char \* toBytes(double value, uint8_t decimals = 2)** makes from a big number
6579representing an amount of bytes a shorter string usable for displaying.
@@ -78,6 +92,29 @@ Should be big enough for some time.
7892To have some support the code uses lowercase for the next 8 levels:
7993treda sorta rinta quexa pepta ocha nena minga luma (1024\^ 21 ~~ 10\^ 63)
8094
95+ #### hex() bin()
96+
97+ The default print() function of Arduino does not have leading zero's
98+ for HEX and BIN. This often causes a "broken" layout especially if one
99+ wants to print in columns or so.
100+
101+ To solve this the following functions are added that will generate a
102+ constant length char array.
103+
104+ - ** char \* hex(uint64_t value, uint8_t digits = 16)**
105+ - ** char \* hex(uint32_t value, uint8_t digits = 8)**
106+ - ** char \* hex(uint16_t value, uint8_t digits = 4)**
107+ - ** char \* hex(uint8_t value, uint8_t digits = 2)**
108+ - ** char \* bin(uint64_t value, uint8_t digits = 64)**
109+ - ** char \* bin(uint32_t value, uint8_t digits = 32)**
110+ - ** char \* bin(uint16_t value, uint8_t digits = 16)**
111+ - ** char \* bin(uint8_t value, uint8_t digits = 8)**
112+
113+ Note: Data types not supported, must be cast to an supported type.
114+
115+ Note: There is overlap between ** hex(value)** and ** print64(value, HEX)** .
116+ The latter does not produce the leading zero's or fixed length output.
117+
81118----
82119
83120More formatting functions might be added in the future.
@@ -119,11 +156,31 @@ See examples.
119156
120157## Future
121158
159+ #### must
160+ - check TODO's in the code
161+
162+ #### should
163+ - Add distant print helpers.
164+ - feet(float cm) as 3'2" or 3-7/8 feet
165+ - inch(float cm) as 3'2" or 3-7/8 feet
166+ - yards(), miles()
167+
168+ #### could
122169- Investigate the precision of ** sci()** and ** eng()** .
123170- Investigate performance of ** sci()** and ** eng()** .
124171- Investigate performance (local variables instead of modifying parameters)
125- - Add option to pass char buffer as parameter (improve threadsafe)
126- - Add more print helpers.
127- - improve readability of the code (even more)
128- - check TODO's in the code
129- -
172+ - Investigate thread safe version
173+ - pass char buffer as parameter (breaking)
174+ - improve readability of the code
175+ - investigate separators in bin() and hex()
176+ - investigate sci() version based upon use of log()
177+ - performance
178+ - accuracy
179+
180+ #### wont
181+ - add ** float()** as Arduino limits floats to "MAXLONG" by code.
182+ - use dtostrf() - is that portable
183+ - use sci() or eng()
184+ - add base(value, digits, base) for any base > 1.
185+ - only upon request.
186+
0 commit comments