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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WidgetTerminal.h Source File

WidgetTerminal.h

Go to the documentation of this file.
00001 /**
00002  * @file       WidgetTerminal.h
00003  * @author     Volodymyr Shymanskyy
00004  * @license    This project is released under the MIT License (MIT)
00005  * @copyright  Copyright (c) 2015 Volodymyr Shymanskyy
00006  * @date       Jan 2015
00007  * @brief
00008  */
00009 
00010 #ifndef WidgetTerminal_h
00011 #define WidgetTerminal_h
00012 
00013 #if !(defined(LINUX) || defined(MBED_LIBRARY_VERSION))
00014     #define BLYNK_USE_PRINT_CLASS
00015 #endif
00016 
00017 #include <Blynk/BlynkApi.h>
00018 
00019 #ifdef BLYNK_USE_PRINT_CLASS
00020     #if !(defined(SPARK) || defined(PARTICLE) || (PLATFORM_ID==88) || defined(ARDUINO_RedBear_Duo)) // 88 -> RBL Duo
00021         // On Particle this is auto-included
00022         #include <Print.h>
00023     #endif
00024 #endif
00025 
00026 class WidgetTerminal
00027 #ifdef BLYNK_USE_PRINT_CLASS
00028     : public Print
00029 #endif
00030 {
00031 public:
00032     WidgetTerminal(int vPin)
00033         : mPin(vPin), mOutQty(0)
00034     {}
00035 
00036     virtual size_t write(uint8_t byte) {
00037         mOutBuf[mOutQty++] = byte;
00038         if (mOutQty >= sizeof(mOutBuf)) {
00039             flush();
00040         }
00041         return 1;
00042     }
00043 
00044     void flush() {
00045         if (mOutQty) {
00046             Blynk.virtualWriteBinary(mPin, mOutBuf, mOutQty);
00047             mOutQty = 0;
00048         }
00049     }
00050 
00051 #ifdef BLYNK_USE_PRINT_CLASS
00052 
00053     using Print::write;
00054 
00055     size_t write(const void* buff, size_t len) {
00056         return write((char*)buff, len);
00057     }
00058 
00059 #else
00060 
00061     size_t write(const void* buff, size_t len) {
00062         uint8_t* buf = (uint8_t*)buff;
00063         while (len--) {
00064             write(*buf++);
00065         }
00066         return len;
00067     }
00068 
00069     size_t write(const char* str) {
00070         return write(str, strlen(str));
00071     }
00072 
00073 #endif
00074 
00075 private:
00076     uint8_t mPin;
00077     uint8_t mOutBuf[32];
00078     uint8_t mOutQty;
00079 };
00080 
00081 #endif
00082