Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Tue Aug 23 20:26:05 2011 +0000
Parent:
3:3fbfdec782f4
Child:
5:38b853bb1afa
Commit message:
Test version for breadboard, using STANAG Edits

Changed in this revision

Keyboard.cpp Show annotated file Show diff for this revision Revisions of this file
Keyboard.h Show annotated file Show diff for this revision Revisions of this file
MBED_ControlBus.h Show annotated file Show diff for this revision Revisions of this file
Testloop.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Keyboard.cpp	Sun Aug 21 19:42:48 2011 +0000
+++ b/Keyboard.cpp	Tue Aug 23 20:26:05 2011 +0000
@@ -49,7 +49,8 @@
     // CDA Key pressed  
     _KeyReady = true;
         
-    data = _read();    // Get the switchvalue and decode it    
+    // Get the switchvalue and decode it
+    data = _read() & D_KEYBOARD_MASK;       
     switch (data) {
       case D_KEYBOARD_MODE:      _KeyCode = KEY_MODE;
                                  break;
--- a/Keyboard.h	Sun Aug 21 19:42:48 2011 +0000
+++ b/Keyboard.h	Tue Aug 23 20:26:05 2011 +0000
@@ -24,8 +24,8 @@
 #define D_KEYBOARD_F_L_UP           0x06
 #define D_KEYBOARD_NOTUSED_7        0x07
 
-// Masks for keyboard codes, bit 7 not used
-#define D_KEYBOARD_MASK             0x7F 
+// Masks for keyboard codes, bit 4-7 not used
+#define D_KEYBOARD_MASK             0x0F 
 
 //Enums for Keyboard codes
 enum Key_Code { KEY_NONE, KEY_MODE, KEY_EDIT_PATH, KEY_BRIGHT, KEY_GRAT_RT, KEY_F_L_UP, KEY_FIRE };
--- a/MBED_ControlBus.h	Sun Aug 21 19:42:48 2011 +0000
+++ b/MBED_ControlBus.h	Tue Aug 23 20:26:05 2011 +0000
@@ -46,7 +46,7 @@
 //    InterruptIn  _CDINT; // Keyboard interrupt pin
 //    InterruptIn  _FIRE;  // Fire interrupt pin
 
-//Debounced and Edge detected input pin (Andy Kirkmans's Lib
+//Debounced and Edge detected input pin (Andy Kirkmans's Lib)
     PinDetect  _CDINT; // Keyboard interrupt pin    
     PinDetect  _FIRE;  // Fire interrupt pin
         
--- a/Testloop.h	Sun Aug 21 19:42:48 2011 +0000
+++ b/Testloop.h	Tue Aug 23 20:26:05 2011 +0000
@@ -39,16 +39,19 @@
     pc.printf("8: Inc STANAG Digit\r");                                    
     pc.printf("9: Test I2C Databus\r");                                        
     pc.printf("A: Test I2C Addressbus\r");                                        
-    pc.printf("B: Test I2C Enablebus\r");        
-    pc.printf("C: Test Status LEDs\r");            
-    pc.printf("D: Test Brightness LEDs\r");                
-    pc.printf("E: Test Display\r");                    
+    pc.printf("E: Test I2C Enablebus\r");        
+    pc.printf("S: Test Status LEDs\r");            
+    pc.printf("B: Test Brightness LEDs\r");                
+    pc.printf("D: Test Display\r");                    
+    pc.printf("K: Test Keyboard\r");                        
+    pc.printf("N: Test STANAG\r");                            
     pc.printf("\r");                
 }
 
 
 void testloop() {
   bool running=true;
+  bool run_test=true;  
   char command;
   int count;
   
@@ -159,7 +162,7 @@
                       
                       break;
  
-          case 'B' :
+          case 'E' :
                       pc.printf("Test I2C Enablebus\r"); 
                       pc.printf("Press any key to quit...");
                       count=0;                       
@@ -224,7 +227,7 @@
                       
                       break;
                       
-          case 'C' :
+          case 'S' :
                       pc.printf("Test Status LEDs\r"); 
                       pc.printf("Press any key to quit...");
                       count=0;                       
@@ -299,7 +302,7 @@
                       
                       break;                      
 
-          case 'D' :
+          case 'B' :
                       pc.printf("Test Brightness LEDs\r"); 
                       pc.printf("Press any key to quit...");
 
@@ -330,7 +333,7 @@
                       
                       break;  
                       
-          case 'E' :
+          case 'D' :
                       pc.printf("Test Display\r"); 
                       pc.printf("Press any key to continue...");
 
@@ -387,8 +390,120 @@
                                             
                       pc.printf("..Done\r");                      
                       
-                      break;                                           
+                      break; 
+                      
+           case 'K' :
+                      pc.printf("Test Keyboard\r"); 
+                      pc.printf("Press any key to continue...");
+
+
+                      while(! pc.readable()) {
+                         if (LF28A_keyboard.readable()) {
+                           pc.printf(".");
+                           
+                           keycode = LF28A_keyboard.getkey();
+                           switch (keycode) {
+                             case KEY_MODE :
+                                                    pc.printf("Mode\r");                             
+                                                    break;
+                             case KEY_EDIT_PATH :
+                                                    pc.printf("Edit\r");                                                          
+                                                    break;
+                             case KEY_BRIGHT :
+                                                    pc.printf("Bright\r");                             
+                                                    break;                               
+                             case KEY_GRAT_RT :
+                                                    pc.printf("Grat\r");                             
+                                                    break;
+                             case KEY_F_L_UP :
+                                                    pc.printf("F-L\r");                             
+                                                    break;
+                             case KEY_FIRE:
+                                                    pc.printf("Fire\r");                             
+                                                    break;                               
+                             case KEY_NONE:
+                                                    pc.printf("None\r");                             
+                                                    break;              
+                                                    
+                             default:  
+                                                    pc.printf("Oops\r");                             
+                                                    break;                               
+                           }; //switch
+                           
+                         } //if
+                      } //while                      
+                      command = pc.getc();                     
+                       
+                      pc.printf("..Done\r");                      
+                      
+                      break;                      
                               
+
+          case 'N' :
+                      pc.printf("Test STANAG\r");
+                                                
+                      pc.printf("Code = %04d; CodeIdx=%d; DigitIdx=%d;\r", STANAG_codes.getCode(), STANAG_codes.getCodeIdx(), STANAG_codes.getDigitIdx() );                      
+
+                      LF28A_display.locate (0);                      
+                      LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                      
+                      LF28A_display.set_flash_mode(true);                      
+                                         
+                      run_test=true;  
+                      while(run_test) {
+                        while(! pc.readable()) {
+                        }
+                        command = pc.getc();
+                        switch(command) {                                                                     
+                          case '0': run_test=false;
+                                    break;
+                          case '1':
+                                    pc.printf("0: Exit\r");
+                                    pc.printf("1: Show Menu\r");    
+                                    pc.printf("f: Next Code\r");                                     
+                                    pc.printf("g: Next Digit\r");                                                                         
+                                    pc.printf("u: Inc Digit\r");                                                                                                             
+                                    break;
+    
+                          case 'f': 
+                                    pc.printf("New Code Idx = %d\r", STANAG_codes.incCodeIdx() );                          
+                                    pc.printf("New Code = %04d\r", STANAG_codes.getCode() );                                                          
+                                    
+                                    LF28A_display.locate (0);                      
+                                    LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                      
+                                                                                                                                  
+                                    break;
+                          case 'g': 
+                                    // Disable previous flashing digit
+                                    LF28A_display.set_char_flash_state(false, 4 + STANAG_codes.getDigitIdx());                          
+                                    
+                                    // Incr selected digit
+                                    pc.printf("New Digit Idx = %d\r", STANAG_codes.incDigitIdx() );
+
+                                    // Enable current flashing digit
+                                    LF28A_display.set_char_flash_state(true, 4 + STANAG_codes.getDigitIdx());                          
+
+                                    break;
+                          case 'u': 
+                                    pc.printf("New Digit = %d\r", STANAG_codes.incDigit() );
+                                    pc.printf("New Code = %04d\r", STANAG_codes.getCode() );                                                         
+                                    
+                                    LF28A_display.locate (0);                      
+                                    LF28A_display.printf ("    %04d",STANAG_codes.getCode() );                      
+                                    
+                                    break;
+                          default:  
+                                    pc.printf("Oops\r");                             
+                                    break;                               
+                        }; //switch
+                      } //while run_test                      
+
+
+                      LF28A_display.set_flash_mode(false);
+                                            
+                      pc.printf("..Done\r");                                                                
+                        
+                      break;
+
         } //switch
       }//if
     }//while
--- 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;