aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-serial-flush.cpp
diff options
context:
space:
mode:
authorbryan newbold <bnewbold@robocracy.org>2014-10-16 20:20:20 -0700
committerbryan newbold <bnewbold@robocracy.org>2014-10-16 20:20:20 -0700
commitdba5a9fe68ebb996eeee69fa9b573fe5a1561ce2 (patch)
tree6d9c249686b81b2b70da9b9a3dd1e246c221b4b3 /tests/test-serial-flush.cpp
parent160d861ba3fe50c30891d1abcb2c520be84aaa85 (diff)
downloadlibrambutan-dba5a9fe68ebb996eeee69fa9b573fe5a1561ce2.tar.gz
librambutan-dba5a9fe68ebb996eeee69fa9b573fe5a1561ce2.zip
refactor: move test-style examples to ./tests
Diffstat (limited to 'tests/test-serial-flush.cpp')
-rw-r--r--tests/test-serial-flush.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test-serial-flush.cpp b/tests/test-serial-flush.cpp
new file mode 100644
index 0000000..409d1f9
--- /dev/null
+++ b/tests/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;
+}