Bayley Wang
/
flash_configuration
flash based config testing
main.cpp@2:cfc39b0843ae, 2017-03-02 (annotated)
- Committer:
- bwang
- Date:
- Thu Mar 02 07:36:56 2017 +0000
- Revision:
- 2:cfc39b0843ae
- Parent:
- 1:df6bbacb7bb9
- Child:
- 3:82c00c8e2cb4
stubs for run/cfg mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 0:941e150e78b6 | 1 | #include "mbed.h" |
bwang | 1:df6bbacb7bb9 | 2 | |
bwang | 0:941e150e78b6 | 3 | #include "PreferenceWriter.h" |
bwang | 0:941e150e78b6 | 4 | #include "FlashWriter.h" |
bwang | 1:df6bbacb7bb9 | 5 | #include "CommandProcessor.h" |
bwang | 2:cfc39b0843ae | 6 | #include "config.h" |
bwang | 0:941e150e78b6 | 7 | |
bwang | 0:941e150e78b6 | 8 | Serial pc(USBTX, USBRX); |
bwang | 0:941e150e78b6 | 9 | PreferenceWriter pref(6); |
bwang | 2:cfc39b0843ae | 10 | DigitalOut led(LED1); |
bwang | 0:941e150e78b6 | 11 | |
bwang | 2:cfc39b0843ae | 12 | int index = 0, mode = MODE_RUN; |
bwang | 1:df6bbacb7bb9 | 13 | char linebuf[128]; |
bwang | 1:df6bbacb7bb9 | 14 | |
bwang | 1:df6bbacb7bb9 | 15 | void rxCallback() { |
bwang | 1:df6bbacb7bb9 | 16 | while (pc.readable()) { |
bwang | 1:df6bbacb7bb9 | 17 | char c = pc.getc(); |
bwang | 1:df6bbacb7bb9 | 18 | if (c != 127 && c != '\r' && c != '\t') { |
bwang | 1:df6bbacb7bb9 | 19 | linebuf[index] = c; |
bwang | 1:df6bbacb7bb9 | 20 | index++; |
bwang | 1:df6bbacb7bb9 | 21 | pc.putc(c); |
bwang | 1:df6bbacb7bb9 | 22 | } else if (c == 127) { |
bwang | 1:df6bbacb7bb9 | 23 | if (index > 0) { |
bwang | 1:df6bbacb7bb9 | 24 | index--; |
bwang | 1:df6bbacb7bb9 | 25 | pc.putc(c); |
bwang | 1:df6bbacb7bb9 | 26 | } |
bwang | 1:df6bbacb7bb9 | 27 | } else if (c == '\r') { |
bwang | 1:df6bbacb7bb9 | 28 | linebuf[index] = 0; |
bwang | 1:df6bbacb7bb9 | 29 | pc.putc(c); |
bwang | 1:df6bbacb7bb9 | 30 | processCmd(&pc, &pref, linebuf); |
bwang | 1:df6bbacb7bb9 | 31 | index = 0; |
bwang | 1:df6bbacb7bb9 | 32 | pc.putc('>'); |
bwang | 1:df6bbacb7bb9 | 33 | } |
bwang | 1:df6bbacb7bb9 | 34 | } |
bwang | 1:df6bbacb7bb9 | 35 | } |
bwang | 1:df6bbacb7bb9 | 36 | |
bwang | 2:cfc39b0843ae | 37 | void commutate() { |
bwang | 2:cfc39b0843ae | 38 | if (mode != MODE_RUN) { |
bwang | 2:cfc39b0843ae | 39 | led = 0; |
bwang | 2:cfc39b0843ae | 40 | } else { |
bwang | 2:cfc39b0843ae | 41 | led = 1; |
bwang | 2:cfc39b0843ae | 42 | } |
bwang | 2:cfc39b0843ae | 43 | } |
bwang | 2:cfc39b0843ae | 44 | |
bwang | 0:941e150e78b6 | 45 | int main() { |
bwang | 0:941e150e78b6 | 46 | pc.baud(115200); |
bwang | 1:df6bbacb7bb9 | 47 | pc.attach(rxCallback); |
bwang | 0:941e150e78b6 | 48 | pc.printf("%s\n", "Serial Configuration Test"); |
bwang | 1:df6bbacb7bb9 | 49 | pc.printf("%s", ">"); |
bwang | 0:941e150e78b6 | 50 | |
bwang | 2:cfc39b0843ae | 51 | Ticker tick; |
bwang | 2:cfc39b0843ae | 52 | tick.attach_us(commutate, 200); |
bwang | 2:cfc39b0843ae | 53 | |
bwang | 0:941e150e78b6 | 54 | for(;;) { |
bwang | 0:941e150e78b6 | 55 | } |
bwang | 0:941e150e78b6 | 56 | } |