Change add_plan_to_notes() to operated on gasmix

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-06-01 17:34:40 -07:00
parent bd142bbee2
commit 0d7ce2704d

View file

@ -505,7 +505,6 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
char buffer[20000]; char buffer[20000];
int len, gasidx, lastdepth = 0, lasttime = 0; int len, gasidx, lastdepth = 0, lasttime = 0;
struct divedatapoint *dp = diveplan->dp; struct divedatapoint *dp = diveplan->dp;
int o2, he;
const char *disclaimer = ""; const char *disclaimer = "";
if (!dp) if (!dp)
@ -525,14 +524,11 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
char gas[64]; char gas[64];
double depthvalue; double depthvalue;
int decimals; int decimals;
int newo2 = -1, newhe = -1;
struct divedatapoint *nextdp; struct divedatapoint *nextdp;
if (dp->time == 0) if (dp->time == 0)
continue; continue;
gasmix = dp->gasmix; gasmix = dp->gasmix;
o2 = get_o2(&gasmix);
he = get_he(&gasmix);
depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit); depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
/* analyze the dive points ahead */ /* analyze the dive points ahead */
nextdp = dp->next; nextdp = dp->next;
@ -540,16 +536,15 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
nextdp = nextdp->next; nextdp = nextdp->next;
if (nextdp) { if (nextdp) {
newgasmix = nextdp->gasmix; newgasmix = nextdp->gasmix;
newo2 = get_o2(&newgasmix); if (gasmix_is_null(&newgasmix))
newhe = get_he(&newgasmix); newgasmix = gasmix;
if (newhe == 0 && newo2 == 0) {
/* same as last segment */
newo2 = o2;
newhe = he;
}
} }
/* do we want to skip this leg as it is devoid of anything useful? */ /* do we want to skip this leg as it is devoid of anything useful? */
if (!dp->entered && o2 == newo2 && he == newhe && nextdp && dp->depth != lastdepth && nextdp->depth != dp->depth) if (!dp->entered &&
gasmix_distance(&gasmix, &newgasmix) == 0 &&
nextdp &&
dp->depth != lastdepth &&
nextdp->depth != dp->depth)
continue; continue;
get_gas_string(&gasmix, gas, sizeof(gas)); get_gas_string(&gasmix, gas, sizeof(gas));
gasidx = get_gasidx(dive, &gasmix); gasidx = get_gasidx(dive, &gasmix);
@ -566,13 +561,12 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
FRACTION(dp->time - lasttime, 60), FRACTION(dp->time - lasttime, 60),
FRACTION(dp->time, 60), FRACTION(dp->time, 60),
gas); gas);
if (nextdp && (o2 != newo2 || he != newhe) ) { if (nextdp && gasmix_distance(&gasmix, &newgasmix)) {
// gas switch at this waypoint // gas switch at this waypoint
get_gas_string(&newgasmix, gas, sizeof(gas)); get_gas_string(&newgasmix, gas, sizeof(gas));
len = strlen(buffer); len = strlen(buffer);
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s\n"), gas); snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s\n"), gas);
o2 = newo2; gasmix = newgasmix;
he = newhe;
} }
lasttime = dp->time; lasttime = dp->time;
lastdepth = dp->depth; lastdepth = dp->depth;