RF24Log  0.1.3
Unified logging library
ArduinoPrintLogger.cpp
Go to the documentation of this file.
1 
14 #include <Arduino.h> // millis()
15 #include "../RF24LogLevel.h"
16 #include "ArduinoPrintLogger.h"
17 #include <stdio.h> // size_t
18 
19 /****************************************************************************/
20 
22 {
23  _stream = stream;
24 }
25 
26 /****************************************************************************/
27 
29 {
30  unsigned long now = millis();
31  uint16_t w = numbCharsToPrint(now);
32  appendChar(' ', (w < 10 ? 10 - w : 0));
33  appendUInt(now, 10);
35 }
36 
37 /****************************************************************************/
38 
39 void ArduinoPrintLogger::appendChar(char data, uint16_t depth)
40 {
41  while (depth > 0)
42  {
43  --depth;
44  _stream->print((char)data);
45  }
46 }
47 
48 /****************************************************************************/
49 
51 {
52  _stream->print((long)data);
53 }
54 
55 /****************************************************************************/
56 
57 void ArduinoPrintLogger::appendUInt(unsigned long data, uint8_t base)
58 {
59  _stream->print((unsigned long)data, (int)base);
60 }
61 
62 /****************************************************************************/
63 
64 void ArduinoPrintLogger::appendDouble(double data, uint8_t precision)
65 {
66  _stream->print(data, precision);
67 }
68 
69 /****************************************************************************/
70 
71 void ArduinoPrintLogger::appendStr(const char* data)
72 {
73  _stream->print(data);
74 }
75 
76 /****************************************************************************/
77 
78 #ifdef ARDUINO_ARCH_AVR
79 void ArduinoPrintLogger::appendStr(const __FlashStringHelper* data)
80 {
81  _stream->print(data);
82 }
83 #endif
handler for Print::print() function calls based on Arduino API
uint16_t numbCharsToPrint(int64_t numb, uint8_t base)
how wide (in characters) does it take to display a number
Definition: Common.cpp:18
#define RF24LOG_DELIMITER
Change The Delimiter character used in the header prefix of log messages.
void appendTimestamp()
output a timestamp
void appendInt(long data)
append a signed (+/-) number
void appendStr(const char *data)
append a c-string
ArduinoPrintLogger(Print *stream)
instance constructor
void appendChar(char data, uint16_t depth=1)
append a character a number of times
void appendUInt(unsigned long data, uint8_t base=10)
append an ‘unsigned’ (only +) number
Print * _stream
The output stream.
void appendDouble(double data, uint8_t precision=2)
append a floating point number