BLE Application to open a Garage door

Dependencies:   BLE_API Crypto RNG mbed nRF51822

Fork of BLE_LED by Bluetooth Low Energy

Revision:
10:80850cd6c29e
Parent:
9:329af8cdc923
--- a/History.h	Tue Aug 25 22:18:21 2015 +0000
+++ b/History.h	Tue Aug 25 23:26:43 2015 +0000
@@ -4,11 +4,19 @@
 template<uint32_t BufferSize>
 class History {
 public:
-    History() : _head(0) {
+    History() : _head(0),_read(0) {
+        for(int i=0; i<BufferSize; i++)
+            _pool[i] = 0;
     }
 
     ~History() {
     }
+    
+    uint64_t getToken() {
+        uint64_t tok = _pool[_read++];
+        _read %= BufferSize;
+        return tok;
+    }
 
     void save(const uint64_t& data) {
         _pool[_head++] = data;
@@ -39,11 +47,12 @@
      */
     void reset() {
         _head = 0;
+        _read = 0;
     }
 
 private:
     uint64_t _pool[BufferSize];
-    volatile uint32_t _head;
+    volatile uint32_t _head, _read;
 };