Microduino

Dependencies:   mbed

Fork of Io_moon by Li Weiyi

Committer:
lixianyu
Date:
Thu Jun 23 11:16:14 2016 +0000
Revision:
0:740c1eb2df13
* AM2321?????????2s????i2c?????; * SimpleTimer??bug?????????????????????????; * Blynk??bug??????????????; * ?????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:740c1eb2df13 1 /**
lixianyu 0:740c1eb2df13 2 * @file WidgetBridge.h
lixianyu 0:740c1eb2df13 3 * @author Volodymyr Shymanskyy
lixianyu 0:740c1eb2df13 4 * @license This project is released under the MIT License (MIT)
lixianyu 0:740c1eb2df13 5 * @copyright Copyright (c) 2015 Volodymyr Shymanskyy
lixianyu 0:740c1eb2df13 6 * @date Apr 2015
lixianyu 0:740c1eb2df13 7 * @brief
lixianyu 0:740c1eb2df13 8 *
lixianyu 0:740c1eb2df13 9 */
lixianyu 0:740c1eb2df13 10
lixianyu 0:740c1eb2df13 11 #ifndef WidgetBridge_h
lixianyu 0:740c1eb2df13 12 #define WidgetBridge_h
lixianyu 0:740c1eb2df13 13
lixianyu 0:740c1eb2df13 14 #include <Blynk/BlynkApi.h>
lixianyu 0:740c1eb2df13 15
lixianyu 0:740c1eb2df13 16 class WidgetBridge
lixianyu 0:740c1eb2df13 17 {
lixianyu 0:740c1eb2df13 18 public:
lixianyu 0:740c1eb2df13 19 WidgetBridge(int vPin)
lixianyu 0:740c1eb2df13 20 : mPin(vPin)
lixianyu 0:740c1eb2df13 21 {}
lixianyu 0:740c1eb2df13 22 void onWrite(BlynkReq& request, const BlynkParam& param) {}
lixianyu 0:740c1eb2df13 23
lixianyu 0:740c1eb2df13 24 void setAuthToken(const char* token) {
lixianyu 0:740c1eb2df13 25 char mem[64];
lixianyu 0:740c1eb2df13 26 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 27 cmd.add(mPin);
lixianyu 0:740c1eb2df13 28 cmd.add("i");
lixianyu 0:740c1eb2df13 29 cmd.add(token);
lixianyu 0:740c1eb2df13 30 Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
lixianyu 0:740c1eb2df13 31 }
lixianyu 0:740c1eb2df13 32
lixianyu 0:740c1eb2df13 33 template <typename T>
lixianyu 0:740c1eb2df13 34 void digitalWrite(const T& pin, int val) {
lixianyu 0:740c1eb2df13 35 char mem[64];
lixianyu 0:740c1eb2df13 36 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 37 cmd.add(mPin);
lixianyu 0:740c1eb2df13 38 cmd.add("dw");
lixianyu 0:740c1eb2df13 39 cmd.add(pin);
lixianyu 0:740c1eb2df13 40 cmd.add(val);
lixianyu 0:740c1eb2df13 41 Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
lixianyu 0:740c1eb2df13 42 }
lixianyu 0:740c1eb2df13 43
lixianyu 0:740c1eb2df13 44 template <typename T>
lixianyu 0:740c1eb2df13 45 void analogWrite(const T& pin, int val) {
lixianyu 0:740c1eb2df13 46 char mem[64];
lixianyu 0:740c1eb2df13 47 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 48 cmd.add(mPin);
lixianyu 0:740c1eb2df13 49 cmd.add("aw");
lixianyu 0:740c1eb2df13 50 cmd.add(pin);
lixianyu 0:740c1eb2df13 51 cmd.add(val);
lixianyu 0:740c1eb2df13 52 Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
lixianyu 0:740c1eb2df13 53 }
lixianyu 0:740c1eb2df13 54
lixianyu 0:740c1eb2df13 55 template <typename T>
lixianyu 0:740c1eb2df13 56 void virtualWrite(int pin, const T& data) {
lixianyu 0:740c1eb2df13 57 char mem[64];
lixianyu 0:740c1eb2df13 58 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 59 cmd.add(mPin);
lixianyu 0:740c1eb2df13 60 cmd.add("vw");
lixianyu 0:740c1eb2df13 61 cmd.add(pin);
lixianyu 0:740c1eb2df13 62 cmd.add(data);
lixianyu 0:740c1eb2df13 63 Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
lixianyu 0:740c1eb2df13 64 }
lixianyu 0:740c1eb2df13 65
lixianyu 0:740c1eb2df13 66 template <typename T1, typename T2>
lixianyu 0:740c1eb2df13 67 void virtualWrite(int pin, const T1& data1, const T2& data2) {
lixianyu 0:740c1eb2df13 68 char mem[64];
lixianyu 0:740c1eb2df13 69 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 70 cmd.add(mPin);
lixianyu 0:740c1eb2df13 71 cmd.add("vw");
lixianyu 0:740c1eb2df13 72 cmd.add(pin);
lixianyu 0:740c1eb2df13 73 cmd.add(data1);
lixianyu 0:740c1eb2df13 74 cmd.add(data2);
lixianyu 0:740c1eb2df13 75 Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength()-1);
lixianyu 0:740c1eb2df13 76 }
lixianyu 0:740c1eb2df13 77
lixianyu 0:740c1eb2df13 78 template <typename T1, typename T2, typename T3>
lixianyu 0:740c1eb2df13 79 void virtualWrite(int pin, const T1& data1, const T2& data2, const T3& data3) {
lixianyu 0:740c1eb2df13 80 char mem[64];
lixianyu 0:740c1eb2df13 81 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 82 cmd.add(mPin);
lixianyu 0:740c1eb2df13 83 cmd.add("vw");
lixianyu 0:740c1eb2df13 84 cmd.add(pin);
lixianyu 0:740c1eb2df13 85 cmd.add(data1);
lixianyu 0:740c1eb2df13 86 cmd.add(data2);
lixianyu 0:740c1eb2df13 87 cmd.add(data3);
lixianyu 0:740c1eb2df13 88 Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength()-1);
lixianyu 0:740c1eb2df13 89 }
lixianyu 0:740c1eb2df13 90
lixianyu 0:740c1eb2df13 91 template <typename T1, typename T2, typename T3, typename T4>
lixianyu 0:740c1eb2df13 92 void virtualWrite(int pin, const T1& data1, const T2& data2, const T3& data3, const T4& data4) {
lixianyu 0:740c1eb2df13 93 char mem[64];
lixianyu 0:740c1eb2df13 94 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 95 cmd.add(mPin);
lixianyu 0:740c1eb2df13 96 cmd.add("vw");
lixianyu 0:740c1eb2df13 97 cmd.add(pin);
lixianyu 0:740c1eb2df13 98 cmd.add(data1);
lixianyu 0:740c1eb2df13 99 cmd.add(data2);
lixianyu 0:740c1eb2df13 100 cmd.add(data3);
lixianyu 0:740c1eb2df13 101 cmd.add(data4);
lixianyu 0:740c1eb2df13 102 Blynk.sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength()-1);
lixianyu 0:740c1eb2df13 103 }
lixianyu 0:740c1eb2df13 104
lixianyu 0:740c1eb2df13 105 void virtualWriteBinary(int pin, const void* buff, size_t len) {
lixianyu 0:740c1eb2df13 106 char mem[8];
lixianyu 0:740c1eb2df13 107 BlynkParam cmd(mem, 0, sizeof(mem));
lixianyu 0:740c1eb2df13 108 cmd.add(mPin);
lixianyu 0:740c1eb2df13 109 cmd.add("vw");
lixianyu 0:740c1eb2df13 110 cmd.add(pin);
lixianyu 0:740c1eb2df13 111 Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength(), buff, len);
lixianyu 0:740c1eb2df13 112 }
lixianyu 0:740c1eb2df13 113
lixianyu 0:740c1eb2df13 114 void virtualWrite(int pin, const BlynkParam& param) {
lixianyu 0:740c1eb2df13 115 virtualWriteBinary(pin, param.getBuffer(), param.getLength()-1);
lixianyu 0:740c1eb2df13 116 }
lixianyu 0:740c1eb2df13 117
lixianyu 0:740c1eb2df13 118 private:
lixianyu 0:740c1eb2df13 119 int mPin;
lixianyu 0:740c1eb2df13 120 };
lixianyu 0:740c1eb2df13 121
lixianyu 0:740c1eb2df13 122 #endif
lixianyu 0:740c1eb2df13 123