|
@@ -1,21 +1,21 @@
|
1
|
1
|
/*
|
2
|
2
|
Print.cpp - Base class that provides print() and println()
|
3
|
3
|
Copyright (c) 2008 David A. Mellis. All right reserved.
|
4
|
|
-
|
|
4
|
+
|
5
|
5
|
This library is free software; you can redistribute it and/or
|
6
|
6
|
modify it under the terms of the GNU Lesser General Public
|
7
|
7
|
License as published by the Free Software Foundation; either
|
8
|
8
|
version 2.1 of the License, or (at your option) any later version.
|
9
|
|
-
|
|
9
|
+
|
10
|
10
|
This library is distributed in the hope that it will be useful,
|
11
|
11
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
12
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
13
|
Lesser General Public License for more details.
|
14
|
|
-
|
|
14
|
+
|
15
|
15
|
You should have received a copy of the GNU Lesser General Public
|
16
|
16
|
License along with this library; if not, write to the Free Software
|
17
|
17
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
|
-
|
|
18
|
+
|
19
|
19
|
Modified 23 November 2006 by David A. Mellis
|
20
|
20
|
Modified 03 August 2015 by Chuck Todd
|
21
|
21
|
*/
|
|
@@ -37,7 +37,7 @@ typedef signed long sint32_t;
|
37
|
37
|
/* default implementation: may be overridden */
|
38
|
38
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
39
|
39
|
{
|
40
|
|
-
|
|
40
|
+
|
41
|
41
|
size_t n = 0;
|
42
|
42
|
while (size--) {
|
43
|
43
|
if (write(*buffer++)) n++;
|
|
@@ -49,7 +49,7 @@ size_t Print::write(const uint8_t *buffer, size_t size)
|
49
|
49
|
|
50
|
50
|
size_t Print::print(const char str[])
|
51
|
51
|
{
|
52
|
|
-
|
|
52
|
+
|
53
|
53
|
//while(1);
|
54
|
54
|
return write(str);
|
55
|
55
|
}
|
|
@@ -195,15 +195,15 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
|
195
|
195
|
return write(str);
|
196
|
196
|
}
|
197
|
197
|
|
198
|
|
-size_t Print::printFloat(double number, uint8_t digits)
|
199
|
|
-{
|
|
198
|
+size_t Print::printFloat(double number, uint8_t digits)
|
|
199
|
+{
|
200
|
200
|
size_t n = 0;
|
201
|
|
-
|
|
201
|
+
|
202
|
202
|
if (isnan(number)) return print("nan");
|
203
|
203
|
if (isinf(number)) return print("inf");
|
204
|
204
|
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
205
|
205
|
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
206
|
|
-
|
|
206
|
+
|
207
|
207
|
// Handle negative numbers
|
208
|
208
|
if (number < 0.0)
|
209
|
209
|
{
|
|
@@ -215,7 +215,7 @@ size_t Print::printFloat(double number, uint8_t digits)
|
215
|
215
|
double rounding = 0.5;
|
216
|
216
|
for (uint8_t i=0; i<digits; ++i)
|
217
|
217
|
rounding /= 10.0;
|
218
|
|
-
|
|
218
|
+
|
219
|
219
|
number += rounding;
|
220
|
220
|
|
221
|
221
|
// Extract the integer part of the number and print it
|
|
@@ -225,7 +225,7 @@ size_t Print::printFloat(double number, uint8_t digits)
|
225
|
225
|
|
226
|
226
|
// Print the decimal point, but only if there are digits beyond
|
227
|
227
|
if (digits > 0) {
|
228
|
|
- n += print(".");
|
|
228
|
+ n += print(".");
|
229
|
229
|
}
|
230
|
230
|
|
231
|
231
|
// Extract digits from the remainder one at a time
|
|
@@ -234,14 +234,14 @@ size_t Print::printFloat(double number, uint8_t digits)
|
234
|
234
|
remainder *= 10.0;
|
235
|
235
|
int toPrint = int(remainder);
|
236
|
236
|
n += print(toPrint);
|
237
|
|
- remainder -= toPrint;
|
238
|
|
- }
|
239
|
|
-
|
|
237
|
+ remainder -= toPrint;
|
|
238
|
+ }
|
|
239
|
+
|
240
|
240
|
return n;
|
241
|
241
|
}
|
242
|
242
|
|
243
|
243
|
|
244
|
|
-#if (PrintfEnable == 1)
|
|
244
|
+#if (PrintfEnable == 1)
|
245
|
245
|
size_t Print::printf(const char *argList, ...)
|
246
|
246
|
{
|
247
|
247
|
const char *ptr;
|
|
@@ -279,7 +279,7 @@ size_t Print::printf(const char *argList, ...)
|
279
|
279
|
else
|
280
|
280
|
{
|
281
|
281
|
numOfDigits = 0xff;
|
282
|
|
- }
|
|
282
|
+ }
|
283
|
283
|
|
284
|
284
|
|
285
|
285
|
switch(ch) /* Decode the type of the argument */
|
|
@@ -297,14 +297,14 @@ size_t Print::printf(const char *argList, ...)
|
297
|
297
|
case 'D':
|
298
|
298
|
num_s32 = va_arg(argp, int);
|
299
|
299
|
print(num_s32, 10);
|
300
|
|
- break;
|
|
300
|
+ break;
|
301
|
301
|
|
302
|
302
|
|
303
|
303
|
case 'u':
|
304
|
304
|
case 'U': /* Argument type is of integer, hence read 32bit unsigend data */
|
305
|
305
|
num_u32 = va_arg(argp, uint32_t);
|
306
|
|
- print(num_u32, 10);
|
307
|
|
- break;
|
|
306
|
+ print(num_u32, 10);
|
|
307
|
+ break;
|
308
|
308
|
|
309
|
309
|
|
310
|
310
|
|
|
@@ -312,21 +312,21 @@ size_t Print::printf(const char *argList, ...)
|
312
|
312
|
case 'x':
|
313
|
313
|
case 'X': /* Argument type is of hex, hence hexadecimal data from the argp */
|
314
|
314
|
num_u32 = va_arg(argp, uint32_t);
|
315
|
|
- print(num_u32, 16);
|
|
315
|
+ print(num_u32, 16);
|
316
|
316
|
break;
|
317
|
317
|
|
318
|
318
|
|
319
|
319
|
case 'b':
|
320
|
320
|
case 'B': /* Argument type is of binary,Read int and convert to binary */
|
321
|
|
- num_u32 = va_arg(argp, uint32_t);
|
322
|
|
- print(num_u32, 2);
|
|
321
|
+ num_u32 = va_arg(argp, uint32_t);
|
|
322
|
+ print(num_u32, 2);
|
323
|
323
|
break;
|
324
|
324
|
|
325
|
325
|
|
326
|
326
|
|
327
|
327
|
case 'F':
|
328
|
328
|
case 'f': /* Argument type is of float, hence read double data from the argp */
|
329
|
|
- floatNum_f32 = va_arg(argp, double);
|
|
329
|
+ floatNum_f32 = va_arg(argp, double);
|
330
|
330
|
printFloat(floatNum_f32,10);
|
331
|
331
|
break;
|
332
|
332
|
|
|
@@ -335,7 +335,7 @@ size_t Print::printf(const char *argList, ...)
|
335
|
335
|
case 'S':
|
336
|
336
|
case 's': /* Argument type is of string, hence get the pointer to sting passed */
|
337
|
337
|
str = va_arg(argp, char *);
|
338
|
|
- print(str);
|
|
338
|
+ print(str);
|
339
|
339
|
break;
|
340
|
340
|
|
341
|
341
|
|
|
@@ -356,4 +356,4 @@ size_t Print::printf(const char *argList, ...)
|
356
|
356
|
}
|
357
|
357
|
|
358
|
358
|
|
359
|
|
-#endif
|
|
359
|
+#endif
|