yuhang zhu / Mbed 2 deprecated ADAM_menu

Dependencies:   mbed

Revision:
4:e8142db2bbfd
Parent:
3:32e67d121c7f
Child:
5:50ea1502a949
--- a/main.cpp	Fri Jul 12 20:02:01 2013 +0000
+++ b/main.cpp	Fri Jul 12 21:33:33 2013 +0000
@@ -11,7 +11,8 @@
 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;
+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() {
 
@@ -36,38 +37,45 @@
                 pc.printf("%s", cmd1);
                 line_buf[3] = 0;
                 line_pt = 0;
+                line_length = 0;
                 
                 while(1)
                 {
                     recv = pc.getc();
-                    if(recv == 13)
+                    if(recv == 13)   //enter is pressed 
                     {
-                        if(line_pt == 0)
+                        if(line_length == 0)
                             line_buf[3] = 0;
                         else
                             line_buf[3] = 1;
-                            
-                        break;  //enter pressed
+                        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)
+                    else if(recv == 8)   //backspace is pressed
                     {
                         pc.putc(8);
                         pc.putc(32);
                         pc.putc(8);
-                        if(line_pt == 0)
-                            line_buf[0] = 255;
-                        else if(line_pt > 0)
+                        
+                        if(line_length <= 3 && line_length>=1)   
                         {
+                            line_pt --;
                             line_buf[line_pt] = 255;
-                            line_pt --;
                         }
+                        if(line_length > 0)
+                            line_length --;
                     }
                     else
                     {
                         pc.putc(recv);
-                        line_buf[line_pt] = recv;
-                        if(line_pt < 2)
+                        line_length ++;
+                        
+                        if(line_length <= 3)
+                        {
+                            line_buf[line_pt] = recv;
                             line_pt ++;
+                        }
                     }
                 }