This example shows how to use the CircularBuffer library.
Dependencies: CircularBuffer mbed
Diff: main.cpp
- Revision:
- 0:aad8c5c41dac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Sep 20 10:47:53 2013 +0000 @@ -0,0 +1,19 @@ +#include "mbed.h" +#include "CircularBuffer.h" + +int main() +{ + CircularBuffer<16> buffer; + uint32_t n = buffer.write((uint8_t*)"Hello World !", strlen("Hello World !")); + printf("wrote %d bytes\n", n); + char str[10]; + n = buffer.read((uint8_t*)str, 5); + str[n] = '\0'; + printf("str=%s\n", str); // prints:Hello + buffer.read((uint8_t*)str, 1); // discard space + n = buffer.read((uint8_t*)str, 7); + str[n] = '\0'; + printf("str=%s\n", str); // prints:World ! + + return 0; +}