aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2010-07-20 15:43:11 -0400
committerbnewbold <bnewbold@robocracy.org>2010-07-20 15:43:11 -0400
commit4298a45c5a35e0173175b297c98eebf6e5826fab (patch)
tree43809f026213b2db7aeb9e74b61f1cad759a46af /examples
parent4263903592a9bfa03571783dda86d00791be36d2 (diff)
downloadlibrambutan-4298a45c5a35e0173175b297c98eebf6e5826fab.tar.gz
librambutan-4298a45c5a35e0173175b297c98eebf6e5826fab.zip
test of serialN.flush()
Diffstat (limited to 'examples')
-rw-r--r--examples/test-serial-flush.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/test-serial-flush.cpp b/examples/test-serial-flush.cpp
new file mode 100644
index 0000000..d7fbf7a
--- /dev/null
+++ b/examples/test-serial-flush.cpp
@@ -0,0 +1,45 @@
+// Tests the "flush" Serial function
+
+#include "wirish.h"
+
+void setup()
+{
+ /* Send a message out USART2 */
+ Serial2.begin(9600);
+ Serial2.println("Hello world!");
+}
+
+int toggle = 0;
+
+void loop() {
+
+ Serial2.println("This is the first line.");
+ Serial2.end();
+ Serial2.println("This is the second line.");
+
+ Serial2.begin(9600);
+ Serial2.println("Waiting for multiple input...");
+ while(Serial2.available() < 5) { }
+ Serial2.println(Serial2.read());
+ Serial2.println(Serial2.read());
+ Serial2.flush();
+ if(Serial2.available()) {
+ Serial2.println("FAIL! Still had junk in the buffer...");
+ }
+}
+
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
+ init();
+}
+
+int main(void)
+{
+ setup();
+
+ while (1) {
+ loop();
+ }
+ return 0;
+}