-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintString.h
51 lines (41 loc) · 901 Bytes
/
PrintString.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This should *really* be in the Arduino base libraries.
// Stolen with adjustments from https://github.com/RobTillaart/PrintString (MIT)
// (can you even have copyright on a file this simple?)
#pragma once
//
// FILE: PrintString.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.4
// PURPOSE: Class that captures prints into a String
// DATE: 2017-12-09
// URL: https://github.com/RobTillaart/PrintString
#include <Arduino.h>
#include <Print.h>
class PrintString : public Print {
public:
PrintString() = default;
virtual size_t write(uint8_t c) override
{
buffer.concat(char(c));
return 1;
}
virtual size_t write(uint8_t const* str, size_t length) override
{
buffer.concat((char*)str, length);
return length;
}
size_t size()
{
return buffer.length();
}
void clear()
{
buffer = String();
}
String getString()
{
return buffer;
}
private:
String buffer;
};