voor willem test

Dependencies:   4DGL MODSERIAL mbed mbos

Files at this revision

API Documentation at this revision

Comitter:
LvdK
Date:
Thu Jul 17 10:09:14 2014 +0000
Parent:
6:e0bf3b244d7c
Commit message:
CDU V21

Changed in this revision

4DGL.lib Show annotated file Show diff for this revision Revisions of this file
CDU2FS_message_2.cpp Show diff for this revision Revisions of this file
CDU2FS_message_4.cpp Show annotated file Show diff for this revision Revisions of this file
FS2CDU_data_2.cpp Show diff for this revision Revisions of this file
FS2CDU_data_4.cpp Show annotated file Show diff for this revision Revisions of this file
FS_datastructures.h Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show diff for this revision Revisions of this file
USB_receive_2.cpp Show diff for this revision Revisions of this file
USB_receive_3.cpp Show annotated file Show diff for this revision Revisions of this file
buttontest.cpp Show diff for this revision Revisions of this file
debug_lvdk.h 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
display.h 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
mbed.bld Show diff for this revision Revisions of this file
mbed.lib Show annotated file Show diff for this revision Revisions of this file
mbos_def.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
show_data.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e0bf3b244d7c -r 6576a287e563 4DGL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL.lib	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Engravity-CDU/code/4DGL/#f34ce48346bc
diff -r e0bf3b244d7c -r 6576a287e563 CDU2FS_message_2.cpp
--- a/CDU2FS_message_2.cpp	Tue Jan 29 14:54:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-// L. van der Kolk, ELVEDEKA, Holland //
-// File:  CDU2FS_message_2.cpp 
-
-#include "mbed.h"
-#include "MODSERIAL.h"
-
-extern MODSERIAL USB;
-extern int CDU_FS_interface; 
-
-int key_hit_ID = 0;         // : number of key that was hit, 0 = no hit of any key. ( global flag ! )
-
-char key_message[20]   =  "$PCDUKEY,";  // : setup begin of KEY message to FS
-char val_message[50]   =  "$PCDUVAL,";  // : setup begin of VAL message to FS
-char alive_message[20] =  "$PCDUOKE,";  // : setup begin of ALIVE message to FS
-
-// ---- Key strings for FS-to-CDU key message SPCDUKEY ------------------------------------------------
-#define max_keys_CDUpanel 70 // : absolute max. number of keys found on CDU panel
-const char *key_value[max_keys_CDUpanel] =  // : array of pointers to keystrings terminated by '*'
-           { "???*",     // key 0 not valid
-             "LSK1*",    // key 1
-             "LSK2*",    // key 2
-             "LSK3*",    // key 3
-             "LSK4*",    // key 4         
-             "LSK5*",    // key 5
-             "LSK6*",    // key 6
-             "INITRF*",  // key 7
-             "RTE*",     // key 8             
-             "CLB*",     // key 9                                   
-             "CRZ*",     // key 10
-             "DES*",     // key 11           
-             "MENU*",    // key 12
-             "LEGS*",    // key 13            
-             "DEPARR*",  // key 14             
-             "HOLD*",    // key 15
-             "PROG*",    // key 16 
-             "EXEC*",    // key 17
-             "N1LMT*",   // key 18 
-             "FIX*",     // key 19
-             "PRPAGE*",  // key 20            
-             "NXPAGE*",  // key 21             
-             "1*",       // key 22
-             "2*",       // key 23             
-             "4*",       // key 24
-             "5*",       // key 25             
-             "6*",       // key 26             
-             "7*",       // key 27             
-             "8*",       // key 28             
-             "9*",       // key 29             
-             "0*",       // key 30
-             ".*",       // key 31
-             "+/-*",     // key 32
-             "A*",       // key 33
-             "B*",       // key 34             
-             "C*",       // key 35             
-             "D*",       // key 36
-             "E*",       // key 37                          
-             "F*",       // key 38
-             "G*",       // key 39
-             "H*",       // key 40
-             "I*",       // key 41                                                                                           
-             "J*",       // key 42
-             "K*",       // key 43             
-             "L*",       // key 44             
-             "M*",       // key 45             
-             "N*",       // key 46             
-             "O*",       // key 47  
-             "P*",       // key 48               
-             "Q*",       // key 49               
-             "R*",       // key 50               
-             "S*",       // key 51  
-             "T*",       // key 52               
-             "U*",       // key 53               
-             "V*",       // key 54               
-             "W*",       // key 55               
-             "X*",       // key 56               
-             "Y*",       // key 57  
-             "Z*",       // key 58 
-             "SPC*",     // key 59
-             "DEL*",     // key 60
-             "CLR*",     // key 61
-             "/*",       // key 62
-             "RSK1*",    // key 63
-             "RSK2*",    // key 64
-             "RSK3*",    // key 65
-             "RSK4*",    // key 67                                      
-             "RSK5*",    // key 68
-             "RSK6*"     // key 69             
-            }; 
-// ------------------------------------------------------------------------------------------------
-
-void send_message_to_FS(char *message_string) {
-    // Common fnction to send a created message string (VAL, KEY or OKE) to the FS.
-    // Parameter is pointer to char string that has to be sent.
-    // Interface can be USB port or Ethernet port.
-    if ( CDU_FS_interface == 0 ) {  // : messages will be sent by USB port
-        // Test if TX buffer is not full:
-        // Note: Only writing in the Tx buffer if there is enough space,
-        // prevents Tx buffer overflow, but caharcters can be lost when Tx buffersize is defined too small !
-        // In this case the Blue-Leds-Of-Death due to a TX overflow interrupt will never occur,
-        // and Mbed will keep running !
-        USB.puts(message_string); // : write total string in USB TX buffer <<<<<<<<<<<<<<<<<  ????
-    }
-    //if ( CDU_FS_interface == 1 ) Ethernet.puts(message_string); // : messages will be sent by Ehternet
-}
-
-void Send_VAL_message(int var, char *char_pntr) {
-     // Function creates a valid VAL message out of var parameter and out of value string
-     // which is addressed by parameter char_pntr.
-     // After adding a checksum, the total VAL message string will be sent.
-     
-        //USB.printf("pseudo VAL message:  %d , %s\n",var,char_pntr); // debug only !
-        int i;
-        char byte_read;
-        char exor_byte = 0;
-        //  Create VAL message, starting with "$PCDUVAL," message header
-        i = 9; // : i points to first place after "$PCDUVAL," header
-        // : add 2 digit var number and comma to message:
-        sprintf(&val_message[i],"%02d,",var);
-        // Add value of var and extra '*' char to VAL message:
-        i = 12;
-        sprintf(&val_message[i],"%s*",char_pntr);
-        // Calculate checksum now : 
-        i = 1; // : i points to first place after '$' in message
-        do { byte_read = val_message[i];
-             if (byte_read == '*') break; // : exclude '*' from calculation
-             exor_byte = exor_byte ^ byte_read;
-             i++;
-        } while ( i < 50 );
-        i++;  // : i now points to first digit of checksum after '*'
-        // Add exor_byte in 2 hex digits and a CR + LF:
-        sprintf(&val_message[i],"%02x\r\n",exor_byte); // : extra NULL char added by sprintf
-        send_message_to_FS(val_message); // : send message to defined CDU-FS interface        
-}
-
-void Send_ALIVE_message(int seconds){
-    int i;
-    char byte_read;
-    char exor_byte = 0;
-     //Create alive message:
-        i = 9; // : i points to first place after "$PCDUOKE,"
-        // Add seconds in 2 dec digits and a '*' char :
-        sprintf(&alive_message[i],"%02d*",seconds); 
-        // Calculate checksum now : 
-        i = 1; // : i points to first place after '$'
-        do { byte_read = alive_message[i];
-             if (byte_read == '*') break; // : exclude '*' from exor calculation
-             exor_byte = exor_byte ^ byte_read;
-             i++;
-        } while ( i < 20 );
-        i++;  // : i now points to first digit of checksum after '*'
-        // Add exor_byte in 2 hex chars (with upper case A-F) and a CR + LF:
-        sprintf(&alive_message[i],"%02X\r\n",exor_byte); // : + extra NULL char added by sprintf 
-        send_message_to_FS(alive_message); // : send message to defined CDU-FS interface
-        
-}
-
-void Send_KEY_message(int key_nr) {
-        // Function creates a valid KEY message out of key_nr parameter.
-        // Based on key_nr, a key char string is looked up and added to the message.
-        // After adding a checksum, the total KEY message will be sent.
-        int i;
-        char byte_read;
-        char exor_byte = 0;
-        //  Create key message, starting with "$PCDUKEY," message header
-        i = 9; // : i points to first position after "$PCDUKEY," message header 
-        // Add key string to message string including '*'
-        if ( key_nr != 0 && key_nr < max_keys_CDUpanel ) {
-             strcpy(&key_message[i],key_value[key_nr]); 
-        }
-        // Calculate checksum now : 
-        i = 1; // : i points to first place after '$' in message
-        do { byte_read = key_message[i];
-             if (byte_read == '*') break; // : exclude '*' from calculation
-             exor_byte = exor_byte ^ byte_read;
-             i++;
-        } while ( i < 20 );
-        i++;  // : i now points to first digit of checksum after '*'
-        // Add exor_byte in 2 hex digits and a CR + LF:
-        sprintf(&key_message[i],"%02x\r\n",exor_byte); // : extra NULL char added by sprintf
-        send_message_to_FS(key_message); // : send message to defined CDU-FS interface   
-}           
-        
-
-
-
-    
-    
-    
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 CDU2FS_message_4.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CDU2FS_message_4.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,88 @@
+// L. van der Kolk, ELVEDEKA, Holland 
+// File:  CDU2FS_message_4.cpp 
+//
+// -- Message handling from CDU to FS --
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "keys.h"
+#include "debug_lvdk.h" // : debug mode control
+
+extern MODSERIAL USB;
+extern MODSERIAL SERIAL_DEBUG;
+extern int CDU_FS_interface;
+
+int key_hit_ID = 0;   // : number of key that was hit, 0 = no hit of any key. ( global flag )
+
+char key_message[25]   =  "$PCDUKEY,";  // : setup begin of KEY message to FS
+char alive_message[25] =  "$PCDUOKE,";  // : setup begin of ALIVE message to FS
+
+
+void send_message_to_FS(char *message_string) {
+    // Common fnction to send a created message string (KEY or OKE) to the FS.
+    // Parameter is pointer to char string that has to be sent.
+    // Interface can be USB port or Ethernet port.
+    int i = 0;
+    if ( CDU_FS_interface == 0 ) {  // : messages will be sent out by USB port
+        while (  message_string[i] != '\0' ) {
+                   USB.putc(message_string[i]);
+                   i++;
+        }
+    }
+    if ( CDU_FS_interface == 1 )  { 
+     // Messages will be sent out by Ehternet interface
+     // - Not implemented -
+    }
+}
+
+
+void Send_ALIVE_message(int seconds){
+    int i;
+    char byte_read;
+    char exor_byte = 0;
+     //Create alive message:
+        i = 9; // : i points to first place after "$PCDUOKE,"
+        // Add seconds in 2 dec digits and a '*' char :
+        sprintf(&alive_message[i],"%02d*",seconds); 
+        // Calculate checksum now : 
+        i = 1; // : i points to first place after '$'
+        do { byte_read = alive_message[i];
+             if (byte_read == '*') break; // : exclude '*' from exor calculation
+             exor_byte = exor_byte ^ byte_read;
+             i++;
+        } while ( i < 20 );
+        i++;  // : i now points to first digit of checksum after '*'
+        // Add exor_byte in 2 hex chars (with upper case A-F) and a CR + LF:
+        sprintf(&alive_message[i],"%02X\r\n",exor_byte); // : + extra NULL char added by sprintf 
+        send_message_to_FS(alive_message); // : send message to defined CDU-FS interface
+        
+}
+
+void Send_KEY_message(int key_nr) {
+        // Function creates a valid KEY message out of key_nr parameter.
+        // Based on key_nr, a key char string is looked up and added to the message.
+        // After adding a checksum, the total KEY message will be sent.
+        int i;
+        char byte_read;
+        char exor_byte = 0;
+        //  Create key message, starting with "$PCDUKEY," message header
+        i = 9; // : i points to first position after "$PCDUKEY," message header 
+        // Add key string to message string including '*' 
+        
+        if ( key_nr != 0 && key_nr < max_keys_CDUpanel ) {
+             strcpy(&key_message[i],key_value[key_nr]); 
+            // Calculate checksum now : 
+            i = 1; // : i points to first place after '$' in message
+            do { byte_read = key_message[i];
+                if (byte_read == '*') break; // : exclude '*' from calculation
+                exor_byte = exor_byte ^ byte_read;
+                i++;
+            } while ( i < 20 );
+            i++;  // : i now points to first digit of checksum after '*'
+            // Add exor_byte in 2 hex digits and a CR + LF:
+            sprintf(&key_message[i],"%02X\r\n",exor_byte); // : extra NULL char added by sprintf
+            send_message_to_FS(key_message); // : send message to defined CDU-FS interface 
+        } 
+}           
+        
+   
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 FS2CDU_data_2.cpp
--- a/FS2CDU_data_2.cpp	Tue Jan 29 14:54:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,669 +0,0 @@
-// L. van der Kolk, ELVEDEKA, Holland //
-// File:  FS2CDU_data_2.cpp  
-
-#include "mbed.h"
-#include "MODSERIAL.h"  
-
-// ---- FS-to-CDU data structures filled with received data ---------------------------------------
-#define max_text0    48   //  max text length font 0      
-#define max_text1    24   //  max text length font 1  
-#define max_lines    14   //  max nr of screen lines 
-#define max_font      1   //  possible fonts are 0 to max_font, so now 0 and 1 possible
-#define max_col_nr  255   //  highest possible R,G, or B colour number
-#define fstyle_1     'S'  //  possible font style character 1
-#define fstyle_2     'N'  //  possible font style character 2
-#define max_keys    100   //  max total nr of select keys 0 - 99
-#define max_leftkeys  6   //  max nr of used LEFT select keys ( 0 - 49 )
-#define max_rightkeys 6   //  max nr of used RIGHT select keys ( 50 - 99 )
-
-// Background colour of display:
-struct { int   RED;                 //  : RED value 
-         int   GREEN;               //  : GREEN value 
-         int   BLUE;                //  : BLUE value     
-         int   updated;             //  : update flag, true when background colour was updated
-         } BACKGROUND_COL;
-
-// Maintext lines at selectkeys:
-struct { char  text[max_text0+2];    //  : maintext string, ending with '\0'   
-         int   font_size;            //  : fontsize             
-         char  font_style;           //  : style character                          
-         int   text_RED;             //  : RED value of textline
-         int   text_GREEN;           //  : GREEN value of textline
-         int   text_BLUE;            //  : BLUE value of textline
-         int   updated;              //  : update flag, true when a selectkey maintext was updated
-         } SELKEY_MAINTEXT[max_keys];//  : array of selectkey Maintext structures
-        
-// Subtext lines at selectkeys:
-struct { char  text[max_text0+2];    //  : subtext string, ending with '\0'   
-         int   font_size;            //  : fontsize                                
-         char  font_style;           //  : style character                          
-         int   text_RED;             //  : RED value of textline
-         int   text_GREEN;           //  : GREEN value of textline
-         int   text_BLUE;            //  : BLUE value of textline
-         int   updated;              //  : update flag, true when a selectkey subtext was updated
-         } SELKEY_SUBTEXT[max_keys]; //  : array of selectkey Subtext structures 
-
-// Screen textlines:
-struct { char  text[max_text0+2];    //  : text line string, ending with '\0'   
-         int   font_size;            //  : fontsize of textline           
-         char  font_style;           //  : style character                             
-         int   text_RED;             //  : RED value of textline
-         int   text_GREEN;           //  : GREEN value of textline
-         int   text_BLUE;            //  : BLUE value of textline
-         int   updated;              //  : update flag, true when a textline was updated
-         } TEXTLINE[max_lines+1];    //  : array of textline structures
-            
-// CDU status:            
-struct { int mess_light;            //  : 0 = light OFF, 1 = light ON
-         int exec_indicator;        //  : 0 = indicator OFF, 1 = indicator ON
-         int backlight;             //  : 0 = light OFF, 1 = light ON 
-         int stby_mode;             //  : 0 = operational mode, 1 = standby mode
-         int updated;               //  : update flag, true when one or more status items were updated
-         } CDU_STATUS;           
-            
-// Clear screen flag:
-int DO_CLR_SCREEN = false;          //  : Clear screen flag, true = perform a clear-screen
-
-// CDU settings:
-struct { int Baud;              //  : Baudrate can be 2400, 4800, 9600, 19200, 38400
-         char Firmware_nr[15];  //  : firmware ID string, terminated with '\0' !
-         char CDU_type[15];     //  : CDU type ID string, terminated with '\0' !
-         int  Serial_nr;        //  : integer serial number
-         char IP_address[20];   //  : IP address, 0.0.0.0 to 255.255.255.255 , terminated with '\0' !
-         int  Port_nr;          //  : integer Port number
-         char Server_ip[20];    //  : IP address of server , terminated with '\0' !     
-         int  updated;          //  : update flag, true when one or more items were updated
-         } CDU_SET;
-
-// Common flag to signal that one or more updates were performed:
-int FSdata_received_flag = false;  //  : true when one or more FS-to-CDU data was updated                                 
-// --------------------------------------------------------------------------------------------------
-
-extern MODSERIAL USB;      // >>>>>>>>>>> alleen t.b.v TEST output !!
-extern char string_received[];  
-extern int comma[];
-
-void Send_VAL_message(int var, char *char_pntr); 
-
-void set_initial_CDU_screen()
-{  // Fill all FS-to-CDU datastructures with data for initial power-up conditions:
-   int key_nr, line_nr;
- 
-    FSdata_received_flag = true;    // <<<<<<<<<<<<<< !
-    
-  // Init background colour of screen :
-   BACKGROUND_COL.RED = 0;
-   BACKGROUND_COL.GREEN = 0;
-   BACKGROUND_COL.BLUE = 0;
-   BACKGROUND_COL.updated = true;
-   
-  // Init Maintext at left selectkeys starting from 0 :
-  for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
-  {  SELKEY_MAINTEXT[key_nr].text_RED =   255;
-     SELKEY_MAINTEXT[key_nr].text_GREEN = 255;
-     SELKEY_MAINTEXT[key_nr].text_BLUE =  255;
-     SELKEY_MAINTEXT[key_nr].font_size =    0;
-     SELKEY_MAINTEXT[key_nr].font_style = fstyle_1;
-     strncpy(SELKEY_MAINTEXT[key_nr].text, "0|....key maintext..............................|\0",
-     max_text0 + 2 ); // (max_text0+2) chars copied
-     SELKEY_MAINTEXT[key_nr].updated = true;   
-   }
-  // Init Maintext at right selectkeys starting from 50 :
-  for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
-  {  SELKEY_MAINTEXT[key_nr].text_RED =   255;
-     SELKEY_MAINTEXT[key_nr].text_GREEN = 255;
-     SELKEY_MAINTEXT[key_nr].text_BLUE =  255;
-     SELKEY_MAINTEXT[key_nr].font_size =    0;
-     SELKEY_MAINTEXT[key_nr].font_style = fstyle_1; 
-     strncpy(SELKEY_MAINTEXT[key_nr].text, "0|....key maintext..............................|\0",
-     max_text0 + 2 ); // (max_text0+2) chars copied
-     SELKEY_MAINTEXT[key_nr].updated = true;   
-   }
-  // Init Subtext at left selectkeys starting from 0 :
-  for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
-  {  SELKEY_SUBTEXT[key_nr].text_RED =   255;
-     SELKEY_SUBTEXT[key_nr].text_GREEN = 255;
-     SELKEY_SUBTEXT[key_nr].text_BLUE =  255;
-     SELKEY_SUBTEXT[key_nr].font_size =    0;
-     SELKEY_SUBTEXT[key_nr].font_style = fstyle_1; 
-     strncpy(SELKEY_SUBTEXT[key_nr].text, "0|....key subtext...............................|\0",
-     max_text0 + 2 ); // (max_text0+2) chars copied
-     SELKEY_SUBTEXT[key_nr].updated = true;   
-   }   
-  // Init Subtext at right selectkeys starting from 50 :
-  for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
-  {  SELKEY_SUBTEXT[key_nr].text_RED =   255;
-     SELKEY_SUBTEXT[key_nr].text_GREEN = 255;
-     SELKEY_SUBTEXT[key_nr].text_BLUE =  255;
-     SELKEY_SUBTEXT[key_nr].font_size =    0;
-     SELKEY_SUBTEXT[key_nr].font_style = fstyle_1; 
-     strncpy(SELKEY_SUBTEXT[key_nr].text, "0|....key subtext...............................|\0",
-     max_text0 + 2 ); // (max_text0+2) chars copied 
-     SELKEY_SUBTEXT[key_nr].updated = true;   
-   }     
-  // Init screentext :
-  for ( line_nr = 1; line_nr <= 14; line_nr++ )
-  {  TEXTLINE[line_nr].text_RED =   255;
-     TEXTLINE[line_nr].text_GREEN = 255;
-     TEXTLINE[line_nr].text_BLUE =  255;
-     TEXTLINE[line_nr].font_size =    0;
-     TEXTLINE[line_nr].font_style = fstyle_1; 
-     strncpy(TEXTLINE[line_nr].text, "0|....text line.................................|\0",
-     max_text0 + 2 ); // (max_text0+2) chars copied 
-     TEXTLINE[line_nr].updated = true;   
-   }   
-   // Init CDU status items:
-   CDU_STATUS.mess_light = 1;
-   CDU_STATUS.exec_indicator = 1;
-   CDU_STATUS.backlight = 1;
-   CDU_STATUS.stby_mode = 0;
-   CDU_STATUS.updated = true;
-   
-   // Init Clear screen flag:
-   DO_CLR_SCREEN = false;       
-   
-   // INIT CDU settings:
-   CDU_SET.Baud = 38400; // : will be default baudrate
-   strcpy(CDU_SET.Firmware_nr, "v1.0a\0"); // copy chars incl. '\0'
-   strcpy(CDU_SET.CDU_type, "colour CDU\0"); // copy chars incl. '\0'
-   CDU_SET.Serial_nr = 12345;
-   strcpy(CDU_SET.IP_address, "255.255.255.123\0"); // copy chars incl. '\0'
-   CDU_SET.Port_nr = 4321;
-   strcpy(CDU_SET.Server_ip, "255.255.255.456\0"); // copy chars incl. '\0'
-   CDU_SET.updated = true;
-}
-
-void read_datafields(int command_number) {
-    // Function to read all comma seperated datafields in string_received[]
-    // and fill in FS-to-CDU data structures.
-    // Parameter is found command_number.
-    int colour, size, pos, line, last, cnt, k_id, var, a ;
-    int modified, char_pntr;
-    char val_string[25]; // <<<<<---------------------------------------------------------Local !!!!! 
-    char ch;
-        
-    modified = false;    
-    switch ( command_number )
-    {
-        case 0:  
-        {   // 0 is no valid commandnumber
-             break;
-        }
-        
-        case 1:  // MSG command, message indicator control CDU
-        {              
-             // Get message indicator status:
-             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
-             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
-             { CDU_STATUS.mess_light = atoi(&string_received[char_pntr]);
-               CDU_STATUS.updated = true;    // : signal update of CDU status
-               FSdata_received_flag = true;  // : set common update flag
-             }
-             break;
-        }
-        
-        case 2: // EXC command, exec indicator control CDU
-        {               
-             // Get exec indicator status:
-             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
-             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
-             { CDU_STATUS.exec_indicator = atoi(&string_received[char_pntr]);
-               CDU_STATUS.updated = true;   // : signal update of of CDU status
-               FSdata_received_flag = true;  // : set common update flag
-             }
-             break;
-        }
-
-        case 3: // BLT command, backlight control CDU     
-        {                 
-             // Get backlight status:
-             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
-             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
-             { CDU_STATUS.backlight = atoi(&string_received[char_pntr]);
-               CDU_STATUS.updated = true;   // : signal update of of CDU status
-               FSdata_received_flag = true;  // : set common update flag
-             }
-             break;
-        } 
-        
-        case 4: // SBY command, standby control CDU      
-        {               
-             // Get standby status:
-             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
-             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
-             { CDU_STATUS.stby_mode = atoi(&string_received[char_pntr]);
-               CDU_STATUS.updated = true;   // : signal update of CDU status
-               FSdata_received_flag = true;  // : set common update flag
-             }
-             break;
-        }        
-        
-        case 5: // CLS command, CDU clear screen control
-        {    
-             DO_CLR_SCREEN = true;        // : tell to clear the screen
-             FSdata_received_flag = true;  // : set common update flag
-             break;
-        }        
-
-
-        case 6: // SBC command, screen background colour control       
-        {                 
-             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                BACKGROUND_COL.RED = colour;
-                modified = true;
-             }
-             char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                BACKGROUND_COL.GREEN = colour;
-                modified = true;
-             }
-             char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                BACKGROUND_COL.BLUE = colour; 
-                modified = true;
-             }                       
-             if ( modified == true )
-             { BACKGROUND_COL.updated = true;   // : signal update of background colour
-               FSdata_received_flag = true;      // : set common update flag 
-             } 
-                         
-             break;
-        }        
-
-        
-        case 7: // WTX command, write textline to CDU screen   
-        {  
-          // Read linenumber:
-          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
-          line = atoi(&string_received[char_pntr]);
-          // Read char position:
-          char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
-          pos = atoi(&string_received[char_pntr]);
-           
-          // Test if char X,Y position is within range:
-          if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
-          {  // Read font size 0 - 9:
-                char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
-                size = atoi(&string_received[char_pntr]);
-                // Test if size is valid:
-                if ( size >= 0 && size <= max_font ) {
-                    TEXTLINE[line].font_size = atoi(&string_received[char_pntr]);
-                    modified = true;
-                }
-             // Read line font style:
-             char_pntr = comma[4] + 1; // : set char pointer to char after comma 4 
-             ch = string_received[char_pntr];
-             if (ch == fstyle_1 || ch == fstyle_2 ) {
-                 TEXTLINE[line].font_style = ch;                                     
-                 modified = true;
-             }
-             // Read RGB line colour:
-             char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                TEXTLINE[line].text_RED = colour;
-                modified = true;
-             }
-             char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                TEXTLINE[line].text_GREEN = colour;
-                modified = true;
-             }
-             char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                TEXTLINE[line].text_BLUE = colour; 
-                modified = true;
-             }                       
-             // Read textfield :
-             char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
-             last = 0;
-             // read font size to determine last possible position:
-             if ( TEXTLINE[line].font_size == 0 )last = max_text0;
-             else if ( TEXTLINE[line].font_size == 1 )last = max_text1;
-             
-             if (last > 0 && pos <= last) {  // : test for valid area and valid fontsize
-                a = pos;
-                modified = true;
-                while ( a <= last )
-                 {  ch = string_received[char_pntr];
-                    if (ch == '*') break; // : do not include * in text
-                    TEXTLINE[line].text[a] = ch;
-                    a++;
-                    char_pntr++;
-                 }
-             //TEXTLINE[line].text[a] = '\0'; // : mark end of text <<<<<<<<<< ??
-             }            
-          } 
-           
-          if ( modified == true )  {
-            TEXTLINE[line].updated = true;    // : signal update of text line
-            FSdata_received_flag = true;      // : set common update flag 
-          }
-           
-          // Debug:
-          // Print all fields : ----------------------------------------------------------------
-          USB.printf("WTX line        : %d\n",line );                         // show line nr 
-          USB.printf("WTX position    : %d\n",pos );                          // show pos   
-          USB.printf("WTX text is     : %s\n",TEXTLINE[line].text );          // show text  
-          USB.printf("WTX fontsize is : %d\n",TEXTLINE[line].font_size );     // show fontsize 
-          USB.printf("WTX fontstyle is: %c\n",TEXTLINE[line].font_style);     // show fontstyle 
-          USB.printf("WTX R_colour is : %d\n",TEXTLINE[line].text_RED );      // show textcolour 
-          USB.printf("WTX G_colour is : %d\n",TEXTLINE[line].text_GREEN );    // show textcolour 
-          USB.printf("WTX B_colour is : %d\n",TEXTLINE[line].text_BLUE );     // show textcolour 
-          // END of debug printing --------------------------------------------------------------
-                    
-          break;
-        }        
-        
-        case 8: // ETX command, erase (part of) textline of CDU screen        
-        { 
-          // Read linenumber:
-          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
-          line = atoi(&string_received[char_pntr]);
-          // Read char position:
-          char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
-          pos = atoi(&string_received[char_pntr]);
-          // Read nr of char to be erased:
-          char_pntr = comma[3] + 1; // : set char pointer to char after comma 3          
-          cnt = atoi(&string_received[char_pntr]);
-          // Test if char X,Y position is within range:
-          if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
-          {  
-             last = 0;          
-             // read font size to determine last possible position:
-             if ( TEXTLINE[line].font_size == 0 )last = max_text0;
-             else if ( TEXTLINE[line].font_size == 1 )last = max_text1;
-             
-             if (last > 0 && pos <= last && cnt > 0) {  // : test if in valid area and chars > 0
-                a = pos;
-                modified = true;
-                while ( a <= last && cnt > 0)
-                 {  
-                    TEXTLINE[line].text[a] = ' '; //: write space
-                    a++;
-                    cnt--;
-                 }
-             }              
-          } 
-          if ( modified == true )  {
-            TEXTLINE[line].updated = true;    // : signal update of text line
-            FSdata_received_flag = true;      // : set common update flag 
-          }
-           
-          // Debug:
-          // Print : -------------------------------------------------------------------------
-          USB.printf("ETX line : %d\n",line );                                // show line nr 
-          USB.printf("ETX position : %d\n",pos );                             // show pos   
-          USB.printf("ETX modified text : %s\n",TEXTLINE[line].text );        // show text  
-          // END of debug printing ------------------------------------------------------------
-        }        
-        
-        case 9: // KTX command, write textline to select key area  
-        {                    
-           // Read key ID:
-          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
-          k_id = atoi(&string_received[char_pntr]);
-          // Read text type:
-          char_pntr = comma[2] + 1; // : set char pointer to char after comma 2 
-          ch = string_received[char_pntr];
-          
-          if (ch == 'M' && k_id < max_keys ) // : text type = MAIN text and keyID valid
-          {   // Read font size 0 - 9:
-              char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
-              size = atoi(&string_received[char_pntr]);
-              // Test if size is valid:
-              if ( size >= 0 && size <= max_font ) {
-                  SELKEY_MAINTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
-                  modified = true;
-              }
-             // Read line font style:
-             char_pntr = comma[4] + 1; // : set char pointer to char after comma 4 
-             ch = string_received[char_pntr];
-             if (ch == fstyle_1 || ch == fstyle_2 ) {
-                 SELKEY_MAINTEXT[k_id].font_style = ch;                                     
-                 modified = true;
-             }
-             // Read RGB line colour:
-             char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                SELKEY_MAINTEXT[k_id].text_RED = colour;
-                modified = true;
-             }
-             char_pntr = comma[6] + 1; // : set char pointer to char after comma 5
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                SELKEY_MAINTEXT[k_id].text_GREEN = colour;
-                modified = true;
-             }
-             char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                SELKEY_MAINTEXT[k_id].text_BLUE = colour; 
-                modified = true;
-             }                       
-             // Read textfield :
-             char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
-             last = 0;
-             // read font size to determine last possible position:
-             if ( SELKEY_MAINTEXT[k_id].font_size == 0 )last = max_text0;
-             else if ( SELKEY_MAINTEXT[k_id].font_size == 1 )last = max_text1;
-             
-             if (last > 0) {  // : test on valid fontsize
-                a = 1;
-                modified = true;
-                while ( a <= last )
-                 {  ch = string_received[char_pntr];
-                    if (ch == '*') break; // : do not include * in text
-                    SELKEY_MAINTEXT[k_id].text[a] = ch;
-                    a++;
-                    char_pntr++;
-                 }
-             //SELKEY_MAINTEXT[k_id].text[a] = '\0'; // : mark end of text <<< ???
-             }            
- 
-             if ( modified == true )  {
-              SELKEY_MAINTEXT[k_id].updated = true;  // : signal update 
-              FSdata_received_flag = true;      // : set common update flag 
-             }
- 
-          // Debug:
-          // Print all fields : --------------------------------------------------------------------
-          USB.printf("KTX key nr is   : %d\n",k_id );                             // show key nr 
-          USB.printf("KTX MAINTEXT is : %s\n",SELKEY_MAINTEXT[k_id].text );       // show text  
-          USB.printf("KTX fontsize is : %d\n",SELKEY_MAINTEXT[k_id].font_size );  // show fontsize 
-          USB.printf("KTX fontstyle is: %c\n",SELKEY_MAINTEXT[k_id].font_style);  // show fontstyle 
-          USB.printf("KTX R_colour is : %d\n",SELKEY_MAINTEXT[k_id].text_RED );   // show textcolour 
-          USB.printf("KTX G_colour is : %d\n",SELKEY_MAINTEXT[k_id].text_GREEN ); // show textcolour 
-          USB.printf("KTX B_colour is : %d\n",SELKEY_MAINTEXT[k_id].text_BLUE );  // show textcolour 
-          // END of debug printing -----------------------------------------------------------------
-          
-          }
-          
-          else if ( ch == 'S' && k_id < max_keys ) // : text type = SUB text and keyID valid
-          {   // Read font size 0 - 9:
-              char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
-              size = atoi(&string_received[char_pntr]);
-              // Test if size is valid:
-              if ( size >= 0 && size <= max_font ) {
-                  SELKEY_SUBTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
-                  modified = true;
-              }
-             // Read line font style:
-             char_pntr = comma[4] + 1; // : set char pointer to char after comma 4 
-             ch = string_received[char_pntr];
-             if (ch == fstyle_1 || ch == fstyle_2 ) {
-                 SELKEY_SUBTEXT[k_id].font_style = ch;                                     
-                 modified = true;
-             }
-             // Read RGB line colour:
-             char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                 SELKEY_SUBTEXT[k_id].text_RED = colour;
-                 modified = true;
-             }
-             char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                 SELKEY_SUBTEXT[k_id].text_GREEN = colour;
-                 modified = true;
-             }
-             char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
-             colour = atoi(&string_received[char_pntr]);
-             if ( colour >= 0 && colour <= max_col_nr ) {
-                 SELKEY_SUBTEXT[k_id].text_BLUE = colour; 
-                 modified = true;
-             }                       
-             // Read textfield :
-             char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
-             last = 0;
-             // read font size to determine last possible position:
-             if ( SELKEY_SUBTEXT[k_id].font_size == 0 )last = max_text0;
-             else if ( SELKEY_SUBTEXT[k_id].font_size == 1 )last = max_text1;
-             
-             if (last > 0) {  // : test on valid fontsize
-                a = 1;
-                modified = true;
-                while ( a <= last )
-                 {  ch = string_received[char_pntr];
-                    if (ch == '*') break; // : do not include * in text
-                    SELKEY_SUBTEXT[k_id].text[a] = ch;
-                    a++;
-                    char_pntr++;
-                 }
-             //SELKEY_SUBTEXT[k_id].text[a] = '\0'; // : mark end of text <<<<<<< ???
-             }            
- 
-             if ( modified == true )  {
-              SELKEY_SUBTEXT[k_id].updated = true;  // : signal update 
-              FSdata_received_flag = true;      // : set common update flag 
-             }
-             
-          // Debug:
-          // Print all fields : --------------------------------------------------------------------
-          USB.printf("KTX key nr is   : %d\n",k_id );                            // show key nr 
-          USB.printf("KTX SUBTEXT is : %s\n",SELKEY_SUBTEXT[k_id].text );        // show text  
-          USB.printf("KTX fontsize is : %d\n",SELKEY_SUBTEXT[k_id].font_size );  // show fontsize 
-          USB.printf("KTX fontstyle is: %c\n",SELKEY_SUBTEXT[k_id].font_style);  // show fontstyle 
-          USB.printf("KTX R_colour is : %d\n",SELKEY_SUBTEXT[k_id].text_RED );   // show textcolour 
-          USB.printf("KTX G_colour is : %d\n",SELKEY_SUBTEXT[k_id].text_GREEN ); // show textcolour 
-          USB.printf("KTX B_colour is : %d\n",SELKEY_SUBTEXT[k_id].text_BLUE );  // show textcolour 
-          // END of debug printing -----------------------------------------------------------------
-          
-          }
-     
-          break;
-        }        
-        
-        case 10: // STV command, set a status value:
-        { // Read var_number :
-          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
-          var = atoi(&string_received[char_pntr]);
-          if ( var == 0 ) // : test if valid var to write (var 0 = baudrate permitted only now)
-          { // Set baudrate :
-            char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
-            a = atoi(&string_received[char_pntr]);
-            // Test for valid baudrates:
-            if (a==2400 || a==4800 || a==9600 || a== 19200 || a==38400 )
-            { CDU_SET.Baud = a;
-                CDU_SET.updated = true;  // : signal status update 
-                // Send a responding VAL message:
-                sprintf(val_string,"%d",CDU_SET.Baud);                
-                Send_VAL_message(var,val_string);
-                FSdata_received_flag = true;      // : set common update flag
-            }
-            else { // no valid baudrate in command
-                   // Send a responding VAL NACK message :
-                   strcpy(val_string,"NACK\0"); // copy chars incl. '\0'
-                   Send_VAL_message(var,val_string);
-            }
-          }
-          else { // var is not valid var for writing
-                   // Send a responding VAL NACK message :
-                   strcpy(val_string,"NACK\0"); // copy chars incl. '\0'
-                   Send_VAL_message(var,val_string);
-          }
-                  
-          break;
-        }               
-        
-        case 11: // GTV command, get a status value:     
-        { // Read var_number :
-          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
-          var = atoi(&string_received[char_pntr]);
-          if ( var >= 0 && var <= 6) // : test if valid var to read
-          { // Read value :
-            switch ( var ) {
-                case 0: { // baudrate asked
-                          sprintf(val_string,"%d",CDU_SET.Baud);
-                          Send_VAL_message(var,val_string);
-                break;
-                }
-                case 1: { // firmware ID asked
-                          strcpy(val_string,CDU_SET.Firmware_nr); // copy chars incl. '\0'
-                          Send_VAL_message(var,val_string);                
-                break;
-                }
-                case 2: { // CDU type ID asked
-                          strcpy(val_string,CDU_SET.CDU_type); // copy chars incl. '\0'
-                          Send_VAL_message(var,val_string);
-                break;                
-                } 
-                case 3: { // serial number asked
-                          sprintf(val_string,"%d",CDU_SET.Serial_nr);
-                          Send_VAL_message(var,val_string);                          
-                break;                
-                }
-                case 4: { // IP address of CDU asked
-                          strcpy(val_string,CDU_SET.IP_address); // copy chars incl. '\0''
-                          Send_VAL_message(var,val_string);               
-                break;
-                }
-                case 5: { // Port number asked
-                          sprintf(val_string,"%d",CDU_SET.Port_nr);                
-                          Send_VAL_message(var,val_string);
-                break;                
-                }
-                case 6: { // IP address of server asked
-                          strcpy(val_string,CDU_SET.Server_ip); // copy chars incl. '\0'
-                          Send_VAL_message(var,val_string);
-                break;                
-                }            
-
-                default : { // invalid var , not possible 
-                break;
-                }   
-                           
-            }
-          }
-          else { // var is not valid 
-                   // Send a responding VAL NACK message :
-                   strcpy(val_string,"NACK\0"); // copy chars incl. '\0'
-                   Send_VAL_message(var,val_string); 
-          }
-          break;
-        }        
-               
-        case 12: // dbg, special debug command        
-        {                    
-
-          break;
-        }               
-        
-        default:
-        {   
-          // unknown commandnumber !
-          break;
-        }
-
-
-    } 
-}
-
diff -r e0bf3b244d7c -r 6576a287e563 FS2CDU_data_4.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FS2CDU_data_4.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,596 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File:  FS2CDU_data_4.cpp 
+// -- Message handling from FS to CDU --
+// Data field analyzing and filling data structures
+
+#include "mbed.h"
+#include "MODSERIAL.h" 
+#include "mbos.h"
+#include "debug_lvdk.h" // : debug mode control
+#include "mbos_def.h"
+
+extern mbos CDU_OS;
+
+// ---- FS-to-CDU data structures to be filled with received data --------------------------------
+#define max_text0    48   //  max text position font 0  (pos 0 invalid )    
+#define max_text1    24   //  max text position font 1  (pos 0 invalid )
+#define max_lines    14   //  max nr of screen lines 
+#define max_col_nr  255   //  highest possible R,G, or B colour number
+#define fstyle_1     'S'  //  possible font style character 1
+#define fstyle_2     'N'  //  possible font style character 2
+#define max_keys    100   //  max total nr of select keys 0 - 99
+#define max_leftkeys  6   //  max nr of used LEFT select keys ( 0 - 49 )
+#define max_rightkeys 6   //  max nr of used RIGHT select keys ( 50 - 99 )
+
+// Background colour of CDU display:
+struct { int   BG_RED;            //  : RED value   0 - 255
+         int   BG_GREEN;          //  : GREEN value 0 - 255
+         int   BG_BLUE;           //  : BLUE value  0 - 255   
+       } BACKGROUND_COL;
+
+// Maintext lines at selectkeys:
+struct { char  text[52];             //  : maintext string, ending with '\0'   
+         int   font_size;            //  : fontsize of textline 0 or 1            
+         char  font_style;           //  : style character S or N                       
+         int   text_RED;             //  : RED value of textline
+         int   text_GREEN;           //  : GREEN value of textline
+         int   text_BLUE;            //  : BLUE value of textline
+       } SELKEY_MAINTEXT[100];  //  : array of selectkey Maintext structures
+        
+// Subtext lines at selectkeys:
+struct { char  text[52];             //  : subtext string, ending with '\0'   
+         int   font_size;            //  : fontsize of textline 0 or 1                            
+         char  font_style;           //  : style character S or N                        
+         int   text_RED;             //  : RED value of textline
+         int   text_GREEN;           //  : GREEN value of textline
+         int   text_BLUE;            //  : BLUE value of textline
+       } SELKEY_SUBTEXT[100];   //  : array of selectkey Subtext structures 
+
+// Screen textlines:
+struct { char  text[52];             //  : text line string, ending with '\0'   
+         int   font_size;            //  : fontsize of textline 0 or 1         
+         char  font_style;           //  : style character S or N                             
+         int   text_RED;             //  : RED value of textline
+         int   text_GREEN;           //  : GREEN value of textline
+         int   text_BLUE;            //  : BLUE value of textline
+         } TEXTLINE[15];             //  : array of textline structures
+            
+// CDU status:            
+ struct { int msg_indicator;       //  : MSG  0 = light OFF, 1 = light ON
+          int exec_indicator;      //  : EXEC 0 = indicator OFF, 1 = indicator ON
+          int fail_indicator;      //  : FAIL 0 = indicator OFF, 1 = indicator ON
+          int dspy_indicator;      //  : DSPY 0 = indicator OFF, 1 = indicator ON  
+          int ofst_indicator;      //  : OFST 0 = indicator OFF, 1 = indicator ON                              
+          int backlight;           //  : 0 = light OFF, 1 = light ON 
+          int stby_mode;           //  : 0 = operational mode, 1 = standby mode
+        } CDU_STATUS;           
+        
+
+// FS_data_update_ID:
+// These global(!) flags indicate what data has been updated.
+// Should be tested when FS_DATA_EVENT occurs.
+ int Background_Col_Update      = 0;    // : 1 when color was updated, must be reset to 0 when data has been read
+ int CDU_Status_Update          = 0;    // : 1 when status was updated, must be reset to 0 when data has been read
+ int DO_CLR_SCREEN              = 0;    // : 1 when screen should be cleared, must be reset to 0 when done
+ int Text_Line_Update           = 0;    // : equal to line number whose text was updated, must be reset to 0 when text has been read 
+ int Key_Maintext_Update        = -1;   // : equal to keynumber whose main text line was updated, must be reset to -1 (!) when text has been read
+ int Key_Subtext_Update         = -1;   // : equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
+
+
+//------------- debug only ---------------------------
+extern MODSERIAL SERIAL_DEBUG; // : debug serial port
+//----------------------------------------------------
+
+extern MODSERIAL USB; 
+extern char string_received[];  
+extern int comma[];
+
+// Common flag to signal that an update was stored in the datastructures:
+int FSdata_received_flag = false;  //  : true when some FS-to-CDU data was updated 
+
+void set_initial_data()
+{  // Function to fill all FS-to-CDU datastructures with (dummy) data for initial power-up conditions:
+   int key_nr, line_nr;  
+  // Init background colour of screen :
+   BACKGROUND_COL.BG_RED =   128;
+   BACKGROUND_COL.BG_GREEN = 128;
+   BACKGROUND_COL.BG_BLUE =  128;
+   
+  // ---- Filling of all select key datastructures: ------------------------------
+  // Init Maintext at left selectkeys starting from 0 :
+  for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
+  {  SELKEY_MAINTEXT[key_nr].text_RED =   128;
+     SELKEY_MAINTEXT[key_nr].text_GREEN = 128;
+     SELKEY_MAINTEXT[key_nr].text_BLUE =  128;
+     SELKEY_MAINTEXT[key_nr].font_size =    0;
+     SELKEY_MAINTEXT[key_nr].font_style = fstyle_1;
+     strcpy(SELKEY_MAINTEXT[key_nr].text, "  \0");  // space char | on pos 0
+  }
+  // Init Maintext at right selectkeys starting from 50 :
+  for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
+  {  SELKEY_MAINTEXT[key_nr].text_RED =   128;
+     SELKEY_MAINTEXT[key_nr].text_GREEN = 128;
+     SELKEY_MAINTEXT[key_nr].text_BLUE =  128;
+     SELKEY_MAINTEXT[key_nr].font_size =    0;
+     SELKEY_MAINTEXT[key_nr].font_style = fstyle_1; 
+     strcpy(SELKEY_MAINTEXT[key_nr].text, "  \0"); // space char | on pos 0
+  }
+  // Init Subtext at left selectkeys starting from 0 :
+  for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
+  {  SELKEY_SUBTEXT[key_nr].text_RED =   128;
+     SELKEY_SUBTEXT[key_nr].text_GREEN = 128;
+     SELKEY_SUBTEXT[key_nr].text_BLUE =  128;
+     SELKEY_SUBTEXT[key_nr].font_size =    0;
+     SELKEY_SUBTEXT[key_nr].font_style = fstyle_1; 
+     strcpy(SELKEY_SUBTEXT[key_nr].text,"  \0"); // space char | on pos 0
+  }   
+  // Init Subtext at right selectkeys starting from 50 :
+  for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
+  {  SELKEY_SUBTEXT[key_nr].text_RED =   128;
+     SELKEY_SUBTEXT[key_nr].text_GREEN = 128;
+     SELKEY_SUBTEXT[key_nr].text_BLUE =  128;
+     SELKEY_SUBTEXT[key_nr].font_size =    0;
+     SELKEY_SUBTEXT[key_nr].font_style = fstyle_1; 
+     strcpy(SELKEY_SUBTEXT[key_nr].text, "  \0"); // space char | on pos 0
+  } 
+ // -----------------------------------------------------------------------------
+       
+  // Init some screentext :
+  strcpy(TEXTLINE[1].text,  "|..............TITLE LINE 1......................\0"); 
+  strcpy(TEXTLINE[14].text, "|............SCRATCHPAD LINE 14..................\0");                          
+  for ( line_nr = 2; line_nr <= 13; line_nr++ )
+  {  TEXTLINE[line_nr].text_RED =   128;
+     TEXTLINE[line_nr].text_GREEN = 128;
+     TEXTLINE[line_nr].text_BLUE =  128;
+     TEXTLINE[line_nr].font_size =    0;
+     TEXTLINE[line_nr].font_style = fstyle_1; 
+     strcpy(TEXTLINE[line_nr].text, "|................................................\0");                         
+  }   
+   // Init CDU status items:
+   CDU_STATUS.msg_indicator = 1;
+   CDU_STATUS.exec_indicator = 1;
+   CDU_STATUS.backlight = 1;
+   CDU_STATUS.stby_mode = 0;
+   
+   // Init flags:
+   //Background_Col_Update   =  0;    
+   //CDU_Status_Update       =  0;   
+   //DO_CLR_SCREEN           =  0;   
+   //Text_Line_update        =  0;    
+   //Key_Maintext_Update     = -1;    
+   //Key_Subtext_Update      = -1;
+      
+}
+
+void read_datafields(int command_number) {
+    // Function to read all comma seperated datafields in string_received[]
+    // and fill in FS-to-CDU data structures.
+    // Parameter is found command_number.
+    int colour, size, pos, line, last, cnt, k_id, a ;
+    int modified, char_pntr;
+    char ch;
+    
+    CDU_OS.LockResource(FS_DATA_RESOURCE); // : lock FS database    
+    modified = false;    
+    switch ( command_number )
+    {
+        case 0:  
+        {   // 0 is no valid commandnumber, do nothing
+           break;
+        }
+        
+        case 1:  // MSG command, message indicator control CDU
+        {              
+             // Get message indicator status:
+             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+             { CDU_STATUS.msg_indicator = atoi(&string_received[char_pntr]);
+               CDU_Status_Update = 1;
+               FSdata_received_flag = true;  // : set common update flag
+             }
+           break;
+        }
+        
+        case 2: // EXC command, exec indicator control CDU
+        {               
+             // Get exec indicator status:
+             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+             { CDU_STATUS.exec_indicator = atoi(&string_received[char_pntr]);
+               CDU_Status_Update = 1;
+               FSdata_received_flag = true;  // : set common update flag
+             }
+           break;
+        }
+
+        case 3: // BLT command, backlight control CDU     
+        {                 
+             // Get backlight status:
+             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+             { CDU_STATUS.backlight = atoi(&string_received[char_pntr]);
+               CDU_Status_Update = 1;
+               FSdata_received_flag = true;  // : set common update flag
+             }
+           break;
+        } 
+        
+        case 4: // SBY command, standby control CDU      
+        {               
+             // Get standby status:
+             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+             if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+             { CDU_STATUS.stby_mode = atoi(&string_received[char_pntr]);
+               CDU_Status_Update = 1;
+               FSdata_received_flag = true;  // : set common update flag
+             }
+           break;
+        }        
+        
+        case 5: // CLS command, CDU clear screen control
+        {    
+             DO_CLR_SCREEN = 1;            // : tell to clear the screen
+             FSdata_received_flag = true;  // : set common update flag
+           break;
+        }        
+
+
+        case 6: // SBC command, screen background colour control       
+        {                 
+             char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                BACKGROUND_COL.BG_RED = colour;
+             }
+             char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                BACKGROUND_COL.BG_GREEN = colour;
+             }
+             char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                BACKGROUND_COL.BG_BLUE = colour; 
+             }                       
+
+             Background_Col_Update = 1;    // : set update of background colour
+             FSdata_received_flag = true;  // : set common update flag                            
+           break;
+        }        
+
+        
+        case 7: // WTX command, write textline to CDU screen   
+        {  
+          // Read linenumber:
+          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
+          line = atoi(&string_received[char_pntr]);
+          // Read char position:
+          char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
+          pos = atoi(&string_received[char_pntr]);
+           
+          // Test if char X,Y position is within range:
+          if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
+          {  // Read font size :
+                char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+                size = atoi(&string_received[char_pntr]);
+                // Test if size is valid:
+                if ( size == 0 || size == 1 ) {
+                    TEXTLINE[line].font_size = atoi(&string_received[char_pntr]);
+                    modified = true;
+                }
+             // Read line font style:
+             char_pntr = comma[4] + 1; // : set char pointer to char after comma 4 
+             ch = string_received[char_pntr];
+             if (ch == fstyle_1 || ch == fstyle_2 ) {
+                 TEXTLINE[line].font_style = ch;                                     
+                 modified = true;
+             }
+             // Read RGB line colour:
+             char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                TEXTLINE[line].text_RED = colour;
+                modified = true;
+             }
+             char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                TEXTLINE[line].text_GREEN = colour;
+                modified = true;
+             }
+             char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                TEXTLINE[line].text_BLUE = colour; 
+                modified = true;
+             }                       
+             // Read textfield :
+             char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
+             last = 0;
+             // read font size to determine last possible position:
+             if ( TEXTLINE[line].font_size == 0 ) last = max_text0;
+             else if ( TEXTLINE[line].font_size == 1 ) last = max_text1;
+             
+             if (last > 0 && pos <= last) {  // : test for valid area and valid fontsize
+                a = pos;
+                while ( a <= last )
+                 {  ch = string_received[char_pntr];
+                    if (ch == '*') break; // : do not include * in text
+                    TEXTLINE[line].text[a] = ch;
+                    a++;
+                    char_pntr++;
+                 }
+                modified = true;
+                TEXTLINE[line].text[a] = '\0'; // : mark end of text 
+             }            
+          } 
+           
+          if ( modified == true )  {
+            Text_Line_Update = line;          // : set update of text line
+            FSdata_received_flag = true;      // : set common update flag 
+          }
+          
+          #ifdef DEBUG_LVDK 
+          // --------------- Debug only -----------------------------------------------------------------------
+          // Print received data:
+          //SERIAL_DEBUG.printf("\rWTX command received (1) :\r\n");          
+          //SERIAL_DEBUG.printf("WTX line        : %d\r\n",line );                         // show line nr 
+          //SERIAL_DEBUG.printf("WTX begin pos   : %d\r\n",pos );                          // show begin position   
+          //SERIAL_DEBUG.printf("WTX fontsize is : %d\r\n",TEXTLINE[line].font_size );     // show fontsize 
+          //SERIAL_DEBUG.printf("WTX fontstyle is: %c\r\n",TEXTLINE[line].font_style);     // show fontstyle 
+          //SERIAL_DEBUG.printf("WTX R_colour is : %d\r\n",TEXTLINE[line].text_RED );      // show textcolour 
+          //SERIAL_DEBUG.printf("WTX G_colour is : %d\r\n",TEXTLINE[line].text_GREEN );    // show textcolour 
+          //SERIAL_DEBUG.printf("WTX B_colour is : %d\r\n",TEXTLINE[line].text_BLUE );     // show textcolour 
+          //SERIAL_DEBUG.printf("WTX line text is: \r\n" );           
+          //SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[line].text );  // show line text
+          //----------------------------------------------------------------------------------------------------
+          #endif
+                   
+         break;
+        }        
+        
+        case 8: // ETX command, erase (part of) textline of CDU screen        
+        { 
+          // Read linenumber:
+          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
+          line = atoi(&string_received[char_pntr]);
+          // Read char position:
+          char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
+          pos = atoi(&string_received[char_pntr]);
+          // Read nr of char to be erased:
+          char_pntr = comma[3] + 1; // : set char pointer to char after comma 3          
+          cnt = atoi(&string_received[char_pntr]);
+          // Test if char X,Y position is within range:
+          if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
+          {  
+             last = 0;          
+             // read font size to determine last possible position:
+             if ( TEXTLINE[line].font_size == 0 )last = max_text0;
+             else if ( TEXTLINE[line].font_size == 1 )last = max_text1;
+             
+             if (last > 0 && pos <= last && cnt > 0) {  // : test if in valid area and chars > 0
+                a = pos;
+                modified = true;
+                while ( a <= last && cnt > 0)
+                 {  
+                    TEXTLINE[line].text[a] = ' '; //: write space
+                    a++;
+                    cnt--;
+                 }
+             }              
+          } 
+          if ( modified == true )  {
+            Text_Line_Update = line;          // : set update of text line
+            FSdata_received_flag = true;      // : set common update flag 
+          }
+           
+          #ifdef DEBUG_LVDK 
+          // ---------------- Debug only -----------------------------------------------
+          // Print :
+          //SERIAL_DEBUG.printf("ETX line : %d\r\n",line );        // show line nr 
+          //SERIAL_DEBUG.printf("ETX first erase pos : %d\r\n",pos );  // show begin pos   
+          //SERIAL_DEBUG.printf("ETX modified text line :\r\n" );  
+          //SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[line].text );    // show text line
+          // ---------------------------------------------------------------------------
+          #endif
+          
+         break; 
+        }        
+        
+        case 9: // KTX command, write textline to select key area  
+        {                    
+           // Read key ID:
+          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
+          k_id = atoi(&string_received[char_pntr]);
+          
+           SERIAL_DEBUG.printf("KTX key nr is   : %d\r\n",k_id );                             // show key nr 
+          
+          // Read text type:
+          char_pntr = comma[2] + 1; // : set char pointer to char after comma 2 
+          ch = string_received[char_pntr];
+          
+          if (ch == 'M' && k_id < max_keys ) // : text type = MAIN text and keyID valid
+          {   // Read font size :
+              char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+              size = atoi(&string_received[char_pntr]);
+              // Test if size is valid:
+              if ( size == 0 || size == 1 ) {
+                  SELKEY_MAINTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
+                  modified = true;
+              }
+             // Read line font style:
+             char_pntr = comma[4] + 1; // : set char pointer to char after comma 4 
+             ch = string_received[char_pntr];
+             if (ch == fstyle_1 || ch == fstyle_2 ) {
+                 SELKEY_MAINTEXT[k_id].font_style = ch;                                     
+                 modified = true;
+             }
+             // Read RGB line colour:
+             char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                SELKEY_MAINTEXT[k_id].text_RED = colour;
+                modified = true;
+             }
+             char_pntr = comma[6] + 1; // : set char pointer to char after comma 5
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                SELKEY_MAINTEXT[k_id].text_GREEN = colour;
+                modified = true;
+             }
+             char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                SELKEY_MAINTEXT[k_id].text_BLUE = colour; 
+                modified = true;
+             }                       
+             // Read textfield :
+             char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
+             last = 0;
+             // read font size to determine last possible position:
+             if ( SELKEY_MAINTEXT[k_id].font_size == 0 )last = max_text0;
+             else if ( SELKEY_MAINTEXT[k_id].font_size == 1 )last = max_text1;
+             
+             if (last > 0) {  // : test on valid fontsize
+                a = 0;  // : !!! pos 0 !!
+                modified = true;
+                while ( a <= last )
+                 {  ch = string_received[char_pntr];
+                    if (ch == '*') break; // : do not include * in text
+                    SELKEY_MAINTEXT[k_id].text[a] = ch;
+                    a++;
+                    char_pntr++;
+                 }
+               SELKEY_MAINTEXT[k_id].text[a] = '\0'; // : mark end of text 
+             }            
+ 
+             if ( modified == true )  {
+              Key_Maintext_Update = k_id;       // : set keynumber whose main text was updated 
+              FSdata_received_flag = true;      // : set common update flag 
+             }
+ 
+         
+          // ----------------------- Debug only -----------------------------------------------------------------
+          // Print all fields :
+          SERIAL_DEBUG.printf("KTX key nr is   : %d\r\n",k_id );                             // show key nr 
+          SERIAL_DEBUG.printf("KTX MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[k_id].text );       // show text  
+          SERIAL_DEBUG.printf("KTX fontsize is : %d\r\n",SELKEY_MAINTEXT[k_id].font_size );  // show fontsize 
+          SERIAL_DEBUG.printf("KTX fontstyle is: %c\r\n",SELKEY_MAINTEXT[k_id].font_style);  // show fontstyle 
+          SERIAL_DEBUG.printf("KTX R_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_RED );   // show textcolour 
+          SERIAL_DEBUG.printf("KTX G_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_GREEN ); // show textcolour 
+          SERIAL_DEBUG.printf("KTX B_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_BLUE );  // show textcolour 
+          
+          // Fake debug printout: if Key 00 detected, put key 00 main text on begin line 3, 
+          // just to show some key 00 info on debug terminal:
+          // if(k_id == 0) {
+             
+             // cnt = 0;
+             // while ( cnt < a) {
+             //    TEXTLINE[3].text[cnt] =  SELKEY_MAINTEXT[k_id].text[cnt]; 
+             //    cnt++;
+             // }
+           //}
+          //----------------------------------------------------------------------------------------------------
+         
+          
+          }
+          
+          else if ( ch == 'S' && k_id < max_keys ) // : text type = SUB text and keyID valid
+          {   // Read font size 0 - 9:
+              char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+              size = atoi(&string_received[char_pntr]);
+              // Test if size is valid:
+              if ( size == 0 || size == 1 ) {
+                  SELKEY_SUBTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
+                  modified = true;
+              }
+             // Read line font style:
+             char_pntr = comma[4] + 1; // : set char pointer to char after comma 4 
+             ch = string_received[char_pntr];
+             if (ch == fstyle_1 || ch == fstyle_2 ) {
+                 SELKEY_SUBTEXT[k_id].font_style = ch;                                     
+                 modified = true;
+             }
+             // Read RGB line colour:
+             char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                 SELKEY_SUBTEXT[k_id].text_RED = colour;
+                 modified = true;
+             }
+             char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                 SELKEY_SUBTEXT[k_id].text_GREEN = colour;
+                 modified = true;
+             }
+             char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
+             colour = atoi(&string_received[char_pntr]);
+             if ( colour >= 0 && colour <= max_col_nr ) {
+                 SELKEY_SUBTEXT[k_id].text_BLUE = colour; 
+                 modified = true;
+             }                       
+             // Read textfield :
+             char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
+             last = 0;
+             // read font size to determine last possible position:
+             if ( SELKEY_SUBTEXT[k_id].font_size == 0 )last = max_text0;
+             else if ( SELKEY_SUBTEXT[k_id].font_size == 1 )last = max_text1;
+             
+             if (last > 0) {  // : test on valid fontsize
+                a = 0;  // : !!! pos 0 !!
+                modified = true;
+                while ( a <= last )
+                 {  ch = string_received[char_pntr];
+                    if (ch == '*') break; // : do not include * in text
+                    SELKEY_SUBTEXT[k_id].text[a] = ch;
+                    a++;
+                    char_pntr++;
+                 }
+               SELKEY_SUBTEXT[k_id].text[a] = '\0'; // : mark end of text 
+             }            
+ 
+             if ( modified == true )  {
+              Key_Subtext_Update = k_id;       // : set keynumber whose sub text was updated 
+              FSdata_received_flag = true;     // : set common update flag 
+             }
+             
+          #ifdef DEBUG_LVDK
+          // ------------------ Debug only ----------------------------------------------------------
+          // Print all fields :
+          //SERIAL_DEBUG.printf("KTX key nr is   : %d\r\n",k_id );                            // show key nr 
+          //SERIAL_DEBUG.printf("KTX SUBTEXT is : %s\r\n",SELKEY_SUBTEXT[k_id].text );        // show text  
+          //SERIAL_DEBUG.printf("KTX fontsize is : %d\r\n",SELKEY_SUBTEXT[k_id].font_size );  // show fontsize 
+          //SERIAL_DEBUG.printf("KTX fontstyle is: %c\r\n",SELKEY_SUBTEXT[k_id].font_style);  // show fontstyle 
+          //SERIAL_DEBUG.printf("KTX R_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_RED );   // show textcolour 
+          //SERIAL_DEBUG.printf("KTX G_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_GREEN ); // show textcolour 
+          //SERIAL_DEBUG.printf("KTX B_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_BLUE );  // show textcolour 
+          // -----------------------------------------------------------------------------------------
+          #endif
+          
+          }
+     
+         break;
+        }        
+
+        default:
+        {   
+          // unknown commandnumber !
+         break;
+        }        
+
+    }
+    
+    CDU_OS.FreeResource(FS_DATA_RESOURCE); // ; free FS database  
+   // set mbos Event:
+   if (FSdata_received_flag == true) {
+          
+         CDU_OS.SetEvent(FS_DATA_EVENT,CDU_DSP_CSS_TASK_ID); // : set event for updating CDU screen task
+      
+         FSdata_received_flag = false; // : reset commomn flag
+   }
+}
+
+
+
+
diff -r e0bf3b244d7c -r 6576a287e563 FS_datastructures.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FS_datastructures.h	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,61 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File:  FS_datastructures.h 
+// Global data structures containing updated data received from FS
+ 
+// ---- FS-to-CDU data structures to be filled with received data ---------------------------------------------------------------------------
+ 
+// Background colour of CDU display:
+extern struct { int   BG_RED;            //  : RED value   0 - 255
+                int   BG_GREEN;          //  : GREEN value 0 - 255
+                int   BG_BLUE;           //  : BLUE value  0 - 255   
+              } BACKGROUND_COL;
+ 
+// Main text lines at selectkeys:
+extern struct { char  text[52];          //  : maintext string, ending with '\0'   
+                int   font_size;         //  : fontsize of textline 0 or 1            
+                char  font_style;        //  : style character S or N                       
+                int   text_RED;          //  : RED value of textline 0 - 255
+                int   text_GREEN;        //  : GREEN value of textline 0 - 255
+                int   text_BLUE;         //  : BLUE value of textline 0 - 255
+              } SELKEY_MAINTEXT[];       //  : array of selectkey Maintext structures 
+        
+// Sub text lines at selectkeys:
+extern struct { char  text[52];          //  : subtext string, ending with '\0'   
+                int   font_size;         //  : fontsize of textline 0 or 1                            
+                char  font_style;        //  : style character S or N                        
+                int   text_RED;          //  : RED value of textline 0 - 255
+                int   text_GREEN;        //  : GREEN value of textline 0 - 255
+                int   text_BLUE;         //  : BLUE value of textline 0 - 255
+              } SELKEY_SUBTEXT[];        //  : array of selectkey Subtext structures 
+ 
+// Screen textlines:
+extern struct { char  text[52];          //  : text line string, ending with '\0'   
+                int   font_size;         //  : fontsize of textline 0 or 1         
+                char  font_style;        //  : style character S or N                             
+                int   text_RED;          //  : RED value of textline  0 - 255
+                int   text_GREEN;        //  : GREEN value of textline 0 - 255
+                int   text_BLUE;         //  : BLUE value of textline 0 - 255
+              } TEXTLINE[];              //  : array of textline structures
+            
+// CDU status:            
+extern struct { int msg_indicator;       //  : MSG  0 = light OFF, 1 = light ON
+                int exec_indicator;      //  : EXEC 0 = indicator OFF, 1 = indicator ON
+                int fail_indicator;      //  : FAIL 0 = indicator OFF, 1 = indicator ON
+                int dspy_indicator;      //  : DSPY 0 = indicator OFF, 1 = indicator ON  
+                int ofst_indicator;      //  : OFST 0 = indicator OFF, 1 = indicator ON                              
+                int backlight;           //  : 0 = light OFF, 1 = light ON 
+                int stby_mode;           //  : 0 = operational mode, 1 = standby mode
+              } CDU_STATUS;           
+ 
+ 
+// FS_data_update_ID:
+// These global flags indicate what data has been updated.
+// Should be tested when FS_DATA_EVENT occurs.
+extern int Background_Col_Update;    // : 1 when color was updated, must be reset to 0 when data has been read
+extern int CDU_Status_Update    ;    // : 1 when status was updated, must be reset to 0 when data has been read
+extern int DO_CLR_SCREEN        ;    // : 1 when screen should be cleared, must be reset to 0 when done
+extern int Text_Line_Update     ;    // : equal to line number whose text was updated, must be reset to 0 when text has been read 
+extern int Key_Maintext_Update  ;    // : equal to keynumber whose main text line was updated, must be reset to -1 (!)when text has been read
+extern int Key_Subtext_Update   ;    // : equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
+ 
+ 
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 MODSERIAL.lib
--- a/MODSERIAL.lib	Tue Jan 29 14:54:14 2013 +0000
+++ b/MODSERIAL.lib	Thu Jul 17 10:09:14 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Sissors/code/MODSERIAL/#3ba4341d74d6
+http://mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
diff -r e0bf3b244d7c -r 6576a287e563 TextLCD.lib
--- a/TextLCD.lib	Tue Jan 29 14:54:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r e0bf3b244d7c -r 6576a287e563 USB_receive_2.cpp
--- a/USB_receive_2.cpp	Tue Jan 29 14:54:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +0,0 @@
-// L. van der Kolk, ELVEDEKA, Holland //
-// File:  USB_receive_2.cpp Mbos version
-
-#include "mbed.h"
-#include "MODSERIAL.h" // : Note: import lib of Erk Olieman V1.25 to prevent compiler error!
-
-// Instantiate USB communication defined by Mbed USB TX and RX lines
-// with TX and RX ringbuffers :
-MODSERIAL USB(USBTX, USBRX, 256, 512);   
-   
-void decode_string(int nummer_of_chars);
-void read_datafields(int command_number);
-
-#define max_string_length 80 // : max length of received string starting with $ and ending with CR/LF
-#define min_string_length 10 // : min length of received string starting with $ and ending with CR/LF
-char string_received[max_string_length + 2]; // : holds received string starting with $ and ending with CR/LF
-
-int  receive_flag = false;   // :  global flag, signals a receive 'event' 
-
-#define max_commas 10  // : max. nr of possible field separating commas in a valid message string to CDU
-int comma[max_commas];      // : array with positions of all found commas in string_receved[]
-#define message_header "$PCDU"  // : common message header in all messages
-
-#define max_nr_of_commands 16   // : max nr of possible FS-to-CDU commands
-// Define array of pointers to possible FS-to-CDU commands with 3 characters:
-const char *command[max_nr_of_commands] = {
-   "123",    // : no valid CDU command nr. 0 , used for debugging only
-   "MSG",    // : command nr. 1
-   "EXC",    // : command nr. 2
-   "BLT",    // : command nr. 3
-   "SBY",    // : command nr. 4
-   "CLS",    // : command nr. 5
-   "SBC",    // : command nr. 6
-   "WTX",    // : command nr. 7
-   "ETX",    // : command nr. 8
-   "KTX",    // : command nr. 9
-   "STV",    // : command nr. 10
-   "GTV",    // : command nr. 11
-};
-
-void collect_FSdata()  {
-     // Function reads data from the RX buffer
-     // and collects strings starting with $ and ending with CR/LF.
-     // Strings shorter than min_string_length or longer than
-     // max_string_length will be ignored, others will be decoded further.
-    static int $_detected = false;      // : no valid begin of string detected (init only on first call)
-    static int string_pntr = 0;         // : pointer at begin of string (init only on first call)
-    static int nr_of_received_char = 0; // : counter of received characters (init only on first call)
-    char rx_char;
-             
-    while ( !USB.rxBufferEmpty() )
-    {    rx_char = USB.getc(); // : get a char from Rx buffer
-        //USB.putc(rx_char);    // : unprotected (!) immediate echo of char in case of debugging  <<<
-        // Check for string starting with $ char:
-        if ( rx_char == '$' && $_detected == false ){
-            $_detected = true;  // : begin of string is detected 
-            string_pntr = 0;    // : set pointer to begin of string_received[] buffer
-        }
-        string_received[string_pntr] = rx_char;
-        string_pntr++;
-        
-        if (string_pntr >= max_string_length) {
-            // command string looks too long, so start all over again:
-            string_pntr = 0;  // : set pointer back to begin of string_received[] again
-            nr_of_received_char = 0;   // : reset number of received chars
-            $_detected = false;
-        }
-    
-        if ( rx_char == '\n' && $_detected == true ) { 
-            if ( string_pntr > min_string_length ) { // : check minimum string length 
-                // Received string can be interesting now because
-                // it starts with '$' AND it ends on New-Line  AND
-                // it has a minimum length AND it is not too long:
-                string_received[string_pntr] = '\0'; // : mark end of string
-                //  USB.printf("string_received : %s",string_received );  // show string for debugging <<
-                nr_of_received_char = string_pntr;
-                //Call decoder to analyse this string:
-                decode_string(nr_of_received_char);
-                  
-                // Get ready for receiving new commands:
-                $_detected = false;
-                string_pntr = 0;  // : set pointer back to begin of string_received[] again
-                nr_of_received_char = 0;   // : reset number of received chars
-            }
-            else {
-                $_detected = false;  
-                string_pntr = 0; // : set pointer back to begin of string_received[] again
-                nr_of_received_char = 0;   // : reset number of received chars
-            }
-         }
-    } 
-}
-    
-void decode_string(int nummer_of_chars)
-{   // -- This function decodes a received $.....CR/LF string written in string_received[] --
-    // First it checks for a valid checksum and reads the positions of commas in the string.
-    // When checksum is OK, it will continue to look for valid 3 char FS-to-CDU commands.
-    // When a valid command is found, data fields will be analyzed further using the found positions
-    // of commas in the string.
-    int  i,c, equal;
-    char byte_read, exor_byte;
-    char command_string[6], received_checksum[4], calc_checksum[4];
-      
-    // Get checksum and position of commas in string_received[] :
-    exor_byte = 0;
-    i = 1;  // : i points to first char after $
-    c = 1;  // : position of first comma
-      do {
-          byte_read = string_received[i];
-          if (byte_read == ',' && c < max_commas) {
-              comma[c] = i;
-              c++;
-          }
-          if (byte_read == '*') break;
-          exor_byte = exor_byte ^ byte_read;
-          i++;
-      } while ( i < nummer_of_chars );
-    //USB.printf("commas found : %d\n",c-1 );  // : show commas for debugging <<<<<<
-    i++;   // : i points to first checksum char after * char
-    strncpy(received_checksum,&string_received[i],2);   // : copy 2 char checksum after * 
-    // Get calculated checksum by transforming exor_byte in 2 hex chars (with upper case A-F) :
-    sprintf(calc_checksum,"%02X",exor_byte); // : + extra NULL char added by sprintf 
-    equal = strncmp(received_checksum,calc_checksum,2);
-    if (equal != 0) { 
-       //USB.printf("checksum is NOT OK ! \n" );  // : show message for debugging <<<
-    }
-    else { // checksum is OK, go on:
-       // Check for 5 char "$PCDU" header:
-       equal = strncmp(string_received,message_header,strlen(message_header));
-        if (equal != 0) {
-            // USB.printf("no $PCDU header in message !\n" );  // : show message for debugging <<<
-        }
-        else {
-             // Read 3 char command after message_header:
-             strncpy(command_string,&string_received[strlen(message_header)],3);
-             //USB.printf("command found : %3s\n",command_string );  // : show command for debugging <<<
-             // Compare found string with known 3 char command list:
-             i = 0; 
-               do {
-                  equal = strncmp(&command_string[0],command[i],3);
-                  if( equal == 0) break;
-                  i++;
-               } while ( i < max_nr_of_commands);
-              //USB.printf("command number is : %d\n",i );  // : show command nr for debugging <<<
-             if (equal == 0) {
-                 // Command is known now, so now read all data fields:
-                 read_datafields(i);
-             }
-        } 
-    } 
-    
-   receive_flag = false;
- }
- 
- 
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 USB_receive_3.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USB_receive_3.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,195 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File:  USB_receive_3.cpp     
+
+#include "mbed.h"
+#include "MODSERIAL.h" 
+#include "debug_lvdk.h"
+
+extern MODSERIAL USB;
+extern int CDU_FS_interface;  
+
+#ifdef DEBUG_LVDK
+//------- debug only -----------
+extern MODSERIAL SERIAL_DEBUG;
+//------------------------------
+#endif
+   
+void decode_string(int nummer_of_chars);
+void read_datafields(int command_number);
+
+#define max_string_length 80 // : max length of received string starting with $ and ending with CR/LF
+#define min_string_length 10 // : min length of received string starting with $ and ending with CR/LF
+char string_received[max_string_length + 2]; // : holds received string starting with $ and ending with CR/LF
+
+#define message_header "$PCDU"  // : common message header in all messages
+#define max_commas 10  // : max. nr of possible field separating commas in a valid message string to CDU
+int comma[max_commas];      // : array with positions of all found commas in string_receved[]
+
+#define max_nr_of_commands 10   // : max nr of possible FS-to-CDU commands
+// Define array of pointers to possible FS-to-CDU commands with 3 characters:
+const char *command[max_nr_of_commands] = {
+   "123",    // : no valid CDU command nr. 0 , used for debugging only
+   "MSG",    // : command nr. 1
+   "EXC",    // : command nr. 2
+   "BLT",    // : command nr. 3
+   "SBY",    // : command nr. 4
+   "CLS",    // : command nr. 5
+   "SBC",    // : command nr. 6
+   "WTX",    // : command nr. 7
+   "ETX",    // : command nr. 8
+   "KTX",    // : command nr. 9
+};
+
+void collect_FSdata()  {
+     // Function reads characters from FS written in receive buffer.
+     // Wiil be called after each RX receive interrupt, so characters will allways be stored.
+     // When analyze_busy is false, function will start reading characters from defined buffer and 
+     // collects strings starting with $ and ending with CR/LF. 
+     // Strings shorter than min_string_length or longer than max_string_length will be ignored,
+     // others will be analyzed further.
+     // After analyzing, flag analyze_busy will be set to false again.
+    static int $_detected = false;      // : no valid begin of string detected (init only on first call)
+    static int string_pntr = 0;         // : pointer at begin of string (init only on first call)
+    static int nr_of_received_char = 0; // : counter of received characters (init only on first call)
+           char rx_char;                // : character which is analyzed 
+             
+ if ( CDU_FS_interface == 0 ) {  // : USB Port will be used 
+   while ( !USB.rxBufferEmpty() )
+   {    rx_char = USB.getc(); // : get a char from Rx buffer
+        #ifdef DEBUG_LVDK
+        // ----------- Debug only ! -------------------------------------------
+        //SERIAL_DEBUG.putc(rx_char);    // : unprotected immediate echo of char 
+        // --------------------------------------------------------------------
+        #endif
+        // Check for string starting with $ char:
+        if ( rx_char == '$' && $_detected == false ){
+            $_detected = true;  // : begin of string is detected 
+            string_pntr = 0;    // : set pointer to begin of string_received[] buffer
+        }    
+        string_received[string_pntr] = rx_char;
+        string_pntr++;     
+        if (string_pntr >= max_string_length) {
+            // command string looks too long, so start all over again:
+            string_pntr = 0;  // : set pointer back to begin of string_received[] again
+            nr_of_received_char = 0;   // : reset number of received chars
+            $_detected = false;
+        }    
+        if ( rx_char == '\r' && $_detected == true ) {             
+            if ( string_pntr > min_string_length ) { // : check minimum string length 
+                // Received string can be interesting now because
+                // it starts with '$' AND it ends on New-Line  AND
+                // it has a minimum length AND it is not too long:
+                string_received[string_pntr] = '\0'; // : mark end of string
+                #ifdef DEBUG_LVDK
+                // ----------- Debug only ! -------------------------------------------------------------------
+                // SERIAL_DEBUG.printf("string_received : %s",string_received );  // show string for debugging 
+                // --------------------------------------------------------------------------------------------
+                #endif
+                nr_of_received_char = string_pntr;
+                //Call decoder to analyse this string:
+                decode_string(nr_of_received_char);
+                // Get ready for receiving new commands:
+                $_detected = false;
+                string_pntr = 0;  // : set pointer back to begin of string_received[] again
+                nr_of_received_char = 0;   // : reset number of received chars
+            }
+            else {
+                $_detected = false;  
+                string_pntr = 0; // : set pointer back to begin of string_received[] again
+                nr_of_received_char = 0;   // : reset number of received chars
+            }
+        }    
+   } 
+    
+ } 
+}
+    
+void decode_string(int nummer_of_chars)
+{   // -- This function decodes a received $.....CR/LF string written in string_received[] --
+    // First it checks for a valid checksum and reads the positions of commas in the string.
+    // If checksum is OK, it will continue to look for valid 3 char FS-to-CDU commands.
+    // When a valid command is found, data fields will be analyzed further using the found positions
+    // of commas in the string.
+    int  i,c, equal;
+    char byte_read, exor_byte;
+    char command_string[6], received_checksum[4], calc_checksum[4];
+   // Get checksum and position of commas in string_received[] :
+    exor_byte = 0;
+    i = 1;  // : i points to first char after $
+    c = 1;  // : position of first comma
+      do {
+          byte_read = string_received[i];
+          if (byte_read == ',' && c < max_commas) {
+              comma[c] = i;
+              c++;
+          }
+          if (byte_read == '*') break;
+          exor_byte = exor_byte ^ byte_read;
+          i++;
+      } while ( i < nummer_of_chars );
+      
+    #ifdef DEBUG_LVDK
+    // ----------- Debug only ---------------------------------------------------------  
+    //SERIAL_DEBUG.printf("commas found : %d\n",c-1 );  // : show commas for debugging 
+    // --------------------------------------------------------------------------------
+    #endif
+    i++;   // : i points to first checksum char after char *
+    strncpy(received_checksum,&string_received[i],2);   // : copy 2 char checksum after * 
+    // Get calculated checksum by transforming exor_byte in 2 hex chars (with upper case A-F) :
+    sprintf(calc_checksum,"%02X",exor_byte); // : + extra NULL char added by sprintf 
+    equal = strncmp(received_checksum,calc_checksum,2);
+    
+    // bypass checksum check: ------- !!!!!!!!!
+    equal = 0;
+    //-------------------------------
+    
+    if (equal != 0) {
+       #ifdef DEBUG_LVDK
+       // ----------- Debug only ------------------------------------------------------- 
+       SERIAL_DEBUG.printf("checksum is NOT OK ! \n" );  // : show message for debugging
+       // ------------------------------------------------------------------------------
+       #endif
+    }
+    else { // checksum is OK, go on:
+        // Check for 5 char "$PCDU" header:
+        equal = strncmp(string_received,message_header,strlen(message_header));
+          if (equal != 0) {
+            #ifdef DEBUG_LVDK
+            // ----------- Debug only --------------------------------------------------------------
+            SERIAL_DEBUG.printf("no $PCDU header in message !\n" );  // : show message for debugging 
+            // -------------------------------------------------------------------------------------
+            #endif
+          }
+          else {
+               // Read 3 char command after message_header:
+               strncpy(command_string,&string_received[strlen(message_header)],3);
+               #ifdef DEBUG_LVDK
+               // ----------- Debug only ---------------------------------------------------------------------
+               //SERIAL_DEBUG.printf("\ncommand found : %3s\n",command_string ); // : show command for debugging 
+               //SERIAL_DEBUG.printf("commas found : %d\n",c-1 );               // : show commas for debugging
+               // --------------------------------------------------------------------------------------------
+               #endif
+               // Compare found string with known 3 char command list:
+               i = 0; 
+               do {
+                  equal = strncmp(&command_string[0],command[i],3);
+                  if( equal == 0) break;
+                  i++;
+               } while ( i < max_nr_of_commands);
+               
+                #ifdef DEBUG_LVDK
+                // ----------- Debug only ---------------------------------------------------------------
+                //SERIAL_DEBUG.printf("command number is : %d\n",i );  // : show command nr for debugging 
+                // --------------------------------------------------------------------------------------
+                #endif
+                
+               if (equal == 0) {
+                 // Command is known now, so now read all data fields:
+                 read_datafields(i);
+              }
+         } 
+    } 
+    
+ }
+ 
+ 
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 buttontest.cpp
--- a/buttontest.cpp	Tue Jan 29 14:54:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-// L. van der Kolk, ELVEDEKA, Holland //
-// File:  buttontest.cpp 
-// Functions to test KEY message with 4 Mbed board test buttons 
-
-#include "mbed.h"
-#include "MODSERIAL.h"
-
-#include "mbos.h"
-//#include "mbos_definitions.h ------!!!!!    
-#define SEND_KEYMESSAGE_TASK_ID  3      //
-#define KEY_EVENT    4                  //
-//----------------------------------------
-
-DigitalOut led4(LED4); // : LED 4 on Mbed board for test     
-BusInOut button(p24, p23, p22, p21); // : Mbed buttons as 4 bit bus 
-
-extern mbos CDU_OS; 
-extern int key_hit_ID;
-
-int button_info = 0;     
-
-void init_buttons_Mbed() {
-    // set button bus as input :
-    button.input();
-    // enable pull up resistors on inputs:
-    button.mode(PullUp);
-}
-
-void scan_buttons_Mbed() {
-  static int pushed = false;
-  
-  switch (button) {
-    case 0xF : {
-    // nothing pushed, reset pushed flag:
-        pushed = false;
-        break;
-    }
-    case 0x7 : {
-    // button 1 pushed:
-        if ( pushed == false ) button_info = 33;
-        pushed = true;
-        break;
-    }
-    case 0xB : {
-    // button 2 pushed:
-        if ( pushed == false ) button_info = 34;
-        pushed = true;
-        break; 
-    }   
-    case 0xD : {
-    // button 3 pushed:
-        if ( pushed == false ) button_info = 12;
-        pushed = true;
-        break;
-    }
-    case 0xE : {
-    // button 4 pushed:
-        if ( pushed == false ) button_info = 21;
-        pushed = true;
-        break;
-    }
-    default :  {
-         break;
-    }
-  }
-    if (button_info != 0) {
-        key_hit_ID = button_info;  // : set global key_ID
-        button_info = 0;
-        CDU_OS.SetEvent(KEY_EVENT,SEND_KEYMESSAGE_TASK_ID); // : set KEY event ( = key pressed )
-        led4 = !led4; // : toggle LED 4 to show button pressed
-        
-    }  
-}
diff -r e0bf3b244d7c -r 6576a287e563 debug_lvdk.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug_lvdk.h	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,10 @@
+// File: debug_lvdk.h
+// L. van der Kolk, ELVEDEKA, Holland 
+//
+// Include file for debug compilation  on / off
+//
+// --- Debug compilation control: ------------------------
+// --> Put next line as //comment when NOT debugging !
+//#define DEBUG_LVDK 1 
+// - so debugging is off now ! -
+// -------------------------------------------------------
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 display.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,407 @@
+//Display control functions --
+ 
+#include "mbed.h"
+#include "TFT_4DGL.h"
+#include "display.h"
+#include <string> 
+using namespace std;
+ 
+DigitalOut VGA_SOURCE( p7 ); //control line for video switch between INT and EXT video
+DigitalOut VGA_SELECT( p8 ); //control line to select/deselect video switch
+ 
+/*
+=====================================================
+SGC (Serial Graphics Controller) PLATFORM OUTPUT FILE
+=====================================================
+ 
+*******************************************************
+* Must set 'New image format' for usage on Picaso SGC *
+* Data:                                               *
+*  0x59, 0x06, 0x00                                   *
+* 4DSL command:                                       *
+*  Control(6,0)                                       *
+*******************************************************
+ 
+---------------------------------------------------------------------------------------
+File "logo_flyengravity.jpg" (logo_flyengravity.jpg)
+Sector Address 0x000000
+X = 0 Y = 135 Width = 640 Height = 215 Bits = 16
+ 
+Display Image from Memory Card (Serial Command):
+Syntax:
+@, I, x, y, SectorAdd(hi), SectorAdd(mid), SectorAdd(lo)
+Picaso Data:
+0x40, 0x49, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00
+4DSL command:
+NewUSDImage(0, 135, 0x000000)
+ 
+---------------------------------------------------------------------------------------
+File "Testscreen.png" (Testscreen.png)
+Sector Address 0x00021A
+X = 0 Y = 0 Width = 640 Height = 480 Bits = 16
+ 
+Display Image from Memory Card (Serial Command):
+Syntax:
+@, I, x, y, SectorAdd(hi), SectorAdd(mid), SectorAdd(lo)
+Picaso Data:
+0x40, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1A
+4DSL command:
+NewUSDImage(0, 0, 0x00021A)
+ 
+*/
+ 
+/*Display Commands
+ 
+$PCDUCLS Erase to active background colour (default black) or white
+===================================================================
+Syntax: $PCDUCLS, <mode>*<checksum>CRLF
+ <mode>=0 : Clear screen to current background colour (default=black)
+ <mode>=1 : Clear screen to white
+ 
+$PCDUSBC Set Background Color
+====================================================================
+Syntax: $PCDUSBC,<Rcolour>,<Gcolour>,<Bcolour>*<checksum>CRLF
+ < Rcolour > : RED (000‐255)
+ < Gcolour > : GREEN (000‐255)
+ < Bcolour > : BLUE (000‐255)
+ Set background colour to RGB as defined in the three data fields.
+ 
+$PCDUWTX WTX=WRITE TEXT Write text on any X,Y position on the screen.
+=====================================================================
+Syntax: $PCDUWTX,<Fsize>,<Fstyle>,<Rcolour>,<Gcolour>,<Bcolour>,<Text><Col>,<Row>*<checksum>CRLF
+ <Fsize> : Font size (F0..F9). Currently F0 and F1 are implemented.
+ <Fstyle> : Font style (S=Standard, B=Bold, I=Italic, U=Underline, N=Negative)
+ < Rcolour > : RED (000‐255)
+ < Gcolour > : GREEN (000‐255)
+ < Bcolour > : BLUE (000‐255)
+ <Text> : Any printable ASCII character except the * character as this is used as the text field delimiter. 
+  Maximum length is 24 characters, minimum length is 1 character for font F0.
+  Maximum length is 48 characters, minumum length is 1 character for font F1.
+ <Col> : Horizontal position of the first character (1..24)
+ <Row> : Vertical position of the line (1..14)
+ 
+$PCDUETX ETX=ERASE TEXT
+============================================================= 
+Syntax: $PCDUETX, <Col>,<Row>,<n>*<checksum>CRLF
+ <Col> : Horizontal position of the first character (1..24 for font F0 or 1..48 for font F1)
+ <Row> : Vertical position of the line (1‐14)
+ <n> : number of characters to be erased (1..24 for font F0 or 1..48 for font F1)
+ 
+$PCDUKTX                Write text attached to a Select Key
+===========================================================
+Syntax: $PCDUKTX,<KeyID>,<Texttype>,<Fsize>,<Fstyle>,<Rcolour>,<Gcolour>,<Bcolour>,<Text>*< checksum>CRLF
+ <KeyID> : Numbering is 00 – 49 for left keys and 50 – 99 for right keys. Top keys are 00 and 50.
+ <Texttype> : M or S, meaning Main text or Subtext.
+ <Fsize> : Font size (F0..F9). Currently F0 and F1 are implemented.
+ <Fstyle> : Font style (S=Standard, B=Bold, I=Italic, U=Underline, N=Negative)
+ < Rcolour > : RED (000‐255)
+ < Gcolour > : GREEN (000‐255)
+ < Bcolour > : BLUE (000‐255)
+ <Text> : Any printable ASCII character within the character set.except the * character as this is used as the text field delimiter. 
+ Maximum length is 24 characters, minimum length is 1 character for font F0
+ Maximum length is 48 characters, minumum length is 1 character for font F1.
+*/
+ 
+//Control lines for VGA driver board
+TFT_4DGL display(p13,p14,p15); // serial tx, serial rx, reset pin
+ 
+//Character & String functions
+ 
+char* str2char( string cString ) //convert a string to a character array
+    {
+    int nStrLen=cString.size();
+    std::string cInput( cString );
+    char* cText = new char[nStrLen+1];
+    strncpy(cText, cInput.c_str(), nStrLen);
+    cText[nStrLen] = '\0';
+    return cText;
+    }
+    
+int centertext( string cString, int nChars, int nCharWidth )
+    //calculates the startposition on the screen to center the text
+    //needs the actual string (cString), screenwidth in characters (nChars) and the character width (nCharWidth)
+    {
+    int nStart;
+    nStart = nCharWidth*( nChars/2-( cString.size()/2 ));
+    return nStart;
+    }
+    
+int righttext( string cString, int nChars, int nCharWidth )
+    //calculates the startposition on the screen to right-align the text
+    //needs the actual string (cString), screenwidth in characters (nChars) and the character width (nCharWidth)
+    {
+    int nStart;
+    nStart = nCharWidth*( nChars - cString.size());
+    return nStart;
+    }
+ 
+int nFontSize( int nfont_number )
+{
+    int nFont = 0;
+    switch ( nfont_number )
+    {
+        case 0:
+        {
+            nFont = FONT_12X34;
+            break;
+        }
+        case 1:
+        {
+            nFont = FONT_24X34;
+            break;
+        }
+    }
+    return ( nFont );
+}    
+ 
+int nFontWidth (int nfont_number )
+{
+    int nFont = 12;
+    switch ( nfont_number )
+    {
+        case 0:
+        {
+            nFont = 12;
+            break;
+        }
+        case 1:
+        {
+            nFont = 24;
+            break;
+        }
+    }
+    return ( nFont );
+}    
+ 
+unsigned int cRGB( char cRED, char cGREEN, char cBLUE )
+{
+    //assemble separate colors into 1 integer value as 0xRRGGBB
+    //Display driver requires this format
+    unsigned int RGB = cBLUE + 256*cGREEN + 65536*cRED;
+    return ( RGB );
+}    
+ 
+int LeftOrRight( int nTextLine, string cString, int nChars, int nCharWidth )
+{
+    //decide to print data left aligned or right aligned
+    //00 - 49 is left  side of screen
+    //50 - 99 is right side of screen
+    int nHorPos = 0; 
+    // nChars is number of characters on this line (24 or 48)
+    // nCharWidth is the character width in pixels
+    
+    if ( nTextLine < 50 )
+    // Left side adjust
+    {
+        nHorPos = 0;
+    }
+    else
+    // Right side adjust
+    {
+        nHorPos = righttext( cString, nChars, nCharWidth );
+    }
+    return ( nHorPos );
+}
+ 
+int nLine2Pixel( int nLine )
+{
+    //calculate vertical pixelposition from linenumber
+    int nPixel = 0;
+    switch ( nLine )
+    {
+        case 1:
+        {
+            nPixel = LINE1;
+            break;
+        }
+        case 2:
+        {
+            nPixel = LINE2;
+            break;
+        }
+        
+        case 3:
+        {
+            nPixel = LINE3;
+            break;
+        }
+        
+        case 4:
+        {
+            nPixel = LINE4;
+            break;
+        }
+        
+        case 5:
+        {
+            nPixel = LINE5;
+            break;
+        }
+        
+        case 6:
+        {
+            nPixel = LINE6;
+            break;
+        }
+        
+        case 7:
+        {
+            nPixel = LINE7;
+            break;
+        }
+        
+        case 8:
+        {
+            nPixel = LINE8;
+            break;
+        }
+        
+        case 9:
+        {
+            nPixel = LINE9;
+            break;
+        }
+        
+        case 10:
+        {
+            nPixel = LINE10;
+            break;
+        }
+        
+        case 11:
+        {
+            nPixel = LINE11;
+            break;
+        }
+        
+        case 12:
+        {
+            nPixel = LINE12;
+            break;
+        }
+        
+        case 13:
+        {
+            nPixel = LINE13;
+            break;
+        }
+        
+        case 14:
+        {
+            nPixel = LINE14;
+            break;
+        }
+        
+    }
+    return ( nPixel ) ;
+}
+ 
+void VGA_SIGNAL( int Source, int On_Off)
+{
+    VGA_SOURCE = Source;
+    VGA_SELECT = On_Off;
+}
+ 
+void CDU_InitDisplay()
+{
+    display.baudrate( 9600 );       //init uVGAIII card
+    VGA_SIGNAL( VGA_INT, VGA_ON );  //select INTERNTAL video and set VGA switch ON
+}
+ 
+void CDU_StartScreen()
+ {
+    string cTitle1="ENGRAVITY";
+    string cTitle2="CONTROL & DISPLAY UNIT";
+    display.cls();   
+    
+    display.graphic_string( str2char( cTitle1 ), centertext( cTitle1, 24, LARGECHAR), LINE6, FONT_24X34, WHITE, 1, 1 );
+    wait_ms(1000);
+    display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, RED, 1, 1 );
+    wait_ms(1000);
+    display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, GREEN, 1, 1 );
+    wait_ms(1000);
+    display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, BLUE, 1, 1 );
+    wait_ms(1000);
+    display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, WHITE, 1, 1 );
+    wait_ms(1000);
+ }
+ 
+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_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
+}
+ 
+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
+}
+
+void CDU_Page()
+{
+    display.cls();
+    display.graphic_string( "PERF INIT" , 8*24,  LINE1, FONT_24X34, WHITE, 1, 1 );
+   
+    display.graphic_string( "GW/CRZ CG" , 0,  LINE2, FONT_12X34, WHITE, 1, 1 );
+    display.graphic_string( "CRZ ALT"   , 41*12, LINE2, FONT_12X34, WHITE, 1, 1 );
+    
+    display.graphic_string( "___._ / 26.2%" , 0,  LINE3, FONT_24X34, WHITE, 1, 1 );
+    display.graphic_string( "_____"     , 19*24, LINE3, FONT_24X34, WHITE, 1, 1 );
+ 
+    display.graphic_string( "FUEL" , 0,  LINE4, FONT_12X34, WHITE, 1, 1 );
+    display.graphic_string( "CRZ/WIND"   , 40*12, LINE4, FONT_12X34, WHITE, 1, 1 );
+        
+    display.graphic_string( "0.0" , 0,  LINE5, FONT_24X34, WHITE, 1, 1 );
+    display.graphic_string( "000$ /---" , 15*24,  LINE5, FONT_24X34, WHITE, 1, 1 );
+   
+    display.graphic_string( "ZFW" , 0,  LINE6, FONT_12X34, WHITE, 1, 1 );
+    display.graphic_string( "___._ " , 0,  LINE7, FONT_24X34, WHITE, 1, 1 );
+   
+    display.graphic_string( "RESERVES" , 0,  LINE8, FONT_12X34, WHITE, 1, 1 );
+    display.graphic_string( "__._ " , 0,  LINE9, FONT_24X34, WHITE, 1, 1 );
+        
+    display.graphic_string( "COST INDEX" , 0,  LINE10, FONT_12X34, WHITE, 1, 1 );
+    display.graphic_string( "TRANS ALT"   , 39*12, LINE10, FONT_12X34, WHITE, 1, 1 ); 
+    
+    display.graphic_string( "___" , 0,  LINE11, FONT_24X34, WHITE, 1, 1 );
+    display.graphic_string( "_____"     , 19*24, LINE11, FONT_24X34, WHITE, 1, 1 );
+   
+    display.graphic_string( "------------------------------------------------"   , 0, LINE12, FONT_12X34, WHITE, 1, 1 ); 
+ 
+    display.graphic_string( "<INDEX" , 0,  LINE13, FONT_24X34, WHITE, 1, 1 );
+    display.graphic_string( "N1 LIMIT>"     , 15*24, LINE13, FONT_24X34, WHITE, 1, 1 );
+   
+    display.graphic_string( "SCRATCHPAD DATA LINE", centertext("SCRATCHPAD DATA LINE", 24, LARGECHAR) , LINE14, FONT_24X34, RED, 1, 1 );
+    
+}
+
+void  CDU_displayclear(){
+    display.cls();
+}
+    
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 display.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.h	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,33 @@
+//MBED CONTROL LINES
+//VGA selector lines
+#define VGA_INT 0   //use internal VGA screen
+#define VGA_EXT 1   //loop through external VGA screen from DB9 connector to display
+#define VGA_ON  0   //wwitch VGA on
+#define VGA_OFF 1   //switch VGA off
+ 
+//LINE and pixel definitions
+#define LINE1 0
+#define LINE2 34
+#define LINE3 68
+#define LINE4 102
+#define LINE5 136
+#define LINE6 170
+#define LINE7 204
+#define LINE8 238
+#define LINE9 272
+#define LINE10 306
+#define LINE11 340
+#define LINE12 374
+#define LINE13 408
+#define LINE14 442
+ 
+//Borders of display
+#define XMIN 0
+#define XMAX 576
+#define YMIN 0
+#define YMAX 476
+ 
+//Width of characters
+#define SMALLCHAR 12
+#define LARGECHAR 24
+ 
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 keyboard.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keyboard.h	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,76 @@
+/* Keyboard TCA8418 declarations */
+ 
+ 
+/* TCA8418 hardware limits */
+#define TCA8418_MAX_ROWS        8
+#define TCA8418_MAX_COLS        10
+ 
+/* TCA8418 register offsets */
+#define REG_CFG                 0x01
+#define REG_INT_STAT            0x02
+#define REG_KEY_LCK_EC          0x03
+#define REG_KEY_EVENT_A         0x04
+#define REG_KEY_EVENT_B         0x05
+#define REG_KEY_EVENT_C         0x06
+#define REG_KEY_EVENT_D         0x07
+#define REG_KEY_EVENT_E         0x08
+#define REG_KEY_EVENT_F         0x09
+#define REG_KEY_EVENT_G         0x0A
+#define REG_KEY_EVENT_H         0x0B
+#define REG_KEY_EVENT_I         0x0C
+#define REG_KEY_EVENT_J         0x0D
+#define REG_KP_LCK_TIMER        0x0E
+#define REG_UNLOCK1             0x0F
+#define REG_UNLOCK2             0x10
+#define REG_GPIO_INT_STAT1      0x11
+#define REG_GPIO_INT_STAT2      0x12
+#define REG_GPIO_INT_STAT3      0x13
+#define REG_GPIO_DAT_STAT1      0x14
+#define REG_GPIO_DAT_STAT2      0x15
+#define REG_GPIO_DAT_STAT3      0x16
+#define REG_GPIO_DAT_OUT1       0x17
+#define REG_GPIO_DAT_OUT2       0x18
+#define REG_GPIO_DAT_OUT3       0x19
+#define REG_GPIO_INT_EN1        0x1A
+#define REG_GPIO_INT_EN2        0x1B
+#define REG_GPIO_INT_EN3        0x1C
+#define REG_KP_GPIO1            0x1D
+#define REG_KP_GPIO2            0x1E
+#define REG_KP_GPIO3            0x1F
+#define REG_GPI_EM1             0x20
+#define REG_GPI_EM2             0x21
+#define REG_GPI_EM3             0x22
+#define REG_GPIO_DIR1           0x23
+#define REG_GPIO_DIR2           0x24
+#define REG_GPIO_DIR3           0x25
+#define REG_GPIO_INT_LVL1       0x26
+#define REG_GPIO_INT_LVL2       0x27
+#define REG_GPIO_INT_LVL3       0x28
+#define REG_DEBOUNCE_DIS1       0x29
+#define REG_DEBOUNCE_DIS2       0x2A
+#define REG_DEBOUNCE_DIS3       0x2B
+#define REG_GPIO_PULL1          0x2C
+#define REG_GPIO_PULL2          0x2D
+#define REG_GPIO_PULL3          0x2E
+ 
+/* TCA8418 bit definitions */
+#define CFG_AI                  BIT(7)
+#define CFG_GPI_E_CFG           BIT(6)
+#define CFG_OVR_FLOW_M          BIT(5)
+#define CFG_INT_CFG             BIT(4)
+#define CFG_OVR_FLOW_IEN        BIT(3)
+#define CFG_K_LCK_IEN           BIT(2)
+#define CFG_GPI_IEN             BIT(1)
+#define CFG_KE_IEN              BIT(0)
+ 
+#define INT_STAT_CAD_INT        BIT(4)
+#define INT_STAT_OVR_FLOW_INT   BIT(3)
+#define INT_STAT_K_LCK_INT      BIT(2)
+#define INT_STAT_GPI_INT        BIT(1)
+#define INT_STAT_K_INT          BIT(0)
+ 
+/* TCA8418 register masks */
+#define KEY_LCK_EC_KEC          0x7
+#define KEY_EVENT_CODE          0x7f
+#define KEY_EVENT_VALUE         0x80
+ 
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 keyboard2.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keyboard2.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,177 @@
+/* File: keyboard2.cpp   W. Braat */
+/* Keyboard chip TCA8418 control */
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "keyboard.h"
+#include "mbos.h"
+#include "mbos_def.h"
+ 
+const int CDU_KB_ADRS  = 0x68;  //Base address TCA8418 keypad scanner
+const int I2C_ACK  = 0x00;
+//const int NACK = 0x01;
+ 
+extern int key_hit_ID;
+extern mbos CDU_OS;
+extern MODSERIAL SERIAL_DEBUG;
+ 
+//CDU Keyboard communications KEYBOARD_INT
+InterruptIn CDU_KB_INT( p5 );  //Set CDU keyboard interrupt line
+I2C CDU_I2C(p28, p27);         //I2C bus for keyboard/temp chip.
+ 
+//CDU Keyboard LEDS
+DigitalOut EXEC( p12 );
+DigitalOut FAIL( p17 );
+DigitalOut DSPY( p18 ); 
+DigitalOut  MSG( p19 );
+DigitalOut OFST( p20 );
+ 
+//CDU background lighting
+AnalogIn BGL_POT( p16 ); //background light control potmeter
+PwmOut BGL_LED( p21 );   //PWM output background lighting
+
+// ---- added by LvdK : -----------------------------------------------------------
+DigitalOut Key_led(LED2); // : LED 2 on Mbed board toggles when CDU key is pressed
+// --------------------------------------------------------------------------------
+ 
+void CDU_KB_COMM_INIT()
+{   //initialize communication with TCA84818
+    char cmd[2];
+    
+    cmd[0] = REG_CFG; //pointer byte to CFG register
+    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
+        cmd[0] = REG_INT_STAT; //pointer byte to Interrupt Status Register
+        cmd[1] = 0x01; //Reset KE-INT flag      
+        CDU_I2C.write(CDU_KB_ADRS,cmd, 2 );  //Write to Interrupt Status Register from TCA4818 
+        
+        //Set TCA8418 to Keypad mode
+        cmd[0]=REG_KP_GPIO1; //KP_GIO1
+        cmd[1]=0xFF; //Set to Keypad mode
+        CDU_I2C.write(CDU_KB_ADRS,cmd, 2);
+       
+        cmd[0]=REG_KP_GPIO2; //KP_GIO2
+        cmd[1]=0xFF; //Set to Keypad mode
+        CDU_I2C.write(CDU_KB_ADRS,cmd, 2);
+      
+        cmd[0]=REG_KP_GPIO3; //KP_GIO3
+        cmd[1]=0xFF; //Set to Keypad mode
+        CDU_I2C.write(CDU_KB_ADRS,cmd, 2);
+       
+    }
+    else
+    {
+        //No response from TCA8418 keyboard chip
+        FAIL = 1; //Switch on FAIL indicator
+    }  
+}
+ 
+void CDU_KB_GET_KEY()
+{
+        
+    Key_led = !Key_led;  // : toggle LED 2
+          
+    char cmd[2];
+    //Read interrupt status flag
+    cmd[0] = REG_INT_STAT; //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 key value
+    
+    //Read Key Lock and Event Counter
+    cmd[0] = REG_KEY_LCK_EC; //pointer byte KEY_LCK_EC
+    CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle
+    CDU_I2C.read(CDU_KB_ADRS, cmd, 1);  //read key value
+          
+    //Keypress --> read data from keybuffer
+    cmd[0] = REG_KEY_EVENT_A; //pointer to Key Event Register KEY_EVENT_A
+    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]);
+        SERIAL_DEBUG.printf("keynumber : %d,%d\r\n",key_hit_ID,cmd[1] ); // : TEST only !
+ 
+    //Reset interrupt flag
+    cmd[0] = REG_INT_STAT; //pointer byte to Interrupt Status Register
+    cmd[1] = 0x01; //Reset KE-INT flag
+    CDU_I2C.write(CDU_KB_ADRS,cmd, 2);
+    
+     //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
+   
+    if ( cmd[0] == 1 )
+    { //reset INT flag failed!
+        while (1)
+        {
+            cmd[0] = 0x04; //pointer to Key Event Register KEY_EVENT_A
+            CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle
+            CDU_I2C.read(CDU_KB_ADRS, cmd, 2);  //read key value (=2 words)
+       
+            //Reset interrupt flag
+            cmd[0] = 0x02; //pointer byte to Interrupt Status Register
+            cmd[1] = 0x01; //Reset KE-INT flag
+            CDU_I2C.write(CDU_KB_ADRS,cmd, 2 );
+   
+            //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
+           
+            if ( cmd[0] == 0 ) break;
+        }   
+    }
+} 
+ 
+void SET_KEY_EVENT()
+{
+    // set KEY_EVENT to wakeup SEND_KEYMESSAGE_TASK :
+    CDU_OS.SetEvent(KEY_EVENT,SEND_KEYMESSAGE_TASK_ID );
+}
+
+void CDU_KB_INT_START()
+{
+    CDU_KB_INT.mode( PullUp );          //Keyboard chip pulls this line to 0 on a keypress
+    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
+    //AnalogIn BGL_POT( p15 ); //background light control potmeter. Returns a value between 0.0 and 1.0
+    //PwmOut BGL_LED( p21 );   //PWM output
+    //calculate required brightness in percentage from 0%-100%
+    //nVal 255     --> calculate brightness from potmeter value (default value if no parameter is passed)
+    //nVal = 0     --> switch off backlight
+    //nVal = 100   --> switch on backlight max
+ 
+    switch (nVal) 
+    {
+        case 0:
+        {
+            //switch off backlighting
+            BGL_LED.pulsewidth( 0.0 );
+            break;
+        }
+        case 100:
+        {
+            //switch on backlighting
+            BGL_LED.pulsewidth( 100.0 );
+            break;
+        }
+        case 255:
+        {
+            //calculate percentage from potmeter value
+        if ( BGL_POT < 0.01 )
+            {
+                BGL_LED = 0.0; //prevents flickering when low intensity
+            }
+        else
+            {
+                BGL_LED = BGL_POT; 
+            }
+        }
+    }
+}          
diff -r e0bf3b244d7c -r 6576a287e563 keys.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keys.h	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,87 @@
+/// File: keys.h  LvdK, ELVEDEKA, Holland
+// Key strings for FS-to-CDU key message SPCDUKEY 
+
+#define max_keys_CDUpanel 80 // : max. number of keys found on CDU panel
+
+const char *key_value[max_keys_CDUpanel] =  // : array of pointers to keystrings terminated by '*'
+           { "???*",     // key 0 not valid, not used
+             "LSK1*",    // key 1
+             "INITRF*",  // key 2
+             "RTE*",     // key 3
+             "LSK4*",    // key 4         
+             "CLB*",     // key 5
+             "CRZ*",     // key 6
+             "DES*",     // key 7
+             "???*",     // key 8             
+             "???*",     // key 9                                   
+             "RSK1*",    // key 10
+             "LSK2*",    // key 11           
+             "MENU*",    // key 12
+             "LEGS*",    // key 13            
+             "???*",     // key 14             
+             "DEPARR*",  // key 15
+             "HOLD*",    // key 16 
+             "PROG*",    // key 17
+             "N1LMT*",   // key 18 
+             "EXEC*",    // key 19
+             "RSK2*",    // key 20            
+             "???*",     // key 21             
+             "N1LMT*",   // key 22
+             "FIX*",     // key 23             
+             "???*",     // key 24
+             "A*",       // key 25             
+             "B*",       // key 26             
+             "C*",       // key 27             
+             "D*",       // key 28             
+             "E*",       // key 29             
+             "RSK3*",    // key 30
+             "LSK4*",    // key 31
+             "PRPAGE*",  // key 32
+             "NXPAGE*",  // key 33
+             "???*",     // key 34             
+             "F*",       // key 35             
+             "G*",       // key 36
+             "H*",       // key 37                          
+             "I*",       // key 38
+             "J*",       // key 39
+             "RSK4*",    // key 40
+             "LSK5*",    // key 41                                                                                           
+             "1*",       // key 42
+             "2*",       // key 43             
+             "3*",       // key 44             
+             "K*",       // key 45             
+             "L*",       // key 46             
+             "M*",       // key 47  
+             "N*",       // key 48               
+             "O*",       // key 49               
+             "RSK5*",    // key 50               
+             "LSK6*",    // key 51  
+             "4*",       // key 52               
+             "5*",       // key 53               
+             "6*",       // key 54               
+             "P*",       // key 55               
+             "Q*",       // key 56               
+             "R*",       // key 57  
+             "S*",       // key 58 
+             "T*",       // key 59
+             "RSK6*",    // key 60
+             "???*",     // key 61
+             "7*",       // key 62
+             "8*",       // key 63
+             "9*",       // key 64
+             "U*",       // key 65
+             "V*",       // KEY 66
+             "W*",       // key 67                                      
+             "X*",       // key 68
+             "Y*",        // key 69 
+             "???*",     // key 70
+             "???*",     // key 71
+             ".*",       // key 72
+             "0*",       // key 73
+             "+/-*",     // key 74
+             "Z*",       // key 75
+             "SP*",      // key 76
+             "DEL*",     // key 77
+             "/*",       // key 78
+             "CLR*",     // key 79
+            }; 
diff -r e0bf3b244d7c -r 6576a287e563 main.cpp
--- a/main.cpp	Tue Jan 29 14:54:14 2013 +0000
+++ b/main.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -1,178 +1,201 @@
-// L. van der Kolk, ELVEDEKA, Holland //
-// File:  main.cpp  Mbos O.S testversion  
+// L. van der Kolk,  W.Braat  
+// File:  main.cpp  
+// Version 21 
+// ---------------------------- 
 
 #include "mbed.h"
 #include "MODSERIAL.h"
 #include "mbos.h"
+#include "debug_lvdk.h" // : debug mode control LvdK
+#include "mbos_def.h"   // : Mbos tasks, timer and resource definitions
 
-//--------------------------------------------------------------------------------
-#include "TextLCD.h"                    //  < LCD connected for testing only << !
-TextLCD lcd(p8, p9, p10, p11, p12, p13); // rs, e, d4-d7 << for testing only << !
-//--------------------------------------------------------------------------------
+// Setup USB communication defined by Mbed USB TX and RX lines
+// with TX and RX ringbuffers :
+MODSERIAL USB(USBTX, USBRX, 256, 512);
+DigitalOut alive_led(LED1); // : LED 1 on Mbed board toggles when CDU is alive
+
+//DigitalOut test_led(LED4); // : LED 4 on Mbed board <<<<<<<< TEST LED !!!
 
-DigitalOut led1(LED1); // : LED 1 on Mbed board toggles when CDU is alive
- 
-extern MODSERIAL USB; 
-extern int key_hit_ID;
+void test_update_flags(); // << for testing only << !!!!!!!
+
+// extra serial port to show debug info :
+MODSERIAL SERIAL_DEBUG(p9, p10, 1024, 64);     //: tx, rx
+
 int CDU_FS_interface = 0;   // : defines interface to FS: 0 = USB, 1 = Ethernet
+extern int key_hit_ID;
+extern PwmOut BGL_LED;
 
-void init_USB();
-void set_initial_CDU_screen();
-void Send_KEY_message(int button); 
+void init_USB(void);
+void set_initial_data(); // : fill datastructures with initial data
+void Send_KEY_message(int button);
 void Send_ALIVE_message(int seconds);
 void collect_FSdata();
 
-//----------------------------------------------------------------
-void init_buttons_Mbed(); // << for testing only << !
-void scan_buttons_Mbed(); // << for testing only << !
-//----------------------------------------------------------------
+mbos CDU_OS( 9, 5, 5); // : instantiate mbos O.S (tasks, timers, resources)
 
-// ALIVE_TASK properties:
-#define ALIVE_TASK_ID           1
-#define ALIVE_TASK_PRIO         50
-#define ALIVE_TASK_STACK_SZ     100    // : must be 100 to prevent stack overflow error!
-
-// ALIVE_TIMER properties:
-#define ALIVE_TIMER_ID          1
-#define ALIVE_TIMER_PERIOD      500  // = 5 sec
-
-// RECEIVE_DECODE_TASK properties:
-#define RECEIVE_DECODE_TASK_ID       2
-#define RECEIVE_DECODE_TASK_PRIO     80
-#define RECEIVE_DECODE_TASK_STACK_SZ 256  // : must be 256 to prevent stack overflow error!
+// Task function prototypes:
+void ALIVE_TASK(void);
+void RECEIVE_DECODE_TASK(void);
+void SEND_KEYMESSAGE_TASK(void);
+void CDU_DSP_CSS_TASK(void);
+void READ_POT_TASK(void);
 
-// SEND_KEYMESSAGE_TASK properties:
-#define SEND_KEYMESSAGE_TASK_ID      3
-#define SEND_KEYMESSAGE_TASK_PRIO    60
-#define SEND_KEYMESSAGE_TASK_STACK_SZ 100   // : must be 100 to prevent stack overflow error!
-
-//------------------------------ LvdK button scan --------------
-// SCAN_KEYS_TASK properties:  
-#define SCAN_KEYS_TASK_ID      4
-#define SCAN_KEYS_TASK_PRIO    85
-#define SCAN_KEYS_TASK_STACK_SZ 100
+// keyboard function prototypes:
+void CDU_KB_COMM_INIT(void);
+void CDU_KB_INT_START(void);
+void CDU_KB_GET_KEY(void);
+void CDU_SET_BGL_INTENSITY(int);
 
-// SCAN_KEYS_TIMER properties: ( LvdK button scan )
-#define SCAN_KEYS_TIMER_ID          2
-#define SCAN_KEYS_TIMER_PERIOD      50  // = 50msec 
-//----------------------------------------------------------------  
-
-// Mbos EVENTS:
-#define ALIVE_EVENT     1      
-#define RX_EVENT        2    // : Event flag caused by serial RX interrupt
-#define KEY_EVENT       4
-#define SCAN_KEYS_TIMER_EVENT 8    // : LvdK button scan timer event
-
-// Mbos resources:
-#define USB_TX_RESOURCE      1     // : for locking USB TX buffer
-#define USB_TX_PRIO         95     // : USB TX resource priority ( = highest! )
+// display function prototype:
+void CDU_InitDisplay(void);
+void CDU_ScreenAlign(void);
+void CDU_StartScreen(void);
+void CDU_Page(void);
+void CDU_DSP_CSS(void);
+void CDU_displayclear(void);
 
 
-mbos CDU_OS( 8, 6, 5); //instantiate mbos O.S (tasks, timers, resources)
-
- // Task function prototypes:
- void ALIVE_TASK(void);
- void RECEIVE_DECODE_TASK(void);
- void SCAN_KEYS_TASK(void);
- void SEND_KEYMESSAGE_TASK(void);
- 
- void char_received(MODSERIAL_IRQ_INFO *q) {
-    // -- This functiom will be called on EACH rx interrupt --
-    // Note: this is Rx interrupt handling, NOT a mbos task.
-    // It only set an mbos Event.
+void char_received(MODSERIAL_IRQ_INFO *q)
+{
+    // -- This functiom will be called on EACH USB receive interrupt --
+    // It only sets an mbos Event:
     CDU_OS.SetEvent(RX_EVENT,RECEIVE_DECODE_TASK_ID); // : set event flag for Read Serial Task
 }
 
-//------------ USB error handling ------------------------------------------------------------
-void rx_buf_overflow(MODSERIAL_IRQ_INFO *q) {
-    // This functiom will be called when RX buffer overflows
-    // Blue-Leds-of-Death will be showed, USB is dead so message itself will not be seen !
-    error("RX OVERFLOW !"); 
+//------------ USB error interrupts ----------------------------------
+void rx_buf_overflow(MODSERIAL_IRQ_INFO *q)
+{
+    // This functiom will be called when RX buffer overflows.
+    // Blue-Leds-of-Death will be showed on Mbed board
+    error("RX OVERFLOW !");
 }
 
-void tx_buf_overflow(MODSERIAL_IRQ_INFO *q) {
-    // This functiom will be called when TX buffer overflows
-    // Blue-Leds-of-Death will be showed, USB is dead so message itself will not be seen !
-    error("TX OVERFLOW !");  
+void tx_buf_overflow(MODSERIAL_IRQ_INFO *q)
+{
+    // This functiom will be called when TX buffer overflows.
+    // Blue-Leds-of-Death will be showed on Mbed board
+    error("RX OVERFLOW !");
 }
-//---------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------
 
 void init_USB()
-{   // -- This function controls the setup for the CDU-FS USB communication --
-    // Function char_received() is attached to Rx interrupt.
-    USB.baud(38400); // allways set default baudrate to 38400
-    USB.attach(&char_received, MODSERIAL::RxIrq);    // : attach function char_received to RX inerrupt
-    USB.attach(&rx_buf_overflow, MODSERIAL::RxOvIrq); //: attach function to call when RX buffer overflows
-    USB.attach(&tx_buf_overflow, MODSERIAL::TxOvIrq); //: attach function to call when TX buffer overflows
+{
+    // -- This function controls the setup for the CDU-FS USB communication --
+    // Function char_received() will be attached to RX interrupt.
+    USB.baud(38400);     // :  set default baudrate to 38400
+    USB.rxBufferFlush(); // : empty USB rx buffer in case it is not empty:
+    USB.txBufferFlush(); // : empty USB tx buffer in case it is not empty:
+    USB.attach(&char_received, MODSERIAL::RxIrq);     // : attach function char_received to USB RX inerrupt
+    USB.attach(&rx_buf_overflow, MODSERIAL::RxOvIrq); // : attach function to call when USB RX buffer overflows
+    USB.attach(&tx_buf_overflow, MODSERIAL::TxOvIrq); // : attach function to call when USB TX buffer overflows
 }
- 
-main()
+
+main() // : MBOS main() 
 {
-  init_USB();  // : setup USB communication 
-  set_initial_CDU_screen();
-  
-  //------------------ for testing only ! ----------------------------------
-  init_buttons_Mbed();   
-  lcd.cls(); // : clear LCD display
-  lcd.printf("CDU USB Mbos\n");
-  USB.printf("\n--- CDU USB Mbos ---\n");
-  //------------------------------------------------------------------------
+    init_USB();  // : setup USB communication to FS
+     
+    // Keyboard initialisation and keyboard interrrupt setup:
+    CDU_KB_COMM_INIT();
+    CDU_KB_INT_START();
+    BGL_LED.period(0.01);
     
-  // Configure all tasks, timers and resources:
-  CDU_OS.CreateTask(ALIVE_TASK_ID, ALIVE_TASK_PRIO, ALIVE_TASK_STACK_SZ, ALIVE_TASK);
-  CDU_OS.CreateTask(RECEIVE_DECODE_TASK_ID, RECEIVE_DECODE_TASK_PRIO, RECEIVE_DECODE_TASK_STACK_SZ, RECEIVE_DECODE_TASK);
-  CDU_OS.CreateTask(SEND_KEYMESSAGE_TASK_ID, SEND_KEYMESSAGE_TASK_PRIO, SEND_KEYMESSAGE_TASK_STACK_SZ, SEND_KEYMESSAGE_TASK);  
-  CDU_OS.CreateTask(SCAN_KEYS_TASK_ID, SCAN_KEYS_TASK_PRIO, SCAN_KEYS_TASK_STACK_SZ, SCAN_KEYS_TASK );
-  CDU_OS.CreateTimer(ALIVE_TIMER_ID, ALIVE_TASK_ID, ALIVE_EVENT);  
-  CDU_OS.CreateTimer(SCAN_KEYS_TIMER_ID, SCAN_KEYS_TASK_ID, SCAN_KEYS_TIMER_EVENT);    
-  CDU_OS.CreateResource(USB_TX_RESOURCE, USB_TX_PRIO);
-  //CDU_OS.CreateTask(TASK4_ID, TASK4_PRIO, TASK4_STACK_SZ, task4);
-     
-  // Start mbos O.S with final statement in main() :
-  CDU_OS.Start(); // : will never return!    
-}        
+    // Display initialisation:
+    CDU_InitDisplay();
+    CDU_StartScreen();
+    wait(1);
+    CDU_Page();
+    CDU_ScreenAlign();
+    wait(1);
+      
+        
+    set_initial_data(); //: fill FS datastructures with initial (dummy) data
+
+#ifdef DEBUG_LVDK
+    //------------------ Testing only ! ----------------------------------
+    init_buttons_Mbed();
+    USB.printf("\n--- CDU_Mbed_21 ---\r\n");
+#endif
+    //---------------------------------------------------------------------
+      
+    SERIAL_DEBUG.baud(38400); // : set baudrate to 38400
+    SERIAL_DEBUG.printf("\n--- CDU_Mbed_21 ---\r\n");
+
+    // Create all tasks and timers:
+    CDU_OS.CreateTask(ALIVE_TASK_ID, ALIVE_TASK_PRIO, ALIVE_TASK_STACK_SZ, ALIVE_TASK);
+    CDU_OS.CreateTask(RECEIVE_DECODE_TASK_ID, RECEIVE_DECODE_TASK_PRIO, RECEIVE_DECODE_TASK_STACK_SZ, RECEIVE_DECODE_TASK);
+    CDU_OS.CreateTask(SEND_KEYMESSAGE_TASK_ID, SEND_KEYMESSAGE_TASK_PRIO, SEND_KEYMESSAGE_TASK_STACK_SZ, SEND_KEYMESSAGE_TASK);
+    CDU_OS.CreateTask(CDU_DSP_CSS_TASK_ID, CDU_DSP_CSS_TASK_PRIO, CDU_DSP_CSS_TASK_STACK_SZ, CDU_DSP_CSS_TASK );
+    CDU_OS.CreateTimer(ALIVE_TIMER_ID, ALIVE_TASK_ID, ALIVE_EVENT);
+    CDU_OS.CreateTask(READ_POT_TASK_ID, READ_POT_TASK_PRIO, READ_POT_TASK_STACK_SZ, READ_POT_TASK );
+    CDU_OS.CreateTimer(READ_POT_TIMER_ID, READ_POT_TASK_ID, READ_POT_TIMER_EVENT);
+       
+    // Create resources:
+    CDU_OS.CreateResource(USB_TX_RESOURCE, USB_TX_PRIO);
+    CDU_OS.CreateResource(FS_DATA_RESOURCE, FS_DATA_PRIO); // : highest prio !
+
+    // Start mbos O.S with a final statement in main() :
+    CDU_OS.Start(); // : MBOS is running tasks now....
+    // end of main , program never reaches this point !
+}
 
 void RECEIVE_DECODE_TASK(void)
-{    // Task waits for RX_EVENT, then 
-     // collects and decodes data from FS
-    while(1){  
+{   // Task waits for RX_EVENT, then
+    // collects and decodes data from FS
+    while(1) { // : loop forever because it is a mbos taskfunction
         CDU_OS.WaitEvent(RX_EVENT); // : wait for RX event
         collect_FSdata();
-    } 
+    }
 }
 
-void SEND_KEYMESSAGE_TASK(void) 
+void SEND_KEYMESSAGE_TASK(void)
 {
-    while(1){  
-        CDU_OS.WaitEvent(KEY_EVENT); // : wait for KEY event ( = CDU key pressed )
+    while(1) {  // : loop forever because it is a mbos taskfunction
+        CDU_OS.WaitEvent(KEY_EVENT); // : wait for KEY event ( = "CDU key pressed" )
+        CDU_KB_GET_KEY(); // : read key from CDU keyboard
+        CDU_OS.LockResource(USB_TX_RESOURCE);
         Send_KEY_message(key_hit_ID);
-        key_hit_ID = 0;  // : reset Id flag
+        key_hit_ID = 0;   // : reset key_hit_ID flag
+        CDU_OS.FreeResource(USB_TX_RESOURCE);
     }
 }
 
 void ALIVE_TASK(void)
-{   // Mbos task started by mbos timer to send ALIVE message to FS every 5 sec.
+{
+    // Mbos task started by mbos timer to send ALIVE message to FS every 5 sec.
     CDU_OS.SetTimer( ALIVE_TIMER_ID, ALIVE_TIMER_PERIOD, ALIVE_TIMER_PERIOD );
     static int seconds = 0;
-    while(1){  // : loop forever because it is a mbos taskfunction
+    while(1) { // : loop forever because it is a mbos taskfunction
         CDU_OS.WaitEvent(ALIVE_EVENT ); // : wait for Mbos timer event (5 sec)
-        seconds += 5 ; // : increase seconds by 5 
-        if (seconds >= 60) seconds = 0 ;
+        seconds += 5 ; // : increase seconds by 5
+        if (seconds >= 60) seconds = 0 ; // : overflow handling
+        CDU_OS.LockResource(USB_TX_RESOURCE);
         Send_ALIVE_message(seconds);
-        led1 = !led1;
+        CDU_OS.FreeResource(USB_TX_RESOURCE);
+        alive_led = !alive_led;  // : toggle LED
     }
-}     
+}
 
-// ------------- LvdK button scan, test only -------------------------------------------------
-void SCAN_KEYS_TASK(void) // : Test if button pressed
-{     // Will be task written by W.B
-      // Is now LvdK test Task, scans some buttons attached to Mbed board.
-      // Task scans buttons every 50msec.
-    CDU_OS.SetTimer( SCAN_KEYS_TIMER_ID, SCAN_KEYS_TIMER_PERIOD, SCAN_KEYS_TIMER_PERIOD );
-  
-    while(1){  // : loop forever because it is a mbos taskfunction
-        CDU_OS.WaitEvent(SCAN_KEYS_TIMER_EVENT );   // : scan buttons every 50msec
-        scan_buttons_Mbed(); 
-    } 
+void CDU_DSP_CSS_TASK(void) // : read new screendata from FS datastructures
+{
+    while(1) { // : loop forever because it is a mbos taskfunction
+        CDU_OS.WaitEvent(FS_DATA_EVENT);
+        CDU_OS.LockResource(FS_DATA_RESOURCE); //lock resource to prevent intermediate updates
+        
+        //test_update_flags(); // : >>>>>>>>>>>>>>>>>>>>>   LvdK TEST ONLY !!!
+        
+        CDU_DSP_CSS();
+                    
+        CDU_OS.FreeResource(FS_DATA_RESOURCE); //free resource
+    }
 }
-// -------------------------------------------------------------------------------------------
\ No newline at end of file
+
+void READ_POT_TASK(void) 
+{    // Mbos task started by mbos timer to scan potmeter every 100 msec
+     CDU_OS.SetTimer( READ_POT_TIMER_ID, READ_POT_TIMER_PERIOD, READ_POT_TIMER_PERIOD );
+
+    while(1) { // : loop forever because it is a mbos taskfunction
+        CDU_OS.WaitEvent(READ_POT_TIMER_EVENT );   // : scan potmeter every 100msec
+        CDU_SET_BGL_INTENSITY(255);
+    }
+}
+
diff -r e0bf3b244d7c -r 6576a287e563 mbed.bld
--- a/mbed.bld	Tue Jan 29 14:54:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 mbed.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/#4096f863f923
diff -r e0bf3b244d7c -r 6576a287e563 mbos_def.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbos_def.h	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,68 @@
+// File: mbos_def.h
+// L. van der Kolk, ELVEDEKA, Holland
+
+// -------------- Mbos definitions for CDU -------------------------------------------
+// ALIVE_TASK properties:
+#define ALIVE_TASK_ID             1
+#define ALIVE_TASK_PRIO          50
+#define ALIVE_TASK_STACK_SZ     100    // : must be 100 to prevent stack overflow error!
+
+// ALIVE_TIMER properties:
+#define ALIVE_TIMER_ID            1
+#define ALIVE_TIMER_PERIOD     5000   // = 5 sec
+
+// RECEIVE_DECODE_TASK properties:
+#define RECEIVE_DECODE_TASK_ID         2
+#define RECEIVE_DECODE_TASK_PRIO      90   
+#define RECEIVE_DECODE_TASK_STACK_SZ 256  // : must be 256 to prevent stack overflow error!
+
+// SEND_KEYMESSAGE_TASK properties:
+#define SEND_KEYMESSAGE_TASK_ID         3
+#define SEND_KEYMESSAGE_TASK_PRIO      97
+#define SEND_KEYMESSAGE_TASK_STACK_SZ 256  
+
+// CDU_DSP_CSS_TASK properties: 
+#define CDU_DSP_CSS_TASK_ID            5
+#define CDU_DSP_CSS_TASK_PRIO         80
+#define CDU_DSP_CSS_TASK_STACK_SZ    512 
+
+// Mbos EVENTS:
+#define ALIVE_EVENT             1      
+#define RX_EVENT                2   // : Event caused by serial Rx interrupt
+#define KEY_EVENT               4    
+#define FS_DATA_EVENT          16    
+
+// Mbos resources:
+// NOTE: priority should be higher than that of any task which will access the resource !
+#define USB_TX_RESOURCE     2       // : for locking USB TX buffer
+#define USB_TX_PRIO         99      // : USB TX buffer resource priority 
+#define FS_DATA_RESOURCE    1       // : for locking FS data structures
+#define FS_DATA_PRIO        95      // : FS data resource priority 
+
+// READ_POT_TIMER properties: 
+#define READ_POT_TIMER_ID           2   
+#define READ_POT_TIMER_PERIOD      100  // : 100msec scan time   
+#define READ_POT_TIMER_EVENT        8   
+
+// READ_POT_TASK properties: 
+#define READ_POT_TASK_ID            4       
+#define READ_POT_TASK_PRIO         40      
+#define READ_POT_TASK_STACK_SZ    180      
+
+#ifdef DEBUG_LVDK
+//------------------------- LvdK test only! ---------------------------------------------
+// SCAN_KEYS_TASK properties:   test only !
+#define SCAN_KEYS_TASK_ID           4       
+#define SCAN_KEYS_TASK_PRIO        40      
+#define SCAN_KEYS_TASK_STACK_SZ   180       
+// SCAN_KEYS_TIMER properties: ( LvdK button scan )
+#define SCAN_KEYS_TIMER_ID           2  // : test only !
+#define SCAN_KEYS_TIMER_PERIOD      50  // = 50msec , test only !
+#define SCAN_KEYS_TIMER_EVENT        8  // : LvdK button scan timer event, test only !
+//---------------------------------------------------------------------------------------- 
+#endif 
+
+
+
+
+
diff -r e0bf3b244d7c -r 6576a287e563 screen_handler.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/screen_handler.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,191 @@
+#include "mbed.h"
+#include "TFT_4DGL.h"
+#include "display.h"
+#include "FS_datastructures.h"
+#include "MODSERIAL.h"
+
+ 
+#include <string> 
+using namespace std;
+
+extern MODSERIAL SERIAL_DEBUG; // <----- debug only !!
+  
+extern int FSdata_received_flag;    //Prototype of data flag (declared in main.cpp)
+extern TFT_4DGL display;            //Prototype of Display Driver (declared in display.cpp)
+ 
+//Prototype of indicators (declared in keyboard.cpp)
+extern DigitalOut EXEC;
+extern DigitalOut FAIL;
+extern DigitalOut DSPY;
+extern DigitalOut  MSG;
+extern DigitalOut OFST;
+ 
+extern void CDU_SET_BGL_INTENSITY( int nVal );      //Prototype of function controlling CDU backlight (declared in keyboard.cpp)
+extern int nFontSize( int nfont_number );           //Prototype of function for fontselection (declared in display.cpp)
+extern int nFontWidth (int nfont_number );          //Prototype of function to retrieve font width (declared in display.cpp)
+extern int nLine2Pixel( int nLine );                //Prototype of function to calculate vertical pixelposition from line number (declared in display.cpp)
+extern int LeftOrRight( int nTextLine, string cString, int nChars, int nCharWidth ); //declared in display.cpp
+extern int cRGB( char cRED, char cGREEN, char cBLUE ); //Prototype of function for assembly color word (declared in display.cpp)
+ 
+// FS_data_update_ID:
+// These global flags indicate what data has been updated.
+// Should be tested when FS_DATA_EVENT occurs.
+extern int Background_Col_Update;    // 1 when color was updated, must be reset to 0 when data has been read
+extern int CDU_Status_Update    ;    // 1 when status was updated, must be reset to 0 when data has been read
+extern int DO_CLR_SCREEN        ;    // 1 when screen should be cleared, must be reset to 0 when done
+extern int Text_Line_Update     ;    // equal to line number whose text was updated, must be reset to 0 when text has been read 
+extern int Key_Maintext_Update  ;    // equal to keynumber whose main text line was updated, must be reset to -1 (!)when text has been read
+extern int Key_Subtext_Update   ;    // equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
+ 
+// Common flag to signal that one or more updates were performed:
+//int FSdata_received_flag = false;  //  : true when one or more FS-to-CDU data structures were updated
+                                   
+// --------------------------------------------------------------------------------------------------
+ 
+void CDU_DSP_CSS()
+/*Check flags to see if action is required
+Background_Col_Update;    // : 1 when color was updated, must be reset to 0 when data has been read
+CDU_Status_Update    ;    // : 1 when status was updated, must be reset to 0 when data has been read
+DO_CLR_SCREEN        ;    // : 1 when screen should be cleared, must be reset to 0 when done
+Text_Line_Update     ;    // : equal to line number whose text was updated, must be reset to 0 when text has been read
+Key_Maintext_Update  ;    // : equal to keynumber whose main text line was updated, must be reset to -1 (!)when text has been read
+Key_Subtext_Update   ;    // : equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
+*/
+   
+{
+    int nLine = 1;  //default value
+    //check common flag
+
+        if ( Background_Col_Update == 1)
+        {
+            display.background_color( cRGB( BACKGROUND_COL.BG_RED, BACKGROUND_COL.BG_GREEN, BACKGROUND_COL.BG_BLUE ) );
+            Background_Col_Update = 0;
+        }
+       
+        if ( Key_Maintext_Update > -1 )
+            //Key_Maintext_Update contains the line number 00-49 is LSK text, 50-99 is RSK text
+            //Currently used:
+            //00-14 left  side of screen --> left  adjust, horizontal position = 0
+            //50-64 right side of screen --> right adjust, horizontal position calculated with righttext() (declared in display.cpp)
+           
+            //00 = LSK1         50 = RSK1   Print on LINE 3
+            //01 = LSK2         51 = RSK2   Print on LINE 5
+            //02 = LSK3         52 = RSK3   Print on LINE 7
+            //03 = LSK4         53 = RSK4   Print on LINE 9
+            //04 = LSK5         54 = RSK5   Print on LINE 11
+            //05 = LSK6         55 = RSK6   Print on LINE 13
+        {
+            switch ( Key_Maintext_Update )
+            {
+                case ( 00 ): nLine = 3; break;
+                case ( 50 ): nLine = 3; break;
+                case ( 01 ): nLine = 5; break;
+                case ( 51 ): nLine = 5; break;
+                case ( 02 ): nLine = 7; break;
+                case ( 52 ): nLine = 7; break;
+                case ( 03 ): nLine = 9; break;
+                case ( 53 ): nLine = 9; break;
+                case ( 04 ): nLine = 11; break;
+                case ( 54 ): nLine = 11; break;
+                case ( 05 ): nLine = 13; break;
+                case ( 55 ): nLine = 13; break;
+            }
+            
+            SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text );       // show text 
+            
+            //display.graphic_string(char *s, int x, int y, char font, int color, char width multiplier, char height multiplier)
+            /*
+            display.graphic_string( SELKEY_MAINTEXT[Key_Maintext_Update].text ,                         //Text to display
+                                    LeftOrRight( Key_Maintext_Update, SELKEY_MAINTEXT[Key_Maintext_Update].text,24,24*nFontWidth( SELKEY_MAINTEXT[Key_Maintext_Update].font_size )) ,    //Horizontal position
+                                    nLine2Pixel( nLine ),                                 //Vertical position
+                                    nFontSize( 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 );
+            */
+            display.graphic_string( SELKEY_MAINTEXT[Key_Maintext_Update].text ,                         //Text to display
+                                    12*24 ,    //Horizontal position
+                                    nLine2Pixel( nLine ),                                 //Vertical position
+                                    nFontSize( 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 );
+            
+            
+            Key_Maintext_Update = -1;
+        }
+       
+        if ( Key_Subtext_Update > -1 )
+            //Key Subtext_Update contains the line number 00-49 is LSK subtext, 50-99 is RSK subtext
+            //Currently used:
+            //00-14 left  side of screen --> left  adjust, horizontal position = 0
+            //50-64 right side of screen --> right adjust, horizontal position calculated with righttext() (declared in display.cpp)           
+            //00 = LSK1         50 = RSK1   Print on LINE 2
+            //01 = LSK2         51 = RSK2   Print on LINE 4
+            //02 = LSK3         52 = RSK3   Print on LINE 6
+            //03 = LSK4         53 = RSK4   Print on LINE 8
+            //04 = LSK5         54 = RSK5   Print on LINE 10
+            //05 = LSK6         55 = RSK6   Print on LINE 12
+        {
+            switch ( Key_Subtext_Update )
+            {
+                case ( 00 ): nLine = 2; break;
+                case ( 50 ): nLine = 2; break;
+                case ( 01 ): nLine = 4; break;
+                case ( 51 ): nLine = 4; break;
+                case ( 02 ): nLine = 6; break;
+                case ( 52 ): nLine = 6; break;
+                case ( 03 ): nLine = 8; break;
+                case ( 53 ): nLine = 8; break;
+                case ( 04 ): nLine = 10; break;
+                case ( 54 ): nLine = 10; break;
+                case ( 05 ): nLine = 12; break;
+                case ( 55 ): nLine = 12; break;
+            }
+            //display.graphic_string(char *s, int x, int y, char font, int color, char width multiplier, char height multiplier)           
+            display.graphic_string( SELKEY_SUBTEXT[Key_Subtext_Update].text ,                       //Text to display
+                                    LeftOrRight( Key_Subtext_Update, SELKEY_SUBTEXT[Key_Subtext_Update].text,12,48*nFontWidth( SELKEY_SUBTEXT[Key_Subtext_Update].font_size )) ,  //Horizontal position
+                                    nLine2Pixel( nLine ),                              //Vertical position
+                                    nFontSize( 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
+            Key_Subtext_Update = -1;
+        }
+       
+        if ( Text_Line_Update > 0)
+        {
+            //Text_Line_Update contains the the line number to write
+             display.graphic_string( TEXTLINE[Text_Line_Update].text ,                      //Text to display
+                                    0,                                                      //Horizontal position always 0
+                                    nLine2Pixel( Text_Line_Update ),                        //Vertical position
+                                    nFontSize( 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
+            Text_Line_Update = 0;
+        }
+       
+        if ( CDU_Status_Update == 1 )
+        {
+/*                           
+                CDU_STATUS.stby_mode;           //  : 0 = operational mode, 1 = standby mode
+*/          if ( CDU_STATUS.backlight )         // Backlight control
+            {
+                CDU_SET_BGL_INTENSITY( 255 );
+            }
+            else
+            {
+                CDU_SET_BGL_INTENSITY( 0 ); 
+            }
+            // Set CDU indicators
+            MSG  = CDU_STATUS.msg_indicator;
+            EXEC = CDU_STATUS.exec_indicator;
+            FAIL = CDU_STATUS.fail_indicator;
+            DSPY = CDU_STATUS.dspy_indicator;
+            OFST = CDU_STATUS.ofst_indicator;
+ 
+            CDU_Status_Update =0;
+        }
+        if ( DO_CLR_SCREEN )
+        {
+            display.cls();
+            DO_CLR_SCREEN =0;
+        }
+}   
\ No newline at end of file
diff -r e0bf3b244d7c -r 6576a287e563 show_data.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/show_data.cpp	Thu Jul 17 10:09:14 2014 +0000
@@ -0,0 +1,114 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File:  show_data.cpp 
+
+// -----  Testing only --------------------------------------------
+// - Functions to test received and updated CDU data
+
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "mbos.h"
+#include "mbos_def.h"
+#include "FS_datastructures.h"
+
+extern mbos CDU_OS; 
+extern MODSERIAL SERIAL_DEBUG;
+static int command_cntr = 0;
+
+void test_update_flags()
+{
+    // Tset if DCU data was updated:
+    
+// Background_Col_Update  : 1 when color was updated, must be reset to 0 when data has been read
+// CDU_Status_Update      : 1 when status was updated, must be reset to 0 when data has been read
+// DO_CLR_SCREEN          : 1 when screen should be cleared, must be reset to 0 when done
+// Text_Line_Update       : equal to line number whose text was updated, must be reset to 0 when text has been read 
+// Key_Maintext_Update    : equal to keynumber whose main text line was updated, must be reset to -1 text has been read
+// Key_Subtext_Update     : equal to keynumber whose sub text line was updated, must be reset to -1 text has been read
+  
+  if ( Text_Line_Update != 0 ) {  //: textline was updated !
+          // read textline data and print:
+          SERIAL_DEBUG.printf("\rTextline updated:\r\n");          
+          SERIAL_DEBUG.printf("line        : %d\r\n",Text_Line_Update );                         // show line nr 
+          //SERIAL_DEBUG.printf("WTX begin pos   : %d\r\n",pos );                          // show begin position   
+          SERIAL_DEBUG.printf("fontsize is : %d\r\n",TEXTLINE[Text_Line_Update].font_size );     // show fontsize 
+          SERIAL_DEBUG.printf("fontstyle is: %c\r\n",TEXTLINE[Text_Line_Update].font_style);     // show fontstyle 
+          SERIAL_DEBUG.printf("R_colour is : %d\r\n",TEXTLINE[Text_Line_Update].text_RED );      // show textcolour 
+          SERIAL_DEBUG.printf("G_colour is : %d\r\n",TEXTLINE[Text_Line_Update].text_GREEN );    // show textcolour 
+          SERIAL_DEBUG.printf("B_colour is : %d\r\n",TEXTLINE[Text_Line_Update].text_BLUE );     // show textcolour 
+          SERIAL_DEBUG.printf("line text is: \r\n" );           
+          SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[Text_Line_Update].text );    // show line text
+          command_cntr++;
+          SERIAL_DEBUG.printf("command count : %d\r\n",command_cntr );    // : show counter for debugging
+       
+    }
+        
+    if ( Background_Col_Update != 0 ) {  // : background colour was updated
+          // read new colour data and print: 
+          SERIAL_DEBUG.printf("\rSBC command received:\r\n");
+          SERIAL_DEBUG.printf("background R_colour : %d\r\n",BACKGROUND_COL.BG_RED);
+          SERIAL_DEBUG.printf("background G_colour : %d\r\n",BACKGROUND_COL.BG_GREEN);
+          SERIAL_DEBUG.printf("background B_colour : %d\r\n",BACKGROUND_COL.BG_BLUE);
+          command_cntr++;
+          SERIAL_DEBUG.printf("command count : %d\r\n",command_cntr );    // : show counter for debugging
+        
+    }            
+
+    if ( CDU_Status_Update != 0 ) { // : CDU status was updated
+         // read new status data and print: 
+          SERIAL_DEBUG.printf("\r\r Setting command received :\r\n" );
+          SERIAL_DEBUG.printf("Message indicator is : %d \r\n", CDU_STATUS.msg_indicator);
+          SERIAL_DEBUG.printf("EXEC indicator is : %d \r\n", CDU_STATUS.exec_indicator);
+          SERIAL_DEBUG.printf("Backlight is : %d \r\n", CDU_STATUS.backlight); 
+          SERIAL_DEBUG.printf("Standby mode is : %d \r\n", CDU_STATUS.stby_mode);
+          command_cntr++;
+          SERIAL_DEBUG.printf("command count : %d\r\n",command_cntr );    // : show counter for debugging          
+        
+     }
+        
+     if ( DO_CLR_SCREEN != 0 ) {   // : clr screen request received
+          SERIAL_DEBUG.printf("\r\r CLR screen request received :\r\n" );
+          SERIAL_DEBUG.printf("DO_CLR_CSCREEN : %d \r\n", DO_CLR_SCREEN );
+          command_cntr++;
+          SERIAL_DEBUG.printf("command count : %d\r\n",command_cntr );    // : show counter for debugging
+       
+     }
+     
+     if (Key_Maintext_Update >= 0) {  // : key maintext was updated
+                             
+          SERIAL_DEBUG.printf("\rKey command received:\r\n"); 
+          SERIAL_DEBUG.printf("Key number is : %d\r\n",Key_Maintext_Update);                            
+          SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text );       // show text  
+          SERIAL_DEBUG.printf("Keyfontsize is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].font_size );  // show fontsize 
+          SERIAL_DEBUG.printf("Key fontstyle is: %c\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].font_style);  // show fontstyle 
+          SERIAL_DEBUG.printf("Key R_colour is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text_RED );   // show textcolour 
+          SERIAL_DEBUG.printf("Key G_colour is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text_GREEN ); // show textcolour 
+          SERIAL_DEBUG.printf("Key B_colour is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text_BLUE );  // show textcolour 
+           
+         
+     }
+     
+     if (Key_Subtext_Update >= 0) {  // : key subtext was updated
+     
+          SERIAL_DEBUG.printf("\rKey command received:\r\n"); 
+          SERIAL_DEBUG.printf("Key number is : %d\r\n",Key_Subtext_Update);                            
+          SERIAL_DEBUG.printf("Key SUBTEXT is  : %s\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text );       // show text  
+          SERIAL_DEBUG.printf("Key fontsize is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].font_size );  // show fontsize 
+          SERIAL_DEBUG.printf("Key fontstyle is: %c\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].font_style);  // show fontstyle 
+          SERIAL_DEBUG.printf("Key R_colour is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text_RED );   // show textcolour 
+          SERIAL_DEBUG.printf("Key G_colour is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text_GREEN ); // show textcolour 
+          SERIAL_DEBUG.printf("Key B_colour is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text_BLUE );  // show textcolour     
+          
+         
+     }
+     
+ /*   Text_Line_Update = 0;  // : reset FS data update ID flag
+     Background_Col_Update = 0;  // : reset FS data update ID flag
+     CDU_Status_Update = 0;   // : reset FS data update ID flag
+     CDU_Status_Update = 0;   // : reset FS data update ID flag  
+     DO_CLR_SCREEN = 0;
+     Key_Maintext_Update = -1;
+     Key_Subtext_Update = -1;
+*/
+       
+}
\ No newline at end of file