-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgetTerminal.h
executable file
·84 lines (67 loc) · 1.68 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @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
#if !(defined(LINUX) || defined(MBED_LIBRARY_VERSION))
#define BLYNK_USE_PRINT_CLASS
#endif
#include "BlynkWidgetBase.h"
#ifdef BLYNK_USE_PRINT_CLASS
#if !(defined(SPARK) || defined(PARTICLE) || (PLATFORM_ID==88) || defined(ARDUINO_RedBear_Duo)) // 88 -> RBL Duo
// On Particle this is auto-included
#include <Print.h>
#endif
#endif
class WidgetTerminal
: public BlynkWidgetBase
#ifdef BLYNK_USE_PRINT_CLASS
, public Print
#endif
{
public:
WidgetTerminal(uint8_t vPin)
: BlynkWidgetBase(vPin)
, mOutQty(0)
{}
//virtual ~WidgetTerminal() {}
virtual size_t write(uint8_t byte) {
mOutBuf[mOutQty++] = byte;
if (mOutQty >= sizeof(mOutBuf)) {
flush();
}
return 1;
}
void flush() {
if (mOutQty) {
Blynk.virtualWriteBinary(mPin, mOutBuf, mOutQty);
mOutQty = 0;
}
}
#ifdef BLYNK_USE_PRINT_CLASS
using Print::write;
size_t write(const void* buff, size_t len) {
return write((char*)buff, len);
}
#else
size_t write(const void* buff, size_t len) {
uint8_t* buf = (uint8_t*)buff;
while (len--) {
write(*buf++);
}
return len;
}
size_t write(const char* str) {
return write(str, strlen(str));
}
#endif
private:
uint8_t mOutBuf[BLYNK_MAX_SENDBYTES];
uint8_t mOutQty;
};
#endif