coursework
Dependencies: USBDevice mbed-rtos mbed
Diff: function_generator/serial.cpp
- Revision:
- 0:c059d38d6074
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/function_generator/serial.cpp Mon Nov 28 10:32:43 2016 +0000 @@ -0,0 +1,24 @@ +#include "serial.h" + +char* buffer = new char[BUFFER_SIZE]; + +USB_Serial serial; + +void USB_Serial::flush() { + while(serial.readable()) + serial.getc(); +} + +int USB_Serial::gets (char* str, int size) { + int i=0; + char c; + while(1) { + c = serial.getc(); + if(c=='\r' || c=='\n') break; + str[i++] = c; + if(i+1==size) break; + } + str[i]=0; + return i; +} +