aboutsummaryrefslogtreecommitdiffstats
path: root/examples/test-serial-flush.cpp
blob: 6c4e1005f3a9a1ad57c942cbe931459e815ada20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Tests the "flush" Serial function.
 */

#include "wirish.h"

#define COMM Serial1

void setup() {
    COMM.begin(9600);
    COMM.println("Hello world!");
}

void loop() {
    COMM.println("Waiting for multiple input...");
    while (COMM.available() < 5)
        ;
    COMM.println(COMM.read());
    COMM.println(COMM.read());
    COMM.flush();

    if (COMM.available()) {
        COMM.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;
}