* AM2321的取温度间隔得大于2s,否则,i2c会不工作了 * SimpleTimer有个bug,会导致两次快速的读温度,现在读温度函数里加了保护 * Blynk有个bug,会导致无法把数据传到服务器 * 现在可以正常工作了

Dependencies:   mbed

Committer:
lixianyu
Date:
Fri Jun 24 02:06:43 2016 +0000
Revision:
1:e34100dd6532
Parent:
0:740c1eb2df13
?Arduino??????????0~255??????LPC824????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:740c1eb2df13 1 /**
lixianyu 0:740c1eb2df13 2 * @file WidgetTerminal.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 Jan 2015
lixianyu 0:740c1eb2df13 7 * @brief
lixianyu 0:740c1eb2df13 8 */
lixianyu 0:740c1eb2df13 9
lixianyu 0:740c1eb2df13 10 #ifndef WidgetTerminal_h
lixianyu 0:740c1eb2df13 11 #define WidgetTerminal_h
lixianyu 0:740c1eb2df13 12
lixianyu 0:740c1eb2df13 13 #if !(defined(LINUX) || defined(MBED_LIBRARY_VERSION))
lixianyu 0:740c1eb2df13 14 #define BLYNK_USE_PRINT_CLASS
lixianyu 0:740c1eb2df13 15 #endif
lixianyu 0:740c1eb2df13 16
lixianyu 0:740c1eb2df13 17 #include <Blynk/BlynkApi.h>
lixianyu 0:740c1eb2df13 18
lixianyu 0:740c1eb2df13 19 #ifdef BLYNK_USE_PRINT_CLASS
lixianyu 0:740c1eb2df13 20 #if !(defined(SPARK) || defined(PARTICLE) || (PLATFORM_ID==88) || defined(ARDUINO_RedBear_Duo)) // 88 -> RBL Duo
lixianyu 0:740c1eb2df13 21 // On Particle this is auto-included
lixianyu 0:740c1eb2df13 22 #include <Print.h>
lixianyu 0:740c1eb2df13 23 #endif
lixianyu 0:740c1eb2df13 24 #endif
lixianyu 0:740c1eb2df13 25
lixianyu 0:740c1eb2df13 26 class WidgetTerminal
lixianyu 0:740c1eb2df13 27 #ifdef BLYNK_USE_PRINT_CLASS
lixianyu 0:740c1eb2df13 28 : public Print
lixianyu 0:740c1eb2df13 29 #endif
lixianyu 0:740c1eb2df13 30 {
lixianyu 0:740c1eb2df13 31 public:
lixianyu 0:740c1eb2df13 32 WidgetTerminal(int vPin)
lixianyu 0:740c1eb2df13 33 : mPin(vPin), mOutQty(0)
lixianyu 0:740c1eb2df13 34 {}
lixianyu 0:740c1eb2df13 35
lixianyu 0:740c1eb2df13 36 virtual size_t write(uint8_t byte) {
lixianyu 0:740c1eb2df13 37 mOutBuf[mOutQty++] = byte;
lixianyu 0:740c1eb2df13 38 if (mOutQty >= sizeof(mOutBuf)) {
lixianyu 0:740c1eb2df13 39 flush();
lixianyu 0:740c1eb2df13 40 }
lixianyu 0:740c1eb2df13 41 return 1;
lixianyu 0:740c1eb2df13 42 }
lixianyu 0:740c1eb2df13 43
lixianyu 0:740c1eb2df13 44 void flush() {
lixianyu 0:740c1eb2df13 45 if (mOutQty) {
lixianyu 0:740c1eb2df13 46 Blynk.virtualWriteBinary(mPin, mOutBuf, mOutQty);
lixianyu 0:740c1eb2df13 47 mOutQty = 0;
lixianyu 0:740c1eb2df13 48 }
lixianyu 0:740c1eb2df13 49 }
lixianyu 0:740c1eb2df13 50
lixianyu 0:740c1eb2df13 51 #ifdef BLYNK_USE_PRINT_CLASS
lixianyu 0:740c1eb2df13 52
lixianyu 0:740c1eb2df13 53 using Print::write;
lixianyu 0:740c1eb2df13 54
lixianyu 0:740c1eb2df13 55 size_t write(const void* buff, size_t len) {
lixianyu 0:740c1eb2df13 56 return write((char*)buff, len);
lixianyu 0:740c1eb2df13 57 }
lixianyu 0:740c1eb2df13 58
lixianyu 0:740c1eb2df13 59 #else
lixianyu 0:740c1eb2df13 60
lixianyu 0:740c1eb2df13 61 size_t write(const void* buff, size_t len) {
lixianyu 0:740c1eb2df13 62 uint8_t* buf = (uint8_t*)buff;
lixianyu 0:740c1eb2df13 63 while (len--) {
lixianyu 0:740c1eb2df13 64 write(*buf++);
lixianyu 0:740c1eb2df13 65 }
lixianyu 0:740c1eb2df13 66 return len;
lixianyu 0:740c1eb2df13 67 }
lixianyu 0:740c1eb2df13 68
lixianyu 0:740c1eb2df13 69 size_t write(const char* str) {
lixianyu 0:740c1eb2df13 70 return write(str, strlen(str));
lixianyu 0:740c1eb2df13 71 }
lixianyu 0:740c1eb2df13 72
lixianyu 0:740c1eb2df13 73 #endif
lixianyu 0:740c1eb2df13 74
lixianyu 0:740c1eb2df13 75 private:
lixianyu 0:740c1eb2df13 76 uint8_t mPin;
lixianyu 0:740c1eb2df13 77 uint8_t mOutBuf[32];
lixianyu 0:740c1eb2df13 78 uint8_t mOutQty;
lixianyu 0:740c1eb2df13 79 };
lixianyu 0:740c1eb2df13 80
lixianyu 0:740c1eb2df13 81 #endif
lixianyu 0:740c1eb2df13 82