blynk & neopixelring & w7500

Fork of WIZwiki-7500_Blynk by IOP

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 #define BlynkBitSet(value, bit)   ((value) |= (1UL << (bit)))
00038 #define BlynkBitClear(value, bit) ((value) &= ~(1UL << (bit)))
00039 #define BlynkBitRead(value, bit)  (((value) >> (bit)) & 0x01)
00040 #define BlynkBitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
00041 
00042 #endif