Skip to content

Commit 501c41e

Browse files
authored
Merge pull request mrRobot62#2 from joscha/log-double
feat: allow double and float
2 parents cbb82d8 + 2b8ea52 commit 501c41e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Diff for: ArduinoLog.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ void Logging::printFormat(const char format, va_list *args) {
8585
return;
8686
}
8787

88+
if( format == 'D' || format == 'F') {
89+
_logOutput->print(va_arg( *args, double ));
90+
return;
91+
}
92+
8893
if( format == 'x' ) {
8994
_logOutput->print(va_arg( *args, int ),HEX);
9095
return;

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ where the format string can be used to format the log variables
108108
* %B display as binary number, prefixed by `0b'
109109
* %t display as boolean value "t" or "f"
110110
* %T display as boolean value "true" or "false"
111+
* %D,%F display as double value
111112
```
112113
113114
The format string may come from flash memory.

Diff for: examples/Log/Log.ino

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ long longValue1, longValue2;
1111
bool boolValue1, boolValue2;
1212
const char * charArray = "this is a string";
1313
String stringValue1 = "this is a string";
14+
float floatValue;
15+
double doubleValue;
1416

1517
void setup() {
1618
// Set up serial port and wait until connected
@@ -41,6 +43,8 @@ void loop() {
4143
longValue2 = random(100000000);
4244
boolValue1 = random(2)==0;
4345
boolValue2 = random(2)==1;
46+
floatValue = 12.34;
47+
doubleValue= 1234.56789;
4448

4549
Log.notice ( "Log as Info with integer values : %d, %d" CR , intValue1, intValue2);
4650
Log.notice (F("Log as Info with hex values : %x, %X" CR ), intValue1, intValue1);
@@ -51,12 +55,16 @@ void loop() {
5155
Log.notice ( "Log as Info with bool values : %t, %T" CR , boolValue1, boolValue2);
5256
Log.notice (F("Log as Info with string value : %s" CR ), charArray);
5357
Log.notice ( "Log as Info with string value : %s" CR , stringValue1.c_str());
58+
Log.notice (F("Log as Info with float value : %F" CR ), floatValue);
59+
Log.notice ( "Log as Info with float value : %F" CR , floatValue);
60+
Log.notice (F("Log as Info with double value : %D" CR ), doubleValue);
61+
Log.notice ( "Log as Info with double value : %D" CR , doubleValue);
5462
Log.notice (F("Log as Debug with mixed values : %d, %d, %l, %l, %t, %T" CR ), intValue1 , intValue2,
5563
longValue1, longValue2, boolValue1, boolValue2);
5664
Log.trace ( "Log as Trace with bool value : %T" CR , boolValue1);
5765
Log.warning ( "Log as Warning with bool value : %T" CR , boolValue1);
5866
Log.error ( "Log as Error with bool value : %T" CR , boolValue1);
5967
Log.fatal ( "Log as Fatal with bool value : %T" CR , boolValue1);
60-
Log.verbose (F("Log as Vebose with bool value : %T" CR CR CR ), boolValue2);
68+
Log.verbose (F("Log as Verbose with bool value : %T" CR CR CR ), boolValue2);
6169
delay(5000);
6270
}

0 commit comments

Comments
 (0)