Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc. http://www.blynk.cc/

Dependents:   Blynk_RBL_BLE_Nano Blynk_MicroBit Blynk_Serial Blynk_RBL_BLE_Nano

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BlynkUtility.h Source File

BlynkUtility.h

Go to the documentation of this file.
00001 /**
00002  * @file       BlynkUtility.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       Jun 2015
00007  * @brief      Utility functions
00008  *
00009  */
00010 
00011 #ifndef BlynkUtility_h
00012 #define BlynkUtility_h
00013 
00014 template<class T>
00015 const T& BlynkMin(const T& a, const T& b)
00016 {
00017     return (b < a) ? b : a;
00018 }
00019 
00020 template<class T>
00021 const T& BlynkMax(const T& a, const T& b)
00022 {
00023     return (b < a) ? a : b;
00024 }
00025 
00026 template <unsigned WSIZE, typename T>
00027 void BlynkAverageSample (T& avg, const T& input) {
00028     avg -= avg/WSIZE;
00029     const T add = input/WSIZE;
00030     // Fix for shorter delays
00031     if (add > 0)
00032       avg += add;
00033     else
00034       avg -= 1;
00035 }
00036 
00037 class BlynkHelperAutoInc {
00038 public:
00039     BlynkHelperAutoInc(uint8_t& counter) : c(counter) { ++c; }
00040     ~BlynkHelperAutoInc() { --c; }
00041 private:
00042     uint8_t& c;
00043 };
00044 
00045 #define BlynkBitSet(value, bit)   ((value) |= (1UL << (bit)))
00046 #define BlynkBitClear(value, bit) ((value) &= ~(1UL << (bit)))
00047 #define BlynkBitRead(value, bit)  (((value) >> (bit)) & 0x01)
00048 #define BlynkBitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
00049 
00050 #endif