replaces CDU_Mbed_26

Dependencies:   4DGL MODSERIAL mbed mbos

Fork of CDU_Mbed_26 by Engravity-CDU

Files at this revision

API Documentation at this revision

Comitter:
LvdK
Date:
Sun Jul 20 16:33:53 2014 +0000
Parent:
7:6576a287e563
Child:
9:1e117310b481
Child:
10:9a5f1b389973
Commit message:
CDU_Mbed_26; - other mbos setup !; - WTX hor. pos. changed; - no fontstyle check; - no checksum check

Changed in this revision

CDU2FS_message_4.cpp Show diff for this revision Revisions of this file
CDU2FS_message_5.cpp Show annotated file Show diff for this revision Revisions of this file
FS2CDU_data_4.cpp Show diff for this revision Revisions of this file
FS2CDU_data_5.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
USB_receive_3.cpp Show diff for this revision Revisions of this file
USB_receive_5.cpp Show annotated file Show diff for this revision Revisions of this file
debug_lvdk.h Show diff for this revision Revisions of this file
display.cpp 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
mbos_def.h Show diff for this revision Revisions of this file
mbos_def2.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
--- a/CDU2FS_message_4.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-// 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CDU2FS_message_5.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -0,0 +1,84 @@
+// L. van der Kolk, ELVEDEKA, Holland 
+// File:  CDU2FS_message_5.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 FS       
+}
+
+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 FS
+        } 
+}           
+        
+   
\ No newline at end of file
--- a/FS2CDU_data_4.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,596 +0,0 @@
-// 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
-   }
-}
-
-
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FS2CDU_data_5.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -0,0 +1,540 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File:  FS2CDU_data_5.cpp 
+// -- Message handling from FS to CDU --
+// Data field analyzing and filling data structures
+
+#include "mbed.h"
+#include "MODSERIAL.h" 
+#include "mbos.h"
+#include "mbos_def2.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[55];             //  : 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[55];             //  : 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[55];             //  : 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[16];             //  : 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:
+ 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 at initial power-up conditions.
+   // Prevents non-printable chars in data structures !
+   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");  // some space chars
+  }
+  // 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"); // some space chars
+  }
+  // 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"); // some space chars 
+  }   
+  // 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"); // some space chars
+  } 
+        
+  // Init screen text lines with space chars :
+  for ( line_nr = 1; line_nr <= 14; 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");   // : all space chars                      
+  }   
+   // Init CDU status items:
+   CDU_STATUS.msg_indicator = 0;
+   CDU_STATUS.exec_indicator = 0;
+   CDU_STATUS.backlight = 0;
+   CDU_STATUS.stby_mode = 0;
+}
+
+void read_datafields(int command_number) {
+    // Function to read all comma seperated datafields in string_received[] from USB
+    // and fill in the FS-to-CDU data structures.
+    // Parameter is found command_number by decoder.
+    int colour, size, pos, line, last, cnt, k_id, a ;
+    int modified, char_pntr;
+    char ch;
+    
+    modified = false; 
+    //CDU_OS.LockResource(FS_DATA_RESOURCE); // : lock FS database  <<--- !!
+      
+    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;
+             }
+           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;
+             }
+           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;
+             }
+           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;
+             }
+           break;
+        }        
+        
+        case 5: // CLS command, CDU clear screen control
+        {    
+             DO_CLR_SCREEN = 1;            // : tell to clear the screen
+            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
+           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];
+             // !! Font style check disabled:
+             //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-1;    // : !!!!!!
+                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
+          }
+          
+          // --------------- Debug only -----------------------------------------------------------------------
+          //SERIAL_DEBUG.printf("\rWTX command received :\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
+          //----------------------------------------------------------------------------------------------------
+                   
+          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-1; //: !!!!!!
+                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
+          }
+           
+          // ---------------- Debug only -----------------------------------------------
+          //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
+          // ---------------------------------------------------------------------------
+        
+          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]);
+          
+          // 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];
+             // !! Font style check disabled:
+             //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 
+              
+             }
+          
+          // ----------------------- Debug only -----------------------------------------------------------------
+          //SERIAL_DEBUG.printf("KTX decoded key nr is   : %d\r\n\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 
+          //----------------------------------------------------------------------------------------------------
+          }
+          
+          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 
+             }
+             
+          // ------------------ Debug only ----------------------------------------------------------
+          //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 
+          // -----------------------------------------------------------------------------------------
+          }
+         break;
+        }        
+
+        default:
+        {   
+          // unknown commandnumber !
+         break;
+        }        
+
+    }
+    
+    CDU_OS.SetEvent(FS_DATA_EVENT,CDU_DSP_CSS_TASK_ID); // : set event for CDU screen update task
+}
+
+
+
+
--- a/FS_datastructures.h	Thu Jul 17 10:09:14 2014 +0000
+++ b/FS_datastructures.h	Sun Jul 20 16:33:53 2014 +0000
@@ -2,8 +2,7 @@
 // File:  FS_datastructures.h 
 // Global data structures containing updated data received from FS
  
-// ---- FS-to-CDU data structures to be filled with received data ---------------------------------------------------------------------------
- 
+// ---- 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
@@ -11,27 +10,27 @@
               } BACKGROUND_COL;
  
 // Main text lines at selectkeys:
-extern struct { char  text[52];          //  : maintext string, ending with '\0'   
+extern struct { char  text[55];          //  : maintext string, ending with '\0'   
                 int   font_size;         //  : fontsize of textline 0 or 1            
-                char  font_style;        //  : style character S or N                       
+                char  font_style;        //  : style character                       
                 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'   
+extern struct { char  text[55];          //  : subtext string, ending with '\0'   
                 int   font_size;         //  : fontsize of textline 0 or 1                            
-                char  font_style;        //  : style character S or N                        
+                char  font_style;        //  : style character                       
                 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'   
+extern struct { char  text[55];          //  : text line string, ending with '\0'   
                 int   font_size;         //  : fontsize of textline 0 or 1         
-                char  font_style;        //  : style character S or N                             
+                char  font_style;        //  : style character                            
                 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
@@ -49,8 +48,7 @@
  
  
 // FS_data_update_ID:
-// These global flags indicate what data has been updated.
-// Should be tested when FS_DATA_EVENT occurs.
+// These global flags indicate what data has been updated:
 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
--- a/USB_receive_3.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,195 +0,0 @@
-// 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USB_receive_5.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -0,0 +1,197 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File:  USB_receive_5.cpp     
+
+#include "mbed.h"
+#include "MODSERIAL.h" 
+
+extern MODSERIAL USB;
+
+extern int FSdata_received_flag;
+
+//------- debug only ---------------------
+extern MODSERIAL SERIAL_DEBUG;
+//----------------------------------------
+   
+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 ( FSdata_received_flag == false ) {  // : process received chars only if no decoding busy now
+   while ( !USB.rxBufferEmpty() )  // : do as long as USB receive buffer is not empty
+   {    rx_char = USB.getc(); // : get a char from Rx buffer
+       
+        // ----------- Debug only ! ---------------------------------------------
+        //SERIAL_DEBUG.putc(rx_char);    // : unprotected immediate echo of char 
+        // ----------------------------------------------------------------------
+     
+        // 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;
+            FSdata_received_flag = 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
+                
+                FSdata_received_flag = true;
+                 
+                // ----------- Debug only ! -------------------------------------------
+                // SERIAL_DEBUG.printf("string_received from USB: %s",string_received );  
+                // --------------------------------------------------------------------
+               
+                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
+                FSdata_received_flag = false;
+            }
+        }    
+   } 
+    
+ } 
+}
+    
+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 );
+      
+
+    // ----------- Debug only ------------------------------------------- 
+    //SERIAL_DEBUG.printf("commas found : %d\n",c-1 );  // : show commas 
+    // ------------------------------------------------------------------
+
+    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);
+    
+    // ******************************************************************************************
+    // -- Force checksum to allways OK : < -- debug only !!
+    equal = 0;
+    // ******************************************************************************************
+    
+    if (equal != 0) {
+       // ----------- Debug only ------------------------------------------------------- 
+       //SERIAL_DEBUG.printf("checksum is NOT OK ! \n" );  // : show message for debugging
+       // ------------------------------------------------------------------------------
+       FSdata_received_flag = false;
+    }
+    else { // checksum is OK, go on:
+        // Check for 5 char "$PCDU" header:
+        equal = strncmp(string_received,message_header,strlen(message_header));
+          if (equal != 0) {
+
+            // ----------- Debug only ---------------------------------------------------
+            //SERIAL_DEBUG.printf("no $PCDU header in message !\n" );  // : show message 
+            // --------------------------------------------------------------------------
+
+            FSdata_received_flag = false;
+          }
+          else {
+               // Read 3 char command after message_header:
+               strncpy(command_string,&string_received[strlen(message_header)],3);
+
+               // ----------- 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
+               // --------------------------------------------------------------------------------------------
+ 
+               // 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);
+              
+                // ----------- Debug only ---------------------------------------------------------------
+                //SERIAL_DEBUG.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);
+               }
+               else FSdata_received_flag = false;
+         } 
+    } 
+    
+ }
+ 
+ 
\ No newline at end of file
--- a/debug_lvdk.h	Thu Jul 17 10:09:14 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-// 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
--- a/display.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ b/display.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -1,19 +1,15 @@
 //Display control functions --
- 
 #include "mbed.h"
 #include "TFT_4DGL.h"
 #include "display.h"
-#include <string> 
+#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:                                               *
@@ -21,12 +17,10 @@
 * 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)
@@ -34,12 +28,10 @@
 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)
@@ -47,66 +39,56 @@
 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
- 
+<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.
- 
+< 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. 
+<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)
- 
+<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)
- 
+<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. 
+<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.
+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();
@@ -116,7 +98,7 @@
     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)
@@ -125,7 +107,7 @@
     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)
@@ -134,25 +116,26 @@
     nStart = nCharWidth*( nChars - cString.size());
     return nStart;
     }
- 
 int nFontSize( int nfont_number )
 {
-    int nFont = 0;
+    int nFontWidth = 24;
     switch ( nfont_number )
     {
         case 0:
         {
-            nFont = FONT_12X34;
+            nFontWidth = SMALLCHAR; 
+            //nFontWidth = FONT_12X34;
             break;
         }
         case 1:
         {
-            nFont = FONT_24X34;
+            nFontWidth = LARGECHAR;
+            //nFontWidth = FONT_24X34;
             break;
         }
     }
-    return ( nFont );
-}    
+    return ( nFontWidth );
+}   
  
 int nFontWidth (int nfont_number )
 {
@@ -171,7 +154,7 @@
         }
     }
     return ( nFont );
-}    
+}   
  
 unsigned int cRGB( char cRED, char cGREEN, char cBLUE )
 {
@@ -179,17 +162,19 @@
     //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 )
 {
+    // nChars is the maximum numbers of characters on the line
+    // nCharWidth is the characterwidth in pixels
     //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; 
+    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
     {
@@ -202,7 +187,6 @@
     }
     return ( nHorPos );
 }
- 
 int nLine2Pixel( int nLine )
 {
     //calculate vertical pixelposition from linenumber
@@ -219,118 +203,114 @@
             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.cls();  
     
     display.graphic_string( str2char( cTitle1 ), centertext( cTitle1, 24, LARGECHAR), LINE6, FONT_24X34, WHITE, 1, 1 );
-    wait_ms(1000);
+    wait_ms(100);
     display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, RED, 1, 1 );
-    wait_ms(1000);
+    wait_ms(100);
     display.graphic_string( str2char( cTitle2 ), centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, GREEN, 1, 1 );
-    wait_ms(1000);
+    wait_ms(100);
     display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, BLUE, 1, 1 );
-    wait_ms(1000);
+    wait_ms(100);
     display.graphic_string( str2char( cTitle2) , centertext( cTitle2, 24, LARGECHAR), LINE8, FONT_24X34, WHITE, 1, 1 );
-    wait_ms(1000);
- }
- 
+    wait_ms(100);
+}
 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);
@@ -346,62 +326,59 @@
     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.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( "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( "------------------------------------------------"   , 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
--- a/keyboard2.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ b/keyboard2.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -5,7 +5,7 @@
 #include "MODSERIAL.h"
 #include "keyboard.h"
 #include "mbos.h"
-#include "mbos_def.h"
+#include "mbos_def2.h"
  
 const int CDU_KB_ADRS  = 0x68;  //Base address TCA8418 keypad scanner
 const int I2C_ACK  = 0x00;
@@ -90,7 +90,8 @@
     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 !
+    
+        //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
--- a/keys.h	Thu Jul 17 10:09:14 2014 +0000
+++ b/keys.h	Sun Jul 20 16:33:53 2014 +0000
@@ -1,5 +1,5 @@
-/// File: keys.h  LvdK, ELVEDEKA, Holland
-// Key strings for FS-to-CDU key message SPCDUKEY 
+// File: keys.h  
+// Key strings for FS-to-CDU key message SPCDUKEY..... 
 
 #define max_keys_CDUpanel 80 // : max. number of keys found on CDU panel
 
--- a/main.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ b/main.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -1,33 +1,32 @@
 // L. van der Kolk,  W.Braat  
 // File:  main.cpp  
-// Version 21 
-// ---------------------------- 
+// Version 26 --->> other MBOS setup ! 
+// ----------------------------------------- 
 
 #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 "mbos_def2.h"   // : Mbos tasks, timer and resource definitions
 
 // Setup USB communication defined by Mbed USB TX and RX lines
 // with TX and RX ringbuffers :
-MODSERIAL USB(USBTX, USBRX, 256, 512);
+MODSERIAL USB(USBTX, USBRX, 256, 1024);
 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 !!!
+//void test_update_flags(); // << for testing only << !!!!!!!
 
-void test_update_flags(); // << for testing only << !!!!!!!
-
+// --- Debug only ----------------------------------------
 // extra serial port to show debug info :
-MODSERIAL SERIAL_DEBUG(p9, p10, 1024, 64);     //: tx, rx
+  MODSERIAL SERIAL_DEBUG(p9, p10, 512, 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);
-void set_initial_data(); // : fill datastructures with initial data
-void Send_KEY_message(int button);
+void set_initial_data(void); // : fill datastructures with initial data
+void Send_KEY_message(int key_nr);
 void Send_ALIVE_message(int seconds);
 void collect_FSdata();
 
@@ -46,7 +45,7 @@
 void CDU_KB_GET_KEY(void);
 void CDU_SET_BGL_INTENSITY(int);
 
-// display function prototype:
+// display function prototypes:
 void CDU_InitDisplay(void);
 void CDU_ScreenAlign(void);
 void CDU_StartScreen(void);
@@ -54,38 +53,26 @@
 void CDU_DSP_CSS(void);
 void CDU_displayclear(void);
 
-
-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 interrupts ----------------------------------
+//------ USB buffer overflow interrupt handling: -------------
 void rx_buf_overflow(MODSERIAL_IRQ_INFO *q)
-{
-    // This functiom will be called when RX buffer overflows.
+{   // 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.
+{   // 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 --
+{   // -- 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
 }
@@ -94,74 +81,72 @@
 {
     init_USB();  // : setup USB communication to FS
      
-    // Keyboard initialisation and keyboard interrrupt setup:
+    // CDU keyboard initialisation and keyboard interrrupt setup:
     CDU_KB_COMM_INIT();
     CDU_KB_INT_START();
     BGL_LED.period(0.01);
     
-    // Display initialisation:
+    // CDU display initialisation:
     CDU_InitDisplay();
     CDU_StartScreen();
-    wait(1);
-    CDU_Page();
+    wait(0.2);
+    //CDU_Page();
     CDU_ScreenAlign();
-    wait(1);
-      
-        
-    set_initial_data(); //: fill FS datastructures with initial (dummy) data
+            
+    set_initial_data(); //: fill FS datastructures with initial data
 
-#ifdef DEBUG_LVDK
-    //------------------ Testing only ! ----------------------------------
-    init_buttons_Mbed();
-    USB.printf("\n--- CDU_Mbed_21 ---\r\n");
-#endif
-    //---------------------------------------------------------------------
-      
+    // -- debug only -------------------------------------      
     SERIAL_DEBUG.baud(38400); // : set baudrate to 38400
-    SERIAL_DEBUG.printf("\n--- CDU_Mbed_21 ---\r\n");
+    SERIAL_DEBUG.printf("\n--- CDU_Mbed_26 ---\r\n");
+    // ---------------------------------------------------
 
-    // Create all tasks and timers:
+    // Create all mbos tasks, timers and resources:
+    // Tasks:
     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 );
+    // Timers:
     CDU_OS.CreateTimer(READ_POT_TIMER_ID, READ_POT_TASK_ID, READ_POT_TIMER_EVENT);
-       
-    // Create resources:
+    CDU_OS.CreateTimer(ALIVE_TIMER_ID, ALIVE_TASK_ID, ALIVE_EVENT);
+    CDU_OS.CreateTimer(DECODE_TIMER_ID, RECEIVE_DECODE_TASK_ID, DECODE_TIMER_EVENT); 
+    // Resources:
     CDU_OS.CreateResource(USB_TX_RESOURCE, USB_TX_PRIO);
-    CDU_OS.CreateResource(FS_DATA_RESOURCE, FS_DATA_PRIO); // : highest prio !
+    CDU_OS.CreateResource(FS_DATA_RESOURCE, FS_DATA_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 !
+    // 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
+{   // Mbos task triggered by mbos timer to scan USB receive buffer every 100 msec.
+    // Collects and decodes data received from USB.
+    CDU_OS.SetTimer( DECODE_TIMER_ID, DECODE_TIMER_PERIOD, DECODE_TIMER_PERIOD );
     while(1) { // : loop forever because it is a mbos taskfunction
-        CDU_OS.WaitEvent(RX_EVENT); // : wait for RX event
+        CDU_OS.WaitEvent(DECODE_TIMER_EVENT );   // : wait for Mbos timer event
+        // start collecting and decoding of received data:
+        CDU_OS.LockResource(FS_DATA_RESOURCE); // : lock FS database 
         collect_FSdata();
+        CDU_OS.FreeResource(FS_DATA_RESOURCE); // : free FS database
     }
 }
 
 void SEND_KEYMESSAGE_TASK(void)
-{
+{   // Mbos task triggered by a 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_OS.WaitEvent(KEY_EVENT); // : wait for KEY event 
         CDU_KB_GET_KEY(); // : read key from CDU keyboard
         CDU_OS.LockResource(USB_TX_RESOURCE);
         Send_KEY_message(key_hit_ID);
+        CDU_OS.FreeResource(USB_TX_RESOURCE);
         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 triggered 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
@@ -175,27 +160,34 @@
     }
 }
 
-void CDU_DSP_CSS_TASK(void) // : read new screendata from FS datastructures
-{
+void CDU_DSP_CSS_TASK(void) 
+{   // Mbos task to read new screendata from FS datastructures and show on CDU screen.
+    // Triggered by FS_DATA_EVENT ( = "new screendata available" )
     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
-    }
+    
+              if (CDU_OS.TestResource(FS_DATA_RESOURCE) == 0) {
+                // FS_DATA_RESOURCE is free to access.
+                // Lock it to get exclusive access and prevent intermediate updates:
+                CDU_OS.LockResource(FS_DATA_RESOURCE); 
+                CDU_OS.WaitEvent(FS_DATA_EVENT); //  wait for FS_DATA_EVENT
+                //test_update_flags(); // : >>>>> debug ONLY !!!
+                CDU_DSP_CSS(); // : get data and show on screen
+                CDU_OS.FreeResource(FS_DATA_RESOURCE); // : free FS_DATA_RESOURCE
+              }
+              else {
+                 // FS_DATA_RESOURCE is occupied, don’t read it !
+              }
+     }
 }
 
+
 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 );
-
+    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_OS.WaitEvent(READ_POT_TIMER_EVENT );  // : wait for Mbos timer event
         CDU_SET_BGL_INTENSITY(255);
     }
 }
 
+
--- a/mbos_def.h	Thu Jul 17 10:09:14 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-// 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 
-
-
-
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbos_def2.h	Sun Jul 20 16:33:53 2014 +0000
@@ -0,0 +1,52 @@
+// File: mbos_def2.h
+// L. van der Kolk, ELVEDEKA, Holland
+
+// -------------- Mbos definitions for CDU -------------------------------------------
+// MBOS TASKS:
+// ALIVE_TASK properties:
+#define ALIVE_TASK_ID             1
+#define ALIVE_TASK_PRIO          50
+#define ALIVE_TASK_STACK_SZ     100    
+// READ_POT_TASK properties: 
+#define READ_POT_TASK_ID            4       
+#define READ_POT_TASK_PRIO         40  // : lowest priority    
+#define READ_POT_TASK_STACK_SZ    100
+// RECEIVE_DECODE_TASK properties:
+#define RECEIVE_DECODE_TASK_ID         2
+#define RECEIVE_DECODE_TASK_PRIO      80  
+#define RECEIVE_DECODE_TASK_STACK_SZ  256  
+// SEND_KEYMESSAGE_TASK properties:
+#define SEND_KEYMESSAGE_TASK_ID         3
+#define SEND_KEYMESSAGE_TASK_PRIO      90
+#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         95  // : highest priority !
+#define CDU_DSP_CSS_TASK_STACK_SZ    512
+
+// MBOS TIMERS:
+// ALIVE_TIMER properties:
+#define ALIVE_TIMER_ID               1
+#define ALIVE_TIMER_PERIOD        5000   // = 5 sec
+// READ_POT_TIMER properties: 
+#define READ_POT_TIMER_ID            2   
+#define READ_POT_TIMER_PERIOD      100   // = 100msec scan time
+// DECODE_TIMER properties:
+#define DECODE_TIMER_ID              3   
+#define DECODE_TIMER_PERIOD         50   // = 50msec scan time   
+
+// MBOS EVENTS:
+#define ALIVE_EVENT             1      
+#define DECODE_TIMER_EVENT      2   
+#define KEY_EVENT               4 
+#define READ_POT_TIMER_EVENT    8   
+#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        97      // : FS data resource priority 
+
+// -------------------------------------------------------------------------------------------  
\ No newline at end of file
--- a/screen_handler.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ b/screen_handler.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -3,45 +3,37 @@
 #include "display.h"
 #include "FS_datastructures.h"
 #include "MODSERIAL.h"
-
  
-#include <string> 
+#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 int FSdata_received_flag;    
 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 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
@@ -51,23 +43,24 @@
 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
+    int nLine = 1;          //default line number
+    int nCharsLine = 24;    //characters per line
     //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
@@ -90,34 +83,41 @@
                 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 
+           
+            switch ( SELKEY_MAINTEXT[Key_Maintext_Update].font_size )
+            {
+                case ( 0 ): nCharsLine = 48; break;
+                case ( 1 ): nCharsLine = 24; break;
+            }
+           
+            //SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text );       // DEBUG, 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, nCharsLine, nFontWidth( SELKEY_MAINTEXT[Key_Maintext_Update].font_size )) ,    //Horizontal position
+                                    nLine2Pixel( nLine ),                                 //Vertical position
+                                    SELKEY_MAINTEXT[Key_Maintext_Update].font_size,        //Font
+                                    cRGB( SELKEY_MAINTEXT[Key_Maintext_Update].text_RED ,SELKEY_MAINTEXT[Key_Maintext_Update].text_GREEN ,SELKEY_MAINTEXT[Key_Maintext_Update].text_BLUE ),
+                                    1, 1 );
+          
             /*
             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
+                                    12*24 ,    //Horizontal position
                                     nLine2Pixel( nLine ),                                 //Vertical position
-                                    nFontSize( SELKEY_MAINTEXT[Key_Maintext_Update].font_size ),        //Font
+                                    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)           
+            //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
@@ -140,31 +140,37 @@
                 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)           
+           
+            switch ( SELKEY_SUBTEXT[Key_Subtext_Update].font_size )
+            {
+                case ( 0 ): nCharsLine = 48; break;
+                case ( 1 ): nCharsLine = 24; 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
+                                    LeftOrRight( Key_Subtext_Update, SELKEY_SUBTEXT[Key_Subtext_Update].text, nCharsLine, nFontWidth( SELKEY_SUBTEXT[Key_Subtext_Update].font_size )) ,  //Horizontal position
                                     nLine2Pixel( nLine ),                              //Vertical position
-                                    nFontSize( SELKEY_SUBTEXT[Key_Subtext_Update].font_size ),      //Font
+                                    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
+                                    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
             {
@@ -172,7 +178,7 @@
             }
             else
             {
-                CDU_SET_BGL_INTENSITY( 0 ); 
+                CDU_SET_BGL_INTENSITY( 0 );
             }
             // Set CDU indicators
             MSG  = CDU_STATUS.msg_indicator;
@@ -180,7 +186,6 @@
             FAIL = CDU_STATUS.fail_indicator;
             DSPY = CDU_STATUS.dspy_indicator;
             OFST = CDU_STATUS.ofst_indicator;
- 
             CDU_Status_Update =0;
         }
         if ( DO_CLR_SCREEN )
@@ -188,4 +193,7 @@
             display.cls();
             DO_CLR_SCREEN =0;
         }
-}   
\ No newline at end of file
+        
+        FSdata_received_flag = false; // : reset commomn FS data update flag = all updates ready <-------- !!!!
+        
+}    
\ No newline at end of file
--- a/show_data.cpp	Thu Jul 17 10:09:14 2014 +0000
+++ b/show_data.cpp	Sun Jul 20 16:33:53 2014 +0000
@@ -1,23 +1,25 @@
 // L. van der Kolk, ELVEDEKA, Holland //
 // File:  show_data.cpp 
 
-// -----  Testing only --------------------------------------------
+// -----  FOR DEBUG ONLY ----------------------------
 // - Functions to test received and updated CDU data
-
+// --------------------------------------------------
 
 #include "mbed.h"
 #include "MODSERIAL.h"
 #include "mbos.h"
-#include "mbos_def.h"
+#include "mbos_def2.h"
 #include "FS_datastructures.h"
 
 extern mbos CDU_OS; 
 extern MODSERIAL SERIAL_DEBUG;
-static int command_cntr = 0;
+extern int FSdata_received_flag;
+
+int step_counter = 0;
 
 void test_update_flags()
 {
-    // Tset if DCU data was updated:
+// Test 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
@@ -28,7 +30,7 @@
   
   if ( Text_Line_Update != 0 ) {  //: textline was updated !
           // read textline data and print:
-          SERIAL_DEBUG.printf("\rTextline updated:\r\n");          
+          SERIAL_DEBUG.printf("\r show data read from datastructure:\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 
@@ -38,59 +40,63 @@
           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
-       
-    }
+          
+          Text_Line_Update = 0;  // : reset FS data update ID flag
+     }
         
     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("\r show data read from datastructure:\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
-        
+          
+          Background_Col_Update = 0;  // : reset FS data update ID flag       
     }            
 
     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("\r show data read from datastructure:\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          
-        
+          
+          CDU_Status_Update = 0;   // : reset FS data update ID flag
      }
         
      if ( DO_CLR_SCREEN != 0 ) {   // : clr screen request received
-          SERIAL_DEBUG.printf("\r\r CLR screen request received :\r\n" );
+          SERIAL_DEBUG.printf("\r\r CLR screen request read:\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
-       
+          
+           DO_CLR_SCREEN = 0;
      }
      
-     if (Key_Maintext_Update >= 0) {  // : key maintext was updated
+     if (Key_Maintext_Update > -1) {  // : 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 
-           
+          SERIAL_DEBUG.printf("\r show data read from datastructure:\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[50].text );      // show text
+         SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[51].text );       // show text
+         SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[52].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 
+          
+          Key_Maintext_Update = -1; 
+          
+          step_counter=5;
+          SERIAL_DEBUG.printf("step_counter: %d\r\n", step_counter );  //  debug 
          
      }
      
-     if (Key_Subtext_Update >= 0) {  // : key subtext was updated
+     if (Key_Subtext_Update > -1) {  // : key subtext was updated
      
-          SERIAL_DEBUG.printf("\rKey command received:\r\n"); 
+          SERIAL_DEBUG.printf("\r show data read from datastructure:\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 
@@ -99,16 +105,12 @@
           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     
           
+          Key_Subtext_Update = -1;
          
      }
+          
+     FSdata_received_flag = false; // : reset commomn FS data update flag
+     step_counter = 10;
+     SERIAL_DEBUG.printf("step_counter: %d\r\n", step_counter );  //  debug 
      
- /*   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