diff options
author | Robert C. Helling <helling@atdotde.de> | 2015-01-15 23:22:12 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-20 06:47:28 +1200 |
commit | 39b528d6dae2ad3e05a385821736688b6e590c2f (patch) | |
tree | c4665781a87dd76b40b796a42e997cb55dff9d7c /planner.c | |
parent | f8f5ffa69741982a1b7d658775219b8ddfacd242 (diff) | |
download | subsurface-39b528d6dae2ad3e05a385821736688b6e590c2f.tar.gz |
Adopt planner gas calculation to PSCR mode and include low pO2 warning
[Dirk Hohndel: fixed obvious compile problem]
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r-- | planner.c | 50 |
1 files changed, 34 insertions, 16 deletions
@@ -224,11 +224,15 @@ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_dept volume_t gas_used; pressure_t delta_p; depth_t mean_depth; + int factor = 1000; + + if (d->dc.divemode == PSCR) + factor = prefs.pscr_ratio; if (!cyl) return; mean_depth.mm = (old_depth + new_depth) / 2; - gas_used.mliter = depth_to_atm(mean_depth.mm, d) * sac / 60 * duration; + gas_used.mliter = depth_to_atm(mean_depth.mm, d) * sac / 60 * duration * factor / 1000; cyl->gas_used.mliter += gas_used.mliter; if (in_deco) cyl->deco_gas_used.mliter += gas_used.mliter; @@ -740,23 +744,37 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool len += snprintf(buffer + len, sizeof(buffer) - len, "%s%s<br>", temp, warning); } dp = diveplan->dp; - while (dp) { - if (dp->time != 0) { - int pO2 = depth_to_atm(dp->depth, dive) * get_o2(&dp->gasmix); - - if (pO2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2)) { - const char *depth_unit; - int decimals; - double depth_value = get_depth_units(dp->depth, &decimals, &depth_unit); - len = strlen(buffer); - snprintf(temp, sizeof(temp), - translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), - pO2 / 1000.0, FRACTION(dp->time, 60), gasname(&dp->gasmix), decimals, depth_value, depth_unit); - len += snprintf(buffer + len, sizeof(buffer) - len, "<span style='color: red;'>%s </span> %s<br>", - translate("gettextFromC", "Warning:"), temp); + if (dive->dc.divemode != CCR) { + while (dp) { + if (dp->time != 0) { + struct gas_pressures pressures; + fill_pressures(&pressures, depth_to_atm(dp->depth, dive), &dp->gasmix, 0.0, dive->dc.divemode); + + if (pressures.o2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) { + const char *depth_unit; + int decimals; + double depth_value = get_depth_units(dp->depth, &decimals, &depth_unit); + len = strlen(buffer); + snprintf(temp, sizeof(temp), + translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), + pressures.o2, FRACTION(dp->time, 60), gasname(&dp->gasmix), decimals, depth_value, depth_unit); + len += snprintf(buffer + len, sizeof(buffer) - len, "<span style='color: red;'>%s </span> %s<br>", + translate("gettextFromC", "Warning:"), temp); + } else if (pressures.o2 < 0.16) { + const char *depth_unit; + int decimals; + double depth_value = get_depth_units(dp->depth, &decimals, &depth_unit); + len = strlen(buffer); + snprintf(temp, sizeof(temp), + translate("gettextFromC", "low pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), + pressures.o2, FRACTION(dp->time, 60), gasname(&dp->gasmix), decimals, depth_value, depth_unit); + len += snprintf(buffer + len, sizeof(buffer) - len, "<span style='color: red;'>%s </span> %s<br>", + translate("gettextFromC", "Warning:"), temp); + + } } + dp = dp->next; } - dp = dp->next; } snprintf(buffer + len, sizeof(buffer) - len, "</div>"); dive->notes = strdup(buffer); |