Libraries and Example of mbed parallel bus using I2C port expanders
Dependencies: HDSP253X mbed PCF8574_Bus
Diff: main.cpp
- Revision:
- 3:3fbfdec782f4
- Parent:
- 2:1dab1089c332
- Child:
- 4:745fbbd5e4e5
--- a/main.cpp Sat Aug 20 12:49:44 2011 +0000 +++ b/main.cpp Sun Aug 21 19:42:48 2011 +0000 @@ -63,7 +63,7 @@ enum RangeSelect { RNG_F, RNG_L }; -enum MessageToHost { LFPON, LFRDY, LFSTA }; +enum MessageToHost { LFPON, LFRDY_0, LFRDY_1, LFSTA, LFIDL }; enum MessageFromHost { LFRES, LFRNG }; //Typedef for Laser Range finder data @@ -180,7 +180,8 @@ LF28A_status.set_brightness(brightness); // Init Alphanumeric Display - LF28A_display.cls(); + LF28A_display.cls(); // Clear display and Cursor home + LF28A_display.set_flash_mode(true); // Enable flashing digits //Done, Tell me about it DBG("Init Done, Originator = %d\r", hostResetCmd); @@ -288,18 +289,20 @@ case LFPON : pc.printf("$LFPON*00\r\n"); break; - case LFRDY : if (!hostResetCmd) { - pc.printf("$LFRDY,0*00\r\n"); - } - else { - pc.printf("$LFRDY,1*00\r\n"); - hostResetCmd = false; - } + case LFRDY_0 : // No hostResetCmd + pc.printf("$LFRDY,0*00\r\n"); + break; + + case LFRDY_1 : // hostResetCmd + pc.printf("$LFRDY,1*00\r\n"); break; case LFSTA : pc.printf("$LFSTA,D,0,1234,1*00\r\n"); break; + case LFIDL : // No Message + break; + default: // Oops, we should never end up here.... result = -1; @@ -321,6 +324,7 @@ clear_screen(); version_string(); +#ifndef __TESTCODE lamp_test(); BITE(); @@ -330,9 +334,7 @@ // Prepare main State Machine mode = INIT_ENTRY; // Start with Init hostResetCmd = false; // Start with regular PowerOn reset - - -#ifndef __TESTCODE + // Main Controlloop: // Check keyboard input and respond as required in the current device mode // Check Host commands and respond as required @@ -350,8 +352,16 @@ init_state(); // Inform Host that Init has completed - SendHostMessage(LFRDY); - + if (!hostResetCmd) { + // Regular PowerOn Reset + SendHostMessage(LFRDY_0) + } + else { + // Host initiated a Reset + SendHostMessage(LFRDY_1); + hostResetCmd = false; + } + mode = INIT_EXIT; break; @@ -362,7 +372,11 @@ // DESIG MODEs - Laser Designator case DESIG_ENTRY: // Transitional state + // Status LEDs + LF28A_status.LED(LED_DESIG, LED_ON); + //Display current STANAG Code + LF28A_display.printf("Designat"); // Inform Host of change SendHostMessage(LFSTA); @@ -398,13 +412,20 @@ case DESIG_EXIT: // Transitional state + // Status LEDs + LF28A_status.LED(LED_DESIG, LED_OFF); + mode = RANGE_ENTRY; break; // RANGE MODEs case RANGE_ENTRY: // Transitional state + // Status LEDs + LF28A_status.LED(LED_RANGE, LED_ON); + //Display current STANAG Code + LF28A_display.printf("Range "); // Inform Host of change SendHostMessage(LFSTA); @@ -443,6 +464,10 @@ break; case RANGE_EXIT: // Transitional state + + // Status LEDs + LF28A_status.LED(LED_RANGE, LED_OFF); + mode = CODE_ENTRY; break; @@ -450,9 +475,13 @@ // CODE MODEs case CODE_ENTRY: // Transitional state - + + // Status LEDs + LF28A_status.LED(LED_CODE, LED_ON); + //Display current STANAG Code - + LF28A_display.printf("Code "); + // Inform Host of change SendHostMessage(LFSTA); @@ -529,7 +558,7 @@ case KEY_F_L_UP : //Incr current digit STANAG_code.incDigitIdx(); - // Inform Host of change ro wait untip done editing ?? + // Inform Host of change or wait until done editing ?? //SendHostMessage(LFSTA); break; @@ -542,7 +571,10 @@ break; case CODE_EXIT: // Transitional state - + + // Status LEDs + LF28A_status.LED(LED_CODE, LED_OFF); + mode = DESIG_ENTRY; break;