|
|
|
@ -1,21 +1,21 @@
|
|
|
|
|
/*
|
|
|
|
|
Print.cpp - Base class that provides print() and println()
|
|
|
|
|
Copyright (c) 2008 David A. Mellis. All right reserved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Modified 23 November 2006 by David A. Mellis
|
|
|
|
|
Modified 03 August 2015 by Chuck Todd
|
|
|
|
|
*/
|
|
|
|
@ -37,7 +37,7 @@ typedef signed long sint32_t;
|
|
|
|
|
/* default implementation: may be overridden */
|
|
|
|
|
size_t Print::write(const uint8_t *buffer, size_t size)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t n = 0;
|
|
|
|
|
while (size--) {
|
|
|
|
|
if (write(*buffer++)) n++;
|
|
|
|
@ -49,7 +49,7 @@ size_t Print::write(const uint8_t *buffer, size_t size)
|
|
|
|
|
|
|
|
|
|
size_t Print::print(const char str[])
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//while(1);
|
|
|
|
|
return write(str);
|
|
|
|
|
}
|
|
|
|
@ -195,15 +195,15 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
|
|
|
|
|
return write(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t Print::printFloat(double number, uint8_t digits)
|
|
|
|
|
{
|
|
|
|
|
size_t Print::printFloat(double number, uint8_t digits)
|
|
|
|
|
{
|
|
|
|
|
size_t n = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isnan(number)) return print("nan");
|
|
|
|
|
if (isinf(number)) return print("inf");
|
|
|
|
|
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
|
|
|
|
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle negative numbers
|
|
|
|
|
if (number < 0.0)
|
|
|
|
|
{
|
|
|
|
@ -215,7 +215,7 @@ size_t Print::printFloat(double number, uint8_t digits)
|
|
|
|
|
double rounding = 0.5;
|
|
|
|
|
for (uint8_t i=0; i<digits; ++i)
|
|
|
|
|
rounding /= 10.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
number += rounding;
|
|
|
|
|
|
|
|
|
|
// Extract the integer part of the number and print it
|
|
|
|
@ -225,7 +225,7 @@ size_t Print::printFloat(double number, uint8_t digits)
|
|
|
|
|
|
|
|
|
|
// Print the decimal point, but only if there are digits beyond
|
|
|
|
|
if (digits > 0) {
|
|
|
|
|
n += print(".");
|
|
|
|
|
n += print(".");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extract digits from the remainder one at a time
|
|
|
|
@ -234,14 +234,14 @@ size_t Print::printFloat(double number, uint8_t digits)
|
|
|
|
|
remainder *= 10.0;
|
|
|
|
|
int toPrint = int(remainder);
|
|
|
|
|
n += print(toPrint);
|
|
|
|
|
remainder -= toPrint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remainder -= toPrint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if (PrintfEnable == 1)
|
|
|
|
|
#if (PrintfEnable == 1)
|
|
|
|
|
size_t Print::printf(const char *argList, ...)
|
|
|
|
|
{
|
|
|
|
|
const char *ptr;
|
|
|
|
@ -279,7 +279,7 @@ size_t Print::printf(const char *argList, ...)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
numOfDigits = 0xff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(ch) /* Decode the type of the argument */
|
|
|
|
@ -297,14 +297,14 @@ size_t Print::printf(const char *argList, ...)
|
|
|
|
|
case 'D':
|
|
|
|
|
num_s32 = va_arg(argp, int);
|
|
|
|
|
print(num_s32, 10);
|
|
|
|
|
break;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
|
case 'U': /* Argument type is of integer, hence read 32bit unsigend data */
|
|
|
|
|
num_u32 = va_arg(argp, uint32_t);
|
|
|
|
|
print(num_u32, 10);
|
|
|
|
|
break;
|
|
|
|
|
print(num_u32, 10);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -312,21 +312,21 @@ size_t Print::printf(const char *argList, ...)
|
|
|
|
|
case 'x':
|
|
|
|
|
case 'X': /* Argument type is of hex, hence hexadecimal data from the argp */
|
|
|
|
|
num_u32 = va_arg(argp, uint32_t);
|
|
|
|
|
print(num_u32, 16);
|
|
|
|
|
print(num_u32, 16);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
|
case 'B': /* Argument type is of binary,Read int and convert to binary */
|
|
|
|
|
num_u32 = va_arg(argp, uint32_t);
|
|
|
|
|
print(num_u32, 2);
|
|
|
|
|
num_u32 = va_arg(argp, uint32_t);
|
|
|
|
|
print(num_u32, 2);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
|
case 'f': /* Argument type is of float, hence read double data from the argp */
|
|
|
|
|
floatNum_f32 = va_arg(argp, double);
|
|
|
|
|
floatNum_f32 = va_arg(argp, double);
|
|
|
|
|
printFloat(floatNum_f32,10);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
@ -335,7 +335,7 @@ size_t Print::printf(const char *argList, ...)
|
|
|
|
|
case 'S':
|
|
|
|
|
case 's': /* Argument type is of string, hence get the pointer to sting passed */
|
|
|
|
|
str = va_arg(argp, char *);
|
|
|
|
|
print(str);
|
|
|
|
|
print(str);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -356,4 +356,4 @@ size_t Print::printf(const char *argList, ...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|