blynk & neopixelring & w7500
Fork of WIZwiki-7500_Blynk by
Embed:
(wiki syntax)
Show/hide line numbers
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/BlynkWidgetBase.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 : public BlynkWidgetBase 00028 #ifdef BLYNK_USE_PRINT_CLASS 00029 , public Print 00030 #endif 00031 { 00032 public: 00033 WidgetTerminal(uint8_t vPin) 00034 : BlynkWidgetBase(vPin) 00035 , mOutQty(0) 00036 {} 00037 00038 //virtual ~WidgetTerminal() {} 00039 00040 virtual size_t write(uint8_t byte) { 00041 mOutBuf[mOutQty++] = byte; 00042 if (mOutQty >= sizeof(mOutBuf)) { 00043 flush(); 00044 } 00045 return 1; 00046 } 00047 00048 void flush() { 00049 if (mOutQty) { 00050 Blynk.virtualWriteBinary(mPin, mOutBuf, mOutQty); 00051 mOutQty = 0; 00052 } 00053 } 00054 00055 #ifdef BLYNK_USE_PRINT_CLASS 00056 00057 using Print::write; 00058 00059 size_t write(const void* buff, size_t len) { 00060 return write((char*)buff, len); 00061 } 00062 00063 #else 00064 00065 size_t write(const void* buff, size_t len) { 00066 uint8_t* buf = (uint8_t*)buff; 00067 while (len--) { 00068 write(*buf++); 00069 } 00070 return len; 00071 } 00072 00073 size_t write(const char* str) { 00074 return write(str, strlen(str)); 00075 } 00076 00077 #endif 00078 00079 private: 00080 uint8_t mOutBuf[64]; 00081 uint8_t mOutQty; 00082 }; 00083 00084 #endif
Generated on Thu Jul 14 2022 00:21:50 by 1.7.2