-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgetBridge.h
executable file
·81 lines (70 loc) · 2.14 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
/**
* @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 "BlynkWidgetBase.h"
class WidgetBridge
: private BlynkWidgetBase
{
public:
WidgetBridge(uint8_t vPin)
: BlynkWidgetBase(vPin)
{}
void setAuthToken(const char* token) {
char mem[BLYNK_MAX_SENDBYTES];
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[BLYNK_MAX_SENDBYTES];
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[BLYNK_MAX_SENDBYTES];
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... Args>
void virtualWrite(int pin, Args... values) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
cmd.add_multi(values...);
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);
}
};
#endif