yuhang zhu / Mbed 2 deprecated ADAM_menu

Dependencies:   mbed

Revision:
23:0b6901c9302c
Parent:
21:4d6b26eecdac
Child:
24:f8fea5e5bf73
diff -r 311523c6a152 -r 0b6901c9302c main.cpp
--- a/main.cpp	Sun Jul 21 06:19:30 2013 +0000
+++ b/main.cpp	Mon Jul 22 17:53:24 2013 +0000
@@ -1,13 +1,21 @@
-//This main funtion implements a mode transfer.
-//When mcu resets, it's in MODE_IDLE. Then depends on the keyboard input(1 to 7), the 
-//mode switches to transition modes such as 
-//MODE_CHAxPHA, which is for phase input of channel x, or
-//MODE_CHAxAMP, which is for attenuation input of channel x, or
-//MODE_DISPLAY, which is for displaying the current parameters, or
-//MODE_HELP, which is for displaying the help infomation, or
-//MODE_SEND, which is for sending the bit stream through the SPI bus by MOSI and read the data back from MISO.
-//After each transition mode completes, mcu returns to MODE_IDLE to wait for another user input.
+/*************************************************************************************
+Author: Yuhang Zhu(46609@freescale.com)
+Date: July 20, 2013
+
+Function name: main
 
+Function description:
+This main function implements a mode transfer.
+When MCU resets, it's in MODE_IDLE. Then depends on the keyboard input(1 to 7), 
+mode switches to transition modes such as 
+MODE_CHAxPHA, which is for phase input of channel x, or
+MODE_CHAxAMP, which is for attenuation input of channel x, or
+MODE_DISPLAY, which is for displaying the current parameters, or
+MODE_HELP, which is for displaying the help information, or
+MODE_SEND, which is for sending the bit stream through the SPI bus by MOSI and reading the data back from MISO.
+After each transition mode completes, MCU returns to MODE_IDLE to wait for another user input.
+
+***************************************************************************************/
 
 #include "mbed.h"
 #include "menu.h"
@@ -41,8 +49,8 @@
 
 int main() {
 
-    pc.baud(19200);   //config buad rate. Note: 115200 seems too high for the current board
-    cs = 1;           //spi config
+    pc.baud(19200);   //Configure baud rate. Note: 115200 seems too high for the current board
+    cs = 1;           //SPI config
     spi.format(8,0);  //16 bit frame is not working, so need to send twice 8 bit frame
                       //For more info about format, see http://mbed.org/forum/bugs-suggestions/topic/4419/?page=1#comment-22056
     spi.frequency(1000000);  
@@ -64,7 +72,7 @@
             case MODE_IDLE:
                 pc.printf("%s", main_menu);
                 recv = pc.getc();
-                mode_idle_handler(&state, recv);  //change state based on recv input
+                mode_idle_handler(&state, recv);  //Change state based on recv input
                 
                 break;
                 
@@ -91,7 +99,7 @@
                 while(1)   //Character input into line buffer, terminated by enter key
                 {
                     recv = pc.getc();
-                    if(recv == 13)   //enter is pressed, break
+                    if(recv == 13)   //Enter is pressed, break
                     {
                         if(line_length == 0)
                             line_buf[3] = LINEBUF_EMPTY;
@@ -106,9 +114,9 @@
                            
                         break;  
                     }
-                    else if(recv == 8 || recv == 127)   //backspace is pressed, delete one character both on screen and line buffer
+                    else if(recv == 8 || recv == 127)   //Backspace is pressed, delete one character both on screen and line buffer
                     {
-                        if(line_length > 0)  //delete one char on screen
+                        if(line_length > 0)  //Delete one char on screen
                         {
                             pc.putc(8);
                             pc.putc(32);
@@ -123,7 +131,7 @@
                         if(line_length > 0)
                             line_length --;
                     }
-                    else if(recv == '.' || recv == '-' || (recv >= '0' && recv <= '9') )   //the line buffer accepts -, ., 0-9 only
+                    else if(recv == '.' || recv == '-' || (recv >= '0' && recv <= '9') )   //The line buffer accepts -, ., 0-9 only
                     {
                         pc.putc(recv);
                         line_length ++;
@@ -135,8 +143,8 @@
                         }
                     }
                 }
-                //input over, now checking 
-                //check phase shift input
+                //Input over, now checking 
+                //Check phase shift input
                 if(state == MODE_CHA1PHA || state == MODE_CHA2PHA)
                 {  
                    if(state == MODE_CHA1PHA)
@@ -160,7 +168,7 @@
                         pc.printf("%s", msg_err);
                         pc.getc();
                    }
-                   else if(ret == PARSE_ROUNDED) //Input is rounded,show the rounded value
+                   else if(ret == PARSE_ROUNDED) //Input is rounded, show the rounded value
                    {    
                         if(state == MODE_CHA1PHA)
                             pc.printf("%s %d\n", msg_rounded, cha1_pha*-7);
@@ -181,7 +189,7 @@
                    }
                 } 
                 
-                //check attenuation input
+                //Check attenuation input
                 if(state == MODE_CHA1AMP || state == MODE_CHA2AMP)
                 {
                     if(state == MODE_CHA1AMP)
@@ -228,13 +236,13 @@
                 state = MODE_IDLE;  //back to idle state after input
                 break;
             
-            // In display mode, show current parameters
+            //In display mode, show current parameters
             case MODE_DISPLAY:
                 pc.printf("\n\n ******** Current Parameters ********\n\n");
                 pc.printf("Phase shift  for RF out1 is %d degrees\n", cha1_pha*-7);
-                pc.printf("Attentuation for RF out1 is %.1f dB\n", cha1_amp*5.0/10.0);
+                pc.printf("Attenuation for RF out1 is %.1f dB\n", cha1_amp*5.0/10.0);
                 pc.printf("Phase shift  for RF out2 is %d degrees\n", cha2_pha*-7);
-                pc.printf("Attentuation for RF out2 is %.1f dB\n", cha2_amp*5.0/10.0);
+                pc.printf("Attenuation for RF out2 is %.1f dB\n", cha2_amp*5.0/10.0);
                 pc.printf("%s", msg_ret);
                 pc.getc();
                 state = MODE_IDLE;
@@ -255,7 +263,7 @@
                 spi_first_byte_s = (cha2_amp << 4) | (cha2_pha);
                 spi_second_byte_s = (cha1_amp << 4) | (cha1_pha);
                 
-                cs = 0;   //SPI start sending, send and recond the response
+                cs = 0;   //SPI start sending, send and record the response
                 spi_first_byte_r = spi.write(spi_first_byte_s);
                 spi_second_byte_r = spi.write(spi_second_byte_s);
                 cs = 1;
@@ -263,9 +271,9 @@
                 //Start printint...
                 pc.printf("******** Now sending parameters ********\n\n");
                 pc.printf("Phase shift  for RF out1 is %d degrees\n", cha1_pha*-7);
-                pc.printf("Attentuation for RF out1 is %.1f dB\n", cha1_amp*5.0/10.0);
+                pc.printf("Attenuation for RF out1 is %.1f dB\n", cha1_amp*5.0/10.0);
                 pc.printf("Phase shift  for RF out2 is %d degrees\n", cha2_pha*-7);
-                pc.printf("Attentuation for RF out2 is %.1f dB\n", cha2_amp*5.0/10.0);
+                pc.printf("Attenuation for RF out2 is %.1f dB\n", cha2_amp*5.0/10.0);
                 pc.printf("\nSPI bit stream sent:\n");
                 pc.printf("%s", bit_index);
                 
@@ -289,9 +297,9 @@
                 //Output the previous parameters:
                 pc.printf("\n\n\n******** Now displaying previous parameters ********\n");
                 pc.printf("\nPrevious phase shift  for RF out1 is %d degrees\n", (spi_second_byte_r&0x07)*-7);
-                pc.printf("Previous attentuation for RF out1 is %.1f dB\n", (spi_second_byte_r>>4)*5.0/10.0);
+                pc.printf("Previous attenuation for RF out1 is %.1f dB\n", (spi_second_byte_r>>4)*5.0/10.0);
                 pc.printf("Previous phase shift  for RF out2 is %d degrees\n", (spi_first_byte_r&0x07)*-7);
-                pc.printf("Previous attentuation for RF out2 is %.1f dB\n", (spi_first_byte_r>>4)*5.0/10.0);
+                pc.printf("Previous attenuation for RF out2 is %.1f dB\n", (spi_first_byte_r>>4)*5.0/10.0);
                 //SPI bit stream for previous parameters
                 pc.printf("\nSPI bit stream received:\n");
                 pc.printf("%s", bit_index);