You may have noticed a bug introduced in 0.0.9 whereby code like this:
while(SerialUSB.available()) {
SerialUSB.print(SerialUSB.read()); // should be an echo server
}
would sometimes give zany results. The problem has been solved. The problem was that consecutive calls to usbReadBytes (called by SerialUSB.read) just read the same bytes over and over again, and already-read bytes were not being dequeued.
If you were having trouble with SerialUSB.read() you have three options:
1) Workaround:
instead of making consecutive calls to SerialUSB.read(), make a single call all the bytes in the buffer like this:
// a more complicated but 100% functional echo server
#include "usb.h" // gives us access to libmaple usb functions
char buf[65];
void loop() {
int newbytes = 0;
if (newbytes = SerialUSB.available()) { // newbytes will never be > 64
usbReadBytes((uint8*)buf,newbytes);
buf[newbytes] = 0; // set the last char to 0 to create a null terminated string
SerialUSB.print(buf);
}
}
2) replace your usb.c file:
in your maple-ide installation directory, locate:
(maple-ide-x.x.x)/hardware/leaflabs/cores/maple/usb.c
replace this file with this version:
https://github.com/leaflabs/libmaple/blob/master/libmaple/usb/usb.c
3) wait for the 0.0.12 or other future release of IDE, where the issue will be fixed.
Happy Hacking!