Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- yuhangzhu
- Date:
- 2013-07-12
- Revision:
- 4:e8142db2bbfd
- Parent:
- 3:32e67d121c7f
- Child:
- 5:50ea1502a949
File content as of revision 4:e8142db2bbfd:
#include "mbed.h" #include "menu.h" #include "parameters.h" #include "handlers.h" Serial pc(USBTX, USBRX); char recv; int state; unsigned char cha1_pha, cha2_pha; unsigned char cha1_amp, cha2_amp; short spi_data; char line_buf[4]; //line_buf[3] is used to indicate if it's empty 0 empty 1 not int line_pt; //line buffer pointer points to next buffer location it's going to write int line_length; //store the current line length int main() { pc.baud(115200); //config buad rate state = MODE_IDLE; line_buf[3] = 0; line_buf[2] = 255; line_buf[1] = 255; line_buf[0] = 255; while(1) { switch(state) { case MODE_IDLE: pc.printf("%s", main_menu); recv = pc.getc(); mode_idle_handler(&state, recv); //pc.printf("%d", state); break; case MODE_CHA1PHA: pc.printf("%s", cmd1); line_buf[3] = 0; line_pt = 0; line_length = 0; while(1) { recv = pc.getc(); if(recv == 13) //enter is pressed { if(line_length == 0) line_buf[3] = 0; else line_buf[3] = 1; pc.printf("decimal output : %d %d %d %d", line_buf[3], line_buf[2], line_buf[1], line_buf[0]); pc.printf("char output: %c %c %c %c", line_buf[3], line_buf[2], line_buf[1], line_buf[0]); break; } else if(recv == 8) //backspace is pressed { pc.putc(8); pc.putc(32); pc.putc(8); if(line_length <= 3 && line_length>=1) { line_pt --; line_buf[line_pt] = 255; } if(line_length > 0) line_length --; } else { pc.putc(recv); line_length ++; if(line_length <= 3) { line_buf[line_pt] = recv; line_pt ++; } } } state = MODE_IDLE; break; case MODE_CHA1AMP: pc.printf("%s", cmd2); state = MODE_IDLE; break; } } return 0; }