diff options
-rw-r--r-- | qt-ui/maintab.cpp | 3 | ||||
-rw-r--r-- | statistics.c | 36 | ||||
-rw-r--r-- | statistics.h | 1 |
3 files changed, 40 insertions, 0 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index b3514e4f2..90a527e3a 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -552,6 +552,9 @@ void MainTab::updateDiveInfo(int dive) } if (!gasUsed.isEmpty()) gasUsedString.append("..."); + volume_t o2_tot = {}, he_tot = {}; + selected_dives_gas_parts(&o2_tot, &he_tot); + gasUsedString.append(QString("These gases could be\nmixed from Air and using:\nHe: %1 and O2: %2\n").arg(get_volume_string(he_tot, true)).arg(get_volume_string(o2_tot, true))); ui.gasConsumption->setText(gasUsedString); } else { /* clear the fields */ diff --git a/statistics.c b/statistics.c index 5da48f225..2f149113d 100644 --- a/statistics.c +++ b/statistics.c @@ -357,3 +357,39 @@ char *get_gaslist(struct dive *dive) buf[MAXBUF - 1] = '\0'; return buf; } + +/* Quite crude reverse-blender-function, but it produces a approx result */ +static void get_gas_parts(struct gasmix mix, volume_t vol, int o2_in_topup, volume_t *o2, volume_t *he) +{ + volume_t air = {}; + + if (gasmix_is_air(&mix)) { + o2->mliter = 0; + he->mliter = 0; + return; + } + + air.mliter = (vol.mliter * (1000 - get_he(&mix) - get_o2(&mix))) / (1000 - o2_in_topup); + he->mliter = (vol.mliter * get_he(&mix)) / 1000; + o2->mliter += vol.mliter - he->mliter - air.mliter; +} + +void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot) +{ + int i, j; + struct dive *d; + for_each_dive (i, d) { + if (!d->selected) + continue; + volume_t diveGases[MAX_CYLINDERS] = {}; + get_gas_used(d, diveGases); + for (j = 0; j < MAX_CYLINDERS; j++) { + if (diveGases[j].mliter) { + volume_t o2 = {}, he = {}; + get_gas_parts(d->cylinder[j].gasmix, diveGases[j], O2_IN_AIR, &o2, &he); + o2_tot->mliter += o2.mliter; + he_tot->mliter += he.mliter; + } + } + } +} diff --git a/statistics.h b/statistics.h index 94a4961cb..e28fb8f55 100644 --- a/statistics.h +++ b/statistics.h @@ -47,6 +47,7 @@ extern void get_selected_dives_text(char *buffer, int size); extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]); extern char *get_gaslist(struct dive *dive); extern void process_selected_dives(void); +void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot); #ifdef __cplusplus } |