New work version with additional functions

Dependencies:   4DGL-UC ConfigFile MODSERIAL mbed mbos

Fork of CDU_Mbed_35 by Engravity-CDU

Revision:
20:2d6ac4577e68
Parent:
17:b3545e9d38f7
--- a/keyboard2.cpp	Thu Aug 28 14:39:32 2014 +0000
+++ b/keyboard2.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -9,7 +9,7 @@
 #include "pins.h"
  
 const int CDU_KB_ADRS  = 0x68;  //Base address TCA8418 keypad scanner
-const int I2C_ACK  = 0x00;
+const int I2C_ACK      = 0x00;
 //const int NACK = 0x01;
  
 extern int key_hit_ID;
@@ -18,7 +18,7 @@
  
 //CDU Keyboard communications KEYBOARD_INT
 InterruptIn CDU_KB_INT( KBD_INT );  //Set CDU keyboard interrupt line
-I2C CDU_I2C(I2C_SDA, I2C_SCL);         //I2C bus for keyboard/temp chip.
+I2C CDU_I2C(I2C_SDA, I2C_SCL);      //I2C bus for keyboard/temp chip.
  
 //CDU Keyboard LEDS
 DigitalOut EXEC( LED_EXEC );
@@ -37,10 +37,18 @@
  
 void CDU_KB_COMM_INIT()
 {   //initialize communication with TCA84818
+    //Switch off Annunciatorleds and backlighting 
+    EXEC=0;
+    FAIL=0;
+    DSPY=0;
+    MSG=0;
+    OFST=0;
+    BGL_LED=0;
+    
     char cmd[2];
     Key_led = 0;
     cmd[0] = REG_CFG; //pointer byte to CFG register
-    cmd[1] = 0x01; //data for CFG register KE_IEN set to 1
+    cmd[1] = 0x01;    //data for CFG register KE_IEN set to 1
     if ( CDU_I2C.write(CDU_KB_ADRS,cmd, 2) == I2C_ACK ) //initiate write cycle and check for ACK
     {
         //intialize all registers from TCA8418 here
@@ -70,8 +78,7 @@
 }
  
 void CDU_KB_GET_KEY()
-{
-        
+{       
     Key_led = !Key_led;  // : toggle LED 2
           
     char cmd[2];
@@ -90,7 +97,7 @@
     CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle
     CDU_I2C.read(CDU_KB_ADRS, cmd, 2);  //read key value (=2 words)
     
-    key_hit_ID =  int(cmd[0]);
+    key_hit_ID =  int(cmd[0]);          //write pressed key_ID to global variable
     
         //SERIAL_DEBUG.printf("keynumber : %d,%d\r\n",key_hit_ID,cmd[1] ); // : TEST only !
  
@@ -99,7 +106,7 @@
     cmd[1] = 0x01; //Reset KE-INT flag
     CDU_I2C.write(CDU_KB_ADRS,cmd, 2);
     
-     //Read interrupt status flag   
+    //Read interrupt status flag   
     cmd[0] = 0x02; //pointer byte to Interrupt Status Register
     CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle
     CDU_I2C.read(CDU_KB_ADRS, cmd, 1);  //read interrupt value
@@ -122,9 +129,14 @@
             CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle
             CDU_I2C.read(CDU_KB_ADRS, cmd, 1);  //read interrupt value
            
-            if ( cmd[0] == 0 ) break;
+            if ( cmd[0] == 0 ) 
+                { 
+                    Key_led = 0;
+                    break;
+                }
         }   
     }
+
 } 
  
 void SET_KEY_EVENT()
@@ -139,6 +151,7 @@
     CDU_KB_INT.fall(&SET_KEY_EVENT);   //Bind function to handle interrupt
 }
 
+
 void CDU_SET_BGL_INTENSITY( int nVal=255 )
 {
     //This routine must be called 5-10x per second. Manual test to see what is pleasant to see
@@ -165,7 +178,7 @@
         case 100:
         {
             //switch on backlighting to normal
-            BGL_LED = BGL_POT;
+            BGL_LED = BGL_POT*float(BGL_SCALE/100.0);
             LightOn = 1;
             FullBright = 0;
             break;
@@ -174,7 +187,7 @@
         case 128:
         {
             //switch backlighting to MAX
-            BGL_LED= 1;
+            BGL_LED= 1*float(BGL_SCALE/100.0);
             FullBright = 1;   
         }
     
@@ -189,12 +202,12 @@
                     }
                 else
                     {
-                        BGL_LED = BGL_POT; 
+                        BGL_LED = BGL_POT*float(BGL_SCALE/100.0); 
                     }
             }
             else  if ( ( LightOn == 1) && (FullBright== 1) ) 
             {
-                BGL_LED = 1;
+                BGL_LED = 1*float(BGL_SCALE/100.0);
                 
             }
         }