# HG changeset patch # User heinrichsweikamp # Date 1683728697 -7200 # Node ID 2c243233c99921616805e2ef3f70325355c83096 # Parent b7e43b28bee12853aff89468ccdfcea1a526234f Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller) diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Inc/check_warning.h --- a/Discovery/Inc/check_warning.h Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Inc/check_warning.h Wed May 10 16:24:57 2023 +0200 @@ -34,6 +34,7 @@ void check_warning(void); void check_warning2(SDiveState *pDiveState); uint8_t actualBetterGasId(void); +uint8_t actualBetterBailoutGasId(void); uint8_t actualBetterSetpointId(void); uint8_t actualLeftMaxDepth(const SDiveState * pDiveState); void set_warning_fallback(void); diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Inc/tMenuEditGasOC.h --- a/Discovery/Inc/tMenuEditGasOC.h Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Inc/tMenuEditGasOC.h Wed May 10 16:24:57 2023 +0200 @@ -29,6 +29,8 @@ #define TMENU_EDIT_GAS_OC_H /* Includes ------------------------------------------------------------------*/ +#include + #include "stm32f4xx_hal.h" #include "gfx_engine.h" #include "settings.h" @@ -36,6 +38,7 @@ void openEdit_GasOC(uint8_t line); void openEdit_GasCC(uint8_t line); -void openEdit_DiveSelectBetterGas(void); +void openEdit_DiveSelectBetterGas(bool doBailout); +void tMEGas_check_switch_to_bailout(void); #endif /* TMENU_EDIT_GAS_OC_H */ diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Inc/tMenuEditSetpoint.h --- a/Discovery/Inc/tMenuEditSetpoint.h Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Inc/tMenuEditSetpoint.h Wed May 10 16:24:57 2023 +0200 @@ -32,6 +32,7 @@ #include void openEdit_Setpoint(uint8_t line); -void openEdit_DiveSelectBetterSetpoint(void); +void openEdit_DiveSelectBetterSetpoint(bool useLastDiluent); +void checkSwitchToLoop(void); #endif /* TMENU_EDIT_SETPOINT_H */ diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Inc/tStructure.h --- a/Discovery/Inc/tStructure.h Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Inc/tStructure.h Wed May 10 16:24:57 2023 +0200 @@ -103,7 +103,7 @@ #define StDCHECK _MB(1,2,12,0,0) #define StDSIM5 _MB(1,2,13,0,0) #define StDSIM6 _MB(1,2,14,0,0) - +#define StDBAILOUT _MB(1,2,15,0,0) #define StUART_STANDARD _MB(3,1,0,0,0) #define StUART_RTECONNECT _MB(3,2,0,0,0) diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Inc/text_multilanguage.h --- a/Discovery/Inc/text_multilanguage.h Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Inc/text_multilanguage.h Wed May 10 16:24:57 2023 +0200 @@ -353,6 +353,8 @@ TXT2BYTE_CcrSummary, TXT2BYTE_Setpoint, TXT2BYTE_Scrubber, + TXT2BYTE_BailoutShort, + TXT2BYTE_LoopShort, TXT2BYTE_END }; diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Src/base.c --- a/Discovery/Src/base.c Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Src/base.c Wed May 10 16:24:57 2023 +0200 @@ -1659,7 +1659,7 @@ if((stateUsed->warnings.betterSetpoint) && (settingsGetPointer()->autoSetpoint) && (settingsGetPointer()->CCR_Mode == CCRMODE_FixedSetpoint)) { - openEdit_DiveSelectBetterSetpoint(); + openEdit_DiveSelectBetterSetpoint(false); } decoLock = DECO_CALC_running; diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Src/check_warning.c --- a/Discovery/Src/check_warning.c Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Src/check_warning.c Wed May 10 16:24:57 2023 +0200 @@ -46,6 +46,7 @@ /* Private variables with access ----------------------------------------------*/ static uint8_t betterGasId = 0; +static uint8_t betterBailoutGasId = 0; static uint8_t betterSetpointId = 1; static int8_t fallback = 0; static uint16_t debounceFallbackTimeMS = 0; @@ -119,6 +120,12 @@ } +uint8_t actualBetterBailoutGasId(void) +{ + return betterBailoutGasId; +} + + uint8_t actualBetterSetpointId(void) { return betterSetpointId; @@ -207,85 +214,76 @@ } -static int8_t check_BetterGas(SDiveState * pDiveState) +static uint8_t getBetterGasId(bool getDiluent, uint8_t startingGasId, SDiveState *diveState) { - if(stateUsed->mode != MODE_DIVE) - { - pDiveState->warnings.betterGas = 0; - betterGasId = 0; - return 0; - } + SDiveSettings diveSettings = diveState->diveSettings; - uint8_t gasIdOffset; - uint8_t bestGasDepth, betterGasIdLocal; + uint8_t betterGasIdLocal = startingGasId; + uint8_t bestGasDepth = 255; - SLifeData* pLifeData = &pDiveState->lifeData; - SDiveSettings* pDiveSettings = &pDiveState->diveSettings; - - pDiveState->warnings.betterGas = 0; - betterGasId = 0; - betterGasIdLocal = pLifeData->actualGas.GasIdInSettings; - bestGasDepth = 255; - - if(isLoopMode(pDiveSettings->diveMode)) - gasIdOffset = NUM_OFFSET_DILUENT; - else - gasIdOffset = 0; + uint8_t gasIdOffset; + if (getDiluent) { + gasIdOffset = NUM_OFFSET_DILUENT; + } else { + gasIdOffset = 0; + } /* life data is float, gas data is uint8 */ - if(actualLeftMaxDepth(pDiveState)) /* deco gases */ - { - for(int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) - { - if( (pDiveSettings->gas[i].note.ub.active) - && (pDiveSettings->gas[i].note.ub.deco) - && (pDiveSettings->gas[i].depth_meter) - && (pDiveSettings->gas[i].depth_meter >= (pLifeData->depth_meter - 0.01f )) - && (pDiveSettings->gas[i].depth_meter <= bestGasDepth) - ) - { - betterGasIdLocal = i; - bestGasDepth = pDiveSettings->gas[i].depth_meter; - } - } - - if(betterGasIdLocal != pLifeData->actualGas.GasIdInSettings) - { - if(!check_helper_same_oxygen_and_helium_content(&pDiveSettings->gas[betterGasIdLocal], &pDiveSettings->gas[pLifeData->actualGas.GasIdInSettings])) - { - betterGasId = betterGasIdLocal; - pDiveState->warnings.betterGas = 1; - } - } - } - else /* travel gases */ - { - bestGasDepth = 0; - //check for travalgas - for(int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) - { - if( (pDiveSettings->gas[i].note.ub.active) - && (pDiveSettings->gas[i].note.ub.travel) - && (pDiveSettings->gas[i].depth_meter_travel) - && (pDiveSettings->gas[i].depth_meter_travel <= (pLifeData->depth_meter + 0.01f )) - && (pDiveSettings->gas[i].depth_meter_travel >= bestGasDepth) - ) - { - betterGasIdLocal = i; - bestGasDepth = pDiveSettings->gas[i].depth_meter; + if (actualLeftMaxDepth(diveState)) { /* deco gases */ + for (int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) { + if ((diveSettings.gas[i].note.ub.active) + && (diveSettings.gas[i].note.ub.deco) + && (diveSettings.gas[i].depth_meter) + && (diveSettings.gas[i].depth_meter >= (diveState->lifeData.depth_meter - 0.01f )) + && (diveSettings.gas[i].depth_meter <= bestGasDepth)) { + betterGasIdLocal = i; + bestGasDepth = diveSettings.gas[i].depth_meter; + } + } + } else { /* travel gases */ + bestGasDepth = 0; + //check for travalgas + for (int i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) { + if ((diveSettings.gas[i].note.ub.active) + && (diveSettings.gas[i].note.ub.travel) + && (diveSettings.gas[i].depth_meter_travel) + && (diveSettings.gas[i].depth_meter_travel <= (diveState->lifeData.depth_meter + 0.01f )) + && (diveSettings.gas[i].depth_meter_travel >= bestGasDepth)) { + betterGasIdLocal = i; + bestGasDepth = diveSettings.gas[i].depth_meter; + } } } - if(betterGasIdLocal != pLifeData->actualGas.GasIdInSettings) - { - if(!check_helper_same_oxygen_and_helium_content(&pDiveSettings->gas[betterGasIdLocal], &pDiveSettings->gas[pLifeData->actualGas.GasIdInSettings])) - { - betterGasId = betterGasIdLocal; - pDiveState->warnings.betterGas = 1; - } + return betterGasIdLocal; +} + + +static int8_t check_BetterGas(SDiveState *diveState) +{ + diveState->warnings.betterGas = 0; + + if (stateUsed->mode != MODE_DIVE) { + betterGasId = 0; + + return 0; } - } - return pDiveState->warnings.betterGas; + + SDiveSettings diveSettings = diveState->diveSettings; + SLifeData lifeData = diveState->lifeData; + + if (isLoopMode(diveSettings.diveMode)) { + betterGasId = getBetterGasId(true, lifeData.actualGas.GasIdInSettings, diveState); + betterBailoutGasId = getBetterGasId(false, lifeData.lastDiluent_GasIdInSettings, diveState); + } else { + betterGasId = getBetterGasId(false, lifeData.actualGas.GasIdInSettings, diveState); + } + + if (betterGasId != lifeData.actualGas.GasIdInSettings && !check_helper_same_oxygen_and_helium_content(&diveSettings.gas[betterGasId], &diveSettings.gas[lifeData.actualGas.GasIdInSettings])) { + diveState->warnings.betterGas = 1; + } + + return diveState->warnings.betterGas; } diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Src/t7.c --- a/Discovery/Src/t7.c Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Src/t7.c Wed May 10 16:24:57 2023 +0200 @@ -2780,6 +2780,20 @@ { snprintf(TextR1,TEXTSIZE,"\a\001%c%c", TXT_2BYTE, TXT2BYTE_DiveMenuQ); GFX_write_string_color(&FontT48,&t7c2,TextR1,0,CLUT_WarningYellow); + } else if (get_globalState() == StDBAILOUT) { + if (isLoopMode(stateUsed->diveSettings.diveMode)) { + textPointer = snprintf(TextR1, TEXTSIZE, "\a\001 %c%c ", TXT_2BYTE, TXT2BYTE_BailoutShort); + textPointer += tHome_gas_writer(stateUsed->diveSettings.gas[actualBetterBailoutGasId()].oxygen_percentage, stateUsed->diveSettings.gas[actualBetterBailoutGasId()].helium_percentage, &TextR1[textPointer]); + TextR1[textPointer++] = ' '; + TextR1[textPointer++] = '?'; + } else { + textPointer = snprintf(TextR1, TEXTSIZE, "\a\001 %c%c %01.2f/", TXT_2BYTE, TXT2BYTE_LoopShort, stateUsed->diveSettings.setpoint[actualBetterSetpointId()].setpoint_cbar / 100.0); + textPointer += tHome_gas_writer(stateUsed->diveSettings.gas[stateUsed->lifeData.lastDiluent_GasIdInSettings].oxygen_percentage, stateUsed->diveSettings.gas[stateUsed->lifeData.lastDiluent_GasIdInSettings].helium_percentage, &TextR1[textPointer]); + TextR1[textPointer++] = ' '; + TextR1[textPointer++] = '?'; + } + + GFX_write_string_color(&FontT48, &t7c2, TextR1, 0, CLUT_WarningYellow); } else if(get_globalState() == StDSIM1) { diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Src/tHome.c --- a/Discovery/Src/tHome.c Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Src/tHome.c Wed May 10 16:24:57 2023 +0200 @@ -157,8 +157,34 @@ } +static void checkSetStateSim(SSettings *settings) +{ + if (is_stateUsedSetToSim()) { + if (settings->design != 3) { + set_globalState(StDSIM1); + } else { +#ifdef ENABLE_T3_PPO_SIM + if (stateUsed->diveSettings.ppo2sensors_deactivated & 0x01 == 0) { + set_globalState(StDSIM1); + } else if (stateUsed->diveSettings.ppo2sensors_deactivated & 0x02 == 0) { + set_globalState(StDSIM3); + } else if (stateUsed->diveSettings.ppo2sensors_deactivated & 0x04 == 0) { + set_globalState(StDSIM5); + } else { + set_globalState(StD); + } +#endif + } + } else { + set_globalState(StD); + } +} + + void tHomeDiveMenuControl(uint8_t sendAction) { + SSettings *settings = settingsGetPointer(); + if(sendAction == ACTION_BUTTON_NEXT) { if(settingsGetPointer()->design == 4) @@ -245,39 +271,19 @@ break; case StDMENU: - if(is_stateUsedSetToSim()) - { - if(settingsGetPointer()->design != 3) - { - set_globalState(StDSIM1); - } - else - { -#ifdef ENABLE_T3_PPO_SIM - if((stateUsed->diveSettings.ppo2sensors_deactivated & 0x01) == 0) - { - set_globalState(StDSIM1); - } - else if((stateUsed->diveSettings.ppo2sensors_deactivated & 0x02) == 0) - { - set_globalState(StDSIM3); - } - else if((stateUsed->diveSettings.ppo2sensors_deactivated & 0x04) == 0) - { - set_globalState(StDSIM5); - } - else - { - set_globalState(StD); - } -#endif - } + if (settings->design == 7 && isLoopMode(settings->dive_mode)) { + set_globalState(StDBAILOUT); + + break; } - else - set_globalState(StD); + checkSetStateSim(settings); + break; + case StDBAILOUT: + checkSetStateSim(settings); + break; case StDSIM1: set_globalState(StDSIM2); break; @@ -398,11 +404,11 @@ switch(get_globalState()) { case StDMGAS: - openEdit_DiveSelectBetterGas(); + openEdit_DiveSelectBetterGas(false); set_globalState(StD); break; case StDMSPT: - openEdit_DiveSelectBetterSetpoint(); + openEdit_DiveSelectBetterSetpoint(false); set_globalState(StD); break; @@ -464,6 +470,20 @@ Sim_DecreasePPO(2); break; #endif + case StDBAILOUT: + if (isLoopMode(stateUsed->diveSettings.diveMode)) { + tMEGas_check_switch_to_bailout(); + + openEdit_DiveSelectBetterGas(true); + } else { + checkSwitchToLoop(); + + openEdit_DiveSelectBetterSetpoint(true); + } + + set_globalState(StD); + + break; case StDBEAR: // t5_gauge stateUsedWrite->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; set_globalState(StD); diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Src/tMenuEditGasOC.c --- a/Discovery/Src/tMenuEditGasOC.c Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Src/tMenuEditGasOC.c Wed May 10 16:24:57 2023 +0200 @@ -145,12 +145,16 @@ /* dive mode */ -void openEdit_DiveSelectBetterGas(void) +void openEdit_DiveSelectBetterGas(bool doBailout) { - uint8_t gasId, ccr; + uint8_t gasId; + if (doBailout) { + gasId = actualBetterBailoutGasId(); + } else { + gasId = actualBetterGasId(); + } - gasId = actualBetterGasId(); - ccr = 0; + uint8_t ccr = 0; if(gasId>5) { gasId -= 5; diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Src/tMenuEditSetpoint.c --- a/Discovery/Src/tMenuEditSetpoint.c Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Src/tMenuEditSetpoint.c Wed May 10 16:24:57 2023 +0200 @@ -27,6 +27,8 @@ ////////////////////////////////////////////////////////////////////////////// /* Includes ------------------------------------------------------------------*/ +#include + #include "tMenuEditSetpoint.h" #include "check_warning.h" @@ -55,6 +57,16 @@ /* Exported functions --------------------------------------------------------*/ +void checkSwitchToLoop(void) +{ + if(!isLoopMode(stateUsedWrite->diveSettings.diveMode)) { + stateUsedWrite->diveSettings.diveMode = settingsGetPointer()->dive_mode; + + unblock_diluent_page(); + } +} + + void openEdit_Setpoint(uint8_t line) { uint8_t useSensorSubMenu = 0; @@ -121,11 +133,7 @@ setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); - if(!isLoopMode(stateUsedWrite->diveSettings.diveMode)) - { - stateUsedWrite->diveSettings.diveMode = settingsGetPointer()->dive_mode; - unblock_diluent_page(); - } + checkSwitchToLoop(); clear_warning_fallback(); @@ -329,7 +337,7 @@ return EXIT_TO_MENU; } -void openEdit_DiveSelectBetterSetpoint(void) +void openEdit_DiveSelectBetterSetpoint(bool useLastDiluent) { uint8_t spId; uint8_t depth; @@ -351,11 +359,19 @@ // new setpoint stateUsedWrite->diveSettings.setpoint[spId].note.ub.first = 1; + uint8_t gasId; + if (useLastDiluent) { + gasId = stateUsed->lifeData.lastDiluent_GasIdInSettings; + } else { + gasId = stateUsed->lifeData.actualGas.GasIdInSettings; + } + // change in lifeData - setActualGas_DM(&stateUsedWrite->lifeData, stateUsedWrite->lifeData.actualGas.GasIdInSettings, stateUsedWrite->diveSettings.setpoint[spId].setpoint_cbar); + setActualGas_DM(&stateUsedWrite->lifeData, gasId, stateUsedWrite->diveSettings.setpoint[spId].setpoint_cbar); } } + static uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) { if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 1) diff -r b7e43b28bee1 -r 2c243233c999 Discovery/Src/text_multilanguage.c --- a/Discovery/Src/text_multilanguage.c Sat Apr 22 21:11:50 2023 -0500 +++ b/Discovery/Src/text_multilanguage.c Wed May 10 16:24:57 2023 +0200 @@ -1802,6 +1802,18 @@ static uint8_t text_IT_Scrubber[] = "Scrubber"; static uint8_t text_ES_Scrubber[] = "Scrubber"; +static uint8_t text_EN_BailoutShort[] = "BO"; +static uint8_t text_DE_BailoutShort[] = "BO"; +static uint8_t text_FR_BailoutShort[] = "BO"; +static uint8_t text_IT_BailoutShort[] = "BO"; +static uint8_t text_ES_BailoutShort[] = "BO"; + +static uint8_t text_EN_LoopShort[] = "CC"; +static uint8_t text_DE_LoopShort[] = "KL"; +static uint8_t text_FR_LoopShort[] = "CC"; +static uint8_t text_IT_LoopShort[] = "CC"; +static uint8_t text_ES_LoopShort[] = "CC"; + /* Lookup Table -------------------------------------------------------------*/ const tText text_array[] = @@ -2070,4 +2082,6 @@ {(uint8_t)TXT2BYTE_CcrSummary, {text_EN_CcrSummary, text_DE_CcrSummary, text_FR_CcrSummary, text_IT_CcrSummary, text_ES_CcrSummary}}, {(uint8_t)TXT2BYTE_Setpoint, {text_EN_Setpoint, text_DE_Setpoint, text_FR_Setpoint, text_IT_Setpoint, text_ES_Setpoint}}, {(uint8_t)TXT2BYTE_Scrubber, {text_EN_Scrubber, text_DE_Scrubber, text_FR_Scrubber, text_IT_Scrubber, text_ES_Scrubber}}, + {(uint8_t)TXT2BYTE_BailoutShort, {text_EN_BailoutShort, text_DE_BailoutShort, text_FR_BailoutShort, text_IT_BailoutShort, text_ES_BailoutShort}}, + {(uint8_t)TXT2BYTE_LoopShort, {text_EN_LoopShort, text_DE_LoopShort, text_FR_LoopShort, text_IT_LoopShort, text_ES_LoopShort}}, };