changeset 295:718e5feded62

Merged in janlmulder/ostc4/div-fixes-6 (pull request #23) Cleanup VPM, NDL to 240 min, and more cleanup
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Mon, 13 May 2019 13:37:34 +0000
parents ba9d99a2e310 (current diff) e424ad056b58 (diff)
children 87f83879cecb b70c26be71a0
files
diffstat 12 files changed, 258 insertions(+), 879 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Mon May 06 15:45:19 2019 +0200
+++ b/.hgtags	Mon May 13 13:37:34 2019 +0000
@@ -1,1 +1,2 @@
 1b9be6040d8279117c7fc99d528790611638f10b V1.4.7 release
+ba9d99a2e310da601a948ff11ad665260c600e18 v1.4.8 release
--- a/Discovery/Inc/tHome.h	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Inc/tHome.h	Mon May 13 13:37:34 2019 +0000
@@ -115,8 +115,6 @@
 void tHome_refresh(void);
 void tHome_sleepmode_fun(void);
 void set_globalState_tHome(void);
-void switch_to_SimData_tHome(void);
-void switch_to_RealData_tHome(void);
 void tHome_change_field_button_pressed(void);
 void tHome_change_customview_button_pressed(void);
 
--- a/Discovery/Inc/vpm.h	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Inc/vpm.h	Mon May 13 13:37:34 2019 +0000
@@ -32,17 +32,7 @@
 
 extern long vpm_time_calc_begin;
 enum DECOLIST{DECOSTOPS,FUTURESTOPS,BAILOUTSTOPS, OFF = -1}; // order is important!!
-enum VPM_CALC_STATUS{CALC_END, CALC_BEGIN, CALC_CRITICAL, CALC_FINAL_DECO, CALC_NULLZEIT };
-//int calc_crushing_pressure(float *starting_depth, float *ending_depth, float *rate);
-//void vpm_check_calc(unsigned short* stoplist);
-//void vpm_init(void);
-//_Bool vpm_crush(void);
-
-//void vpm_reset_variables(void);
-//_Bool vpm_build_variables_from_file(unsigned long in_sdram_start);
-//int vpm_store_variables_in_sdram_for_transfer(unsigned long in_sdram_start);
-//void vpm_calc_crushing_pressure(float starting_ambient_pressure, float ending_ambient_pressure, float rate);
-//void vpm_deco_plan(unsigned short divetime,unsigned short * divetime_first_stop, float* first_stop_depth);
+enum VPM_CALC_STATUS{CALC_END, CALC_BEGIN, CALC_CRITICAL, CALC_FINAL_DECO, CALC_NDL };
 
 float schreiner_equation__2(float *initial_inspired_gas_pressure,float *rate_change_insp_gas_pressure,float *interval_time_minutes,  const float *gas_time_constant,float *initial_gas_pressure);
 
--- a/Discovery/Src/buehlmann.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/buehlmann.c	Mon May 13 13:37:34 2019 +0000
@@ -517,7 +517,7 @@
 	return (pDiveSettings->gf_high - gfSteigung * (pressure - gSurface_pressure_bar) )/ 100.0f;
 }
 
-
+#define MAX_NDL 240
 static int buehlmann_calc_ndl(SDiveSettings *pDiveSettings)
 {
 	float local_tissue_nitrogen_bar[16];
@@ -528,7 +528,7 @@
 	//Check ndl always use gHigh
 	gGF_value = ((float)pDiveSettings->gf_high) / 100.0f;
 	//10 minutes steps
-	while(ndl < (300 * 60))
+	while(ndl < (MAX_NDL * 60))
 	{
 		memcpy(local_tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16));
 		memcpy(local_tissue_helium_bar, gTissue_helium_bar, (4*16));
@@ -545,10 +545,10 @@
 		buehlmann_backup_and_restore(false);
 	}
 
-	if(ndl < (300 * 60))
+	if(ndl < (MAX_NDL * 60))
 		ndl -= 600;
 
-	if(ndl > (150 * 60))
+	if(ndl > (MAX_NDL/2 * 60))
 		return ndl;
 
 	// refine
@@ -559,7 +559,6 @@
 	for(i = 0; i < 10; i++)
 	{
 		ndl += 60;
-		//tissues_exposure_at_gPressure_seconds(60);
 		decom_tissues_exposure2(60, &pDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar);
 		decom_oxygen_calculate_cns_exposure(60,&pDiveSettings->decogaslist[gGas_id],gPressure,&gCNS);
 		buehlmann_backup_and_restore(true);
--- a/Discovery/Src/data_exchange_main.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/data_exchange_main.c	Mon May 13 13:37:34 2019 +0000
@@ -422,27 +422,16 @@
 
 void DataEX_copy_to_deco(void)
 {
-  SDiveState * pStateUsed;
 	if(decoLock == DECO_CALC_running)
         return;
-	if(stateUsed == stateRealGetPointer())
-		pStateUsed = stateRealGetPointerWrite();
-	else{
-		pStateUsed = stateSimGetPointerWrite();
-	}
 
 		if(decoLock == DECO_CALC_init_as_is_start_of_dive)
 		{
-	    vpm_init(&pStateUsed->vpm,  pStateUsed->diveSettings.vpm_conservatism, 0, 0);
+	    vpm_init(&stateUsedWrite->vpm,  stateUsedWrite->diveSettings.vpm_conservatism, 0, 0);
 	    buehlmann_init();
 	    timer_init();
-	    resetEvents(pStateUsed);
-      pStateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0;
-			/*
-			 * ToDo by Peter
-			 * copy VPM stuff etc. pp.
-			 * was   void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm);
-			 */
+	    resetEvents(stateUsedWrite);
+	    stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0;
 		}
 
 		if(decoLock == DECO_CALC_FINSHED_Buehlmann)
@@ -454,48 +443,48 @@
 
     //Deco_calculation finished
     case DECO_CALC_FINSHED_vpm:
-        memcpy(&pStateUsed->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo));
-				pStateUsed->decolistVPM.tickstamp = HAL_GetTick();
-        pStateUsed->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached;
+        memcpy(&stateUsedWrite->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo));
+        stateUsedWrite->decolistVPM.tickstamp = HAL_GetTick();
+        stateUsedWrite->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached;
         for(int i = 0; i< 16; i++)
         {
-            pStateUsed->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i];
-            pStateUsed->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i];
-            pStateUsed->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i];
-            pStateUsed->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i];
-            pStateUsed->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i];
-            pStateUsed->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i];
-            pStateUsed->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i];
+        	stateUsedWrite->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i];
+        	stateUsedWrite->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i];
+        	stateUsedWrite->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i];
+        	stateUsedWrite->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i];
+        	stateUsedWrite->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i];
+        	stateUsedWrite->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i];
+        	stateUsedWrite->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i];
         }
         break;
     case DECO_CALC_FINSHED_Buehlmann:
-        memcpy(&pStateUsed->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo));
-				pStateUsed->decolistBuehlmann.tickstamp = HAL_GetTick();
+        memcpy(&stateUsedWrite->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo));
+        stateUsedWrite->decolistBuehlmann.tickstamp = HAL_GetTick();
         //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann
-        pStateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = stateDeco.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero;
+        stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = stateDeco.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero;
         break;
     case DECO_CALC_FINSHED_FutureBuehlmann:
-        memcpy(&pStateUsed->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo));
-				pStateUsed->decolistFutureBuehlmann.tickstamp = HAL_GetTick();
+        memcpy(&stateUsedWrite->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo));
+        stateUsedWrite->decolistFutureBuehlmann.tickstamp = HAL_GetTick();
         break;
     case DECO_CALC_FINSHED_Futurevpm:
-        memcpy(&pStateUsed->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo));
-				pStateUsed->decolistFutureVPM.tickstamp = HAL_GetTick();
+        memcpy(&stateUsedWrite->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo));
+        stateUsedWrite->decolistFutureVPM.tickstamp = HAL_GetTick();
         break;
     }
 
     //Copy Inputdata from stateReal to stateDeco
-    memcpy(&stateDeco.lifeData,&pStateUsed->lifeData,sizeof(SLifeData));
-    memcpy(&stateDeco.diveSettings,&pStateUsed->diveSettings,sizeof(SDiveSettings));
+    memcpy(&stateDeco.lifeData,&stateUsedWrite->lifeData,sizeof(SLifeData));
+    memcpy(&stateDeco.diveSettings,&stateUsedWrite->diveSettings,sizeof(SDiveSettings));
 
-    stateDeco.vpm.deco_zone_reached = pStateUsed->vpm.deco_zone_reached;
+    stateDeco.vpm.deco_zone_reached = stateUsedWrite->vpm.deco_zone_reached;
     // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm));
     for(int i = 0; i< 16; i++)
     {
-        stateDeco.vpm.max_crushing_pressure_he[i] = pStateUsed->vpm.max_crushing_pressure_he[i];
-        stateDeco.vpm.max_crushing_pressure_n2[i] = pStateUsed->vpm.max_crushing_pressure_n2[i];
-        stateDeco.vpm.adjusted_critical_radius_he[i] = pStateUsed->vpm.adjusted_critical_radius_he[i];
-        stateDeco.vpm.adjusted_critical_radius_n2[i] = pStateUsed->vpm.adjusted_critical_radius_n2[i];
+        stateDeco.vpm.max_crushing_pressure_he[i] = stateUsedWrite->vpm.max_crushing_pressure_he[i];
+        stateDeco.vpm.max_crushing_pressure_n2[i] = stateUsedWrite->vpm.max_crushing_pressure_n2[i];
+        stateDeco.vpm.adjusted_critical_radius_he[i] = stateUsedWrite->vpm.adjusted_critical_radius_he[i];
+        stateDeco.vpm.adjusted_critical_radius_n2[i] = stateUsedWrite->vpm.adjusted_critical_radius_n2[i];
     }
 		decoLock = DECO_CALC_ready;
 }
--- a/Discovery/Src/tHome.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/tHome.c	Mon May 13 13:37:34 2019 +0000
@@ -71,18 +71,6 @@
 }
 
 
-void switch_to_SimData_tHome(void)
-{
-    set_stateUsedToSim();
-}
-
-
-void switch_to_RealData_tHome(void)
-{
-    set_stateUsedToReal();
-}
-
-
 void tHome_init(void)
 {
     t7_init(); // standard + surface
--- a/Discovery/Src/tMenuEditDeco.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/tMenuEditDeco.c	Mon May 13 13:37:34 2019 +0000
@@ -34,27 +34,27 @@
 #include "unit.h"
 
 /* Private variables ---------------------------------------------------------*/
-uint8_t lineSelected = 0;
+static uint8_t lineSelected = 0;
 
 /* Private function prototypes -----------------------------------------------*/
 
-void openEdit_DiveMode(void);
-void openEdit_CCRModeSensorOrFixedSP(void);
-void openEdit_ppO2max(void);
-void openEdit_SafetyStop(void);
-void openEdit_FutureTTS(void);
-void openEdit_Salinity(void);
+static void openEdit_DiveMode(void);
+static void openEdit_CCRModeSensorOrFixedSP(void);
+static void openEdit_ppO2max(void);
+static void openEdit_SafetyStop(void);
+static void openEdit_FutureTTS(void);
+static void openEdit_Salinity(void);
 
 /* Announced function prototypes -----------------------------------------------*/
 
-uint8_t OnAction_OC			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_CC			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_Apnea		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_Gauge		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_FutureTTS	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_ppO2Max	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_SafetyStop (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_Salinity	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_OC			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_CC			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_Apnea		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_Gauge		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_FutureTTS	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_ppO2Max	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_SafetyStop (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_Salinity	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 /* Exported functions --------------------------------------------------------*/
 
 void openEdit_Deco(uint8_t line)
@@ -96,7 +96,7 @@
 /* Private functions ---------------------------------------------------------*/
 
 
-void openEdit_DiveMode(void)
+static void openEdit_DiveMode(void)
 {
 #define APNEAANDGAUGE
 
@@ -153,7 +153,7 @@
     write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
 }
 
-uint8_t OnAction_OC						(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_OC						(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings = settingsGetPointer();
     if(pSettings->dive_mode == DIVEMODE_OC)
@@ -168,7 +168,7 @@
 }
 
 
-uint8_t OnAction_CC						(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_CC						(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings = settingsGetPointer();
     if(pSettings->dive_mode == DIVEMODE_CCR)
@@ -183,7 +183,7 @@
 }
 
 
-uint8_t OnAction_Apnea				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_Apnea				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings = settingsGetPointer();
     if(pSettings->dive_mode == DIVEMODE_Apnea)
@@ -198,7 +198,7 @@
 }
 
 
-uint8_t OnAction_Gauge				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_Gauge				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings = settingsGetPointer();
     if(pSettings->dive_mode == DIVEMODE_Gauge)
@@ -213,7 +213,7 @@
 }
 
 
-void openEdit_CCRModeSensorOrFixedSP(void)
+static void openEdit_CCRModeSensorOrFixedSP(void)
 {
     SSettings *pSettings = settingsGetPointer();
 
@@ -226,7 +226,7 @@
 }
 
 
-void openEdit_SafetyStop(void)
+static void openEdit_SafetyStop(void)
 {
     uint32_t safetystopDuration, safetystopDepth;
     char text[64];
@@ -284,7 +284,7 @@
 }
 
 
-uint8_t OnAction_SafetyStop		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_SafetyStop		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     uint8_t digitContentNew;
     uint32_t newSafetystopDuration, newSafetystopDepth;
@@ -372,7 +372,7 @@
 }
 
 
-void openEdit_Salinity(void)
+static void openEdit_Salinity(void)
 {
     char text[32];
     uint16_t y_line;
@@ -396,7 +396,7 @@
 }
 
 
-uint8_t OnAction_Salinity(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_Salinity(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings;
     uint8_t digitContentNew;
@@ -439,7 +439,7 @@
 }
 
 
-void openEdit_ppO2max(void)
+static void openEdit_ppO2max(void)
 {
     uint8_t maxL_std, maxL_deco;
     uint16_t y_line;
@@ -480,7 +480,7 @@
 }
 
 
-uint8_t OnAction_ppO2Max(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_ppO2Max(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings;
     uint8_t digitContentNew;
@@ -525,7 +525,7 @@
 }
 
 
-void openEdit_FutureTTS(void)
+static void openEdit_FutureTTS(void)
 {
     uint8_t futureTTS;
     uint16_t y_line;
@@ -555,7 +555,7 @@
 }
 
 
-uint8_t OnAction_FutureTTS(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_FutureTTS(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings;
     int8_t digitContentNew;
@@ -592,29 +592,5 @@
             digitContentNew = '0' + 15;
         return digitContentNew;
     }
-/*
-    if(action == ACTION_BUTTON_NEXT)
-    {
-        digitContentNew = digitContent + 1;
-        if((digitNumber == 0) && (digitContentNew > '1'))
-            digitContentNew = '0';
-        else
-        if(digitContentNew > '9')
-            digitContentNew = '0';
-        return digitContentNew;
-    }
-    if(action == ACTION_BUTTON_BACK)
-    {
-        digitContentNew = digitContent - 1;
-        if((digitNumber == 0) && (digitContentNew < '0'))
-            digitContentNew = '1';
-        else
-        if(digitContentNew < '0')
-            digitContentNew = '9';
-        return digitContentNew;
-    }
-*/
     return EXIT_TO_MENU;
 }
-
-
--- a/Discovery/Src/tMenuEditDecoParameter.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/tMenuEditDecoParameter.c	Mon May 13 13:37:34 2019 +0000
@@ -36,12 +36,12 @@
 #define MEDP_TAB (380)
 
 /* Private function prototypes -----------------------------------------------*/
-void openEdit_DecoAlgorithm(void);
-void openEdit_DecoGF(void);
-void openEdit_DecoAltGF(void);
-void openEdit_DecoVPM(void);
-void openEdit_DecoLastStop(void);
-void openEdit_DM_SwitchAlgorithm(uint8_t line);
+static void openEdit_DecoAlgorithm(void);
+static void openEdit_DecoGF(void);
+static void openEdit_DecoAltGF(void);
+static void openEdit_DecoVPM(void);
+static void openEdit_DecoLastStop(void);
+static void openEdit_DM_SwitchAlgorithm(uint8_t line);
 
 //void openEdit_DecoGasUsage(void);
 
@@ -50,11 +50,6 @@
 uint8_t OnAction_VPM			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_AltGF			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_LastStop		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-
-uint8_t OnAction_GasAMV			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_DefaultAMV		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_GasReserve		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-
 uint8_t OnAction_DM_ActiveGF	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_DM_ActiveVPM	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_DM_AltActiveGF	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
@@ -95,42 +90,31 @@
 
 /* Private functions ---------------------------------------------------------*/
 
-void openEdit_DM_SwitchAlgorithm(uint8_t line)
+static void openEdit_DM_SwitchAlgorithm(uint8_t line)
 {
-    SDiveState * pState;
-
-    if(actual_menu_content == MENU_DIVE_REAL)
-    {
-        pState = stateRealGetPointerWrite();
-    }
-    else
-    {
-        pState = stateSimGetPointerWrite();
-    }
-
     switch(line)
     {
     case 1:
     default:
-        pState->diveSettings.deco_type.ub.standard = VPM_MODE;
+        stateUsedWrite->diveSettings.deco_type.ub.standard = VPM_MODE;
         break;
     case 2:
 
-        pState->diveSettings.gf_high = settingsGetPointer()->GF_high;
-        pState->diveSettings.gf_low = settingsGetPointer()->GF_low;
-        pState->diveSettings.deco_type.ub.standard = GF_MODE;
+    	stateUsedWrite->diveSettings.gf_high = settingsGetPointer()->GF_high;
+    	stateUsedWrite->diveSettings.gf_low = settingsGetPointer()->GF_low;
+    	stateUsedWrite->diveSettings.deco_type.ub.standard = GF_MODE;
         break;
     case 3:
-        pState->diveSettings.gf_high = settingsGetPointer()->aGF_high;
-        pState->diveSettings.gf_low = settingsGetPointer()->aGF_low;
-        pState->diveSettings.deco_type.ub.standard = GF_MODE;
+    	stateUsedWrite->diveSettings.gf_high = settingsGetPointer()->aGF_high;
+    	stateUsedWrite->diveSettings.gf_low = settingsGetPointer()->aGF_low;
+    	stateUsedWrite->diveSettings.deco_type.ub.standard = GF_MODE;
         break;
     }
     exitMenuEdit_to_Home_with_Menu_Update();
 }
 
 
-void openEdit_DecoAlgorithm(void)
+static void openEdit_DecoAlgorithm(void)
 {
     SSettings *pSettings = settingsGetPointer();
 
@@ -143,7 +127,7 @@
 }
 
 
-void openEdit_DecoVPM(void)
+static void openEdit_DecoVPM(void)
 {
     uint8_t vpm;
     char text[32];
@@ -167,7 +151,7 @@
 }
 
 
-void openEdit_DecoGF(void)
+static void openEdit_DecoGF(void)
 {
     uint8_t gfLow,gfHigh;
     char text[32];
@@ -192,7 +176,7 @@
 }
 
 
-void openEdit_DecoAltGF(void)
+static void openEdit_DecoAltGF(void)
 {
     uint8_t aGfLow,aGfHigh;
     char text[32];
@@ -216,7 +200,7 @@
 }
 
 
-void openEdit_DecoLastStop(void)
+static void openEdit_DecoLastStop(void)
 {
     uint8_t lastStop;
     char text[32];
@@ -247,62 +231,6 @@
     startEdit();
 }
 
-/*
-void openEdit_DecoGF_DM(void)
-    {
-      const SDiveSettings * pDiveSettings;
-        uint8_t activeGF, activeVPM, aActiveGF;
-        SSettings *pSettings = settingsGetPointer();
-
-        if(actual_menu_content == MENU_DIVE_REAL)
-        {
-            const SDiveState * pState = stateRealGetPointer();
-            pDiveSettings = &pState->diveSettings;
-        }
-        else
-        {
-            const SDiveState * pState = stateSimGetPointer();
-            pDiveSettings = &pState->diveSettings;
-        }
-        if(pDiveSettings->deco_type.ub.standard == VPM_MODE)
-        {
-            aActiveGF = 0;
-            activeGF = 0;
-            activeVPM = 1;
-        }
-        else
-        if((pDiveSettings->gf_high == pSettings->GF_high) && (pDiveSettings->gf_low == pSettings->GF_low))
-        {
-            aActiveGF = 0;
-            activeGF = 1;
-            activeVPM = 0;
-        }
-        else
-        {
-            aActiveGF = 1;
-            activeGF = 0;
-            activeVPM = 0;
-        }
-
-        write_label_fix(  30, 340,  90, &FontT42, TXT_ZHL16GF);
-        write_label_fix(  30, 340, 140, &FontT42, TXT_low_high);
-        write_label_fix( 400, 600,  90, &FontT42, TXT_VPM);
-        write_label_fix( 400, 600, 140, &FontT42, TXT_Conservatism);
-        write_label_fix( 660, 799,  90, &FontT42, TXT_aGF);
-
-        write_field_on_off(StMDECOP7_ActiveGF,		 30, 170, 405, &FontT48, "Active", activeGF);
-
-        write_field_on_off(StMDECOP8_ActiveVPM,	400, 600, 405, &FontT48, "Active", activeVPM);
-
-        write_field_on_off(StMDECOP9_ActiveAltGF,	660, 799, 405, &FontT48, "Active", aActiveGF);
-
-
-        setEvent(StMDECOP7_ActiveGF, 		(uint32_t)OnAction_DM_ActiveGF);
-        setEvent(StMDECOP8_ActiveVPM,		(uint32_t)OnAction_DM_ActiveVPM);
-        setEvent(StMDECOP9_ActiveAltGF, 		(uint32_t)OnAction_DM_AltActiveGF);
-}
-*/
-
 uint8_t OnAction_VPM(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings;
@@ -518,53 +446,9 @@
     return EXIT_TO_MENU;
 }
 
-
-uint8_t OnAction_ActiveGF(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    SSettings *pSettings;
-    pSettings = settingsGetPointer();
-
-    if(pSettings->deco_type.ub.standard == GF_MODE)
-        return 255;
-
-    pSettings->deco_type.ub.standard = GF_MODE;
-    tMenuEdit_set_on_off(editId, 1);
-    tMenuEdit_set_on_off(StMDECOP8_ActiveVPM, 0);
-
-    return UPDATE_DIVESETTINGS;
-}
-
-
-uint8_t OnAction_ActiveVPM(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    SSettings *pSettings;
-    pSettings = settingsGetPointer();
-
-    if(pSettings->deco_type.ub.standard == VPM_MODE)
-        return 255;
-
-    pSettings->deco_type.ub.standard = VPM_MODE;
-    tMenuEdit_set_on_off(editId, 1);
-    tMenuEdit_set_on_off(StMDECOP7_ActiveGF, 0);
-
-    return UPDATE_DIVESETTINGS;
-}
-
-
 uint8_t OnAction_DM_ActiveVPM(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-    SDiveSettings * pDiveSettings;
-    if(actual_menu_content == MENU_DIVE_REAL)
-    {
-        SDiveState * pState = stateRealGetPointerWrite();
-        pDiveSettings = &pState->diveSettings;
-    }
-    else
-    {
-        SDiveState * pState = stateSimGetPointerWrite();
-        pDiveSettings = &pState->diveSettings;
-    }
-    pDiveSettings->deco_type.ub.standard = VPM_MODE;
+    stateUsedWrite->diveSettings.deco_type.ub.standard = VPM_MODE;
     return EXIT_TO_HOME;
 }
 
@@ -572,164 +456,20 @@
 uint8_t OnAction_DM_ActiveGF(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     SSettings *pSettings = settingsGetPointer();
-    SDiveSettings * pDiveSettings;
-    if(actual_menu_content == MENU_DIVE_REAL)
-    {
-        SDiveState * pState = stateRealGetPointerWrite();
-        pDiveSettings = &pState->diveSettings;
-    }
-    else
-    {
-        SDiveState * pState = stateSimGetPointerWrite();
-        pDiveSettings = &pState->diveSettings;
-    }
-    pDiveSettings->gf_high = pSettings->GF_high;
-    pDiveSettings->gf_low = pSettings->GF_low;
-    pDiveSettings->deco_type.ub.standard = GF_MODE;
+
+    stateUsedWrite->diveSettings.gf_high = pSettings->GF_high;
+    stateUsedWrite->diveSettings.gf_low = pSettings->GF_low;
+    stateUsedWrite->diveSettings.deco_type.ub.standard = GF_MODE;
     return EXIT_TO_HOME;
 }
 
 
 uint8_t OnAction_DM_AltActiveGF(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-    SSettings *pSettings = settingsGetPointer();
-    SDiveSettings * pDiveSettings;
-    if(actual_menu_content == MENU_DIVE_REAL)
-    {
-        SDiveState * pState = stateRealGetPointerWrite();
-        pDiveSettings = &pState->diveSettings;
-    }
-    else
-    {
-        SDiveState * pState = stateSimGetPointerWrite();
-        pDiveSettings = &pState->diveSettings;
-    }
-    pDiveSettings->gf_high = pSettings->aGF_high;
-    pDiveSettings->gf_low = pSettings->aGF_low;
-    pDiveSettings->deco_type.ub.standard = GF_MODE;
+	SSettings *pSettings = settingsGetPointer();
+
+    stateUsedWrite->diveSettings.gf_high = pSettings->aGF_high;
+    stateUsedWrite->diveSettings.gf_low = pSettings->aGF_low;
+    stateUsedWrite->diveSettings.deco_type.ub.standard = GF_MODE;
     return EXIT_TO_HOME;
 }
-
-
-/*
-void openEdit_DecoGasUsage(void)
-{
-    uint8_t amv, reserve;
-    char text[32];
-    SSettings *pSettings;
-
-    pSettings = settingsGetPointer();
-
-    amv = pSettings->AtemMinutenVolumenLiter;
-    reserve = pSettings->ReserveFractionDenominator;
-
-    text[0] = '\a';
-    text[1] = TXT_AtemGasVorrat;
-    text[2] = 0;
-
-    write_topline(text);
-
-    write_label_fix(  30, 340,  90, &FontT42, TXT_LiterproMinute);
-    write_label_fix(  30, 340, 250, &FontT42, TXT_Default);
-    write_label_fix( 430, 740,  90, &FontT42, TXT_Reserve);
-
-    strcpy(text, "1/0");
-    text[2] += reserve;
-    write_field_udigit(StMDECOP5_AMV,				 30, 320, 150, &FontT105, "###", (uint32_t)amv, 0, 0, 0);
-    write_field_button(StMDECOP5_DefaultAMV,	 30, 170, 290,  &FontT48, "25");
-    write_field_button(StMDECOP5_RESERVE,		430, 640, 150, &FontT105, text);
-
-    setEvent(StMDECOP5_AMV, 				(uint32_t)OnAction_GasAMV);
-    setEvent(StMDECOP5_DefaultAMV, (uint32_t)OnAction_DefaultAMV);
-    setEvent(StMDECOP5_RESERVE, 		(uint32_t)OnAction_GasReserve);
-}
-
-
-uint8_t OnAction_GasAMV				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    uint8_t digitContentNew;
-    uint32_t newAMV;
-    SSettings *pSettings;
-
-    if(action == ACTION_BUTTON_ENTER)
-    {
-        return digitContent;
-    }
-    if(action == ACTION_BUTTON_ENTER_FINAL)
-    {
-        evaluateNewString(editId, &newAMV, 0, 0, 0);
-
-        if(newAMV < 5)
-            newAMV = 5;
-        if(newAMV > 190)
-            newAMV = 190;
-
-        pSettings = settingsGetPointer();
-        pSettings->AtemMinutenVolumenLiter = newAMV;
-
-        tMenuEdit_newInput(editId, newAMV, 0, 0, 0);
-
-        return 255;
-    }
-    if(action == ACTION_BUTTON_NEXT)
-    {
-        if((digitNumber == 0) && (digitContentNew >= '1'))
-            digitContentNew = '0';
-        else
-            digitContentNew = digitContent + 1;
-        if(digitContentNew > '9')
-            digitContentNew = '0';
-        return digitContentNew;
-    }
-    if(action == ACTION_BUTTON_BACK)
-    {
-        if((digitNumber == 0) && (digitContentNew == '0'))
-            digitContentNew = '1';
-        else
-            digitContentNew = digitContent - 1;
-        if(digitContentNew < '0')
-            digitContentNew = '9';
-        return digitContentNew;
-    }
-
-    return UNSPECIFIC_RETURN;
-}
-
-
-uint8_t OnAction_DefaultAMV		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    uint32_t newAMV;
-    SSettings *pSettings;
-
-    newAMV = 25;
-
-    pSettings = settingsGetPointer();
-    pSettings->AtemMinutenVolumenLiter = newAMV;
-    tMenuEdit_newInput(StMDECOP5_AMV, newAMV, 0, 0, 0);
-
-    return UNSPECIFIC_RETURN;
-}
-
-
-uint8_t OnAction_GasReserve		(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    uint32_t reserve;
-    SSettings *pSettings;
-    char text[32];
-
-    pSettings = settingsGetPointer();
-    reserve = pSettings->ReserveFractionDenominator;
-    if(reserve <= 3)
-        reserve = 4;
-    else
-        reserve = 3;
-
-    pSettings->ReserveFractionDenominator = reserve;
-
-    strcpy(text, "1/0");
-    text[2] += reserve;
-    tMenuEdit_newButtonText(editId, text);
-
-    return UNSPECIFIC_RETURN;
-}
-*/
--- a/Discovery/Src/tMenuEditGasOC.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/tMenuEditGasOC.c	Mon May 13 13:37:34 2019 +0000
@@ -148,24 +148,14 @@
 
 void openEdit_DiveGasSelect_Subroutine(uint8_t line, uint8_t ccr)
 {
-    SDiveState * pState;
     uint8_t setpoint;
 
-    if(actual_menu_content == MENU_DIVE_REAL)
-    {
-        pState = stateRealGetPointerWrite();
-        editGasPage.pGasLine = pState->diveSettings.gas;
-    }
-    else
-    {
-        pState = stateSimGetPointerWrite();
-        editGasPage.pGasLine = pState->diveSettings.gas;
-    }
+    editGasPage.pGasLine = stateUsed->diveSettings.gas;
 
     if(ccr)
     {
         editGasPage.gasID = line + NUM_OFFSET_DILUENT;
-        setpoint = pState->lifeData.actualGas.setPoint_cbar;
+        setpoint = stateUsed->lifeData.actualGas.setPoint_cbar;
     }
     else
     {
@@ -178,7 +168,7 @@
 
     editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 1;
     editGasPage.pGasLine[editGasPage.gasID].note.ub.first = 1;
-    setActualGas_DM(&pState->lifeData,editGasPage.gasID,setpoint);
+    setActualGas_DM(&stateUsedWrite->lifeData,editGasPage.gasID,setpoint);
 }
 
 /* extra gas and gas on/off option */
@@ -186,21 +176,12 @@
 {
     char text[32];
     uint8_t oxygen, helium, gasOffset, textpointer, lineCount, ptrGas;
-    SDiveState * pState;
+    //SDiveState * pState;
 
-    if(actual_menu_content == MENU_DIVE_REAL)
-    {
-        pState = stateRealGetPointerWrite();
-        editGasPage.pGasLine = pState->diveSettings.gas;
-    }
-    else
-    {
-        pState = stateSimGetPointerWrite();
-        editGasPage.pGasLine = pState->diveSettings.gas;
-    }
+    editGasPage.pGasLine = stateUsed->diveSettings.gas;
     if(ccr)
     {
-        editGasPage.setpoint = pState->lifeData.actualGas.setPoint_cbar;
+        editGasPage.setpoint = stateUsed->lifeData.actualGas.setPoint_cbar;
     }
     editGasPage.ccr = ccr;
 
@@ -322,17 +303,12 @@
         if((newOxygen + newHelium) > 100)
             newOxygen = 100 - newHelium;
 
-        SDiveState * pDiveState = 0;
+        //SDiveState * pDiveState = 0;
 
         for(int i=1;i<=(2*NUM_GASES);i++)
             editGasPage.pGasLine[i].note.ub.first = 0;
 
-        if(actual_menu_content == MENU_DIVE_REAL)
-            pDiveState = stateRealGetPointerWrite();
-        else
-            pDiveState = stateSimGetPointerWrite();
-
-        setActualGas_ExtraGas(&pDiveState->lifeData, newOxygen, newHelium, 0);
+        setActualGas_ExtraGas(&stateUsedWrite->lifeData, newOxygen, newHelium, 0);
         tMEGas_check_switch_to_bailout();
         return EXIT_TO_HOME;
     }
@@ -357,16 +333,9 @@
 
 void tMEGas_check_switch_to_bailout(void)
 {
-    SDiveState *pState;
-
-    if(actual_menu_content == MENU_DIVE_REAL)
-        pState = stateRealGetPointerWrite();
-    else
-        pState = stateSimGetPointerWrite();
-
-    if(pState->diveSettings.diveMode == DIVEMODE_CCR)
+    if(stateUsed->diveSettings.diveMode == DIVEMODE_CCR)
     {
-        pState->diveSettings.diveMode = DIVEMODE_OC;
+    	stateUsedWrite->diveSettings.diveMode = DIVEMODE_OC;
         block_diluent_page();
     }
 }
--- a/Discovery/Src/tMenuEditSetpoint.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/tMenuEditSetpoint.c	Mon May 13 13:37:34 2019 +0000
@@ -43,20 +43,15 @@
 
 
 /* Private variables ---------------------------------------------------------*/
-SEditSetpointPage editSetpointPage;
+static SEditSetpointPage editSetpointPage;
 
 /* Private function prototypes -----------------------------------------------*/
 
-
 /* Announced function prototypes -----------------------------------------------*/
-uint8_t OnAction_SP_Setpoint    (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_SP_Depth       (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-//uint8_t OnAction_SP_First     (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-//uint8_t OnAction_SP_Active    (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-//uint8_t OnAction_SP_DM_Select (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_SP_DM_Sensor1	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_SP_DM_Sensor2	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
-uint8_t OnAction_SP_DM_Sensor3	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_SP_Setpoint    (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_SP_DM_Sensor1	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_SP_DM_Sensor2	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+static uint8_t OnAction_SP_DM_Sensor3	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 
 /* Exported functions --------------------------------------------------------*/
 
@@ -68,52 +63,46 @@
     if(actual_menu_content != MENU_SURFACE)
     {
         uint8_t setpointCbar, actualGasID;
-        SDiveState *pState;
         setpointCbar = 100;
 
-        if(actual_menu_content == MENU_DIVE_REAL)
-            pState = stateRealGetPointerWrite();
-        else
-            pState = stateSimGetPointerWrite();
-
         // actualGasID
-        if(pState->diveSettings.diveMode != DIVEMODE_CCR)
+        if(stateUsedWrite->diveSettings.diveMode != DIVEMODE_CCR)
         {
-            actualGasID = pState->lifeData.lastDiluent_GasIdInSettings;
+            actualGasID = stateUsedWrite->lifeData.lastDiluent_GasIdInSettings;
             if((actualGasID <= NUM_OFFSET_DILUENT) || (actualGasID > NUM_GASES + NUM_OFFSET_DILUENT))
                 actualGasID = NUM_OFFSET_DILUENT + 1;
         }
         else
-            actualGasID = pState->lifeData.actualGas.GasIdInSettings;
+            actualGasID = stateUsedWrite->lifeData.actualGas.GasIdInSettings;
 
         // setpointCbar, CCR_Mode and sensor menu
         if(line < 6)
         {
-            setpointCbar = pState->diveSettings.setpoint[line].setpoint_cbar;
-            pState->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
+            setpointCbar = stateUsedWrite->diveSettings.setpoint[line].setpoint_cbar;
+            stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
 
             // BetterSetpoint warning only once
             if(actualBetterSetpointId() == line)
             {
                 uint8_t depth;
-                depth = pState->diveSettings.setpoint[line].depth_meter;
+                depth = stateUsedWrite->diveSettings.setpoint[line].depth_meter;
                 // BetterSetpoint warning only once -> clear active
                 for(int i=0; i<=NUM_GASES; i++)
                 {
-                    pState->diveSettings.setpoint[i].note.ub.first = 0;
-                    if(pState->diveSettings.setpoint[i].depth_meter <= depth)
-                        pState->diveSettings.setpoint[i].note.ub.active = 0;
+                	stateUsedWrite->diveSettings.setpoint[i].note.ub.first = 0;
+                    if(stateUsedWrite->diveSettings.setpoint[i].depth_meter <= depth)
+                    	stateUsedWrite->diveSettings.setpoint[i].note.ub.active = 0;
                 }
-                pState->diveSettings.setpoint[line].note.ub.first = 1;
+                stateUsedWrite->diveSettings.setpoint[line].note.ub.first = 1;
             }
         }
         else
         {
-            if(pState->diveSettings.CCR_Mode != CCRMODE_Sensors)
+            if(stateUsedWrite->diveSettings.CCR_Mode != CCRMODE_Sensors)
             {
                 /* setpoint_cbar will be written by updateSetpointStateUsed() in main.c loop */
                 setpointCbar = 255;
-                pState->diveSettings.CCR_Mode = CCRMODE_Sensors;
+                stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_Sensors;
             }
             else
             {
@@ -121,11 +110,11 @@
             }
         }
 
-        setActualGas_DM(&pState->lifeData,actualGasID,setpointCbar);
+        setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar);
 
-        if(pState->diveSettings.diveMode != DIVEMODE_CCR)
+        if(stateUsedWrite->diveSettings.diveMode != DIVEMODE_CCR)
         {
-            pState->diveSettings.diveMode = DIVEMODE_CCR;
+        	stateUsedWrite->diveSettings.diveMode = DIVEMODE_CCR;
             unblock_diluent_page();
         }
 
@@ -155,11 +144,11 @@
             sensorActive[0] = 1;
             sensorActive[1] = 1;
             sensorActive[2] = 1;
-            if(pState->diveSettings.ppo2sensors_deactivated & 1)
+            if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 1)
                 sensorActive[0] = 0;
-            if(pState->diveSettings.ppo2sensors_deactivated & 2)
+            if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 2)
                 sensorActive[1] = 0;
-            if(pState->diveSettings.ppo2sensors_deactivated & 4)
+            if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 4)
                 sensorActive[2] = 0;
 
             write_field_on_off(StMSP_Sensor1,	 30, 95, ME_Y_LINE1,  &FontT48, "", sensorActive[0]);
@@ -241,7 +230,7 @@
     }
 }
 
-uint8_t OnAction_SP_Setpoint(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_SP_Setpoint(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
     int8_t digitContentNew;
     uint32_t new_integer_part, new_fractional_part, new_cbar, newDepth;
@@ -297,216 +286,73 @@
     return EXIT_TO_MENU;
 }
 
-uint8_t OnAction_SP_Depth(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    uint8_t digitContentNew;
-    uint32_t newDepth;
-
-    if(action == ACTION_BUTTON_ENTER)
-    {
-        return digitContent;
-    }
-    if(action == ACTION_BUTTON_ENTER_FINAL)
-    {
-        evaluateNewString(editId, &newDepth, 0, 0, 0);
-        if(newDepth > 255)
-            newDepth = 255;
-
-        editSetpointPage.pSetpointLine[editSetpointPage.spID].depth_meter = newDepth;
-
-        tMenuEdit_newInput(editId, newDepth, 0, 0, 0);
-        return UPDATE_DIVESETTINGS;
-    }
-    if(action == ACTION_BUTTON_NEXT)
-    {
-        digitContentNew = digitContent + 1;
-        if(digitContentNew > '9')
-            digitContentNew = '0';
-        return digitContentNew;
-    }
-    if(action == ACTION_BUTTON_BACK)
-    {
-        digitContentNew = digitContent - 1;
-        if(digitContentNew < '0')
-            digitContentNew = '9';
-        return digitContentNew;
-    }
-
-    return UNSPECIFIC_RETURN;
-}
-
 void openEdit_DiveSelectBetterSetpoint(void)
 {
     uint8_t spId;
-    SDiveState *pState;
     uint8_t depth;
 
     spId = actualBetterSetpointId();
 
-    if(actual_menu_content == MENU_DIVE_REAL)
-        pState = stateRealGetPointerWrite();
-    else
-        pState = stateSimGetPointerWrite();
-
-    depth = pState->diveSettings.setpoint[spId].depth_meter;
+    depth = stateUsedWrite->diveSettings.setpoint[spId].depth_meter;
 
     // BetterSetpoint warning only once -> clear active
     for(int i=0; i<=NUM_GASES; i++)
     {
-        pState->diveSettings.setpoint[i].note.ub.first = 0;
-        if(pState->diveSettings.setpoint[i].depth_meter <= depth)
-            pState->diveSettings.setpoint[i].note.ub.active = 0;
+    	stateUsedWrite->diveSettings.setpoint[i].note.ub.first = 0;
+        if(stateUsedWrite->diveSettings.setpoint[i].depth_meter <= depth)
+        	stateUsedWrite->diveSettings.setpoint[i].note.ub.active = 0;
     }
 
     // new setpoint
-    pState->diveSettings.setpoint[spId].note.ub.first = 1;
+    stateUsedWrite->diveSettings.setpoint[spId].note.ub.first = 1;
 
     // change in lifeData
-    setActualGas_DM(&pState->lifeData, pState->lifeData.actualGas.GasIdInSettings, pState->diveSettings.setpoint[spId].setpoint_cbar);
+    setActualGas_DM(&stateUsedWrite->lifeData, stateUsedWrite->lifeData.actualGas.GasIdInSettings, stateUsedWrite->diveSettings.setpoint[spId].setpoint_cbar);
 }
 
-uint8_t OnAction_SP_DM_Sensor1	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_SP_DM_Sensor1	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-    SDiveState * pDiveState = 0;
-
-    if(actual_menu_content == MENU_DIVE_REAL)
-        pDiveState = stateRealGetPointerWrite();
-    else
-        pDiveState = stateSimGetPointerWrite();
-
-    if(pDiveState->diveSettings.ppo2sensors_deactivated & 1)
+    if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 1)
     {
-        pDiveState->diveSettings.ppo2sensors_deactivated &= 4+2;
+    	stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 4+2;
         tMenuEdit_set_on_off(editId, 1);
     }
     else
     {
-        pDiveState->diveSettings.ppo2sensors_deactivated |= 1;
+    	stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 1;
         tMenuEdit_set_on_off(editId, 0);
     }
 
     return UNSPECIFIC_RETURN;
 }
 
-uint8_t OnAction_SP_DM_Sensor2	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_SP_DM_Sensor2	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-    SDiveState * pDiveState = 0;
-
-    if(actual_menu_content == MENU_DIVE_REAL)
-        pDiveState = stateRealGetPointerWrite();
-    else
-        pDiveState = stateSimGetPointerWrite();
-
-    if(pDiveState->diveSettings.ppo2sensors_deactivated & 2)
+    if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 2)
     {
-        pDiveState->diveSettings.ppo2sensors_deactivated &= 4+1;
+    	stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 4+1;
         tMenuEdit_set_on_off(editId, 1);
     }
     else
     {
-        pDiveState->diveSettings.ppo2sensors_deactivated |= 2;
+    	stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 2;
         tMenuEdit_set_on_off(editId, 0);
     }
 
     return UNSPECIFIC_RETURN;
 }
 
-uint8_t OnAction_SP_DM_Sensor3	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+static uint8_t OnAction_SP_DM_Sensor3	(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-    SDiveState * pDiveState = 0;
-
-    if(actual_menu_content == MENU_DIVE_REAL)
-        pDiveState = stateRealGetPointerWrite();
-    else
-        pDiveState = stateSimGetPointerWrite();
-
-    if(pDiveState->diveSettings.ppo2sensors_deactivated & 4)
+    if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 4)
     {
-        pDiveState->diveSettings.ppo2sensors_deactivated &= 2+1;
+    	stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 2+1;
         tMenuEdit_set_on_off(editId, 1);
     }
     else
     {
-        pDiveState->diveSettings.ppo2sensors_deactivated |= 4;
+    	stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 4;
         tMenuEdit_set_on_off(editId, 0);
     }
     return UNSPECIFIC_RETURN;
 }
-
-/* Private functions ---------------------------------------------------------*/
-
-/*
-uint8_t OnAction_SP_Active(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    uint8_t active, first;
-
-    first = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first;
-
-    if(first)
-        return UNSPECIFIC_RETURN;
-
-    active = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active;
-
-    if(active)
-    {
-        active = 0;
-        editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 0;
-    }
-    else
-    {
-        active = 1;
-        editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1;
-    }
-    tMenuEdit_set_on_off(editId, active);
-
-    return UPDATE_DIVESETTINGS;
-}
-
-uint8_t OnAction_SP_First(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    uint8_t active, first, i;
-    SDiveState * pStateReal = stateRealGetPointerWrite();
-
-    first = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first;
-
-    if(first)
-        return UNSPECIFIC_RETURN;
-
-    for(i=0;i<NUM_GASES;i++)
-        editSetpointPage.pSetpointLine[i].note.ub.first = 0;
-
-    editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first = 1;
-
-    active = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active;
-    if(active == 0)
-    {
-        editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1;
-    }
-
-    tMenuEdit_set_on_off(editId, 1);
-
-    return UPDATE_DIVESETTINGS;
-}
-
-uint8_t OnAction_SP_DM_Select(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
-{
-    SDiveState * pDiveState = 0;
-
-    if(editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active == 0)
-        editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1;
-
-    for(int i=0;i<NUM_GASES;i++)
-        editSetpointPage.pSetpointLine[i].note.ub.first = 0;
-
-    editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first = 1;
-
-    if(actual_menu_content == MENU_DIVE_REAL)
-        pDiveState = stateRealGetPointerWrite();
-    else
-        pDiveState = stateSimGetPointerWrite();
-
-    setActualGas_DM(&pDiveState->lifeData, pDiveState->lifeData.actualGas.GasIdInSettings, editSetpointPage.pSetpointLine[editSetpointPage.spID].setpoint_cbar);
-
-    return EXIT_TO_HOME;
-}
-*/
--- a/Discovery/Src/tMenuEditXtra.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/tMenuEditXtra.c	Mon May 13 13:37:34 2019 +0000
@@ -77,11 +77,7 @@
 
 void openEdit_SetManualMarker(void)
 {
-    if(stateUsed == stateRealGetPointer())
-        stateRealGetPointerWrite()->events.manualMarker = 1;
-    else
-        stateSimGetPointerWrite()->events.manualMarker = 1;
-
+    stateUsedWrite->events.manualMarker = 1;
     exitMenuEdit_to_Home();
 }
 
--- a/Discovery/Src/vpm.c	Mon May 06 15:45:19 2019 +0200
+++ b/Discovery/Src/vpm.c	Mon May 13 13:37:34 2019 +0000
@@ -77,26 +77,13 @@
 #include <math.h>
 #include <time.h>
 
-//#include "compiler.h"
-//#include "sdramc.h"
 #include "vpm.h"
-//#include "buehlmann.h"
-
 #include "decom.h"
 
-//#include "decompression.h"
-//#include "taskmanagement\tissue_calls.h"
-#define true 1
-#define false 0
-
 #define GAS_N2 0
 #define GAS_HE 1
-/* temp vars to simplify UNFMTLISTs */
-float    fO2, fHe, fN2;
-float    dc, rc, ssc;
-short mc;
 
-const _Bool buehlmannSafety = true;
+static const _Bool buehlmannSafety = true;
 /* Common Block Declarations */
 
 extern const float SURFACE_TENSION_GAMMA;				//!Adj. Range: 0.015 to 0.065 N/m
@@ -104,75 +91,47 @@
 extern const float UNITS_FACTOR;
 extern const float WATER_VAPOR_PRESSURE;				// (Schreiner value)  based on respiratory quotien
 extern const float CRIT_VOLUME_PARAMETER_LAMBDA;			//!Adj. Range: 6500 to 8300 fsw-min
-extern const float GRADIENT_ONSET_OF_IMPERM_ATM;			//!Adj. Range: 5.0 to 10.0 atm
+//extern const float GRADIENT_ONSET_OF_IMPERM_ATM;			//!Adj. Range: 5.0 to 10.0 atm
 extern const float REGENERATION_TIME_CONSTANT;			//!Adj. Range: 10080 to 51840 min
-extern const float PRESSURE_OTHER_GASES_MMHG;				//!Constant value for PO2 up to 2 atm
+//extern const float PRESSURE_OTHER_GASES_MMHG;				//!Constant value for PO2 up to 2 atm
 extern const float CONSTANT_PRESSURE_OTHER_GASES; // PRESSURE_OTHER_GASES_MMHG / 760. * UNITS_FACTOR;
 
 extern const float HELIUM_TIME_CONSTANT[];
 extern const float NITROGEN_TIME_CONSTANT[];
 
-float    minimum_deco_stop_time;
-float    run_time, run_time_first_stop;
-float    segment_time;
-short mix_number;
-float    barometric_pressure;
-_Bool altitude_dive_algorithm_off;
-_Bool units_equal_fsw, units_equal_msw;
+static float    minimum_deco_stop_time;
+static float    run_time, run_time_first_stop;
+static float    segment_time;
+static short mix_number;
+static float    barometric_pressure;
+static _Bool altitude_dive_algorithm_off;
+static _Bool units_equal_fsw, units_equal_msw;
 
 /* by hw 11.06.2015 to allow */
-float gCNS_VPM;
+static float gCNS_VPM;
 
-float    helium_pressure[16], nitrogen_pressure[16];
-//float    helium_pressure_crush[16], nitrogen_pressure_crush[16];
-//float    fraction_helium[MAX_GASMIXES + EXTRA_GASMIXES], fraction_nitrogen[MAX_GASMIXES + EXTRA_GASMIXES];
-//float    initial_critical_radius_he[16], initial_critical_radius_n2[16];
-//float    adjusted_critical_radius_he[16],
-//adjusted_critical_radius_n2[16];
-//float    max_crushing_pressure_he[16],
-//max_crushing_pressure_n2[16];
-float    surface_phase_volume_time[16];
-//float    max_actual_gradient[16];
-//float    amb_pressure_onset_of_imperm[16],
-//gas_tension_onset_of_imperm[16];
-//float    initial_helium_pressure_global[16],
-//initial_nitrogen_pressure_global[16];
-float    regenerated_radius_he[16],
-regenerated_radius_n2[16];
-//float    adjusted_crushing_pressure_he[16],
-//adjusted_crushing_pressure_n2[16];
-float    allowable_gradient_he[16],
-allowable_gradient_n2[16];
-//float    initial_allowable_gradient_he[16],
-//initial_allowable_gradient_n2[16];
+static float    helium_pressure[16], nitrogen_pressure[16];
+static float    surface_phase_volume_time[16];
+static float    regenerated_radius_he[16], regenerated_radius_n2[16];
+static float    allowable_gradient_he[16], allowable_gradient_n2[16];
 
 //_Bool deco_zone_reached;
-_Bool critical_volume_algorithm_off;
-float max_first_stop_depth;
-float max_deco_ceiling_depth;
-long vpm_time_calc_begin = 0;
+static _Bool critical_volume_algorithm_off;
+static float max_first_stop_depth;
+static float max_deco_ceiling_depth;
 //Boylslaw compensation
-float deco_gradient_he[16];
-float deco_gradient_n2[16];
-int last_nullzeit;
-int vpm_calc_what;
-int count_critical_volume_iteration;
-short number_of_changes;
- float   depth_change[11];
- float  step_size_change[11];
- float    rate_change[11];
- short mix_change[11];
+static float deco_gradient_he[16];
+static float deco_gradient_n2[16];
+static int vpm_calc_what;
+static int count_critical_volume_iteration;
+static short number_of_changes;
+static float   depth_change[11];
+static float  step_size_change[11];
+static float    rate_change[11];
+static short mix_change[11];
 
-const _Bool vpm_b = true;
+static const _Bool vpm_b = true;
 
-//extern
-/*extern float tissue_N2_saturation[4][16];
-extern float tissue_He_saturation[4][16];
-extern long dv_divetime;
-extern dive_data_t dive_data;
-extern int dive_ambient_pressure_mbar;
-extern long dv_seconds_since_last_dive;
-extern int tts[4];*/
 extern const float float_buehlmann_N2_factor_expositon_20_seconds[];
 extern const float float_buehlmann_He_factor_expositon_20_seconds[];
 extern const float float_buehlmann_N2_factor_expositon_one_minute[];
@@ -182,89 +141,57 @@
 extern const float float_buehlmann_N2_factor_expositon_one_hour[];
 extern const float float_buehlmann_He_factor_expositon_one_hour[];
 
-//extern buehlmann_configuration_t buehlmann_config;
-
-extern unsigned char CCR_mode; //0x100 // by tissue_calls.c			// uchar
-
-//extern gaschange2_t gaschange_CCR_backup[2][BUEHLMANN_STRUCT_MAX_GASES];
-
-
-float starting_ambient_pressure_global;
-float ending_ambient_pressure_global;
-float    depth_start_of_deco_calc;
-float    depth_start_of_deco_zone;
-float    first_stop_depth;
-float    run_time_start_of_deco_zone;
+static float    depth_start_of_deco_calc;
+static float    depth_start_of_deco_zone;
+static float    first_stop_depth;
+static float    run_time_start_of_deco_zone;
 
-float r_nint(float *x);
-float r_int(float *x);
-_Bool repetitive_variables_not_valid = false;
-_Bool nullzeit_unter60;
-//enum VPM_CALC_STATUS{CALC_END,CALC_BEGIN,CALC_NULLZEIT };
-int vpm_calc_status;
-_Bool buehlmann_wait_exceeded = false;
+static float r_nint(float *x);
+static float r_int(float *x);
+static _Bool nullzeit_unter60;
+static int vpm_calc_status;
+static _Bool buehlmann_wait_exceeded = false;
 
-SLifeData* pInput = NULL;
-SVpm* pVpm = NULL;
-SDecoinfo* pDecoInfo = NULL;
-SDiveSettings* pDiveSettings = NULL;
-float r_nint(float *x)
+static SLifeData* pInput = NULL;
+static SVpm* pVpm = NULL;
+static SDecoinfo* pDecoInfo = NULL;
+static SDiveSettings* pDiveSettings = NULL;
+
+static float r_nint(float *x)
 {
     return( (*x)>=0 ?
     floorf(*x + 0.5f) : -floorf(0.5f - *x) );
 }
 
-float r_int(float *x)
+static float r_int(float *x)
 {
     return( (*x>0) ? floorf(*x) : -floorf(- *x) );
 }
 
 /** private functions
 */
-int onset_of_impermeability(float *starting_ambient_pressure, float *ending_ambient_pressure, float *rate, short *i);
-int radius_root_finder (float *a, float *b, float *c,float *low_bound,  float *high_bound, float *ending_radius);
-int nuclear_regeneration(float *dive_time);// clock_();
-int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowablw);
-
-int calc_barometric_pressure(float *altitude);
-//extern /* Subroutine */ int vpm_repetitive_algorithm();
-//extern /* Subroutine */ int gas_loadings_surface_interval();
-int critical_volume(float *deco_phase_volume_time);	    ;
-int calc_start_of_deco_zone(float *starting_depth, float *rate, float *depth_start_of_deco_zone);
-
-int calc_initial_allowable_gradient(void);
-void decompression_stop(float *deco_stop_depth, float *step_size, _Bool final_deco_calculation);
-int gas_loadings_ascent_descen(float* helium_pressure, float* nitrogen_pressure, float starting_depth,float ending_depth, float rate,_Bool check_gas_change);
+extern int radius_root_finder (float *a, float *b, float *c,float *low_bound,  float *high_bound, float *ending_radius);
 
-int calc_surface_phase_volume_time(void);
-int calc_max_actual_gradient(float *deco_stop_depth);
-int projected_ascent(float *starting_depth, float *rate, float *deco_stop_depth, float *step_size);
-void vpm_calc_deco(void);
-int vpm_calc_critcal_volume(_Bool begin,_Bool calc_nulltime);
-int vpm_check_converged(_Bool calc_nulltime);
-int vpm_calc_final_deco(_Bool begin);
-void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,float * Deco_Stop_Depth,float* Step_Size);
-int vpm_calc_nullzeit(void);
-int vpm_repetitive_algorithm(float *surface_interval_time);
-void  vpm_init_1(void);
-
-void vpm_calc_deco_ceiling(void);
+static int nuclear_regeneration(float *dive_time);// clock_();
+static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowablw);
+static int critical_volume(float *deco_phase_volume_time);	    ;
+static int calc_start_of_deco_zone(float *starting_depth, float *rate, float *depth_start_of_deco_zone);
+static int calc_initial_allowable_gradient(void);
+static void decompression_stop(float *deco_stop_depth, float *step_size, _Bool final_deco_calculation);
+static int gas_loadings_ascent_descen(float* helium_pressure, float* nitrogen_pressure, float starting_depth,float ending_depth, float rate,_Bool check_gas_change);
+static int calc_surface_phase_volume_time(void);
+static int calc_max_actual_gradient(float *deco_stop_depth);
+static int projected_ascent(float *starting_depth, float *rate, float *deco_stop_depth, float *step_size);
+static void vpm_calc_deco(void);
+static int vpm_calc_critcal_volume(_Bool begin,_Bool calc_nulltime);
+static int vpm_check_converged(_Bool calc_nulltime);
+static int vpm_calc_final_deco(_Bool begin);
+static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,float * Deco_Stop_Depth,float* Step_Size);
+static int vpm_calc_ndl(void);
+static void  vpm_init_1(void);
+static void vpm_calc_deco_ceiling(void);
 
-//extern /* Subroutine */ int gas_loadings_constant_depth();
-//extern /* Subroutine */ int vpm_altitude_dive_algorithm();
-//extern /* Subroutine */ int calc_max_actual_gradient(),
-//projected_ascent();
-
-void ______X_X_X___________________________________________________________(void);
-
-//#define ARGGG
-
-void vpm_reset_variables(void)
-{
-    repetitive_variables_not_valid = true;
-}
-
-void vpm_init_1(void)
+static void vpm_init_1(void)
 {
      units_equal_msw = true;
      units_equal_fsw = false;
@@ -313,9 +240,9 @@
         pDECOINFO->output_stop_length_seconds[i] = 0;
     }
 
-    if(pINPUT->dive_time_seconds < 10)
+    if(pINPUT->dive_time_seconds < 60)
     {
-        vpm_calc_status = CALC_NULLZEIT;
+        vpm_calc_status = CALC_NDL;
         return vpm_calc_status;
     }
     pVpm = pVPM;
@@ -323,16 +250,16 @@
     pDecoInfo = pDECOINFO;
     pDiveSettings = pSettings;
 
-    if(vpm_calc_status == CALC_NULLZEIT)
+    if(vpm_calc_status == CALC_NDL)
     {
-        tmp_calc_status = vpm_calc_nullzeit();
+        tmp_calc_status = vpm_calc_ndl();
     }
     else
     {
         tmp_calc_status = CALC_BEGIN;
     }
     //Normal Deco calculation
-    if(tmp_calc_status != CALC_NULLZEIT)
+    if(tmp_calc_status != CALC_NDL)
     {
         max_first_stop_depth =  pVpm->max_first_stop_depth_save;
         run_time_start_of_deco_zone = pVpm->run_time_start_of_deco_zone_save;
@@ -389,7 +316,7 @@
 /*     compartments due to a linear ascent or descent segment at a constant rate. */
 /* =============================================================================== */
 
-int gas_loadings_ascent_descen(float* helium_pressure,
+static int gas_loadings_ascent_descen(float* helium_pressure,
                                float* nitrogen_pressure,
                                float starting_depth,
                                float ending_depth,
@@ -480,24 +407,22 @@
     return 0;
 } /* gas_loadings_ascent_descen */
 
-float last_phase_volume_time[16];
-float n2_pressure_start_of_deco_zone[16];
-float he_pressure_start_of_deco_zone[16];
-float phase_volume_time[16];
-float n2_pressure_start_of_ascent[16];
-float  he_pressure_start_of_ascent[16];
-float    run_time_start_of_deco_calc;
-float starting_depth;
-float last_run_time;
-float deco_phase_volume_time;
+static float last_phase_volume_time[16];
+static float n2_pressure_start_of_deco_zone[16];
+static float he_pressure_start_of_deco_zone[16];
+static float phase_volume_time[16];
+static float n2_pressure_start_of_ascent[16];
+static float  he_pressure_start_of_ascent[16];
+static float    run_time_start_of_deco_calc;
+static float starting_depth;
+static float last_run_time;
+static float deco_phase_volume_time;
+static float run_time_start_of_ascent;
+static float rate;
+static float    step_size;
+static _Bool vpm_violates_buehlmann;
 
-float run_time_start_of_ascent;
-
-float rate;
-float    step_size;
-_Bool vpm_violates_buehlmann;
-
-void  vpm_calc_deco(void)
+static  void  vpm_calc_deco(void)
 {
     /* System generated locals */
 
@@ -662,8 +587,8 @@
 /* =============================================================================== */
 /* L50: */
 
-float  deco_stop_depth;
-int vpm_calc_critcal_volume(_Bool begin,
+static float  deco_stop_depth;
+static int vpm_calc_critcal_volume(_Bool begin,
                             _Bool calc_nulltime)
 {   /* loop will run continuous there is an exit stateme */
 
@@ -767,26 +692,9 @@
                     pDecoInfo->output_stop_length_seconds[dp] = 0;
                 }
                 pDecoInfo->output_ndl_seconds = 0;
-                /*max_first_stop_depth = 0;
-                deco_zone_reached = false;
-                depth_start_of_deco_calc = 0;
-                depth_start_of_deco_zone = 0;
-                first_stop_depth = 0;
-                max_first_stop_depth_save = 0;
-                depth_start_of_deco_zone_save = 0;
-                run_time_start_of_deco_zone_save = 0;
-                tts[DECOSTOPS] = 0;
-                tts[NULLZEIT] = 0;
-                tts[FUTURESTOPS] = 0;
-                nullzeit_unter60 = false;
-                vpm_calc_status = CALC_NULLZEIT;
-                vpm_calc_what = DECOSTOPS;
-                float surfacetime = 0;
-                vpm_repetitive_algorithm(&surfacetime);*/
-
             }
 
-            return CALC_NULLZEIT;
+            return CALC_NDL;
                     /* exit the critical volume l */
         }
 
@@ -878,7 +786,7 @@
 /* =============================================================================== */
 /* end of deco stop loop */
 
-int vpm_check_converged(_Bool calc_nulltime)
+static int vpm_check_converged(_Bool calc_nulltime)
 {
 
     short i;
@@ -975,7 +883,7 @@
     //  }/* end of critical vol loop */
 }
 
-void vpm_calc_deco_ceiling(void)
+static void vpm_calc_deco_ceiling(void)
 {
 
     short i;
@@ -1088,7 +996,7 @@
 /*     DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */
 /* =============================================================================== */
 
-int vpm_calc_final_deco(_Bool begin)
+static int vpm_calc_final_deco(_Bool begin)
 {
     short i;
     float    r1;
@@ -1264,7 +1172,7 @@
 /*     normal length, but will have a major impact for saturation dives. */
 /* =============================================================================== */
 
-int nuclear_regeneration(float *dive_time)
+static int nuclear_regeneration(float *dive_time)
 {
     /* Local variables */
     float crush_pressure_adjust_ratio_he,
@@ -1373,7 +1281,7 @@
 /*     gradients are tracked separately for helium and nitrogen. */
 /* =============================================================================== */
 
-int calc_initial_allowable_gradient()
+static int calc_initial_allowable_gradient()
 {
     float initial_allowable_grad_n2_pa,
     initial_allowable_grad_he_pa;
@@ -1428,7 +1336,7 @@
 /*     subroutine to determine the actual deco schedule. */
 /* =============================================================================== */
 
-int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowable)
+static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowable)
 {
     /* System generated locals */
     float r1, r2;
@@ -1555,7 +1463,7 @@
 /*     the repetitive algorithm from being overly conservative. */
 /* =============================================================================== */
 
-int calc_max_actual_gradient(float *deco_stop_depth)
+static int calc_max_actual_gradient(float *deco_stop_depth)
 {
     /* System generated locals */
     float r1;
@@ -1602,7 +1510,7 @@
 /*     for a more detailed explanation of this algorithm. */
 /* =============================================================================== */
 
-int calc_surface_phase_volume_time()
+static int calc_surface_phase_volume_time()
 {
     /* Local variables */
     float decay_time_to_zero_gradient;
@@ -1662,7 +1570,7 @@
 /*     on the setting of the Critical Volume Parameter Lambda. */
 /* =============================================================================== */
 
-int critical_volume(float *deco_phase_volume_time)
+static int critical_volume(float *deco_phase_volume_time)
 {
     /* System generated locals */
     float r1;
@@ -1778,7 +1686,7 @@
 /*     1992. */
 /* =============================================================================== */
 
-int calc_start_of_deco_zone(float *starting_depth,
+static int calc_start_of_deco_zone(float *starting_depth,
                             float *rate,
                             float *depth_start_of_deco_zone)
 {
@@ -1977,7 +1885,7 @@
 /*     ascent can be made. */
 /* =============================================================================== */
 
-int projected_ascent(float *starting_depth,
+static int projected_ascent(float *starting_depth,
                      float *rate,
                      float *deco_stop_depth,
                      float *step_size)
@@ -2046,7 +1954,7 @@
 /*     decompression stop. */
 /* =============================================================================== */
 
-void decompression_stop(float *deco_stop_depth,
+static void decompression_stop(float *deco_stop_depth,
                         float *step_size,
                         _Bool final_deco_calculation)
 {
@@ -2268,7 +2176,7 @@
 //    with decreasing ambient pressure during the decompression profile based
 //    on Boyle's Law considerations.
 //===============================================================================
-void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,
+static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,
                               float*  Deco_Stop_Depth,
                               float* Step_Size)
 {
@@ -2367,10 +2275,12 @@
 }
 
 /* =============================================================================== */
-//	vpm_calc_nullzeit
-//     Purpose: This function calcs zero time (time where no decostops are needed)
+//	vpm_calc_ndl
+//     Purpose: This function computes NDL (time where no decostops are needed)
 //===============================================================================
-int vpm_calc_nullzeit(void)
+#define MAX_NDL	240
+
+static int vpm_calc_ndl(void)
 {
     static float future_helium_pressure[16];
     static float future_nitrogen_pressure[16];
@@ -2387,8 +2297,7 @@
     int i = 0;
     int count = 0;
     int status = CALC_END;
-    //if(begin)
-    //{
+
         for(i = 0; i < 16;i++)
         {
             future_helium_pressure[i] =  pInput->tissue_helium_bar[i] * 10;//tissue_He_saturation[st_dive][i] * 10;
@@ -2398,25 +2307,19 @@
 
         mix_number = 0;
         ambient_pressure = pInput->pressure_ambient_bar  * 10;
-//		 fraction_helium_begin;
-//		 fraction_nitrogen_begin;
         decom_get_inert_gases( ambient_pressure / 10,  (&pDiveSettings->decogaslist[mix_number]) , &fraction_nitrogen_begin, &fraction_helium_begin );
         inspired_helium_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin;
         inspired_nitrogen_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) *fraction_nitrogen_begin;
 
-        //if(!nullzeit_unter60)
-        //{
             status = CALC_END;
             while (status == CALC_END)
             {
                 count++;
-                //if(count == 7)
-                    //return CALC_NULLZEIT2;
                 temp_segment_time  +=  60;
-                if(temp_segment_time >= 300)
+                if(temp_segment_time >= MAX_NDL)
                 {
                     pDecoInfo->output_ndl_seconds = temp_segment_time * 60;
-                    return CALC_NULLZEIT;
+                    return CALC_NDL;
                 }
                 run_time += 60;
                 //goto L700;
@@ -2440,10 +2343,6 @@
                 future_helium_pressure[i - 1] = previous_helium_pressure[i-1];
                 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1];
             }
-        //}
-    //}
-    //if(!nullzeit_unter60 || begin ||  temp_segment_time > 10)
-    //{
 
         status = CALC_END;
         if(temp_segment_time < 60)
@@ -2451,20 +2350,16 @@
 
         while (status == CALC_END)
         {
-        //	count++;
-            //if(count >= 5)
-                //return CALC_NULLZEIT2;
             temp_segment_time  +=  5;
-            if(temp_segment_time >= 300)
+            if(temp_segment_time >= MAX_NDL)
             {
                 pDecoInfo->output_ndl_seconds = temp_segment_time * 60;
-                return CALC_NULLZEIT;
+                return CALC_NDL;
             }
             if(nullzeit_unter60 && temp_segment_time > 60)
             {
                 nullzeit_unter60 = false;
-                //tts[NULLZEIT] = temp_segment_time * 60;
-                return CALC_NULLZEIT;
+                return CALC_NDL;
             }
             run_time += 5;
             //goto L700;
@@ -2486,19 +2381,11 @@
             future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1];
         }
         status = CALC_END;
-        //if(temp_segment_time < 5)
-            //count = 2;
-    //}
-    //else
-        //count = 1;
+
     if(temp_segment_time <= 20)
     {
         while (status == CALC_END)
         {
-            //time_counter = temp_segment_time;
-            //count++;
-            //if(count > 2)
-                //return CALC_NULLZEIT2;
             temp_segment_time  +=  minimum_deco_stop_time;
             run_time += minimum_deco_stop_time;
             //goto L700;
@@ -2518,7 +2405,7 @@
         temp_segment_time += 5;
     pDecoInfo->output_ndl_seconds = temp_segment_time * 60;
     if(temp_segment_time > 1)
-        return CALC_NULLZEIT;
+        return CALC_NDL;
     else
         return CALC_BEGIN;
 }