New work version with additional functions

Dependencies:   4DGL-UC ConfigFile MODSERIAL mbed mbos

Fork of CDU_Mbed_35 by Engravity-CDU

Files at this revision

API Documentation at this revision

Comitter:
WillemBraat
Date:
Wed Oct 08 14:14:52 2014 +0000
Parent:
19:9d8032cb0f12
Commit message:
New release with additional new functions.
; * File handling for config files
; * CDU setup & test screens
; * External power monitoring

Changed in this revision

4DGL.lib Show annotated file Show diff for this revision Revisions of this file
CDU_Config.cpp Show annotated file Show diff for this revision Revisions of this file
CDU_Maintenance.cpp Show annotated file Show diff for this revision Revisions of this file
CDU_hw_sw.cpp Show annotated file Show diff for this revision Revisions of this file
CDU_hw_sw.h Show annotated file Show diff for this revision Revisions of this file
ConfigFile.lib Show annotated file Show diff for this revision Revisions of this file
display.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
keyboard2.cpp Show annotated file Show diff for this revision Revisions of this file
keys.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
main.h Show annotated file Show diff for this revision Revisions of this file
mbos_def2.h Show annotated file Show diff for this revision Revisions of this file
pins.h Show annotated file Show diff for this revision Revisions of this file
screen_handler.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9d8032cb0f12 -r 2d6ac4577e68 4DGL.lib
--- a/4DGL.lib	Thu Aug 28 14:39:32 2014 +0000
+++ b/4DGL.lib	Wed Oct 08 14:14:52 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Engravity-CDU/code/4DGL-UC/#f90479eeca36
+http://mbed.org/teams/Engravity-CDU/code/4DGL-UC/#9641fb4ceff3
diff -r 9d8032cb0f12 -r 2d6ac4577e68 CDU_Config.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CDU_Config.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -0,0 +1,137 @@
+/**
+ * Test program for configuration file interface class (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+#include "mbed.h"
+#include "ConfigFile.h"
+
+ConfigFile cfg;
+LocalFileSystem local("local");
+//Serial pc(USBTX, USBRX); // tx, rx
+
+/**
+ * View the list.
+ */
+void viewlist(void) {
+    /*
+     * If you need to check all parameters.
+     */
+    const int cnt = cfg.getCount();
+    char buf_key[BUFSIZ];
+    char buf_value[BUFSIZ];
+    for (int i = 0; i < cnt; i++) {
+        if (cfg.getKeyAndValue(i, buf_key, sizeof(buf_key), buf_value, sizeof(buf_value))) {
+            printf("No.%3d:'%s'='%s'\n", i, buf_key, buf_value);
+        } else {
+            printf("No.%3d:Failure to get a configuration.\n", i);
+        }
+    }
+}
+
+/**
+ * ==================================================
+ * Input file (input.cfg)
+ * ==================================================
+ * #
+ * # Configuration file for mbed.
+ * #
+ *
+ * MyKey1=This is a value for key1.
+ * MyKey2=Value 2
+ *
+ * Message1 = This is a test message no.1
+ *  Message2 = This is a test message no.2
+ *   Message3 = This is a test message no.3
+ *
+ * ==================================================
+ * Output file (output1.cfg)
+ * ==================================================
+ * MyKey1=This is a value for key1.
+ * MyKey2=Value 2
+ * Message1 = This is a test message no.1
+ *  Message2  =  This is a test message no.2
+ *   Message3   =   This is a test message no.3
+ *
+ * ==================================================
+ * Output file (output2.txt)
+ * ==================================================
+ * # This is a configuration file for my application.
+ * ABC=123
+ * DEF=456
+ *
+ * ==================================================
+ * Console output
+ * ==================================================
+ * 'MyKey1'='This is a value for key1.'
+ * 'MyKey2'='Value 2'
+ * 'Message1 '=' This is a test message no.1'
+ * ' Message2  '='  This is a test message no.2'
+ * '  Message3   '='   This is a test message no.3'
+ *
+ */
+int ReadConfig() {
+
+    char *key1 = "Baudrate";
+    char *key2 = "Databits";
+    char *key3 = "Parity ";
+    char *key4 = "Stopbit";
+    
+    char *key5 = "USB-Ethernet";
+    
+    
+    char value[BUFSIZ];
+
+    /*
+     * Read a configuration file from a mbed.
+     */
+    cfg.read("/local/input.cfg");
+
+    /*
+     * Read a configuration value.
+     */
+    if (cfg.getValue(key1, &value[0], sizeof(value))) {
+        printf("'%s'='%s'\n", key1, value);
+    }
+
+    if (cfg.getValue(key2, &value[0], sizeof(value))) {
+        printf("'%s'='%s'\n", key2, value);
+    }
+
+    if (cfg.getValue(key3, &value[0], sizeof(value))) {
+        printf("'%s'='%s'\n", key3, value);
+    }
+
+    if (cfg.getValue(key4, &value[0], sizeof(value))) {
+        printf("'%s'='%s'\n", key4, value);
+    }
+
+    if (cfg.getValue(key5, &value[0], sizeof(value))) {
+        printf("'%s'='%s'\n", key5, value);
+    }
+
+    /*
+     * Write a configuration file to a mbed.
+     */
+    cfg.write("/local/output1.cfg");
+
+    /*
+     * Remove all configurations.
+     */
+    cfg.removeAll();
+
+    /*
+     * Write a configuration value.
+     */
+    cfg.setValue("ABC", "123");
+    cfg.setValue("DEF", "456");
+
+    /*
+     * Write a configuration file to a mbed.
+     */
+    cfg.write("/local/output2.cfg", "# This is a configuration file for my application.");
+
+    while (1) {
+    }
+}
diff -r 9d8032cb0f12 -r 2d6ac4577e68 CDU_Maintenance.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CDU_Maintenance.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -0,0 +1,146 @@
+/****************************************************************************/
+/* This file contains entry points to setup and test procedures for the CDU */
+/* Prerequisitions:                                                         */
+/* 1. S-EXEC flag must be set to avoid interference from fs communications  */
+/* 2. Keyboard interrupt routine must be redefined                          */
+/****************************************************************************/
+
+#include "mbed.h"
+#include "TFT_4DGL.h"
+#include "display.h"
+
+#include <string>
+using namespace std;
+
+void CDU_ScreenAlign();
+void CDU_displayclear();
+void ExitKey( string cTitleText );
+
+extern TFT_4DGL display; 
+//extern void CDU_KB_INT_DISABLE(); //disable keyhandler and start internal keyhandler
+extern int key_hit_ID;
+
+//int righttext( string cString, int nChars, int nCharWidth )
+//int centertext( string cString, int nChars, int nCharWidth )
+extern char* str2char( string cString );
+extern int righttext( string cString, int nChars, int nCharWidth );
+extern int centertext( string cString, int nChars, int nCharWidth );
+
+
+void CDU_Maint()
+// Main selection screen SETUP and MAINT
+{
+    ExitKey( "CDU MAINTENANCE");
+    display.graphic_string( str2char( "< SETUP" ), 0, LINE3, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "LIGHT TEST >" ), righttext( "LIGHT TEST >", 24,24) , LINE3, FONT_24X34, WHITE, 2, 2 );     
+    display.graphic_string( str2char( "KEYBOARD TEST >" ), righttext( "KEYBOARD TEST >", 24,24) , LINE5, FONT_24X34, WHITE, 2, 2 );         
+    display.graphic_string( str2char( "FIRMWARE >" ), righttext( "FIRMWARE >", 24,24) , LINE9, FONT_24X34, WHITE, 2, 2 );
+}
+
+//Setup screens
+void CDU_Setup()
+{
+    ExitKey( "CDU SETUP" );
+    display.graphic_string( str2char( "< USB" ), 0, LINE3, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "< ETHERNET" ), 0, LINE5, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "DISPLAY SOURCE >" ), righttext( "DISPLAY SOURCE >", 24,24) , LINE9, FONT_24X34, WHITE, 2, 2 );     
+}
+
+
+void CDU_USB_Setup()
+{
+    ExitKey( "CDU USB SETUP" );
+    display.graphic_string( str2char( "< BAUDRATE" ), 0, LINE3, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "< DATABITS" ), 0, LINE5, FONT_24X34, WHITE, 2, 2 );        
+    display.graphic_string( str2char( "< PARITY" ), 0, LINE7, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "< STOPBITS" ), 0, LINE9, FONT_24X34, WHITE, 2, 2 ); 
+}
+
+void CDU_Ethernet_Setup()
+{
+    ExitKey( "CDU ETHERNET SETUP" );
+    display.graphic_string( str2char( "< AUTO IP" ), 0, LINE3, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "< IP ADDRESS" ), 0, LINE5, FONT_24X34, WHITE, 2, 2 );        
+    display.graphic_string( str2char( "< GATEWAY" ), 0, LINE7, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "< MAC ADDRESS" ), 0, LINE9, FONT_24X34, WHITE, 2, 2 );    
+    
+}
+
+
+void CDU_Source_Setup()
+{
+    ExitKey( "CDU VIDEO SOURCE" );
+    display.graphic_string( str2char( "< INTERNAL" ), 0, LINE3, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "EXTERNAL >" ), righttext( "EXTERNAL >", 24,24) , LINE3, FONT_24X34, WHITE, 2, 2 );   
+}
+
+
+
+//Maintenance screens
+
+void CDU_FW_Update()
+{
+    ExitKey( "FIRMWARE UPDATE" );
+    display.graphic_string( str2char( "REBOOT CDU >" ), righttext( "REBOOT CDU >", 24,24) , LINE3, FONT_24X34, WHITE, 2, 2 );   
+}
+
+void CDU_LightTest()
+{
+    ExitKey( "CDU LIGHT TEST" );
+    display.graphic_string( str2char( "< BACKLIGHT" ), 0, LINE3, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "*=ON" ), centertext( "*=ON", 24, 24 ), LINE2, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "----ANNUNCIATOR TEST----" ), 0, LINE4, FONT_24X34, WHITE, 2, 2 );  
+       
+    display.graphic_string( str2char( "< DSP" ), 0, LINE7, FONT_24X34, RED, 2, 2 );        
+    display.graphic_string( str2char( "< FAIL" ), 0, LINE9, FONT_24X34, RED, 2, 2 ); 
+    
+    display.graphic_string( str2char( "EXEC >" ), righttext( "EXEC >", 24,24) , LINE5, FONT_24X34, GREEN, 2, 2 );  
+    display.graphic_string( str2char( "MSG >" ),  righttext( "MSG >", 24,24) ,  LINE7, FONT_24X34, YELLOW, 2, 2 );  
+    display.graphic_string( str2char( "OFST >" ), righttext( "OFST >", 24,24) , LINE9, FONT_24X34, YELLOW, 2, 2 );              
+}
+
+void CDU_KeyboardTest()
+{
+    ExitKey( "CDU KEYBOARD TEST");
+    display.graphic_string( str2char( "KEYSCAN CODE: " ), 0, LINE6, FONT_24X34, WHITE, 2, 2 );   
+    display.graphic_string( str2char( "FS KEY VALUE: " ), 0, LINE7, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "PRESS 2x [EXEC]" ), 6, LINE12, FONT_24X34, WHITE, 2, 2 );        
+}
+
+void ExitKey( string cTitleText )
+{
+    //clear screen and place exit text
+    CDU_displayclear();
+    display.graphic_string( str2char( cTitleText ), centertext( cTitleText, 24, 24 ), LINE1, FONT_24X34, WHITE, 2, 2 ); 
+    display.graphic_string( str2char( "< EXIT" ), 0, LINE13, FONT_24X34, WHITE, 2, 2 ); 
+}
+
+//Show all setup screens
+
+void CDU_Screens()
+{
+    CDU_Maint();
+    wait_ms( 4000 );
+    
+    CDU_Setup();
+    wait_ms( 4000 );
+    
+    CDU_USB_Setup();
+    wait_ms( 4000 );
+
+    CDU_Ethernet_Setup();
+    wait_ms( 4000 );
+    
+    CDU_Source_Setup();
+    wait_ms( 4000 );
+    
+    CDU_LightTest();
+    wait_ms( 4000);
+    
+    CDU_KeyboardTest();
+    wait_ms( 4000 );
+
+    CDU_FW_Update();
+    wait_ms( 4000 );
+   
+}
\ No newline at end of file
diff -r 9d8032cb0f12 -r 2d6ac4577e68 CDU_hw_sw.cpp
--- a/CDU_hw_sw.cpp	Thu Aug 28 14:39:32 2014 +0000
+++ b/CDU_hw_sw.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -3,6 +3,7 @@
 #include "pins.h"
 
 extern "C" void mbed_mac_address(char *mac); //for reading MAC Address
+extern "C" void mbed_reset();                //reboot CDU
 
 string CDU_Hardware()
 {
@@ -63,4 +64,9 @@
     string cIP = "IP address: ";
     cIP += "000:000:000:000 (not defined)";
     return cIP;
+}
+
+void CDU_BOOT()
+{
+    mbed_reset();
 }
\ No newline at end of file
diff -r 9d8032cb0f12 -r 2d6ac4577e68 CDU_hw_sw.h
--- a/CDU_hw_sw.h	Thu Aug 28 14:39:32 2014 +0000
+++ b/CDU_hw_sw.h	Wed Oct 08 14:14:52 2014 +0000
@@ -4,4 +4,4 @@
 
 //**********Software Version**********
 #define SW_VERSION_MAIN 0
-#define SW_VERSION_SUB  35
\ No newline at end of file
+#define SW_VERSION_SUB  36
\ No newline at end of file
diff -r 9d8032cb0f12 -r 2d6ac4577e68 ConfigFile.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ConfigFile.lib	Wed Oct 08 14:14:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Engravity-CDU/code/ConfigFile/#b0224b2c20fd
diff -r 9d8032cb0f12 -r 2d6ac4577e68 display.cpp
--- a/display.cpp	Thu Aug 28 14:39:32 2014 +0000
+++ b/display.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -13,6 +13,8 @@
 extern string CDU_MAC();
 extern string CDU_IP();
 
+
+
 DigitalOut VGA_SOURCE( VGA_SOURCE_SELECT ); //control line for video switch between INT and EXT video
 DigitalOut VGA_SELECT( VGA_ON_OFF ); //control line to select/deselect video switch
 /*
@@ -301,10 +303,33 @@
 
 void CDU_InitDisplay()
 {
-    display.baudrate( 9600 );       //init uVGAIII card
-    VGA_SIGNAL( VGA_INT, VGA_ON );  //select INTERNTAL video and set VGA switch ON
+    display.baudrate( BAUD_38400 );       //init uVGAIII card
+    VGA_SIGNAL( VGA_INT, VGA_ON );        //select INTERNTAL video and set VGA switch ON
 }
 
+void CDU_ScreenAlign()
+//Draw a wireframe for aligning the screen on display with keys
+{
+    display.cls();
+   
+    display.pen_size(WIREFRAME);
+    display.rectangle(XMIN,YMIN,XMAX,YMAX, WHITE);
+    display.line(XMIN,LINE2,XMAX,LINE2, WHITE);
+    display.line(XMIN,LINE3,XMAX,LINE3, WHITE);
+    display.line(XMIN,LINE4,XMAX,LINE4, WHITE);
+    display.line(XMIN,LINE5,XMAX,LINE5, WHITE);
+    display.line(XMIN,LINE6,XMAX,LINE6, WHITE);
+    display.line(XMIN,LINE7,XMAX,LINE7, WHITE);
+    display.line(XMIN,LINE8,XMAX,LINE8, WHITE);
+    display.line(XMIN,LINE9,XMAX,LINE9, WHITE);
+    display.line(XMIN,LINE10,XMAX,LINE10, WHITE);
+    display.line(XMIN,LINE11,XMAX,LINE11, WHITE);
+    display.line(XMIN,LINE12,XMAX,LINE12, WHITE);
+    display.line(XMIN,LINE13,XMAX,LINE13, WHITE);
+    display.line(XMIN,LINE14,XMAX,LINE14, WHITE);
+}
+
+
 
 void CDU_StartScreen()
 {
@@ -333,38 +358,24 @@
     wait_ms(5000);    
 }
 
-void CDU_ScreenAlign()
-//Draw a wireframe for aligning the screen on display with keys
+
+void CDU_TestScreen()
 {
     display.cls();
-   
-    display.pen_size(WIREFRAME);
-    display.rectangle(XMIN,YMIN,XMAX,YMAX, WHITE);
-    display.line(XMIN,LINE2,XMAX,LINE2, WHITE);
-    display.line(XMIN,LINE3,XMAX,LINE3, WHITE);
-    display.line(XMIN,LINE4,XMAX,LINE4, WHITE);
-    display.line(XMIN,LINE5,XMAX,LINE5, WHITE);
-    display.line(XMIN,LINE6,XMAX,LINE6, WHITE);
-    display.line(XMIN,LINE7,XMAX,LINE7, WHITE);
-    display.line(XMIN,LINE8,XMAX,LINE8, WHITE);
-    display.line(XMIN,LINE9,XMAX,LINE9, WHITE);
-    display.line(XMIN,LINE10,XMAX,LINE10, WHITE);
-    display.line(XMIN,LINE11,XMAX,LINE11, WHITE);
-    display.line(XMIN,LINE12,XMAX,LINE12, WHITE);
-    display.line(XMIN,LINE13,XMAX,LINE13, WHITE);
-    display.line(XMIN,LINE14,XMAX,LINE14, WHITE);
-}
-void CDU_TestScreen()
-{
-    display.display_control(IMAGE_FORMAT, NEW); //set correct image for reading from SD
-    display.cls();
-    display.showpicture(0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0xB5);    // Testscreen
+    display.display_control(IMAGE_FORMAT, NEW); //set correct image type for reading from SD
+    display.showpicture(0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xCD);    // Testscreen
 }
 void CDU_LogoScreen()
 {
-    display.display_control(IMAGE_FORMAT, NEW); //set correct image for reading from SD   
     display.cls();
-    display.showpicture(0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00);    // Engravity logo
+    display.display_control(IMAGE_FORMAT, NEW); //set correct image for reading from SD   
+    display.showpicture(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);    // Engravity logo
+}
+
+void CDU_Waiting()
+{
+    display.cls();
+    display.graphic_string( "WAITING" , 0,  LINE1, FONT_12X34, WHITE, 1, 1 );
 }
  
 void CDU_Page()
@@ -404,7 +415,8 @@
    
 }
  
-void  CDU_displayclear(){
+void  CDU_displayclear()
+{
     display.cls();
 }
    
diff -r 9d8032cb0f12 -r 2d6ac4577e68 keyboard.h
--- a/keyboard.h	Thu Aug 28 14:39:32 2014 +0000
+++ b/keyboard.h	Wed Oct 08 14:14:52 2014 +0000
@@ -1,5 +1,7 @@
 /* Keyboard TCA8418 declarations */
  
+ /*Backlighting scale factor*/
+ #define BGL_SCALE              10 //Select between 0 and 100%
  
 /* TCA8418 hardware limits */
 #define TCA8418_MAX_ROWS        8
diff -r 9d8032cb0f12 -r 2d6ac4577e68 keyboard2.cpp
--- 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);
                 
             }
         }
diff -r 9d8032cb0f12 -r 2d6ac4577e68 keys.h
--- a/keys.h	Thu Aug 28 14:39:32 2014 +0000
+++ b/keys.h	Wed Oct 08 14:14:52 2014 +0000
@@ -73,7 +73,7 @@
              "V*",       // KEY 66
              "W*",       // key 67                                      
              "X*",       // key 68
-             "Y*",        // key 69 
+             "Y*",       // key 69 
              "???*",     // key 70
              "???*",     // key 71
              ".*",       // key 72
diff -r 9d8032cb0f12 -r 2d6ac4577e68 main.cpp
--- a/main.cpp	Thu Aug 28 14:39:32 2014 +0000
+++ b/main.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -8,20 +8,23 @@
 #include "mbos.h"
 #include "mbos_def2.h"   // : Mbos tasks, timer and resource definitions
 #include "pins.h"
+#include "main.h"
 
 // Setup USB communication defined by Mbed USB TX and RX lines
 // with TX and RX ringbuffers :
-MODSERIAL USB(USBTX, USBRX, 256, 1024);
+MODSERIAL USB(USBTX, USBRX, 256, 1024);    //256, 1024
 DigitalOut alive_led( HEARTBEAT ); // : LED 1 on Mbed board toggles when CDU is alive
-
-//void test_update_flags(); // << for testing only << !!!!!!!
+DigitalOut PWR_led( PWR_ON );      // : LED 4 on Mbed board is ON when external power applied to board
+InterruptIn PWR_MON( PWR_IN );     // : Power monitor: input is connected to +5V and indirect to +12V
+ 
+ //void test_update_flags(); // << for testing only << !!!!!!!
 
 // --- Debug only ----------------------------------------
 // extra serial port to show debug info :
   MODSERIAL SERIAL_DEBUG(MODSERIAL_TX, MODSERIAL_RX, 512, 64);  //: tx, rx
 // -------------------------------------------------------
 
-int CDU_FS_interface = 0;   // : defines interface to FS: 0 = USB, 1 = Ethernet
+int CDU_FS_interface = Serial_USB;   // : defines interface to FS: 0 = Serial_USB, 1 = Ethernet
 extern int key_hit_ID;
 extern PwmOut BGL_LED;
 
@@ -50,10 +53,17 @@
 void CDU_InitDisplay(void);
 void CDU_ScreenAlign(void);
 void CDU_StartScreen(void);
+void CDU_LogoScreen(void);
+void CDU_Waiting(void);
 void CDU_Page(void);
 void CDU_DSP_CSS(void);
 void CDU_displayclear(void);
 
+void CDU_Screens();
+
+void CDU_BOOT();    //reboot CDU
+
+
 //------ USB buffer overflow interrupt handling: -------------
 void rx_buf_overflow(MODSERIAL_IRQ_INFO *q)
 {   // This functiom will be called when RX buffer overflows.
@@ -78,22 +88,51 @@
     USB.attach(&tx_buf_overflow, MODSERIAL::TxOvIrq); // : attach function to call when USB TX buffer overflows
 }
 
+char CheckExtPower()
+{
+    char ExtPower =0;
+    ExtPower = PWR_MON; //check on power input: if +5V is ON return 1 else 0
+    //PWR_led  = ExtPower;
+    return ExtPower;
+}
+
+void EXT_PWR_DN()
+{
+    //external power failed, reboot CDU!
+    CDU_BOOT();
+}
+
+
+
 main() // : MBOS main() 
 {
+    /* Check for a valid external power flag during boot sequence
+       When no external power is applied the VGA board and Keyboard chip are not operational
+       After initialization disconnecting external power will trigger interrupt to reboot.
+    */  
+    
+    PWR_MON.mode( PullDown );    //create a solid 0 when no external power supplied
+    while (! CheckExtPower() );  //wait for external power to come up
+    PWR_led = PWR_MON ;          //switch on LED for external power indicator
+    PWR_MON.fall(&EXT_PWR_DN);   //Bind function to handle interrupt when external power fails
+    
     init_USB();  // : setup USB communication to FS
      
-    // CDU keyboard initialisation and keyboard interrrupt setup:
+    // CDU keyboard initialisation and keyboard interrupt setup:
     CDU_KB_COMM_INIT();
     CDU_KB_INT_START();
     BGL_LED.period(0.01);
     
     // CDU display initialisation:
     CDU_InitDisplay();
-    CDU_StartScreen();
-    wait(0.2);
+    //CDU_StartScreen();
+    //CDU_LogoScreen();
+    wait(2);
+    //CDU_Screens();
+    CDU_Waiting();
     //CDU_Page();
-    CDU_ScreenAlign();
-            
+    //CDU_ScreenAlign();
+    //        
     set_initial_data(); //: fill FS datastructures with initial data
 
     // -- debug only -------------------------------------      
diff -r 9d8032cb0f12 -r 2d6ac4577e68 main.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Wed Oct 08 14:14:52 2014 +0000
@@ -0,0 +1,2 @@
+#define Serial_USB 0
+#define Ethernet   1
\ No newline at end of file
diff -r 9d8032cb0f12 -r 2d6ac4577e68 mbos_def2.h
--- a/mbos_def2.h	Thu Aug 28 14:39:32 2014 +0000
+++ b/mbos_def2.h	Wed Oct 08 14:14:52 2014 +0000
@@ -14,7 +14,7 @@
 // RECEIVE_DECODE_TASK properties:
 #define RECEIVE_DECODE_TASK_ID         2
 #define RECEIVE_DECODE_TASK_PRIO      80  
-#define RECEIVE_DECODE_TASK_STACK_SZ  256  
+#define RECEIVE_DECODE_TASK_STACK_SZ  256
 // SEND_KEYMESSAGE_TASK properties:
 #define SEND_KEYMESSAGE_TASK_ID         3
 #define SEND_KEYMESSAGE_TASK_PRIO      90
@@ -22,7 +22,7 @@
 // CDU_DSP_CSS_TASK properties: 
 #define CDU_DSP_CSS_TASK_ID            5
 #define CDU_DSP_CSS_TASK_PRIO         95  // : highest priority !
-#define CDU_DSP_CSS_TASK_STACK_SZ    512
+#define CDU_DSP_CSS_TASK_STACK_SZ    512  
 
 // MBOS TIMERS:
 // ALIVE_TIMER properties:
diff -r 9d8032cb0f12 -r 2d6ac4577e68 pins.h
--- a/pins.h	Thu Aug 28 14:39:32 2014 +0000
+++ b/pins.h	Wed Oct 08 14:14:52 2014 +0000
@@ -52,6 +52,11 @@
 
     //DigitalOut Key_led(LED2); // : LED 2 on Mbed board toggles when CDU key is pressed
     #define KEY_PRESSED         LED2
+    
+    #define PWR_IN              p6   //This pin is connected to the +5V and is 1 when external power is applied
+                                     //Level transition from 1->0 indicates an external power failure
+    #define PWR_ON              LED4 //monitor of external power and reboot CDU after 1-0-1 state change
+    
     #endif
 
 
@@ -106,6 +111,11 @@
 
     //DigitalOut Key_led(LED2); // : LED 2 on Mbed board toggles when CDU key is pressed
     #define KEY_PRESSED         LED2
+        
+    #define PWR_MON             p6   //This pin is connected to the +5V and is 1 when external power is applied
+                                     //Level transition from 1->0 indicates an external power failure
+    #define PWR_ON              LED4 //monitor of external power and reboot CDU after 1-0-1 state change
+  
     #endif
 
 #endif
\ No newline at end of file
diff -r 9d8032cb0f12 -r 2d6ac4577e68 screen_handler.cpp
--- a/screen_handler.cpp	Thu Aug 28 14:39:32 2014 +0000
+++ b/screen_handler.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -109,7 +109,7 @@
                                     nLine2Pixel( nLine ),                                 //Vertical position
                                     SELKEY_MAINTEXT[Key_Maintext_Update].font_size,        //Font
                                     cRGB( SELKEY_MAINTEXT[Key_Maintext_Update].text_RED ,SELKEY_MAINTEXT[Key_Maintext_Update].text_GREEN ,SELKEY_MAINTEXT[Key_Maintext_Update].text_BLUE ),
-                                    1, 1 );
+                                    2, 2 );
           
  
             Key_Maintext_Update = -1;
@@ -154,7 +154,7 @@
                                     nLine2Pixel( nLine ),                              //Vertical position
                                     SELKEY_SUBTEXT[Key_Subtext_Update].font_size,      //Font
                                     cRGB( SELKEY_SUBTEXT[Key_Subtext_Update].text_RED ,SELKEY_SUBTEXT[Key_Subtext_Update].text_GREEN ,SELKEY_SUBTEXT[Key_Subtext_Update].text_BLUE ),
-                                    1, 1 ); //multiplier always on 1
+                                    2, 2 ); //multiplier always on 1
             Key_Subtext_Update = -1;
         }
       
@@ -166,7 +166,7 @@
                                     nLine2Pixel( Text_Line_Update ),                        //Vertical position
                                     TEXTLINE[Text_Line_Update].font_size,      //Font
                                     cRGB( TEXTLINE[Text_Line_Update].text_RED ,TEXTLINE[Text_Line_Update].text_GREEN ,TEXTLINE[Text_Line_Update].text_BLUE ),
-                                    1, 1 ); //multiplier always on 1
+                                    2, 2 ); //multiplier always on 1
             Text_Line_Update = 0;
         }