Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Revision:
4:745fbbd5e4e5
Parent:
3:3fbfdec782f4
Child:
5:38b853bb1afa
--- a/main.cpp	Sun Aug 21 19:42:48 2011 +0000
+++ b/main.cpp	Tue Aug 23 20:26:05 2011 +0000
@@ -78,6 +78,7 @@
 Brightness brightness, graticule; 
 Key_Code keycode;
 Range_t range;
+bool laser;
 bool hostResetCmd;
 MessageToHost messageToHost;
 STANAG_Codes STANAG_codes;
@@ -169,6 +170,8 @@
     range.first = 0;
     range.select = RNG_F;
 
+    laser = false;
+
 // Read Config File if needed..
 // Reload STANAG Codes ?
     STANAG_codes.setCodeIdx(0);
@@ -354,7 +357,7 @@
                            // Inform Host that Init has completed
                             if (!hostResetCmd) {
                               // Regular PowerOn Reset                                                        
-                              SendHostMessage(LFRDY_0)
+                              SendHostMessage(LFRDY_0);
                             }
                             else {
                               // Host initiated a Reset
@@ -376,7 +379,8 @@
                             LF28A_status.LED(LED_DESIG, LED_ON);
 
                             //Display current STANAG Code
-                            LF28A_display.printf("Designat");
+                            LF28A_display.locate (0);                      
+                            LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                      
                           
                             // Inform Host of change
                             SendHostMessage(LFSTA);  
@@ -424,8 +428,9 @@
                             // Status LEDs
                             LF28A_status.LED(LED_RANGE, LED_ON);
                   
-                            //Display current STANAG Code
-                            LF28A_display.printf("Range   ");                            
+                            //Display current STANAG Code ...Is this correct on entry ??
+                            LF28A_display.locate (0);                      
+                            LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                      
                             
                             // Inform Host of change
                             SendHostMessage(LFSTA);  
@@ -451,23 +456,78 @@
 
                                 case KEY_MODE:    mode = RANGE_EXIT;
                                                   break;                              
+
+                                case KEY_F_L_UP : //Toggle First/Last
+                                                  range_selector();                                
+
+                                                  //Display current Range
+                                                  if (range.select == RNG_F) {
+                                                    LF28A_display.locate (0);                      
+                                                    LF28A_display.printf ("F   %04d", range.first );
+                                                  }
+                                                  else {
+                                                    LF28A_display.locate (0);                      
+                                                    LF28A_display.printf ("F   %04d", range.last);                                                     
+                                                  };
+                                                                                                 
+                                                  // Inform Host of change ??
+                                                  //SendHostMessage(LFSTA);  
+                                                  
+                                                  break;
+
+
+                                case KEY_FIRE:    // Check and handle Fire key
+                                                  
+                                                  // Toggle Laser On/Off
+                                                  if (laser) {
+                                                    // Laser is On, Switch Off
+
+                                                    // Status LEDs
+                                                    LF28A_status.LED(LED_LASER, LED_ON);
+                                                    
+                                                  }
+                                                  else {
+                                                    // Laser is Off, Switch On                                                  
+
+                                                    // Status LEDs
+                                                    LF28A_status.LED(LED_LASER, LED_ON);
+                                                     
+                                                    // Automatic Time-out needed
+                                                     
+                                                  };
+                                                  
+                                                  // Inform Host of change (laser on/off)
+                                                  SendHostMessage(LFSTA);  
+                                
+                                                  break;                              
   
                                 default:          // Ignore other keys
                                                   break;                                                              
                               }; //End Keyswitch            
                             }; // End Keyread          
 
-                            // Check and handle Fire key
-                            // Toggle Laser On/Off
-                            // Update and show Range, Toggle First/Last Range
+#if (0)
+                            // tbd Check Automatic Time-out for Laser
+                            Timer.stop()
+                            laser = false;
+                            // Status LEDs
+                            LF28A_status.LED(LED_LASER, LED_ON);
+#endif
 
                             break;                              
 
           case RANGE_EXIT:  // Transitional state
+
+#if (0)
+                            // tbd Check Automatic Time-out for Laser
+                            Timer.stop()
+                            laser = false;
+                            // Status LEDs
+                            LF28A_status.LED(LED_LASER, LED_ON);
+#endif
           
                             // Status LEDs
                             LF28A_status.LED(LED_RANGE, LED_OFF);
-          
 
                             mode = CODE_ENTRY;
                             break;                              
@@ -478,10 +538,14 @@
 
                             // Status LEDs
                             LF28A_status.LED(LED_CODE, LED_ON);          
-                    
+          
+                            //Enable flashing Code                                
+                            LF28A_display.set_flash_mode(true);
+ 
                             //Display current STANAG Code
-                            LF28A_display.printf("Code    "); 
-                                                        
+                            LF28A_display.locate (0);                      
+                            LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                      
+ 
                             // Inform Host of change
                             SendHostMessage(LFSTA);  
                             
@@ -507,13 +571,21 @@
                                 case KEY_MODE:    mode = CODE_EXIT;
                                                   break;                              
 
-                                case KEY_EDIT:    mode = CODE_EDIT;
+                                case KEY_EDIT_PATH:
+                                                  mode = CODE_EDIT;
+                                                  
+                                                  // Enable current flashing digit
+                                                  LF28A_display.set_char_flash_state(true, 4 + STANAG_codes.getDigitIdx());                          
+                                                                                                                                                         
                                                   break;                              
 
                                 case KEY_F_L_UP : //Incr STANAG code idx
-                                                  STANAG_code.incIdx();
+                                                  STANAG_codes.incCodeIdx();
                                                   
-                                                  //Display current STANAG Code                                                  
+                                                  //Display current STANAG Code
+                                                  LF28A_display.locate (0);                      
+                                                  LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                      
+                                                                                                   
 
                                                   // Inform Host of change ??
                                                   //SendHostMessage(LFSTA);  
@@ -534,12 +606,25 @@
 
                               switch (keycode) {
                                 case KEY_GRAT_RT: //Cursor Right;
+                                                  // Disable current flashing digit
+                                                  LF28A_display.set_char_flash_state(false, 4 + STANAG_codes.getDigitIdx());                          
+
+                                                  // Incr selected digit
+                                                  STANAG_codes.incDigitIdx();
+
+                                                  // Enable current flashing digit
+                                                  LF28A_display.set_char_flash_state(true, 4 + STANAG_codes.getDigitIdx());                          
+                                
                                                   break;
 
                                 case KEY_BRIGHT:  disp_bright_selector();
                                                   break;                              
 
-                                case KEY_MODE:                                                     
+                                case KEY_MODE:    // Done, exit Code mode
+                                                                                    
+                                                  // Disable current flashing digit
+                                                  LF28A_display.set_char_flash_state(false, 4 + STANAG_codes.getDigitIdx());                          
+                                
                                                   // Inform Host of change
                                                   SendHostMessage(LFSTA);  
                                                   
@@ -547,7 +632,11 @@
                                                   
                                                   break;                              
 
-                                case KEY_EDIT:
+                                case KEY_EDIT_PATH: // Done, return to Code display mode
+                                
+                                                  // Disable current flashing digit
+                                                  LF28A_display.set_char_flash_state(false, 4 + STANAG_codes.getDigitIdx());                          
+                                 
                                                   // Inform Host of change
                                                   SendHostMessage(LFSTA);  
                                 
@@ -556,7 +645,11 @@
                                                   break;                              
 
                                 case KEY_F_L_UP : //Incr current digit
-                                                  STANAG_code.incDigitIdx();
+                                                  STANAG_codes.incDigitIdx();
+
+                                                  // Display Current STANAG Code
+                                                  LF28A_display.locate (0);                      
+                                                  LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                                                                       
                                 
                                                   // Inform Host of change or wait until done editing ??
                                                   //SendHostMessage(LFSTA);  
@@ -573,8 +666,11 @@
           case CODE_EXIT:  // Transitional state
           
                             // Status LEDs
-                            LF28A_status.LED(LED_CODE, LED_OFF);          
-          
+                            LF28A_status.LED(LED_CODE, LED_OFF); 
+
+                            //Disable flashing Code                                
+                            LF28A_display.set_flash_mode(false);
+                                            
                             mode = DESIG_ENTRY;
                             break;