diff options
Diffstat (limited to 'examples/test-serial-flush.cpp')
-rw-r--r-- | examples/test-serial-flush.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/test-serial-flush.cpp b/examples/test-serial-flush.cpp new file mode 100644 index 0000000..409d1f9 --- /dev/null +++ b/examples/test-serial-flush.cpp @@ -0,0 +1,38 @@ +/* + * Tests the "flush" Serial function. + */ + +#include <wirish/wirish.h> + +void setup() { + Serial1.begin(9600); + Serial1.println("Hello world!"); +} + +void loop() { + Serial1.println("Waiting for multiple input..."); + while (Serial1.available() < 5) + ; + Serial1.println(Serial1.read()); + Serial1.println(Serial1.read()); + Serial1.flush(); + + if (Serial1.available()) { + Serial1.println("FAIL! Still had junk in the buffer..."); + } +} + +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated objects that need libmaple may fail. +__attribute__((constructor)) void premain() { + init(); +} + +int main(void) { + setup(); + + while (true) { + loop(); + } + return 0; +} |