Skip to content

Commit

Permalink
Merge pull request mrRobot62#2 from joscha/log-double
Browse files Browse the repository at this point in the history
feat: allow double and float
  • Loading branch information
thijse authored Sep 26, 2017
2 parents cbb82d8 + 2b8ea52 commit 501c41e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ArduinoLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ void Logging::printFormat(const char format, va_list *args) {
return;
}

if( format == 'D' || format == 'F') {
_logOutput->print(va_arg( *args, double ));
return;
}

if( format == 'x' ) {
_logOutput->print(va_arg( *args, int ),HEX);
return;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ where the format string can be used to format the log variables
* %B display as binary number, prefixed by `0b'
* %t display as boolean value "t" or "f"
* %T display as boolean value "true" or "false"
* %D,%F display as double value
```
The format string may come from flash memory.
Expand Down
10 changes: 9 additions & 1 deletion examples/Log/Log.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ long longValue1, longValue2;
bool boolValue1, boolValue2;
const char * charArray = "this is a string";
String stringValue1 = "this is a string";
float floatValue;
double doubleValue;

void setup() {
// Set up serial port and wait until connected
Expand Down Expand Up @@ -41,6 +43,8 @@ void loop() {
longValue2 = random(100000000);
boolValue1 = random(2)==0;
boolValue2 = random(2)==1;
floatValue = 12.34;
doubleValue= 1234.56789;

Log.notice ( "Log as Info with integer values : %d, %d" CR , intValue1, intValue2);
Log.notice (F("Log as Info with hex values : %x, %X" CR ), intValue1, intValue1);
Expand All @@ -51,12 +55,16 @@ void loop() {
Log.notice ( "Log as Info with bool values : %t, %T" CR , boolValue1, boolValue2);
Log.notice (F("Log as Info with string value : %s" CR ), charArray);
Log.notice ( "Log as Info with string value : %s" CR , stringValue1.c_str());
Log.notice (F("Log as Info with float value : %F" CR ), floatValue);
Log.notice ( "Log as Info with float value : %F" CR , floatValue);
Log.notice (F("Log as Info with double value : %D" CR ), doubleValue);
Log.notice ( "Log as Info with double value : %D" CR , doubleValue);
Log.notice (F("Log as Debug with mixed values : %d, %d, %l, %l, %t, %T" CR ), intValue1 , intValue2,
longValue1, longValue2, boolValue1, boolValue2);
Log.trace ( "Log as Trace with bool value : %T" CR , boolValue1);
Log.warning ( "Log as Warning with bool value : %T" CR , boolValue1);
Log.error ( "Log as Error with bool value : %T" CR , boolValue1);
Log.fatal ( "Log as Fatal with bool value : %T" CR , boolValue1);
Log.verbose (F("Log as Vebose with bool value : %T" CR CR CR ), boolValue2);
Log.verbose (F("Log as Verbose with bool value : %T" CR CR CR ), boolValue2);
delay(5000);
}

0 comments on commit 501c41e

Please sign in to comment.