# HG changeset patch # User ideenmodellierer # Date 1570131016 -7200 # Node ID 73325a78c9072a2271dfb8f180d5f1aa31bebf3f # Parent 4093ac18b25c79b29eeb29db2874e509e2b36d67 Added function to support manuel exit of dive mode In some special cases the diver might want to exit the divemode manually. To avoid immediate return to dive mode the limit for starting next dive is increased for 30 minutes diff -r 4093ac18b25c -r 73325a78c907 Small_CPU/Src/scheduler.c --- a/Small_CPU/Src/scheduler.c Thu Oct 03 21:26:46 2019 +0200 +++ b/Small_CPU/Src/scheduler.c Thu Oct 03 21:30:16 2019 +0200 @@ -57,6 +57,8 @@ uint8_t deviceDataSubSeconds = 0; /* Private variables ---------------------------------------------------------*/ +static uint16_t ManualExitDiveCounter = 0; /* The computer will exit dive mode in shallow area immediately. Increase depth to restart dive while counter is active */ + /* can be lost while in sleep */ uint8_t clearDecoNow = 0; uint8_t setButtonsNow = 0; @@ -262,6 +264,11 @@ } } + if(global.dataSendToSlave.setEndDive) + { + ManualExitDiveCounter = 30 * 60; /* This will cause the computer to leave dive mode if in shallow area and increase the depth to enter dive mode for the next 30 minutes */ + } + if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) { global.mode = MODE_SHUTDOWN; @@ -461,6 +468,14 @@ scheduleSetDate(&global.deviceData.diveCycles); global.lifeData.counterSecondsShallowDepth = 0; + /* Get the last stable value in case of an unstable surface history condition */ + if(!is_surface_pressure_stable()) + { + set_last_surface_pressure_stable(); + } + global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; + ManualExitDiveCounter = 0; /* reset early exit request */ + Scheduler.tickstart = HAL_GetTick(); while(global.mode == MODE_DIVE) { @@ -536,6 +551,10 @@ Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) { + if(ManualExitDiveCounter) + { + ManualExitDiveCounter--; + } scheduleUpdateLifeData(0); // includes tissues global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); @@ -556,11 +575,12 @@ global.demo_mode = 0; } } - + if(is_ambient_pressure_close_to_surface(&global.lifeData)) { global.lifeData.counterSecondsShallowDepth++; - if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) || (global.dataSendToSlave.setEndDive)) + if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) + || (ManualExitDiveCounter)) { global.seconds_since_last_dive = 1; // start counter schedule_update_timer_helper(0); // zum starten :-) @@ -600,7 +620,7 @@ { global.lifeData.dive_time_seconds = 0; // this apnea dive ends here } - if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (global.dataSendToSlave.setEndDive)) + if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (ManualExitDiveCounter)) { global.dataSendToMaster.mode = MODE_ENDDIVE; global.deviceDataSendToMaster.mode = MODE_ENDDIVE; @@ -1381,6 +1401,7 @@ global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); global.dataSendToMaster.boolPressureData = boolPressureData; + global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable(); } @@ -1587,16 +1608,25 @@ /* same as in data_central.c */ _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) { - if(lifeData->pressure_ambient_bar == INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */ + _Bool retval = true; + + if(lifeData->pressure_ambient_bar != INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */ { - return true; + /* this will e.g. apply in case of a significant pressure change during last 30 minutes => use increased offset for surface detection */ + if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) + { + retval = false; + } + else if(is_surface_pressure_stable()) /* this is the expected start condition */ + { + if((lifeData->pressure_ambient_bar >= (lifeData->pressure_surface_bar + 0.1f)) + && (ManualExitDiveCounter == 0)) /* only if diver did not request to exit dive mode */ + { + retval = false; + } + } } - if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) - return false; - else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f - return true; - else - return false; + return retval; }