forked from blynkkk/blynk-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWidgetBridge.h
122 lines (108 loc) · 3.36 KB
/
WidgetBridge.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* @file WidgetBridge.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Apr 2015
* @brief
*
*/
#ifndef WidgetBridge_h
#define WidgetBridge_h
#include <Blynk/BlynkApi.h>
class WidgetBridge
{
public:
WidgetBridge(int vPin)
: mPin(vPin)
{}
void onWrite(BlynkReq& request, const BlynkParam& param) {}
void setAuthToken(const char* token) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("i");
cmd.add(token);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T>
void digitalWrite(const T& pin, int val) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("dw");
cmd.add(pin);
cmd.add(val);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T>
void analogWrite(const T& pin, int val) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("aw");
cmd.add(pin);
cmd.add(val);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T>
void virtualWrite(int pin, const T& data) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
cmd.add(data);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T1, typename T2>
void virtualWrite(int pin, const T1& data1, const T2& data2) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
cmd.add(data1);
cmd.add(data2);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T1, typename T2, typename T3>
void virtualWrite(int pin, const T1& data1, const T2& data2, const T3& data3) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
cmd.add(data1);
cmd.add(data2);
cmd.add(data3);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T1, typename T2, typename T3, typename T4>
void virtualWrite(int pin, const T1& data1, const T2& data2, const T3& data3, const T4& data4) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
cmd.add(data1);
cmd.add(data2);
cmd.add(data3);
cmd.add(data4);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
void virtualWriteBinary(int pin, const void* buff, size_t len) {
char mem[8];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength(), buff, len);
}
void virtualWrite(int pin, const BlynkParam& param) {
virtualWriteBinary(pin, param.getBuffer(), param.getLength()-1);
}
private:
int mPin;
};
#endif