Skip to content

Commit

Permalink
Bridge support
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed May 1, 2015
1 parent 8da34ab commit d0725fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Blynk/BlynkProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ void BlynkProtocol<Transp>::processInput(void)
case BLYNK_CMD_PING: {
sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_SUCCESS);
} break;
case BLYNK_CMD_HARDWARE: {
case BLYNK_CMD_HARDWARE:
case BLYNK_CMD_BRIDGE: {
if (hdr.length > BLYNK_MAX_READBYTES) {
BLYNK_LOG("Packet size (%u) > max allowed (%u)", hdr.length, BLYNK_MAX_READBYTES);
conn.disconnect();
Expand Down
1 change: 1 addition & 0 deletions Blynk/BlynkProtocolDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum BlynkCmd
BLYNK_CMD_TWEET = 12,
BLYNK_CMD_EMAIL = 13,
BLYNK_CMD_PUSH_NOTIFICATION = 14,
BLYNK_CMD_BRIDGE = 15,
BLYNK_CMD_HARDWARE = 20
};

Expand Down
20 changes: 6 additions & 14 deletions WidgetBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,53 @@ class WidgetBridge
{}
void onWrite(BlynkReq& request, const BlynkParam& param) {}

#if defined(BLYNK_EXPERIMENTAL)

void setAuthToken(const char* token) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("bridge_auth");
cmd.add(mPin);
cmd.add("i");
cmd.add(token);
Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength());
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength());
}

#endif

void digitalWrite(int pin, int val) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("vw");
cmd.add(mPin);
cmd.add("dw");
cmd.add(pin);
cmd.add(val);
Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength());
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength());
}

void analogWrite(int pin, int val) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("vw");
cmd.add(mPin);
cmd.add("aw");
cmd.add(pin);
cmd.add(val);
Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength());
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength());
}

template <typename T>
void virtualWrite(int pin, const T& data) {
char mem[64];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("vw");
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
cmd.add(data);
Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength());
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength());
}

void virtualWrite(int pin, const void* buff, size_t len) {
char mem[16];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("vw");
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength(), buff, len);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength(), buff, len);
}

void virtualWrite(int pin, const BlynkParam& param) {
Expand Down

0 comments on commit d0725fa

Please sign in to comment.