Mercurial > public > ostc4
comparison Discovery/Src/tCCR.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 |
|---|---|
| 32 #include "ostc.h" | 32 #include "ostc.h" |
| 33 #include "data_central.h" | 33 #include "data_central.h" |
| 34 #include "data_exchange.h" | 34 #include "data_exchange.h" |
| 35 #include "check_warning.h" | 35 #include "check_warning.h" |
| 36 #include "configuration.h" | 36 #include "configuration.h" |
| 37 #include "logbook.h" | |
| 37 #include <math.h> | 38 #include <math.h> |
| 38 | 39 |
| 39 /* Private types -------------------------------------------------------------*/ | 40 /* Private types -------------------------------------------------------------*/ |
| 40 typedef struct | 41 typedef struct |
| 41 { | 42 { |
| 320 * data is considered old | 321 * data is considered old |
| 321 */ | 322 */ |
| 322 void tCCR_tick(void) | 323 void tCCR_tick(void) |
| 323 { | 324 { |
| 324 SSettings* pSettings = settingsGetPointer(); | 325 SSettings* pSettings = settingsGetPointer(); |
| 325 uint8_t timerId = 0; | |
| 326 | 326 |
| 327 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) | 327 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) |
| 328 { | 328 { |
| 329 if(HUDTimeoutCount < 3 * 10) | 329 if(HUDTimeoutCount < 3 * 10) |
| 330 HUDTimeoutCount++; | 330 HUDTimeoutCount++; |
| 339 } | 339 } |
| 340 | 340 |
| 341 // If we are in the simulator the counter is updated in `simulator.c` | 341 // If we are in the simulator the counter is updated in `simulator.c` |
| 342 if (!is_stateUsedSetToSim()) { | 342 if (!is_stateUsedSetToSim()) { |
| 343 /* decrease scrubber timer only if we are not bailed out */ | 343 /* decrease scrubber timer only if we are not bailed out */ |
| 344 if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (stateUsed->mode == MODE_DIVE) && isLoopMode(stateUsed->diveSettings.diveMode)) | 344 if (isScrubberTimerRunning(stateUsed, pSettings)) { |
| 345 { | |
| 346 ScrubberTimeoutCount++; | 345 ScrubberTimeoutCount++; |
| 347 if(ScrubberTimeoutCount >= 600) /* resolution is minutes */ | 346 if (ScrubberTimeoutCount >= 600) { /* resolution is minutes */ |
| 348 { | |
| 349 ScrubberTimeoutCount = 0; | 347 ScrubberTimeoutCount = 0; |
| 350 for(timerId = 0; timerId < 2; timerId++) | 348 |
| 351 { | 349 int16_t maxScrubberTime = INT16_MIN; |
| 352 if(pSettings->scubberActiveId & (1 << timerId)) | 350 SScrubberData *longestScrubberData = NULL; |
| 353 { | 351 for (unsigned timerId = 0; timerId < 2; timerId++) { |
| 354 if(stateUsed->scrubberDataDive[timerId].TimerCur > MIN_SCRUBBER_TIME) | 352 if (pSettings->scrubberActiveId & (1 << timerId)) { |
| 355 { | 353 SScrubberData *scrubberData = &stateUsedWrite->scrubberDataDive[timerId]; |
| 356 stateUsedWrite->scrubberDataDive[timerId].TimerCur--; | 354 if (scrubberData->TimerCur > MIN_SCRUBBER_TIME) { |
| 357 } | 355 scrubberData->TimerCur--; |
| 358 translateDate(stateUsed->lifeData.dateBinaryFormat, &stateUsedWrite->scrubberDataDive[timerId].lastDive); | 356 } |
| 359 } | 357 |
| 358 if (scrubberData->TimerCur > maxScrubberTime) { | |
| 359 maxScrubberTime = scrubberData->TimerCur; | |
| 360 longestScrubberData = scrubberData; | |
| 361 } | |
| 362 | |
| 363 translateDate(stateUsed->lifeData.dateBinaryFormat, &scrubberData->lastDive); | |
| 364 } | |
| 360 } | 365 } |
| 366 | |
| 367 logScrubberState(longestScrubberData); | |
| 361 } | 368 } |
| 362 } | 369 } |
| 363 } | 370 } |
| 364 } | 371 } |
| 365 | 372 |
