version 1.0

Dependencies:   CMSIS_DSP_401 GPS MPU9150_DMP PID QuaternionMath Servo mbed

Fork of SolarOnFoils_MainModule_20150518 by Dannis Brugman

Files at this revision

API Documentation at this revision

Comitter:
Dannis_mbed
Date:
Tue Aug 11 08:38:55 2015 +0000
Parent:
1:b4a0d63db637
Commit message:
Test version mainmodule

Changed in this revision

LCD_I2C.cpp Show annotated file Show diff for this revision Revisions of this file
LCD_I2C.h Show annotated file Show diff for this revision Revisions of this file
LCD_Menu.cpp Show diff for this revision Revisions of this file
LCD_Menu.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
menu.cpp Show annotated file Show diff for this revision Revisions of this file
menu.h Show annotated file Show diff for this revision Revisions of this file
systemVar.cpp Show annotated file Show diff for this revision Revisions of this file
systemVar.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_I2C.cpp	Tue Aug 11 08:38:55 2015 +0000
@@ -0,0 +1,258 @@
+//////////////////////////////////////////////////////////////////////////////////////
+//                                                                                  //
+//      File        : LCD_I2C.cpp                                                   //
+//      Version     : 1.0                                                           //
+//      Date        : 26 june 2015                                                  //
+//      Author      : Dany Brugman                                                  //
+//      Comment     : Class to write data to a 2x16 LCD by I2C                      //
+//                    using a MCP23017 port expander.                               //
+//                                                                                  //
+//      Changelog   :                                                               //
+//      Date:           Name:       Comment:                                        //
+//      25/03/2015      DNB         First version                                   //
+//      26/06/2015      DNB         Rebuild to class LCD_I2C                        //
+//                                                                                  //
+//////////////////////////////////////////////////////////////////////////////////////
+#include "menu.h"
+#include "LCD_I2C.h"
+
+//////////////////////////////////////////////////////////////////////////////////////
+// constructor                                                                      //
+//////////////////////////////////////////////////////////////////////////////////////
+LCD_I2C::LCD_I2C(PinName data, PinName clk, char deviceID) : 
+         i2c(data, clk), 
+         deviceAdress(deviceID),
+         mcp23017(i2c, 0x40)
+{
+    vLCD_init_I2C();
+};
+
+LCD_I2C::~LCD_I2C()
+{
+};
+
+
+extern Menu mLCDMenu;
+//////////////////////////////////////////////////////////////////////////////////////
+// delay function for LCD                                                           //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_delay_I2C (unsigned int t_delay)
+{
+    unsigned int i;
+    
+    for (i=0; i < t_delay; i++);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// write commando to LCD                                                            //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_cmd_I2C   (unsigned char commando)
+{
+__disable_irq();    // Disable Interrupts
+
+    // write commando to LCD
+    mcp23017.write(PORT_A, commando);
+    
+    // LCD_RS = 0
+    buffer_GPIOB = buffer_GPIOB & 0xFD;   // RS = 0
+    // write to LCD
+    mcp23017.write(PORT_B, buffer_GPIOB);
+    
+    // LCD_EN = 1
+    buffer_GPIOB = buffer_GPIOB | 0x01;   // EN = 1
+    // write to LCD
+    mcp23017.write(PORT_B, buffer_GPIOB);
+    
+    // LCD_EN = 0
+    buffer_GPIOB = buffer_GPIOB & 0xFE;   // EN = 0
+    // write to LCD
+    mcp23017.write(PORT_B, buffer_GPIOB);
+    
+__enable_irq();     // Enable Interrupts
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// write single char to LCD                                                         //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_data_I2C  (unsigned char data)
+{
+__disable_irq();    // Disable Interrupts
+ 
+    // write data to LCD
+    mcp23017.write(PORT_A, data);
+    
+    // LCD_RS = 1
+    buffer_GPIOB = buffer_GPIOB | 0x02;   // RS = 1
+    // write to LCD
+    mcp23017.write(PORT_B, buffer_GPIOB);
+    
+    // LCD_EN = 1
+    buffer_GPIOB = buffer_GPIOB | 0x01;   // EN = 1
+    // write to LCD
+    mcp23017.write(PORT_B, buffer_GPIOB);
+    
+    // LCD_EN = 0
+    buffer_GPIOB = buffer_GPIOB & 0xFE;   // EN = 0
+    // write to LCD
+    mcp23017.write(PORT_B, buffer_GPIOB);
+    
+__enable_irq();     // Enable Interrupts
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// Initialize LCD                                                                   //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_init_I2C  (void)
+{
+    // init port expander
+    //Port A is databus - Output
+    mcp23017.direction(PORT_A, PORT_DIR_OUT);
+    //Port B is controlbus - Output
+    mcp23017.direction(PORT_B, PORT_DIR_OUT);
+    
+    vLCD_cmd_I2C (0x00);
+    // vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    
+    vLCD_cmd_I2C (0x38);
+    // vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    
+    vLCD_cmd_I2C (0x38);
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    
+    vLCD_cmd_I2C (0x38);
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    
+    // Display ON / OFF
+    vLCD_cmd_I2C (0x08);
+    
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    
+    // Clear Display
+    vLCD_cmd_I2C (0x01);
+    
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    
+    // Entry Mode Set
+    vLCD_cmd_I2C (0x06);
+    
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    
+    // Display ON / OFF
+    vLCD_cmd_I2C (0x0C);
+    
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// Write string to LCD                                                              //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_print_I2C (unsigned char *string, unsigned char line)
+{
+    unsigned int i;
+    
+    // select target line to write to
+    if (line == 1)
+    {
+        vLCD_cmd_I2C (0x80);
+    }
+    else if (line == 2)
+    {
+        vLCD_cmd_I2C (0xC0);
+    }
+    else
+    {
+        return;    // End of function: Error in the past value of line
+    }
+    
+    // write data to selected line
+    for (i=0; i<16; i++)
+    {
+        if (string [i] != 0x00) 
+        {
+            vLCD_data_I2C (string [i]);
+        }
+        else
+            vLCD_data_I2C (' ');
+    }
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// Write string to LCD                                                              //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_printPos_I2C (unsigned char *string, unsigned char line, unsigned char character)
+{
+    unsigned int i;
+    
+    // select target line and position to write to
+    if (line == 1)
+    {
+        vLCD_cmd_I2C (0x80+(character-1));
+    }
+    
+    else if (line == 2)
+    {
+        vLCD_cmd_I2C (0xC0+(character-1));
+    }
+    
+    else
+    {
+        return;    // End of function: Error in the past value of line
+    }
+    
+    // write data to selected line and position
+    for (i=0; i<16; i++)
+    {
+        if (string [i] != 0x00)
+        {
+            vLCD_data_I2C (string [i]);
+        }
+        else
+            vLCD_data_I2C (' ');
+    }
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// Writing integer to LCD                                                           //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_printInt_I2C (int value, unsigned char line, unsigned char character)
+{
+        static char buffer[32];
+        // convert int to char
+        sprintf(buffer, "%.2d", value);
+        // write converted int to LCD
+    vLCD_printPos_I2C((unsigned char*)buffer, line, character);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// clear LCD [unsed]                                                                //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_clear_I2C (void)
+{
+    // Clear Display
+    vLCD_cmd_I2C (0x01);
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+    // Display ON / OFF
+    vLCD_cmd_I2C (0x0C);
+    //vLCD_delay_I2C (65535)
+    vLCD_delay_I2C (100);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// update LCD                                                                       //
+//////////////////////////////////////////////////////////////////////////////////////
+void LCD_I2C::vLCD_update (void)
+{
+   vLCD_print_I2C((unsigned char*)mLCDMenu.getLine1(), 1);
+   vLCD_print_I2C((unsigned char*)mLCDMenu.getLine2(), 2);
+   //vLCD_printPos_I2C((unsigned char*)mLCDMenu.getLine1(), 1, 1);
+   //vLCD_printPos_I2C((unsigned char*)mLCDMenu.getLine2(), 2, 1);
+}
\ No newline at end of file
--- a/LCD_I2C.h	Fri Jun 26 09:21:33 2015 +0000
+++ b/LCD_I2C.h	Tue Aug 11 08:38:55 2015 +0000
@@ -10,7 +10,8 @@
 //		Changelog   :																//
 //		Date:			Name:		Comment:										//
 //		25/03/2015		DNB         First version	    							//
-//      25/03/2015      DNB         implemntation LCD_printPos                      //
+//      25/03/2015      DNB         Implementation LCD_printPos                     //
+//		26/06/2015		DNB			Rebuild LCD_I2C to class						//
 //                                                                                  //
 //////////////////////////////////////////////////////////////////////////////////////
 
@@ -20,14 +21,63 @@
 //////////////////////////////////////////////////////////////////////////////////////
 // includes                                                                         //
 //////////////////////////////////////////////////////////////////////////////////////
-
 #include <stdio.h>
 #include "MCP23017.h"
 
 //////////////////////////////////////////////////////////////////////////////////////
-// functions                                                                        //
+// class                                                                            //
+//////////////////////////////////////////////////////////////////////////////////////
+class LCD_I2C
+{
+    private:
+        // resources
+        I2C i2c;
+        MCP23017 mcp23017;
+        
+        // variable
+        uint32_t uiCounter;
+        
+        char deviceAdress;
+        char buffer_GPIOB;
+                
+        bool bError;
+        
+    public:
+        // Constructor
+        LCD_I2C(PinName, PinName, char);
+        // Destructor
+        ~LCD_I2C();
+        
+//////////////////////////////////////////////////////////////////////////////////////
+// base functions                                                                   //
 //////////////////////////////////////////////////////////////////////////////////////
+void vLCD_delay_I2C (unsigned int t_delay);             // delay up to 65535 ticks
+void vLCD_cmd_I2C   (unsigned char commando);           // send commando to LCD
+void vLCD_data_I2C  (unsigned char data);               // write single character to LCD
+void vLCD_init_I2C  (void);                            	// init LCD
+void vLCD_clear_I2C	(void);								// clear LCD
 
+//////////////////////////////////////////////////////////////////////////////////////
+// write functions                                                                  //
+////////////////////////////////////////////////////////////////////////////////////// 
+void vLCD_print_I2C 	(unsigned char *string, unsigned char line);						// write a string to certain line       
+void vLCD_printLine_I2C (unsigned char *string, unsigned char line);						// write a string to certain line
+void vLCD_printPos_I2C 	(unsigned char *sting, unsigned char line, unsigned char character);// write a string to certain line
+void vLCD_printInt_I2C 	(int value, unsigned char line, unsigned char character);			// write a integer to certain line
+
+//////////////////////////////////////////////////////////////////////////////////////
+// update LCD                                                                 		//
+//////////////////////////////////////////////////////////////////////////////////////
+void vLCD_update (void); 																	// update LCD 
+ 
+        
+};//end class
+
+
+//////////////////////////////////////////////////////////////////////////////////////
+// original functions                                                               //
+//////////////////////////////////////////////////////////////////////////////////////
+/*
 void vLCD_delay_I2C (unsigned int t_delay);                          	// delay up to 65535 ticks
 void vLCD_cmd_I2C   (unsigned char commando);                        	// send commando to LCD
 void vLCD_data_I2C  (unsigned char data);                            	// write single character to LCD
@@ -41,6 +91,8 @@
 void vLCD_printInt_I2C (int value, unsigned char line, unsigned char character);
 // update lcd
 void vLCD_update (void);
+*/
+
 #endif /* defined(____LCD_I2C__) */
 
 //////////////////////////////////////////////////////////////////////////////////////
--- a/LCD_Menu.cpp	Fri Jun 26 09:21:33 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-
-
-#include "LCD_Menu.h"
-#include "LCD_I2C.h"
-
-void vActualMenu(MENU_t menu)
-{
-    switch (menu){
-        case STARTUP:
-                        vLCD_printPos_I2C((unsigned char*)"Initialize      ", 1, 3);
-                        vLCD_printPos_I2C((unsigned char*)" Solar on Foils ", 2, 1);
-                        break;
-        default:
-                        vLCD_printPos_I2C((unsigned char*)"Error default   ", 1, 3);
-                        vLCD_printPos_I2C((unsigned char*)" Solar on Foils ", 2, 1);
-                        break;
-    }   // end off switch case
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// EOF                                                                              //
-//////////////////////////////////////////////////////////////////////////////////////
--- a/LCD_Menu.h	Fri Jun 26 09:21:33 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#ifndef LCD_MENU_INCLUDE
-#define LCD_MENU_INCLUDE
-
-//////////////////////////////////////////////////////////////////////////////////////
-// struct's and enumeration                                                         //
-//////////////////////////////////////////////////////////////////////////////////////
-enum MENU_t
-{
-    STARTUP = 0,    // geeft aan welk deel van de initalisatie wordt uitgevoerd
-    STANDBY,        // failure indication
-    ACTIVE,         // relative voltage indication
-    MAINMENU,       // relative frequency
-    SETTINGS,       // absolute power factor
-    VIEWSETTINGS,   // test patern all leds switched on or off
-    DIAGNOSIS,      // failure OS
-    VIEWMINROLL,    // failure wired communication
-    VIEWMAXROLL,    // failure wireless communication
-    VIEWTOSPEED,    // no more failure
-    VIEWFBHEIGHT    // blink
-};
-
-//////////////////////////////////////////////////////////////////////////////////////
-// function prototypes                                                              //
-//////////////////////////////////////////////////////////////////////////////////////
-void vActualMenu(MENU_t);
-
-#endif
\ No newline at end of file
--- a/main.cpp	Fri Jun 26 09:21:33 2015 +0000
+++ b/main.cpp	Tue Aug 11 08:38:55 2015 +0000
@@ -21,7 +21,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "MCP23017.h"
 #include "LCD_I2C.h"
 #include "uart.h"
 #include "GPS.h"
@@ -31,7 +30,6 @@
 #include "Servo.h"
 #include "mRotaryEncoder.h"
 #include "MainModule.h"
-//#include "LCD_Menu.h"
 #include "menu.h"
 #include "systemVar.h"
 
@@ -108,11 +106,12 @@
 //mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode=PullUp, int debounceTime_us=1000)
 mRotaryEncoder  rSwitch(p12, p11, p7);
 CAN CANbus(p30, p29);
-MCP23017 mcp23017 = MCP23017(i2c, 0x40);
 Serial debug(USBTX, USBRX);
 
 PID rollPID(Kc,Ti,Td,RATE); // declare a PID for roll adjustment
 
+LCD_I2C LCD(p9, p10, 0x40);
+
 //////////////////////////////////////////////////////////////////////////////////////
 // function prototypes                                                              //
 //////////////////////////////////////////////////////////////////////////////////////
@@ -134,13 +133,11 @@
 bool enc_rotated = false;       // rotary encoder was totaded left or right
 bool bSystemFail = false;       // sytem fail
 
-char buffer_GPIOB;
 char cBuffer[200];
 char cMessage;
 char text[16];
 char cPTurns[2] ={0};
 char cSTurns[2] ={0};
-//char buffer[16];
 
 float   fRoll, fPitch, fEulerRoll;
 float   fRollDiff;
@@ -196,12 +193,7 @@
     timer.start();      //timer to test imu roll angle
     actualTime.start(); //crash timer 
     // clear line -1-
-    vLCD_printPos_I2C((unsigned char*)"                 ", 1, 1);
-    
-    // put text on lcd
-    
-    //mLCDMenu.vShowScreen(_FOILBORNE);
-    //vLCD_printPos_I2C((unsigned char*)mLCDMenu.getLine1(), 2, 1);
+    LCD.vLCD_printPos_I2C((unsigned char*)"                 ", 1, 1);
     
 //////////////////////////////////////////////////////////////////////////////////////
 // endless loop                                                                     //
@@ -255,7 +247,7 @@
             svSoF.vSetPitch(q1);                                 // call function class SystemVar
             svSoF.vSetRoll(q1);
             mLCDMenu.vShowScreen(mLCDMenu.getScreen());
-            vLCD_update();
+            LCD.vLCD_update();
             
             //debug.printf("Roll: %c\t", svSoF.getValue());
             //debug.printf("Roll: %f\t", getRollAngle(q1));
@@ -277,218 +269,6 @@
 } // END MAIN 
 
 //////////////////////////////////////////////////////////////////////////////////////
-// delay function for LCD                                                           //
-//////////////////////////////////////////////////////////////////////////////////////
-
-void vLCD_delay_I2C (unsigned int t_delay)
-{
-    unsigned int i;
-    
-    for (i=0; i < t_delay; i++);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// write commando to LCD                                                            //
-//////////////////////////////////////////////////////////////////////////////////////
-
-void vLCD_cmd_I2C   (unsigned char commando)
-{
-__disable_irq();    // Disable Interrupts
-
-    // write commando to LCD
-    mcp23017.write(PORT_A, commando);
-    
-    // LCD_RS = 0
-    buffer_GPIOB = buffer_GPIOB & 0xFD;   // RS = 0
-    // write to LCD
-    mcp23017.write(PORT_B, buffer_GPIOB);
-    
-    // LCD_EN = 1
-    buffer_GPIOB = buffer_GPIOB | 0x01;   // EN = 1
-    // write to LCD
-    mcp23017.write(PORT_B, buffer_GPIOB);
-    
-    // LCD_EN = 0
-    buffer_GPIOB = buffer_GPIOB & 0xFE;   // EN = 0
-    // write to LCD
-    mcp23017.write(PORT_B, buffer_GPIOB);
-    
-__enable_irq();     // Enable Interrupts
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// write single char to LCD                                                         //
-//////////////////////////////////////////////////////////////////////////////////////
-
-void vLCD_data_I2C  (unsigned char data)
-{
-__disable_irq();    // Disable Interrupts
- 
-    // write data to LCD
-    mcp23017.write(PORT_A, data);
-    
-    // LCD_RS = 1
-    buffer_GPIOB = buffer_GPIOB | 0x02;   // RS = 1
-    // write to LCD
-    mcp23017.write(PORT_B, buffer_GPIOB);
-    
-    // LCD_EN = 1
-    buffer_GPIOB = buffer_GPIOB | 0x01;   // EN = 1
-    // write to LCD
-    mcp23017.write(PORT_B, buffer_GPIOB);
-    
-    // LCD_EN = 0
-    buffer_GPIOB = buffer_GPIOB & 0xFE;   // EN = 0
-    // write to LCD
-    mcp23017.write(PORT_B, buffer_GPIOB);
-    
-__enable_irq();     // Enable Interrupts
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Initialize LCD                                                                   //
-//////////////////////////////////////////////////////////////////////////////////////
-
-void vLCD_init_I2C  (void)
-{
-    vLCD_cmd_I2C (0x00);
-    // vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    
-    vLCD_cmd_I2C (0x38);
-    // vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    
-    vLCD_cmd_I2C (0x38);
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    
-    vLCD_cmd_I2C (0x38);
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    
-    // Display ON / OFF
-    vLCD_cmd_I2C (0x08);
-    
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    
-    // Clear Display
-    vLCD_cmd_I2C (0x01);
-    
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    
-    // Entry Mode Set
-    vLCD_cmd_I2C (0x06);
-    
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    
-    // Display ON / OFF
-    vLCD_cmd_I2C (0x0C);
-    
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Write string to LCD                                                              //
-//////////////////////////////////////////////////////////////////////////////////////
-
-void vLCD_print_I2C (unsigned char *string, unsigned char line)
-{
-    unsigned int i;
-    
-    // select target line to write to
-    if (line == 1)
-    {
-        vLCD_cmd_I2C (0x80);
-    }
-    else if (line == 2)
-    {
-        vLCD_cmd_I2C (0xC0);
-    }
-    else
-    {
-        return;    // End of function: Error in the past value of line
-    }
-    
-    // write data to selected line
-    for (i=0; i<16; i++)
-    {
-        if (string [i] != 0x00) 
-        {
-            vLCD_data_I2C (string [i]);
-        }
-        else
-            vLCD_data_I2C (' ');
-    }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// Write string to LCD                                                              //
-//////////////////////////////////////////////////////////////////////////////////////
-
-void vLCD_printPos_I2C (unsigned char *string, unsigned char line, unsigned char character)
-{
-    unsigned int i;
-    
-    // select target line and position to write to
-    if (line == 1)
-    {
-        vLCD_cmd_I2C (0x80+(character-1));
-    }
-    
-    else if (line == 2)
-    {
-        vLCD_cmd_I2C (0xC0+(character-1));
-    }
-    
-    else
-    {
-        return;    // End of function: Error in the past value of line
-    }
-    
-    // write data to selected line and position
-    for (i=0; i<16; i++)
-    {
-        if (string [i] != 0x00)
-        {
-            vLCD_data_I2C (string [i]);
-        }
-        else
-            vLCD_data_I2C (' ');
-    }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// update LCD                                                                       //
-//////////////////////////////////////////////////////////////////////////////////////
-void vLCD_clear_I2C (void)
-{
-    // Clear Display
-    vLCD_cmd_I2C (0x01);
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-    // Display ON / OFF
-    vLCD_cmd_I2C (0x0C);
-    //vLCD_delay_I2C (65535)
-    vLCD_delay_I2C (100);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-// update LCD                                                                       //
-//////////////////////////////////////////////////////////////////////////////////////
-void vLCD_update (void)
-{
-   vLCD_print_I2C((unsigned char*)mLCDMenu.getLine1(), 1);
-   vLCD_print_I2C((unsigned char*)mLCDMenu.getLine2(), 2);
-   //vLCD_printPos_I2C((unsigned char*)mLCDMenu.getLine1(), 1, 1);
-   //vLCD_printPos_I2C((unsigned char*)mLCDMenu.getLine2(), 2, 1);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
 // Init SOF module                                                                  //
 //////////////////////////////////////////////////////////////////////////////////////
 void vInit (void)
@@ -496,15 +276,15 @@
     // I2C init
     i2c.frequency(100000);
     //Port A is databus - Output
-    mcp23017.direction(PORT_A, PORT_DIR_OUT);
+//    mcp23017.direction(PORT_A, PORT_DIR_OUT);
     //Port B is controlbus - Output
-    mcp23017.direction(PORT_B, PORT_DIR_OUT);
+//    mcp23017.direction(PORT_B, PORT_DIR_OUT);
    
     debug.baud(115200);
     // initialize LCD
-    vLCD_init_I2C();
+    //vLCD_init_I2C();
     mLCDMenu.vSelectMenu(_MENU0_0);
-    vLCD_update();
+    LCD.vLCD_update();
       
     // led's out
     aliveLed = 1; wait(0.1); aliveLed = 0;
@@ -537,7 +317,7 @@
 {
     if(imu.isReady()) mLCDMenu.vShowScreen(_IMUREADY);
     else  mLCDMenu.vShowScreen(_IMUFAIL);
-    vLCD_update();
+    LCD.vLCD_update();
         
     imu.initialiseDMP();
     imu.setFifoReset(true);    
@@ -588,7 +368,7 @@
                     case GYRO_GPS_DIAGN:        if((msg.id == GYRO_GPS_ID)&&(msg.data[0] == 0xFF)) mLCDMenu.vShowScreen(_CANID205OK); break;
                     case EXT_UI_DIAGN:          if((msg.id == EXT_UI_ID)&&(msg.data[0] == 0xFF)) mLCDMenu.vShowScreen(_CANID1001OK); break;                                                                                      
                 } //end switch
-                vLCD_update();
+                LCD.vLCD_update();
                 bReceived = true;
             } //end if
             else if(iTry == 1){
@@ -600,7 +380,7 @@
                     case GYRO_GPS_DIAGN:        mLCDMenu.vShowScreen(_CANID205FAIL); break;
                     case EXT_UI_DIAGN:          mLCDMenu.vShowScreen(_CANID1001FAIL); break;                                                                                      
                 } //end switch
-                vLCD_update();
+                LCD.vLCD_update();
             } //end if
             if(CANbus.read(msg)){}//unwanted message
             if(!bReceived) iTry--;
@@ -622,7 +402,7 @@
     CANbus.write(CANMessage(EXT_UI_HEIGHT, &cMessage, 1));
     
     mLCDMenu.vSelectMenu(_MENU0_0);
-    vLCD_update();
+    LCD.vLCD_update();
     debug.printf("end can init");  
 }
 
@@ -683,18 +463,6 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
-// Writing integer to LCD                                                           //
-//////////////////////////////////////////////////////////////////////////////////////
-void vLCD_printInt_I2C (int value, unsigned char line, unsigned char character)
-{
-        static char buffer[32];
-        // convert int to char
-        sprintf(buffer, "%.2d", value);
-        // write converted int to LCD
-    vLCD_printPos_I2C((unsigned char*)buffer, line, character);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
 // calculate Roll from quaternion                                                   //
 //////////////////////////////////////////////////////////////////////////////////////
 float getRollAngle(Quaternion q1)
@@ -769,7 +537,7 @@
     
     // reset switch count
     vResetSwitch();
-    vLCD_update();
+    LCD.vLCD_update();
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
@@ -784,7 +552,7 @@
     // reset switch count
     vResetSwitch();
     
-    vLCD_update();
+    LCD.vLCD_update();
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
--- a/menu.cpp	Fri Jun 26 09:21:33 2015 +0000
+++ b/menu.cpp	Tue Aug 11 08:38:55 2015 +0000
@@ -64,21 +64,38 @@
 ////////////////////////////////////////////////////////////////////////////////////// 
 void Menu::vRotaryUp(void)
 {
+    if((nextMenu != _BACKBACK)||(nextMenu != _BACKHOME)) backToFrom = nextMenu;     // remember previous menu exept back and home
     if(bMenu) vSelectMenu(nextMenu);
+    else if(!bMenu)
+    {
+        svSoF.vIncrease(valueToChange);   // to construct
+        vSelectMenu(nextMenu);
+    }
     vCheckReadHeight();
-    //debug.printf("rotary up %i\r\n", nextMenu);  
+    //debug.printf("backToFrom %i\r\n", backToFrom);  
 }
 
 void Menu::vRotaryDown(void)
 {
+    if((nextMenu != _BACKBACK)||(nextMenu != _BACKHOME)) backToFrom = nextMenu;     // remember previous menu exept back and home
     if(bMenu) vSelectMenu(prevMenu);
+    else if(!bMenu)
+    {
+        svSoF.vDecrease(valueToChange);   // to construct
+        vSelectMenu(nextMenu);
+    }
     vCheckReadHeight();
-    //debug.printf("rotary down %i\r\n", prevMenu); 
+    //debug.printf("backToFrom %i\r\n", backToFrom);
 }
 
 void Menu::vRotaryConfirm(void)
 {
     if(bMenu) vSelectMenu(confMenu);
+    else if (!bMenu) 
+    {
+        bMenu = true;
+        vSelectMenu(confMenu);
+    }
     //debug.printf("rotary confirm\r\n"); 
 }
 
@@ -96,7 +113,7 @@
     for (i=length; i < 16; i++) strcat(cTextLine2," ");
 }
 
-void Menu::vCheckReadHeight(void)
+void Menu::vCheckReadHeight(void)       // used for project demo only
 {
      if(bReadHeight)
      { 
@@ -106,7 +123,7 @@
      else 
      {
         cStatus = 0x00;
-        CANbus.write(CANMessage(DEVICE_ID, &cStatus, 1)); // send clearance false  to port height
+        CANbus.write(CANMessage(DEVICE_ID, &cStatus, 1)); // send clearance false to port height
      }
 }
  
@@ -119,23 +136,132 @@
     uiCounter = rand()% 100 + 1;
     switch(screen)
     {
+//////////////////////////////////////////////////////////////////////////////////////
+// base screens                                                                     //
+//////////////////////////////////////////////////////////////////////////////////////        
         case _INIT:             strcpy(cTextLine1," Solar on Foils ");
                                 strcpy(cTextLine2,"   Initialize   "); break;
         
         case _STANDBY:          strcpy(cTextLine1," Solar on Foils ");
                                 strcpy(cTextLine2," system STANDBY "); break;
-                                
+        
+        case _ACTIVE:           strcpy(cTextLine1," Solar on Foils ");
+                                strcpy(cTextLine2," system ACTIVE  "); break;                        
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 0 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////                                
         case _SETTINGS0:        strcpy(cTextLine1,">Settings       ");
                                 strcpy(cTextLine2," View settings  "); break;
                                 
-        case _SETTINGS1:        strcpy(cTextLine1," Settings       ");
-                                strcpy(cTextLine2,">View settings  "); break;
+        case _SETTINGS1:        strcpy(cTextLine1,">View settings  ");
+                                strcpy(cTextLine2," Diagnosis      "); break;
                                 
         case _SETTINGS2:        strcpy(cTextLine1," View settings  ");
                                 strcpy(cTextLine2,">Diagnosis      "); break;
+
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 1 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////                                
+        case _SYSTEMVAR0:       strcpy(cTextLine1,">Safety margins ");
+                                strcpy(cTextLine2," Take-off speed "); break; 
         
-        case _ACTIVE:           strcpy(cTextLine1," Solar on Foils ");
-                                strcpy(cTextLine2," system ACTIVE  "); break;
+        case _SYSTEMVAR1:       strcpy(cTextLine1,">Take-off speed ");
+                                strcpy(cTextLine2," Height F-borne "); break; 
+                                
+        case _SYSTEMVAR2:       strcpy(cTextLine1,">Height f-borne ");
+                                strcpy(cTextLine2," Height f-assist"); break; 
+                                
+        case _SYSTEMVAR3:       strcpy(cTextLine1,">Height f-assist");
+                                strcpy(cTextLine2," AOA f-assist   "); break; 
+                                
+        case _SYSTEMVAR4:       strcpy(cTextLine1,">AOA f-assist   ");
+                                strcpy(cTextLine2," Back           "); break;
+                                                                                                 
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 2 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////
+        case _SYSTEMVARSELECT0: strcpy(cTextLine1," Agree to change");
+                                strcpy(cTextLine2,">Roll angle     "); break;
+                                
+        case _SYSTEMVARSELECT1: strcpy(cTextLine1," Agree to change");
+                                strcpy(cTextLine2,">Pitch angle    "); break;
+                                
+        case _SYSTEMVARSELECT2: strcpy(cTextLine1," Agree to change");
+                                strcpy(cTextLine2,">Take-off speed "); break;
+                                
+        case _SYSTEMVARSELECT3: strcpy(cTextLine1," Agree to change");
+                                strcpy(cTextLine2,">Height f-borne "); break;
+                                
+        case _SYSTEMVARSELECT4: strcpy(cTextLine1," Agree to change");
+                                strcpy(cTextLine2,">Height f-assist"); break;
+                                
+        case _SYSTEMVARSELECT5: strcpy(cTextLine1," Agree to change");
+                                strcpy(cTextLine2,">AOA f-assist   "); break;
+
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 2 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////                                
+        case _MUTATESYSTEMVAR0: svSoF.cShowValue(_MAXROLL);
+                                strcpy(cTextLine1," max roll angle ");
+                                strcpy(cTextLine2,"     ");
+                                strcat(cTextLine2, svSoF.getValue());
+                                strcat(cTextLine2,"\xDF"); 
+                                vFillString2(); break; 
+                                
+        case _MUTATESYSTEMVAR1: svSoF.cShowValue(_MINPITCH);
+                                strcpy(cTextLine1," min pitch angle");
+                                strcpy(cTextLine2,"     ");
+                                strcat(cTextLine2, svSoF.getValue());
+                                strcat(cTextLine2,"\xDF"); 
+                                vFillString2(); break; 
+                                
+        case _MUTATESYSTEMVAR2: svSoF.cShowValue(_MAXPITCH);
+                                strcpy(cTextLine1," max pitch angle ");
+                                strcpy(cTextLine2,"     ");
+                                strcat(cTextLine2, svSoF.getValue());
+                                strcat(cTextLine2,"\xDF"); 
+                                vFillString2(); break;
+                                
+        case _MUTATESYSTEMVAR3: svSoF.cShowValue(_TAKEOFFSPEED);
+                                strcpy(cTextLine1,"  max T-O speed  ");
+                                strcpy(cTextLine2,"     ");
+                                strcat(cTextLine2, svSoF.getValue());
+                                strcat(cTextLine2,"knots"); 
+                                vFillString2(); break; 
+                                
+        case _MUTATESYSTEMVAR4: svSoF.cShowValue(_HEIGHTFOILBORNE);
+                                strcpy(cTextLine1," foilborne height");
+                                strcpy(cTextLine2,"     ");
+                                strcat(cTextLine2, svSoF.getValue());
+                                strcat(cTextLine2,"cm."); 
+                                vFillString2(); break;
+                                
+        case _MUTATESYSTEMVAR5: svSoF.cShowValue(_HEIGHTFOILASSIST);
+                                strcpy(cTextLine1," f-assist height ");
+                                strcpy(cTextLine2,"     ");
+                                strcat(cTextLine2, svSoF.getValue());
+                                strcat(cTextLine2,"cm."); 
+                                vFillString2(); break;
+                                
+        case _MUTATESYSTEMVAR6: svSoF.cShowValue(_AOAFOILASSIST);
+                                strcpy(cTextLine1," AOA foil assist ");
+                                strcpy(cTextLine2,"     ");
+                                strcat(cTextLine2, svSoF.getValue());
+                                strcat(cTextLine2,"\xDF"); 
+                                vFillString2(); break;                                                                                                                                                                                                                                                                                                                                            
+                               
+//////////////////////////////////////////////////////////////////////////////////////
+// Multiple used screens                                                            //
+//////////////////////////////////////////////////////////////////////////////////////         
+        case _BACK:             strcpy(cTextLine1,">Back           ");
+                                strcpy(cTextLine2," Home           "); break;
+                                 
+        case _HOME:             strcpy(cTextLine1," Back           ");
+                                strcpy(cTextLine2,">Home           "); break; 
+                                                                              
+//////////////////////////////////////////////////////////////////////////////////////
+// CAN messages                                                                     //
+////////////////////////////////////////////////////////////////////////////////////// 
                         
         case _FOILBORNE:        strcpy(cTextLine1," Solar on Foils ");
                                 strcpy(cTextLine2," FOILBORNE mode "); break;
@@ -144,11 +270,14 @@
                                 strcpy(cTextLine2," FOILASSIST mode"); break;
                                 
         case _HOMESCREEN:       strcpy(cTextLine1," Solar on Foils ");
-                                strcpy(cTextLine2,">HOME           "); break;                       
+                                strcpy(cTextLine2,">Home           "); break;                                              
                                 
         case _PROGRESS:         strcpy(cTextLine1," Solar on Foils ");
                                 strcpy(cTextLine2,"work in progress"); break;                        
-                        
+
+//////////////////////////////////////////////////////////////////////////////////////
+// CAN messages                                                                     //
+//////////////////////////////////////////////////////////////////////////////////////                         
         case _CANINIT:          strcpy(cTextLine1," Solar on Foils ");
                                 strcpy(cTextLine2," CAN INITIALIZE "); break;
                             
@@ -188,10 +317,17 @@
                                 //string str = string(intStr); 
 //                                strcpy(cTextLine2, intStr);  // about to test
         break;
+        
+//////////////////////////////////////////////////////////////////////////////////////
+// IMU messages                                                                     //
+//////////////////////////////////////////////////////////////////////////////////////         
         case _IMUREADY:         strcpy(cTextLine1,"MPU9150 is ready"); break; 
         
-        case _IMUFAIL:          strcpy(cTextLine1,"MPU9150init fail"); break;  
-        
+        case _IMUFAIL:          strcpy(cTextLine1,"MPU9150init fail"); break;
+          
+//////////////////////////////////////////////////////////////////////////////////////
+// Test screens                                                                     //
+//////////////////////////////////////////////////////////////////////////////////////         
         case _ROLLTEST:         svSoF.cShowValue(_ROLL);
                                 strcpy(cTextLine1," Confirm to end ");
                                 strcpy(cTextLine2,"Roll: ");
@@ -216,21 +352,16 @@
                                 strcat(cTextLine2, svSoF.getValue());
                                 strcat(cTextLine2," cm.");
                                 vFillString2(); break;
-                                
-                                
+                                            
         case _SHOWHEIGHTFB:     svSoF.cShowValue(_HEIGHTFOILBORNE);
                                 strcpy(cTextLine1," Confirm to end ");
                                 strcpy(cTextLine2,"Height:"); 
                                 strcat(cTextLine2, svSoF.getValue());
                                 strcat(cTextLine2," cm."); 
-                                vFillString2(); break;                                   
-        
-    }   // End switch case
-    //debug.printf("strlen %i\t", strlen(cTextLine2)); // debug stringlength 
+                                vFillString2(); break;     
+    }   // End switch case    
     if(strlen(cTextLine1) > 18) strcpy(cTextLine1," Line overflow  ");
     if(strlen(cTextLine2) > 18) strcpy(cTextLine2," Line overflow  ");
-                                // \xDF for degree sign.
-                                // "\x18\x19\x1a\x1b" arrows
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
@@ -243,27 +374,65 @@
     {
         case _MENU0_0:              mLCDMenu.vShowScreen(_INIT); nextMenu = _MENU0_1; break;
         
-        case _MENU0_1:              mLCDMenu.vShowScreen(_STANDBY); nextMenu = _MENU0_2; break;
+        case _MENU0_1:              mLCDMenu.vShowScreen(_STANDBY); nextMenu =  prevMenu = confMenu = _MENU0_2; break;
         
-        case _MENU0_2:              mLCDMenu.vShowScreen(_SETTINGS0); nextMenu = _MENU0_3; prevMenu = _MENU0_4; confMenu = _MENU1_2; break;
+        case _MENU0_2:              mLCDMenu.vShowScreen(_SETTINGS0); nextMenu = _MENU0_3; prevMenu = _MENU0_4; confMenu = _MENU1_20; break;
         
         case _MENU0_3:              mLCDMenu.vShowScreen(_SETTINGS1); nextMenu = _MENU0_4; prevMenu = _MENU0_2; confMenu = _MENU1_31; break;
         
         case _MENU0_4:              mLCDMenu.vShowScreen(_SETTINGS2); nextMenu = _MENU0_2; prevMenu = _MENU0_3; confMenu = _MENU1_4; break;
         
-        case _MENU1_2:              mLCDMenu.vShowScreen(_PROGRESS); nextMenu = _MENU0_2; prevMenu = _MENU0_3; confMenu = _MENU1_2; break;
+        case _MENU1_20:             mLCDMenu.vShowScreen(_SYSTEMVAR0); nextMenu = _MENU1_21; prevMenu = _MENU1_20; confMenu = _MENU2_20; break;
+        
+        case _MENU1_21:             mLCDMenu.vShowScreen(_SYSTEMVAR1); nextMenu = _MENU1_22; prevMenu = _MENU1_20; confMenu = _MENU2_21; break;
+        
+        case _MENU1_22:             mLCDMenu.vShowScreen(_SYSTEMVAR2); nextMenu = _MENU1_23; prevMenu = _MENU1_21; confMenu = _MENU2_22; break;
+                     
+        case _MENU1_23:             mLCDMenu.vShowScreen(_SYSTEMVAR3); nextMenu = _MENU1_24; prevMenu = _MENU1_22; confMenu = _MENU2_23; break;
+        
+        case _MENU1_24:             mLCDMenu.vShowScreen(_SYSTEMVAR4); nextMenu = _BACKBACK; prevMenu = _MENU1_23; confMenu = _MENU2_24; break;
+        
+        case _MENU2_20:             mLCDMenu.vShowScreen(_SYSTEMVARSELECT0); nextMenu = _MENU2_21; prevMenu = _MENU2_20; confMenu = _MENU3_20; valueToChange = _MAXROLL; break;
+        
+        case _MENU2_21:             mLCDMenu.vShowScreen(_SYSTEMVARSELECT1); nextMenu = _MENU2_22; prevMenu = _MENU2_20; confMenu = _MENU3_21; valueToChange = _MINPITCH; break;
+        
+        case _MENU2_22:             mLCDMenu.vShowScreen(_SYSTEMVARSELECT2); nextMenu = _MENU2_23; prevMenu = _MENU2_21; confMenu = _MENU3_23; valueToChange = _TAKEOFFSPEED; break;
+        
+        case _MENU2_23:             mLCDMenu.vShowScreen(_SYSTEMVARSELECT3); nextMenu = _MENU2_24; prevMenu = _MENU2_22; confMenu = _MENU3_24; valueToChange = _HEIGHTFOILBORNE; break;
+        
+        case _MENU2_24:             mLCDMenu.vShowScreen(_SYSTEMVARSELECT4); nextMenu = _MENU2_25; prevMenu = _MENU2_23; confMenu = _MENU3_25; valueToChange = _HEIGHTFOILASSIST; break;
         
-        case _MENU1_4:              mLCDMenu.vShowScreen(_PROGRESS); nextMenu = _MENU0_2; prevMenu = _MENU0_3; confMenu = _MENU1_2; break;
+        case _MENU2_25:             mLCDMenu.vShowScreen(_SYSTEMVARSELECT5); nextMenu = _BACKBACK; prevMenu = _MENU2_24; confMenu = _MENU3_26; valueToChange = _AOAFOILASSIST; break;
+        
+        // system variabele aanpassen
+        case _MENU3_20:             bMenu = false; mLCDMenu.vShowScreen(_MUTATESYSTEMVAR0); confMenu = _MENU2_20; break;
+        
+        case _MENU3_21:             bMenu = false; mLCDMenu.vShowScreen(_MUTATESYSTEMVAR1); confMenu = _MENU3_22; valueToChange = _MAXPITCH; break;
+        
+        case _MENU3_22:             bMenu = false; mLCDMenu.vShowScreen(_MUTATESYSTEMVAR2); confMenu = _MENU2_21; break;
+        
+        case _MENU3_23:             bMenu = false; mLCDMenu.vShowScreen(_MUTATESYSTEMVAR3); confMenu = _MENU2_22; break;
         
-        case _MENU1_31:             mLCDMenu.vShowScreen(_ROLLTEST); nextMenu = _MENU1_32; prevMenu = _HOME; confMenu = _MENU1_31; break;
+        case _MENU3_24:             bMenu = false; mLCDMenu.vShowScreen(_MUTATESYSTEMVAR4); confMenu = _MENU2_23; break;
+        
+        case _MENU3_25:             bMenu = false; mLCDMenu.vShowScreen(_MUTATESYSTEMVAR5); confMenu = _MENU2_24; break;
+        
+        case _MENU3_26:             bMenu = false; mLCDMenu.vShowScreen(_MUTATESYSTEMVAR6); confMenu = _MENU2_25; break;
+        
+        
+        case _MENU1_4:              mLCDMenu.vShowScreen(_PROGRESS); nextMenu = _MENU0_2; prevMenu = _MENU0_3; confMenu = _MENU1_20; break;
+        
+        case _MENU1_31:             mLCDMenu.vShowScreen(_ROLLTEST); nextMenu = _MENU1_32; prevMenu = _BACKHOME; confMenu = _MENU1_31; break;
         
         case _MENU1_32:             mLCDMenu.vShowScreen(_PITCHTEST); nextMenu = _MENU1_33; prevMenu = _MENU1_31; confMenu = _MENU1_32; break;
         
         case _MENU1_33:             mLCDMenu.vShowScreen(_SHOWHEIGHTFB); bReadHeight = false; nextMenu = _MENU1_34; prevMenu = _MENU1_32; confMenu = _MENU1_33; break;
         
-        case _MENU1_34:             mLCDMenu.vShowScreen(_HEIGHTTEST); bReadHeight = true; nextMenu = _HOME; prevMenu = _MENU1_33; confMenu = _MENU1_34; break;
+        case _MENU1_34:             mLCDMenu.vShowScreen(_HEIGHTTEST); bReadHeight = true; nextMenu = _BACKHOME; prevMenu = _MENU1_33; confMenu = _MENU1_34; break;
+        // Todo confMenu to previous menu layer
+        case _BACKBACK:             mLCDMenu.vShowScreen(_BACK); bReadHeight = false; nextMenu = _BACKHOME; prevMenu = backToFrom; confMenu = _MENU0_2; break;
         
-        case _HOME:                 mLCDMenu.vShowScreen(_HOMESCREEN); bReadHeight = false; nextMenu = _MENU1_31; prevMenu = _MENU1_34; confMenu = _MENU0_2; break;
+        case _BACKHOME:             mLCDMenu.vShowScreen(_HOME); bReadHeight = false; nextMenu = _BACKHOME; prevMenu = _BACKBACK; confMenu = _MENU0_2; break;
         
     }//end switch
 }
--- a/menu.h	Fri Jun 26 09:21:33 2015 +0000
+++ b/menu.h	Tue Aug 11 08:38:55 2015 +0000
@@ -7,15 +7,53 @@
 //Solar on Foils display screens
 enum SCREEN_t
 {
+//////////////////////////////////////////////////////////////////////////////////////
+// base screens                                                                     //
+//////////////////////////////////////////////////////////////////////////////////////    
     _INIT = 0,              // Initialize screen
     _STANDBY,               // Standby screen
     _ACTIVE,                // Active screen
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 0 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////    
     _SETTINGS0,             // Settings level 0 screen
     _SETTINGS1,             // Settings level 1 screen
     _SETTINGS2,             // Settings level 2 screen
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 1 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////    
+    _SYSTEMVAR0,            // System variable groep select level 0 screen
+    _SYSTEMVAR1,            // Safety margins level 1 screen
+    _SYSTEMVAR2,            // Safety margins level 2 screen
+    _SYSTEMVAR3,            // Safety margins level 3 screen
+    _SYSTEMVAR4,            // Safety margins level 4 screen
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 2 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////    
+    _SYSTEMVARSELECT0,      // Select system variable to change level 0 screen
+    _SYSTEMVARSELECT1,      // Select system variable to change level 1 screen
+    _SYSTEMVARSELECT2,      // Select system variable to change level 2 screen
+    _SYSTEMVARSELECT3,      // Select system variable to change level 3 screen
+    _SYSTEMVARSELECT4,      // Select system variable to change level 4 screen
+    _SYSTEMVARSELECT5,      // Select system variable to change level 5 screen
+//////////////////////////////////////////////////////////////////////////////////////
+// menulayer 3 settings                                                             //
+//////////////////////////////////////////////////////////////////////////////////////    
+    _MUTATESYSTEMVAR0,      // mutate system variable level 0 screen
+    _MUTATESYSTEMVAR1,      // mutate system variable level 1 screen
+    _MUTATESYSTEMVAR2,      // mutate system variable level 2 screen
+    _MUTATESYSTEMVAR3,      // mutate system variable level 3 screen
+    _MUTATESYSTEMVAR4,      // mutate system variable level 4 screen
+    _MUTATESYSTEMVAR5,      // mutate system variable level 5 screen
+    _MUTATESYSTEMVAR6,      // mutate system variable level 6 screen
+    _MUTATESYSTEMVAR7,      // mutate system variable level 7 screen
+    
     _FOILBORNE,             // foilborne screen
     _FOILASSIST,            // foil assist screen
     _HOMESCREEN,            // home screen
+//////////////////////////////////////////////////////////////////////////////////////
+// CAN messages                                                                     //
+//////////////////////////////////////////////////////////////////////////////////////    
     _CANINIT,
     _CANFAIL,
     _CANERROR,
@@ -33,15 +71,22 @@
     _CANID202FAIL,
     _CANID205FAIL,
     _CANID1001FAIL,
-    _PULSE_IS,
+//////////////////////////////////////////////////////////////////////////////////////
+// IMU messages                                                                     //
+//////////////////////////////////////////////////////////////////////////////////////         
     _IMUREADY,
     _IMUFAIL,
     _ROLLTEST,              // roll test displays roll value
     _PITCHTEST,             // pitch test displays pitch value
     _HEIGHTTEST,
     _SHOWHEIGHTFB,          // display height value
-
+    _PULSE_IS,
     _CAUTION,               // Caution screen
+//////////////////////////////////////////////////////////////////////////////////////
+// multiple used screens                                                            //
+//////////////////////////////////////////////////////////////////////////////////////     
+    _BACK,                  // Back screen
+    _HOME,                  // Home screen
     _PROGRESS               // development screen
 };
 //////////////////////////////////////////////////////////////////////////////////////
@@ -51,20 +96,40 @@
 {
     _MENU0_0 = 0,           // Initialize screen
     _MENU0_1,               // Standby screen
+    
     _MENU0_2,               // Settings screen
-    _MENU1_2,               // Variable settings screen
+    _MENU1_20,              // Variable settings screen 0
+    _MENU1_21,              // Variable settings screen 1
+    _MENU1_22,              // Variable settings screen 2
+    _MENU1_23,              // Variable settings screen 3
+    _MENU1_24,              // Variable settings screen 4
+    
+    _MENU2_20,              // Variable settings select screen 0
+    _MENU2_21,              // Variable settings select screen 1
+    _MENU2_22,              // Variable settings select screen 2
+    _MENU2_23,              // Variable settings select screen 3
+    _MENU2_24,              // Variable settings select screen 4
+    _MENU2_25,              // Variable settings select screen 5
+    
+    _MENU3_20,              // Variable settings mutatie screen 0
+    _MENU3_21,              // Variable settings mutatie screen 1
+    _MENU3_22,              // Variable settings mutatie screen 2
+    _MENU3_23,              // Variable settings mutatie screen 3
+    _MENU3_24,              // Variable settings mutatie screen 4
+    _MENU3_25,              // Variable settings mutatie screen 5
+    _MENU3_26,              // Variable settings mutatie screen 6
+    
     _MENU0_3,               // Viewsettings screen
     _MENU1_31,              // View roll angle screen
     _MENU1_32,              // View pitch angle screen
     _MENU1_33,              // View height settings screen
-    _MENU1_34,               // View port height measured
+    _MENU1_34,              // View port height measured
+    
     _MENU0_4,               // Diagnosis screen
     _MENU1_4,               // Diagnosis menu screen
     
-    
-    
-    
-    _HOME                   // Back home
+    _BACKBACK,              // Back back
+    _BACKHOME               // Back home
 };
 
 class Menu
@@ -77,13 +142,14 @@
         char cStatus;
         
         SCREEN_t screen;
-        MENU_t menu, nextMenu, prevMenu, confMenu;
+        MENU_t menu, nextMenu, prevMenu, confMenu, backToFrom;
+        VALUE_t valueToChange;
         
         uint32_t uiCounter;
                 
-        bool bMenu;     // true item is menu, false item is value
-        bool bConfirm;  // confirm menu or value item 
-        bool bReadHeight;
+        bool bMenu;             // true item is menu, false item is value
+        bool bConfirm;          // confirm menu or value item 
+        bool bReadHeight;       // allow writing CAN height module on CANbus
         bool bError;
         
     public:
@@ -108,8 +174,8 @@
         void vRotaryUp(void);
         void vRotaryDown(void);
         void vRotaryConfirm(void);
-        void vFillString1(void);
-        void vFillString2(void);
+        void vFillString1(void);        // Fill string1 upto 16 characters
+        void vFillString2(void);        // Fill string2 upto 16 characters
         void vCheckReadHeight(void);
         
 };
--- a/systemVar.cpp	Fri Jun 26 09:21:33 2015 +0000
+++ b/systemVar.cpp	Tue Aug 11 08:38:55 2015 +0000
@@ -15,16 +15,34 @@
 #include "systemVar.h"
 
 //////////////////////////////////////////////////////////////////////////////////////
-// Defines                                                                       //
+// Defines                                                                          //
+//////////////////////////////////////////////////////////////////////////////////////
+#define EXT_UI_HEIGHT           1020 
+           
+//////////////////////////////////////////////////////////////////////////////////////
+// Variable limits                                                                  //
 //////////////////////////////////////////////////////////////////////////////////////
-#define EXT_UI_HEIGHT       1020            
+#define MAXMAXROLL              30 
+#define MAXMINPITCH             15
+#define MAXMAXPITCH             30
+#define MAXTAKEOFFSPEED         15
+#define MAXFOILBORNEHEIGHT      30
+#define MAXFOILASSISTHEIGHT     30
+#define MAXAOA                  8
+#define MINMAXROLL              5                 
+#define MINMINPITCH             5
+#define MINMAXPITCH             5
+#define MINTAKEOFFSPEED         1
+#define MINFOILBORNEHEIGHT      1
+#define MINFOILASSISTHEIGHT     1
+#define MINAOA                  1
 
 //////////////////////////////////////////////////////////////////////////////////////
 // Contructor                                                                       //
 //////////////////////////////////////////////////////////////////////////////////////
 SystemVar::SystemVar() : 
            uiCounter(0),
-           uivVarHeightFoilBorne(30),
+           uiVarHeightFoilBorne(30),
            bError(0)           
         {
             init();
@@ -77,8 +95,8 @@
 {
     cMessage = uiValue;
     CANbus.write(CANMessage(EXT_UI_HEIGHT, &cMessage, 1));
-    uivVarHeightFoilBorne = uiValue;
-    debug.printf("set height %i\t", uivVarHeightFoilBorne);
+    uiVarHeightFoilBorne = uiValue;
+    debug.printf("set height %i\t", uiVarHeightFoilBorne);
 }
 
 void SystemVar::vSetPHeight(uint32_t uiValue)
@@ -131,13 +149,57 @@
     return uiRoll[1];
 }
 
+uint32_t SystemVar::uiGetPitch(void)
+{
+    return uiPitch[1];
+}
+
 int32_t SystemVar::iGetHeightFoilBorne(void)
 {
-    return uivVarHeightFoilBorne;
+    return uiVarHeightFoilBorne;
+}
+
+uint32_t SystemVar::uiGetVarMaxRoll(void)
+{
+    return uiVarMaxRoll;    
+}
+        
+uint32_t SystemVar::uiGetVarMinPitch(void)
+{
+    return uiVarMinPitch;   
+}
+       
+uint32_t SystemVar::uiGetVarMaxPitch(void)
+{
+    return uiVarMaxPitch;
 }
 
+uint32_t SystemVar::uiGetVarTakeOffSpeed(void)
+{
+    return uiVarTakeOffSpeed;
+}
+
+uint32_t SystemVar::uiGetVarHeightFoilBorne(void)
+{
+    return uiVarHeightFoilBorne;
+}
+
+uint32_t SystemVar::uiGetVarHeightFoilAssist(void)
+{
+    return uiVarHeightFoilAssist;
+}
+
+uint32_t SystemVar::uiGetVarAOAFoilAssist(void)
+{
+    return uiVarAOAFoilAssist;
+}
+
+        
+        
+        
+        
 //////////////////////////////////////////////////////////////////////////////////////
-// show value                                                                       //
+// convert value to char *                                                          //
 //////////////////////////////////////////////////////////////////////////////////////
 void SystemVar::itoa( uint32_t value, char *str)
 {   
@@ -169,15 +231,71 @@
                                 
         case _PITCH:            itoa(uiPitch[1], cValue); break;
         
-        case _HEIGHTFOILBORNE:  itoa(uivVarHeightFoilBorne, cValue); break;
+        //case _HEIGHTFOILBORNE:  itoa(uiVarHeightFoilBorne, cValue); break;
         
         case _PHEIGHT:          itoa(uiPHeight, cValue); break;
         
+        case _MAXROLL:          itoa(uiVarMaxRoll, cValue); break;
+        
+        case _MINPITCH:         itoa(uiVarMinPitch, cValue); break;
+        
+        case _MAXPITCH:         itoa(uiVarMaxPitch, cValue); break;
+        
+        case _TAKEOFFSPEED:     itoa(uiVarTakeOffSpeed, cValue); break;
+        
+        case _HEIGHTFOILBORNE:  itoa(uiVarHeightFoilBorne, cValue); break;
+        
+        case _HEIGHTFOILASSIST: itoa(uiVarHeightFoilAssist, cValue); break;
+        
+        case _AOAFOILASSIST:    itoa(uiVarAOAFoilAssist, cValue); break;        
     } // end switch
     
 }
 
-
+//////////////////////////////////////////////////////////////////////////////////////
+// in-/decrease value                                                               //
+////////////////////////////////////////////////////////////////////////////////////// 
+void SystemVar::vIncrease(VALUE_t v)
+{
+    value = v;
+    switch(value)
+    {
+        case _MAXROLL:          if(uiVarMaxRoll >= MAXMAXROLL) uiVarMaxRoll++; break; 
+        
+        case _MINPITCH:         if(uiVarMinPitch >= MAXMINPITCH) uiVarMinPitch++; break;
+        
+        case _MAXPITCH:         if(uiVarMaxPitch >= MAXMAXPITCH) uiVarMaxPitch++; break;
+        
+        case _TAKEOFFSPEED:     if(uiVarTakeOffSpeed >= MAXTAKEOFFSPEED) uiVarTakeOffSpeed++; break;
+        
+        case _HEIGHTFOILBORNE:  if(uiVarHeightFoilBorne >= MAXFOILBORNEHEIGHT) uiVarHeightFoilBorne++; break;
+        
+        case _HEIGHTFOILASSIST: if(uiVarHeightFoilAssist >= MAXFOILASSISTHEIGHT) uiVarHeightFoilAssist++; break;
+        
+        case _AOAFOILASSIST:    if(uiVarAOAFoilAssist >= MAXAOA) uiVarAOAFoilAssist++; break;          
+    }//end switch  
+}
+      
+void SystemVar::vDecrease(VALUE_t v)
+{
+    value = v;
+    switch(value)
+    {
+        case _MAXROLL:          if(uiVarMaxRoll <= MINMAXROLL) uiVarMaxRoll--; break; 
+        
+        case _MINPITCH:         if(uiVarMinPitch <= MINMINPITCH) uiVarMinPitch--; break;
+        
+        case _MAXPITCH:         if(uiVarMaxPitch <= MINMAXPITCH) uiVarMaxPitch--; break;
+        
+        case _TAKEOFFSPEED:     if(uiVarTakeOffSpeed <= MINTAKEOFFSPEED) uiVarTakeOffSpeed--; break;
+        
+        case _HEIGHTFOILBORNE:  if(uiVarHeightFoilBorne <= MINFOILBORNEHEIGHT) uiVarHeightFoilBorne--; break;
+        
+        case _HEIGHTFOILASSIST: if(uiVarHeightFoilAssist <= MINFOILASSISTHEIGHT) uiVarHeightFoilAssist--; break;
+        
+        case _AOAFOILASSIST:    if(uiVarAOAFoilAssist <= MINAOA) uiVarAOAFoilAssist--; break;
+    }//end switch     
+}
 
 
 
--- a/systemVar.h	Fri Jun 26 09:21:33 2015 +0000
+++ b/systemVar.h	Tue Aug 11 08:38:55 2015 +0000
@@ -50,11 +50,11 @@
         uint32_t uiSpeed;
         uint32_t uiVarMaxRoll;
         uint32_t uiVarMinPitch;
-        uint32_t uivVarMaxPitch;
-        uint32_t uivVarTakeOffSpeed;
-        uint32_t uivVarHeightFoilBorne;
-        uint32_t uivVarHeightFoilAssist;
-        uint32_t uivVarAOAFoilAssist;
+        uint32_t uiVarMaxPitch;
+        uint32_t uiVarTakeOffSpeed;
+        uint32_t uiVarHeightFoilBorne;
+        uint32_t uiVarHeightFoilAssist;
+        uint32_t uiVarAOAFoilAssist;
                 
         bool bError;
         
@@ -69,7 +69,16 @@
         int iGetRollPolarity(void);
         int iGetPitchPolarity(void);
         uint32_t uiGetRoll(void);
+        uint32_t uiGetPitch(void);
         int32_t iGetHeightFoilBorne(void);
+        uint32_t uiGetVarMaxRoll(void);
+        uint32_t uiGetVarMinPitch(void);
+        uint32_t uiGetVarMaxPitch(void);
+        uint32_t uiGetVarTakeOffSpeed(void);
+        uint32_t uiGetVarHeightFoilBorne(void);
+        uint32_t uiGetVarHeightFoilAssist(void);
+        uint32_t uiGetVarAOAFoilAssist(void);
+
 
         // Sets
         void vSetRoll(Quaternion);
@@ -92,6 +101,8 @@
         void init(void);
         void itoa( uint32_t , char *);
         void cShowValue(VALUE_t);
+        void vIncrease(VALUE_t);
+        void vDecrease(VALUE_t);
         
 };
 #endif