Mercurial > public > ostc4
comparison Discovery/Src/simulation.c @ 1014:8c0134a287da GasConsumption
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
is decremented. The event contains a 12 bit signed integer for the remaining scrubber duration, and two
flags for scrubber warning (0x2000, <= 30 minutes remaining) and scrubber error (0x4000, <= 0 minutes remaining).
(mikeller)
| author | heinrichsweikamp |
|---|---|
| date | Sun, 11 May 2025 16:18:20 +0200 |
| parents | 5a690195b6b7 |
| children |
comparison
equal
deleted
inserted
replaced
| 1013:fa1af49319e5 | 1014:8c0134a287da |
|---|---|
| 41 #include "timer.h" | 41 #include "timer.h" |
| 42 #include "check_warning.h" | 42 #include "check_warning.h" |
| 43 #include "vpm.h" | 43 #include "vpm.h" |
| 44 #include "buehlmann.h" | 44 #include "buehlmann.h" |
| 45 #include "logbook_miniLive.h" | 45 #include "logbook_miniLive.h" |
| 46 #include "logbook.h" | |
| 46 | 47 |
| 47 #include "configuration.h" | 48 #include "configuration.h" |
| 48 | 49 |
| 49 //Private state variables | 50 //Private state variables |
| 50 static float sim_aim_depth_meter; | 51 static float sim_aim_depth_meter; |
| 109 stateSim.lifeData.boolResetAverageDepth = 1; | 110 stateSim.lifeData.boolResetAverageDepth = 1; |
| 110 decoLock = DECO_CALC_init_as_is_start_of_dive; | 111 decoLock = DECO_CALC_init_as_is_start_of_dive; |
| 111 | 112 |
| 112 stateSim.lifeData.apnea_total_max_depth_meter = 0; | 113 stateSim.lifeData.apnea_total_max_depth_meter = 0; |
| 113 | 114 |
| 114 memcpy(stateSim.scrubberDataDive, settingsGetPointer()->scrubberData, sizeof(stateSim.scrubberDataDive)); | 115 SSettings *settings = settingsGetPointer(); |
| 116 memcpy(stateSim.scrubberDataDive, settings->scrubberData, sizeof(stateSim.scrubberDataDive)); | |
| 115 memset(simSensmVOffset,0,sizeof(simSensmVOffset)); | 117 memset(simSensmVOffset,0,sizeof(simSensmVOffset)); |
| 116 if(getReplayOffset() != 0xFFFF) | 118 if(getReplayOffset() != 0xFFFF) |
| 117 { | 119 { |
| 118 simReplayActive = 1; | 120 simReplayActive = 1; |
| 119 getReplayInfo(&pReplayData, &pReplayMarker, &replayDataLength, &max_depth, &diveMinutes); | 121 getReplayInfo(&pReplayData, &pReplayMarker, &replayDataLength, &max_depth, &diveMinutes); |
| 149 void simulation_UpdateLifeData( _Bool checkOncePerSecond) | 151 void simulation_UpdateLifeData( _Bool checkOncePerSecond) |
| 150 { | 152 { |
| 151 SDiveState * pDiveState = &stateSim; | 153 SDiveState * pDiveState = &stateSim; |
| 152 const SDiveState * pRealState = stateRealGetPointer(); | 154 const SDiveState * pRealState = stateRealGetPointer(); |
| 153 SSettings *pSettings; | 155 SSettings *pSettings; |
| 154 uint8_t timerId = 0; | |
| 155 | 156 |
| 156 static int last_second = -1; | 157 static int last_second = -1; |
| 157 static _Bool two_second = 0; | 158 static _Bool two_second = 0; |
| 158 static float lastPressure_bar = 0; | 159 static float lastPressure_bar = 0; |
| 159 | 160 |
| 243 { | 244 { |
| 244 lastPressure_bar = 0; | 245 lastPressure_bar = 0; |
| 245 pDiveState->lifeData.ascent_rate_meter_per_min = 0; | 246 pDiveState->lifeData.ascent_rate_meter_per_min = 0; |
| 246 } | 247 } |
| 247 | 248 |
| 248 if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (pDiveState->mode == MODE_DIVE) && isLoopMode(pDiveState->diveSettings.diveMode)) | 249 if (isScrubberTimerRunning(pDiveState, pSettings)) { |
| 249 { | 250 simScrubberTimeoutCount++; |
| 250 simScrubberTimeoutCount++; | 251 |
| 251 if(simScrubberTimeoutCount >= 60) /* resolution is minutes */ | 252 if (simScrubberTimeoutCount >= 60) { |
| 252 { | 253 /* resolution is minutes */ |
| 253 simScrubberTimeoutCount = 0; | 254 simScrubberTimeoutCount = 0; |
| 254 for(timerId = 0; timerId < 2; timerId++) | 255 |
| 255 { | 256 int16_t maxScrubberTime = INT16_MIN; |
| 256 if(pSettings->scubberActiveId & (1 << timerId)) | 257 SScrubberData *longestScrubberData = NULL; |
| 257 { | 258 for (unsigned timerId = 0; timerId < 2; timerId++) { |
| 258 if(pDiveState->scrubberDataDive[timerId].TimerCur > MIN_SCRUBBER_TIME) | 259 if (pSettings->scrubberActiveId & (1 << timerId)) { |
| 259 { | 260 SScrubberData *scrubberData = &pDiveState->scrubberDataDive[timerId]; |
| 260 pDiveState->scrubberDataDive[timerId].TimerCur--; | 261 if (scrubberData->TimerCur > MIN_SCRUBBER_TIME) { |
| 261 } | 262 scrubberData->TimerCur--; |
| 262 translateDate(stateUsed->lifeData.dateBinaryFormat, &pDiveState->scrubberDataDive[timerId].lastDive); | 263 } |
| 263 } | 264 |
| 264 } | 265 if (scrubberData->TimerCur > maxScrubberTime) { |
| 265 } | 266 maxScrubberTime = scrubberData->TimerCur; |
| 266 } | 267 longestScrubberData = scrubberData; |
| 267 | 268 } |
| 269 | |
| 270 translateDate(stateUsed->lifeData.dateBinaryFormat, &scrubberData->lastDive); | |
| 271 } | |
| 272 } | |
| 273 | |
| 274 logScrubberState(longestScrubberData); | |
| 275 } | |
| 276 } | |
| 268 | 277 |
| 269 if(lastPressure_bar > 0) | 278 if(lastPressure_bar > 0) |
| 270 { | 279 { |
| 271 //1 second * 60 == 1 minute, bar * 10 = meter | 280 //1 second * 60 == 1 minute, bar * 10 = meter |
| 272 pDiveState->lifeData.ascent_rate_meter_per_min = (lastPressure_bar - pDiveState->lifeData.pressure_ambient_bar) * 600.0; | 281 pDiveState->lifeData.ascent_rate_meter_per_min = (lastPressure_bar - pDiveState->lifeData.pressure_ambient_bar) * 600.0; |
