Pranav Thakur / Mbed 2 deprecated daplink-validation

Dependencies:   mbed

Fork of daplink-validation by Russ Butler

Revision:
4:9d5fa3e73be2
Parent:
3:ffa3bbc3725f
Child:
9:17b6e12e46ab
--- a/main.cpp	Fri Sep 18 19:54:50 2015 +0000
+++ b/main.cpp	Sat Dec 19 03:10:11 2015 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include <stdio.h>
 
-Serial pc(USBTX, USBRX);
+RawSerial pc(USBTX, USBRX);
 
 class ByteBuffer
 {
@@ -26,7 +26,11 @@
     }
 
     bool full() {
-        return head == (tail + 1) % size;
+        uint32_t new_tail = tail + 1;
+        if (new_tail >= size) {
+            new_tail = new_tail - size;
+        }
+        return head == new_tail;
     }
 
     void enqueue(uint8_t data) {
@@ -35,7 +39,9 @@
         }
         buffer[tail] = data;
         tail++;
-
+        if (tail >= size) {
+            tail -= size;
+        }
     }
 
     uint8_t dequeue() {
@@ -45,6 +51,9 @@
         }
         data = buffer[head];
         head++;
+        if (head >= size) {
+            head = head - size;
+        }
         return data;
     }