![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork to force BLE id to have prefix that is assumed by the app
Dependencies: BLE_API Crypto RNG mbed nRF51822
Fork of Garagem by
Diff: History.h
- Revision:
- 9:329af8cdc923
- Child:
- 10:80850cd6c29e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/History.h Tue Aug 25 22:18:21 2015 +0000 @@ -0,0 +1,50 @@ +#ifndef HISTORY_H +#define HISTORY_H + +template<uint32_t BufferSize> +class History { +public: + History() : _head(0) { + } + + ~History() { + } + + void save(const uint64_t& data) { + _pool[_head++] = data; + _head %= BufferSize; + } + + bool exist(const uint64_t& data) { + for(uint32_t i=0; i<BufferSize; i++) { + DBG("%llu == %llu\r\n", _pool[i], data); + if(_pool[i]==data) { + return true; + } + } + return false; + } + + uint64_t last() { + uint32_t prev = (_head-1+BufferSize)%BufferSize; + return _pool[prev]; + } + + uint32_t last_ts() { + return (uint32_t) last(); + } + + /** Reset the buffer + * + */ + void reset() { + _head = 0; + } + +private: + uint64_t _pool[BufferSize]; + volatile uint32_t _head; +}; + + +#endif \ No newline at end of file