Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of daplink-validation by
Diff: main.cpp
- 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;
}
