yuhang zhu / Mbed 2 deprecated ADAM_menu

Dependencies:   mbed

Revision:
6:e510aab8f2ce
Parent:
5:50ea1502a949
Child:
7:c268547fb6c8
diff -r 50ea1502a949 -r e510aab8f2ce main.cpp
--- a/main.cpp	Fri Jul 12 22:55:02 2013 +0000
+++ b/main.cpp	Sat Jul 13 18:02:38 2013 +0000
@@ -7,8 +7,10 @@
 
 char recv;
 int state;
-unsigned char cha1_pha, cha2_pha;
-unsigned char cha1_amp, cha2_amp;
+char cha1_pha, cha2_pha;
+char cha1_amp, cha2_amp;
+int ret;
+
 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
@@ -53,20 +55,23 @@
                 line_pt = 0;
                 line_length = 0;
                 
-                while(1)
+                while(1)   //input into line buffer, terminated by enter key
                 {
                     recv = pc.getc();
-                    if(recv == 13)   //enter is pressed 
+                    if(recv == 13)   //enter is pressed, break
                     {
                         if(line_length == 0)
-                            line_buf[3] = 0;
+                            line_buf[3] = LINEBUF_EMPTY;
+                        else if(line_length > 3)
+                            line_buf[3] = LINEBUF_TOOLONG;
                         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]);   
+                            line_buf[3] = LINEBUF_OK;
+                            
+                        //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
+                    else if(recv == 8)   //backspace is pressed, delete one character both on screen and line buffer
                     {
                         pc.putc(8);
                         pc.putc(32);
@@ -80,7 +85,7 @@
                         if(line_length > 0)
                             line_length --;
                     }
-                    else
+                    else        //other character is pressed, record that in line buffer
                     {
                         pc.putc(recv);
                         line_length ++;
@@ -92,6 +97,43 @@
                         }
                     }
                 }
+                //input over, now checking 
+                
+                if(state == MODE_CHA1PHA || state == MODE_CHA2PHA)
+                {  
+                   if(state == MODE_CHA1PHA)
+                        ret = parse_phase(line_buf, &cha1_pha);
+                   else
+                        ret = parse_phase(line_buf, &cha2_pha);
+                        
+                   if(ret == PARSE_LONG)
+                   { 
+                        pc.printf("%s", msg_strlong);
+                        pc.getc();
+                   }
+                   else if(ret == PARSE_ERR)
+                   {
+                        pc.printf("%s", msg_err);
+                        pc.getc();
+                   }
+                   else if(ret == PARSE_ROUNDED)
+                   {    
+                        if(state == MODE_CHA1PHA)
+                            pc.printf("%s -%d\n", msg_rounded, cha1_pha*7);
+                        else if(state == MODE_CHA2PHA)
+                            pc.printf("%s -%d\n", msg_rounded, cha2_pha*7);
+                            
+                        pc.printf("%s", msg_ret);
+                        pc.getc();
+                   }
+                   else
+                   {    
+                        pc.printf("%s", msg_ok);
+                        pc.printf("%d %d\n", cha1_pha*7, cha2_pha*7);
+                        pc.printf("%s", msg_ret);
+                        pc.getc();
+                   }
+                } 
                 
                 state = MODE_IDLE;
                 break;