changeset 907:46a21ff3f5ab Evo_2_23

Adaptation custom view deco plan for VPM: The VPM deco plan now shows the start of deco zone as well as the state of the deco table state. In case the table defined when reaching the deco zone is updated then the header line will change to yellow to indicate this. In case a deco stop is missed the head line will change to red.
author ideenmodellierer
date Sun, 13 Oct 2024 18:13:35 +0200
parents 49ee233c7a74
children eea7c7c041c1
files Discovery/Inc/vpm.h Discovery/Src/data_exchange_main.c Discovery/Src/simulation.c Discovery/Src/t7.c Discovery/Src/vpm.c
diffstat 5 files changed, 88 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/vpm.h	Sun Oct 13 18:07:23 2024 +0200
+++ b/Discovery/Inc/vpm.h	Sun Oct 13 18:13:35 2024 +0200
@@ -34,6 +34,14 @@
 enum DECOLIST{DECOSTOPS,FUTURESTOPS,BAILOUTSTOPS, OFF = -1}; // order is important!!
 enum VPM_CALC_STATUS{CALC_END, CALC_BEGIN, CALC_CRITICAL, CALC_FINAL_DECO, CALC_NDL };
 
+typedef enum
+{
+	VPM_TABLE_INIT = 0,
+	VPM_TABLE_ACTIVE,
+	VPM_TABLE_WARNING,
+	VPM_TABLE_MISSED
+} SvpmTableState;
+
 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);
 
 int  vpm_calc(SLifeData* pINPUT, SDiveSettings* diveSettings, SVpm* pVPM, SDecoinfo*  pDECOINFO, int calc_what);
@@ -44,6 +52,8 @@
 float vpm_get_CNS(void);
 
 void vpm_table_init(void);
+uint8_t vpm_get_decozone(void);
+SvpmTableState vpm_get_TableState(void);
 
 
 #endif /* VPM_H */
--- a/Discovery/Src/data_exchange_main.c	Sun Oct 13 18:07:23 2024 +0200
+++ b/Discovery/Src/data_exchange_main.c	Sun Oct 13 18:13:35 2024 +0200
@@ -481,6 +481,7 @@
 
 	if(decoLock == DECO_CALC_init_as_is_start_of_dive)
 	{
+		vpm_table_init();
 	    vpm_init(&stateUsedWrite->vpm,  stateUsedWrite->diveSettings.vpm_conservatism, 0, 0);
 	    buehlmann_init();
 	    timer_init();
--- a/Discovery/Src/simulation.c	Sun Oct 13 18:07:23 2024 +0200
+++ b/Discovery/Src/simulation.c	Sun Oct 13 18:13:35 2024 +0200
@@ -93,7 +93,6 @@
 
 	copyDiveSettingsToSim();
     copyVpmRepetetiveDataToSim();
-    vpm_table_init();
 
   //vpm_init(&stateSimGetPointerWrite()->vpm,  stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0);
     stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
--- a/Discovery/Src/t7.c	Sun Oct 13 18:07:23 2024 +0200
+++ b/Discovery/Src/t7.c	Sun Oct 13 18:13:35 2024 +0200
@@ -47,6 +47,7 @@
 #include "configuration.h"
 #include "base.h"
 #include "tMenuEditSetpoint.h"
+#include "vpm.h"
 
 #define TIMER_ACTION_DELAY_S 10
 
@@ -128,6 +129,7 @@
 typedef enum
 {
 	SE_INIT = 0,
+	SE_REINIT,
 	SE_ACTIVE,
 	SE_END
 } SSlowExitState;
@@ -2181,6 +2183,8 @@
     SSettingsStatus SettingsStatus;
 	SSettings* pSettings;
 	pSettings = settingsGetPointer();
+	uint8_t decoPlanEntries = 6;
+	uint8_t color = 0;
 
 	uint8_t local_ppo2sensors_deactivated = 0;
 
@@ -2190,7 +2194,7 @@
 	}
 	else
 	{
-			local_ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated;
+		local_ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated;
 	}
 
 	if(last_customview != selection_customview)		/* check if current selection is disabled and should be skipped */
@@ -2636,8 +2640,26 @@
 
     case CVIEW_Decolist:
         snprintf(text,100,"\032\f\001 %c%c", TXT_2BYTE, TXT2BYTE_Decolist);
-        GFX_write_string(&FontT42,&t7cH,text,0);
-
+
+        if(settingsGetPointer()->VPM_conservatism.ub.alternative == 0)
+        {
+        	GFX_write_string(&FontT42,&t7cH,text,0);
+        }
+        else
+        {
+        	switch(vpm_get_TableState())
+        	{
+        		case VPM_TABLE_MISSED: color = CLUT_WarningRed;
+        			break;
+        		case VPM_TABLE_WARNING: color = CLUT_WarningYellow;
+        			break;
+        		case VPM_TABLE_ACTIVE:
+        		case VPM_TABLE_INIT:
+        		default:	color = 0;
+        			break;
+        	}
+			GFX_write_string_color(&FontT42,&t7cH,text,0,color);
+        }
         uint8_t depthNext, depthLast, depthSecond, depthInc;
 
         depthLast 		= (uint8_t)(stateUsed->diveSettings.last_stop_depth_bar * 10);
@@ -2650,15 +2672,19 @@
             depthSecond	= (uint8_t)unit_depth_integer(depthSecond);
             depthInc 		= (uint8_t)unit_depth_integer(depthInc);
         }
+        if(stateUsed->diveSettings.deco_type.ub.standard == VPM_MODE) /* show additional VPM data in last slot */
+        {
+        	decoPlanEntries = 5;
+        }
 
         const SDecoinfo * pDecoinfo = getDecoInfo();
         for(start=DECOINFO_STRUCT_MAX_STOPS-1; start>0; start--)
             if(pDecoinfo->output_stop_length_seconds[start]) break;
-        start -= 6;
+        start -= decoPlanEntries;
         if(start < 0) start = 0;
 
         textpointer = 0;
-        for(int i=start;i<6+start;i++)
+        for(int i=start;i<decoPlanEntries+start;i++)
         {
             if(i == 0)
                 depthNext = depthLast;
@@ -2671,6 +2697,10 @@
                 textpointer += snprintf(&text[textpointer],20,"\031\034   %2u\016\016%c%c\017\n\r",depthNext, unit_depth_char1(), unit_depth_char2());
             if(textpointer > 200) break;
         }
+        if(decoPlanEntries == 5) /* add VPM deco zone */
+        {
+        	textpointer += snprintf(&text[textpointer],20,"\031\034   Zone %2u\016\016%c%c\017\n\r",vpm_get_decozone(), unit_depth_char1(), unit_depth_char2());
+        }
         if(!pSettings->FlipDisplay)
         {
         	t7cY0free.WindowY0 = t7cC.WindowY0 - 10;
@@ -4730,13 +4760,14 @@
 
 #define ASCENT_GRAPH_YPIXEL 120
 
-uint8_t t7_drawSlowExitGraph()
+uint8_t t7_drawSlowExitGraph()  /* this function is only called if diver is below last last stop depth */
 {
 	static SSlowExitState slowExitState = SE_END;
 	static uint16_t countDownSec = 0;
 	static uint8_t drawingMeterStep;
 	static float exitDepthMeter = 0.0;
 	static uint32_t exitSecTick = 0;
+	static uint32_t lastSecTick = 0;
 
 	uint8_t index = 0;
 	static uint8_t color = 0;
@@ -4745,11 +4776,11 @@
 	SSettings* pSettings;
 	pSettings = settingsGetPointer();
 
-	if(stateUsed->lifeData.max_depth_meter < pSettings->last_stop_depth_meter)	/* start of dive => reinit timer */
+	if((stateUsed->lifeData.max_depth_meter < pSettings->last_stop_depth_meter)	/* start of dive => reinit timer */
+			|| (slowExitState == SE_REINIT))
 	{
 		if(slowExitState != SE_INIT)
 		{
-			//stepPerSecond = pSettings->last_stop_depth_meter / pSettings->slowExitTime;
 			countDownSec = pSettings->slowExitTime * 60;
 			drawingMeterStep = ASCENT_GRAPH_YPIXEL / pSettings->last_stop_depth_meter;		/* based on 120 / 4 = 30 of standard ascent graph */
 			slowExitState = SE_INIT;
@@ -4765,13 +4796,18 @@
 			{
 				slowExitState = SE_ACTIVE;
 				exitSecTick = HAL_GetTick();
+				lastSecTick = exitSecTick;
 			}
 			else if(slowExitState == SE_ACTIVE)
 			{
-				if(time_elapsed_ms(exitSecTick, HAL_GetTick()) > 1000)
+				if(time_elapsed_ms(lastSecTick, HAL_GetTick()) > 60000) /* restart timer if diver go below exit zone */
+				{
+					slowExitState = SE_REINIT;
+				}
+				else if(time_elapsed_ms(exitSecTick, HAL_GetTick()) > 1000)
 				{
 					exitSecTick = HAL_GetTick();
-
+					lastSecTick = exitSecTick;
 					/* select depth digit color */
 					if(fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) < 0.5 )
 					{
@@ -4798,8 +4834,12 @@
 						{
 							slowExitState = SE_END;
 							color = 0;
+							exitDepthMeter = 0;
 						}
-						exitDepthMeter -=  (pSettings->last_stop_depth_meter / (float)(pSettings->slowExitTime * 60));
+						else
+						{
+							exitDepthMeter -=  (pSettings->last_stop_depth_meter / (float)(pSettings->slowExitTime * 60));
+						}
 					}
 				}
 				if(!pSettings->FlipDisplay)
--- a/Discovery/Src/vpm.c	Sun Oct 13 18:07:23 2024 +0200
+++ b/Discovery/Src/vpm.c	Sun Oct 13 18:13:35 2024 +0200
@@ -132,6 +132,7 @@
 
 static const _Bool vpm_b = true;
 
+static SvpmTableState vpmTableState = VPM_TABLE_INIT;
 static SDecoinfo vpmTable;
 
 extern const float float_buehlmann_N2_factor_expositon_20_seconds[];
@@ -193,6 +194,8 @@
 static void  vpm_init_1(void);
 static void vpm_calc_deco_ceiling(void);
 
+uint8_t vpm_get_decozone(void);
+
 static void vpm_init_1(void)
 {
      units_equal_msw = true;
@@ -241,12 +244,18 @@
 			{
 				if(decreaseStopTime)
 				{
-					if((pLifeData->depth_meter > (float)(actual_deco_stop - 0.5))
+					if((pLifeData->depth_meter > (float)(actual_deco_stop - 1.5))
 						&& (pLifeData->depth_meter < (float)actual_deco_stop + 1.5))
 					{
 						pDecoInfo->output_stop_length_seconds[index]--;
 						decreaseStopTime = 0;
 					}
+					else if (pLifeData->depth_meter < (float)(actual_deco_stop - 1.5)) /* missed deco stop */
+					{
+						vpmTableState = VPM_TABLE_MISSED;
+						pDecoInfo->output_stop_length_seconds[index] = 0;
+						decreaseStopTime = 0;
+					}
 				}
 				pDecoInfo->output_time_to_surface_seconds += pDecoInfo->output_stop_length_seconds[index];
 			}
@@ -335,6 +344,13 @@
 			{
 				memcpy(&vpmTable, pDECOINFO, sizeof(SDecoinfo));
 				vpmTableActive = 1;
+				if(pVpm->deco_zone_reached) /* table should not change after deco zone was entered */
+				{
+					if(vpmTableState != VPM_TABLE_MISSED)
+					{
+						vpmTableState = VPM_TABLE_WARNING;
+					}
+				}
 			}
 			else
 			{
@@ -2489,5 +2505,14 @@
 void vpm_table_init()
 {
 	vpmTable.output_time_to_surface_seconds = 0;
+	vpmTableState = VPM_TABLE_INIT;
+}
+uint8_t vpm_get_decozone(void)
+{
+	return((uint8_t)pVpm->depth_start_of_deco_zone_save);
+}
+SvpmTableState vpm_get_TableState(void)
+{
+	return vpmTableState;
 }