mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Planner: track gas used even if we don't have a real cylinder
We tracked gas used by simulating a dive with a cylinder - but for that we need a cylinder size and working pressure. If the user just enters a gas but no cylinder data (likely in order to figure out how much gas is used so that she then can pick a big enough cylinder), we didn't show any gas consumption. It kinda sucks to add another member to the cylinder structure, but this seemed far more reasonable then some other, global structure that independently tracks gas usage. This just seemed to make sense. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f44a7509b3
commit
2a871d7fe5
3 changed files with 13 additions and 11 deletions
1
dive.h
1
dive.h
|
@ -60,6 +60,7 @@ typedef struct
|
|||
pressure_t start, end, sample_start, sample_end;
|
||||
depth_t depth;
|
||||
bool used;
|
||||
volume_t gas_used;
|
||||
} cylinder_t;
|
||||
|
||||
typedef struct
|
||||
|
|
|
@ -56,7 +56,8 @@ bool cylinder_nodata(cylinder_t *cyl)
|
|||
!cyl->gasmix.o2.permille &&
|
||||
!cyl->gasmix.he.permille &&
|
||||
!cyl->start.mbar &&
|
||||
!cyl->end.mbar;
|
||||
!cyl->end.mbar &&
|
||||
!cyl->gas_used.mliter;
|
||||
}
|
||||
|
||||
static bool cylinder_nosamples(cylinder_t *cyl)
|
||||
|
@ -197,5 +198,6 @@ void reset_cylinders(struct dive *dive)
|
|||
cyl->depth = gas_mod(&cyl->gasmix, pO2);
|
||||
if (cyl->type.workingpressure.mbar)
|
||||
cyl->start.mbar = cyl->end.mbar = cyl->type.workingpressure.mbar;
|
||||
cyl->gas_used.mliter = 0;
|
||||
}
|
||||
}
|
||||
|
|
19
planner.c
19
planner.c
|
@ -225,12 +225,15 @@ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_dept
|
|||
pressure_t delta_p;
|
||||
depth_t mean_depth;
|
||||
|
||||
if (!cyl || !cyl->type.size.mliter)
|
||||
if (!cyl)
|
||||
return;
|
||||
mean_depth.mm = (old_depth + new_depth) / 2;
|
||||
gas_used.mliter = depth_to_atm(mean_depth.mm, d) * sac / 60 * duration;
|
||||
delta_p.mbar = gas_used.mliter * 1000.0 / cyl->type.size.mliter;
|
||||
cyl->end.mbar -= delta_p.mbar;
|
||||
cyl->gas_used.mliter += gas_used.mliter;
|
||||
if (!cyl->type.size.mliter) {
|
||||
delta_p.mbar = gas_used.mliter * 1000.0 / cyl->type.size.mliter;
|
||||
cyl->end.mbar -= delta_p.mbar;
|
||||
}
|
||||
}
|
||||
|
||||
static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive *master_dive)
|
||||
|
@ -605,19 +608,15 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
|||
break;
|
||||
len = strlen(buffer);
|
||||
get_gas_string(get_o2(&cyl->gasmix), get_he(&cyl->gasmix), gas, sizeof(gas));
|
||||
if (cyl->type.workingpressure.mbar) {
|
||||
int consumed = mbar_to_atm(cyl->start.mbar - cyl->end.mbar) * cyl->type.size.mliter;
|
||||
volume = get_volume_units(consumed, NULL, &unit);
|
||||
volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit);
|
||||
if (cyl->type.size.mliter) {
|
||||
/* Warn if the plan uses more gas than is available in a cylinder
|
||||
* This only works if we have working pressure for the cylinder
|
||||
* 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */
|
||||
if (cyl->end.mbar < 10000)
|
||||
warning = translate("gettextFromC", "WARNING: this is more gas than available in the specified cylinder!");
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s%s\n"), volume, unit, gas, warning);
|
||||
} else {
|
||||
fprintf(stderr, "we really should calculate the consumption even without cylinder data\n");
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "did not track volume for %s"), gas);
|
||||
}
|
||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s%s\n"), volume, unit, gas, warning);
|
||||
}
|
||||
dive->notes = strdup(buffer);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue