forked from blynkkk/blynk-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WidgetTerminal.h
49 lines (41 loc) · 937 Bytes
/
WidgetTerminal.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
/**
* @file WidgetTerminal.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*/
#ifndef WidgetTerminal_h
#define WidgetTerminal_h
#include <Blynk/BlynkApi.h>
#if !defined(SPARK) // On Spark this is auto-included
#include <Print.h>
#endif
class WidgetTerminal
: public Print
{
public:
WidgetTerminal(int vPin)
: mPin(vPin), mOutQty(0)
{}
virtual size_t write(uint8_t byte) {
mOutBuf[mOutQty++] = byte;
if (mOutQty >= sizeof(mOutBuf)) {
flush();
}
return 1;
}
void flush() {
if (mOutQty) {
Blynk.virtualWrite(mPin, mOutBuf, mOutQty);
mOutQty = 0;
}
}
using Print::write;
private:
uint8_t mPin;
uint8_t mOutBuf[32];
uint8_t mOutQty;
};
#endif