diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-05-26 08:23:22 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-26 08:23:22 -0700 |
commit | cfe865dd0c78a81717993b479894fd0e823767d3 (patch) | |
tree | 5abcefc1e943daec1241d59f1dd753685124d635 | |
parent | d14a531510e22baa236f661e2235e20dac6d7f6d (diff) | |
parent | 04b6b6aaf9cc194a698c2302abc2032f730aecb4 (diff) | |
download | subsurface-cfe865dd0c78a81717993b479894fd0e823767d3.tar.gz |
Merge branch 'atdotde'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Conflicts:
qt-ui/diveplanner.cpp
qt-ui/models.cpp
-rw-r--r-- | dive.c | 4 | ||||
-rw-r--r-- | dive.h | 3 | ||||
-rw-r--r-- | planner.c | 54 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 23 |
4 files changed, 48 insertions, 36 deletions
@@ -520,7 +520,7 @@ static int same_rounded_pressure(pressure_t a, pressure_t b) return abs(a.mbar - b.mbar) <= 500; } -static void sanitize_gasmix(struct gasmix *mix) +void sanitize_gasmix(struct gasmix *mix) { unsigned int o2, he; @@ -1253,7 +1253,7 @@ static void merge_weightsystem_info(weightsystem_t *res, weightsystem_t *a, weig *res = *a; } -static int gasmix_distance(const struct gasmix *a, const struct gasmix *b) +int gasmix_distance(const struct gasmix *a, const struct gasmix *b) { int a_o2 = get_o2(a), b_o2 = get_o2(b); int a_he = get_he(a), b_he = get_he(b); @@ -91,6 +91,9 @@ static inline int get_he(const struct gasmix *mix) return mix->he.permille; } +extern void sanitize_gasmix(struct gasmix *mix); +extern int gasmix_distance(const struct gasmix *a, const struct gasmix *b); + static inline bool is_air(int o2, int he) { return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1))); @@ -72,23 +72,19 @@ void get_gas_from_events(struct divecomputer *dc, int time, int *o2, int *he) } } -/* simple helper function to compare two permille values with - * (rounded) percent granularity */ -static inline bool match_percent(int a, int b) -{ - return (a + 5) / 10 == (b + 5) / 10; -} - int get_gasidx(struct dive *dive, int o2, int he) { int gasidx = -1; + struct gasmix mix; + + mix.o2.permille = o2; + mix.he.permille = he; /* we treat air as 0/0 because it is special */ - if (is_air(o2, he)) - o2 = 0; + //if (is_air(o2, he)) + // o2 = 0; while (++gasidx < MAX_CYLINDERS) - if (match_percent(dive->cylinder[gasidx].gasmix.o2.permille, o2) && - match_percent(dive->cylinder[gasidx].gasmix.he.permille, he)) + if (gasmix_distance(&dive->cylinder[gasidx].gasmix, &mix) < 200) return gasidx; return -1; } @@ -138,8 +134,8 @@ double tissue_at_end(struct dive *dive, char **cached_datap) psample = sample = dc->sample; lastdepth = t0 = 0; /* we always start with gas 0 (unless an event tells us otherwise) */ - o2 = dive->cylinder[0].gasmix.o2.permille; - he = dive->cylinder[0].gasmix.he.permille; + o2 = get_o2(&dive->cylinder[0].gasmix); + he = get_he(&dive->cylinder[0].gasmix); for (i = 0; i < dc->samples; i++, sample++) { t1 = sample->time.seconds; get_gas_from_events(&dive->dc, t0, &o2, &he); @@ -189,14 +185,17 @@ static int add_gas(struct dive *dive, int o2, int he) { int i; struct gasmix *mix; + struct gasmix mix_in; cylinder_t *cyl; + mix_in.o2.permille = o2; + mix_in.he.permille = he; for (i = 0; i < MAX_CYLINDERS; i++) { cyl = dive->cylinder + i; mix = &cyl->gasmix; if (cylinder_nodata(cyl)) break; - if (match_percent(o2, mix->o2.permille) && match_percent(he, mix->he.permille)) + if (gasmix_distance(mix, &mix_in) < 200) return i; } if (i == MAX_CYLINDERS) { @@ -206,6 +205,7 @@ static int add_gas(struct dive *dive, int o2, int he) fill_default_cylinder(cyl); mix->o2.permille = o2; mix->he.permille = he; + sanitize_gasmix(mix); return i; } @@ -388,6 +388,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive int nr = 0; struct gaschanges *gaschanges = NULL; struct divedatapoint *dp = diveplan->dp; + struct gasmix mix; while (dp) { if (dp->time == 0 && dp->depth <= depth) { @@ -403,9 +404,10 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive } gaschanges[i].depth = dp->depth; gaschanges[i].gasidx = -1; + mix.o2.permille = dp->o2; + mix.he.permille = dp->he; do { - if (dive->cylinder[j].gasmix.o2.permille == dp->o2 && - dive->cylinder[j].gasmix.he.permille == dp->he) { + if (!gasmix_distance(&dive->cylinder[j].gasmix, &mix)) { gaschanges[i].gasidx = j; break; } @@ -419,8 +421,8 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive #if DEBUG_PLAN & 16 for (nr = 0; nr < *gaschangenr; nr++) printf("gaschange nr %d: @ %5.2lfm gasidx %d (%d/%d)\n", nr, gaschanges[nr].depth / 1000.0, - gaschanges[nr].gasidx, (dive->cylinder[gaschanges[nr].gasidx].gasmix.o2.permille + 5) / 10, - (dive->cylinder[gaschanges[nr].gasidx].gasmix.he.permille + 5) / 10); + gaschanges[nr].gasidx, (get_o2(&dive->cylinder[gaschanges[nr].gasidx].gasmix) + 5) / 10, + (get_he(&dive->cylinder[gaschanges[nr].gasidx].gasmix) + 5) / 10); #endif return gaschanges; } @@ -493,8 +495,8 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive) snprintf(buffer, sizeof(buffer), translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %.0f and GFhigh = %.0f\n\n"), disclaimer, plangflow * 100, plangfhigh * 100); /* we start with gas 0, then check if that was changed */ - o2 = dive->cylinder[0].gasmix.o2.permille; - he = dive->cylinder[0].gasmix.he.permille; + o2 = get_o2(&dive->cylinder[0].gasmix); + he = get_he(&dive->cylinder[0].gasmix); do { const char *depth_unit; char gas[64]; @@ -568,8 +570,8 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive) continue; len = strlen(buffer); volume = get_volume_units(consumption[gasidx], NULL, &unit); - get_gas_string(dive->cylinder[gasidx].gasmix.o2.permille, - dive->cylinder[gasidx].gasmix.he.permille, gas, sizeof(gas)); + get_gas_string(get_o2(&dive->cylinder[gasidx].gasmix), + get_he(&dive->cylinder[gasidx].gasmix), gas, sizeof(gas)); snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s\n"), volume, unit, gas); } dive->notes = strdup(buffer); @@ -625,8 +627,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b /* Let's start at the last 'sample', i.e. the last manually entered waypoint. */ sample = &dive->dc.sample[dive->dc.samples - 1]; /* we start with gas 0, then check if that was changed */ - o2 = dive->cylinder[0].gasmix.o2.permille; - he = dive->cylinder[0].gasmix.he.permille; + o2 = get_o2(&dive->cylinder[0].gasmix); + he = get_he(&dive->cylinder[0].gasmix); get_gas_from_events(&dive->dc, sample->time.seconds, &o2, &he); po2 = dive->dc.sample[dive->dc.samples - 1].po2; if ((current_cylinder = get_gasidx(dive, o2, he)) == -1) { @@ -704,8 +706,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b stopping = true; current_cylinder = gaschanges[gi].gasidx; - o2 = dive->cylinder[current_cylinder].gasmix.o2.permille; - he = dive->cylinder[current_cylinder].gasmix.he.permille; + o2 = get_o2(&dive->cylinder[current_cylinder].gasmix); + he = get_he(&dive->cylinder[current_cylinder].gasmix); #if DEBUG_PLAN & 16 printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx, (o2 + 5) / 10, (he + 5) / 10, gaschanges[gi].depth / 1000.0); diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 3ffacdd2b..ada2b4e73 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -79,8 +79,8 @@ void DivePlannerPointsModel::loadFromDive(dive *d) CylindersModel::instance()->setDive(stagingDive); int lasttime = 0; // we start with the first gas and see if it was changed - int o2 = backupDive.cylinder[0].gasmix.o2.permille; - int he = backupDive.cylinder[0].gasmix.he.permille; + int o2 = get_o2(&backupDive.cylinder[0].gasmix); + int he = get_he(&backupDive.cylinder[0].gasmix); for (int i = 0; i < backupDive.dc.samples - 1; i++) { const sample &s = backupDive.dc.sample[i]; if (s.time.seconds == 0) @@ -118,7 +118,7 @@ QStringList &DivePlannerPointsModel::getGasList() cylinder_t *cyl = &activeDive->cylinder[i]; if (cylinder_nodata(cyl)) break; - list.push_back(gasToStr(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)); + list.push_back(gasToStr(get_o2(&cyl->gasmix), get_he(&cyl->gasmix))); } } return list; @@ -488,6 +488,12 @@ bool divePointsLessThan(const divedatapoint &p1, const divedatapoint &p2) bool DivePlannerPointsModel::addGas(int o2, int he) { + struct gasmix mix; + + mix.o2.permille = o2; + mix.he.permille = he; + sanitize_gasmix(&mix); + if (is_air(o2, he)) o2 = 0; @@ -497,6 +503,7 @@ bool DivePlannerPointsModel::addGas(int o2, int he) fill_default_cylinder(cyl); cyl->gasmix.o2.permille = o2; cyl->gasmix.he.permille = he; + sanitize_gasmix(&cyl->gasmix); /* The depth to change to that gas is given by the depth where its pO2 is 1.6 bar. * The user should be able to change this depth manually. */ pressure_t modppO2; @@ -505,7 +512,7 @@ bool DivePlannerPointsModel::addGas(int o2, int he) CylindersModel::instance()->setDive(stagingDive); return true; } - if (cyl->gasmix.o2.permille == o2 && cyl->gasmix.he.permille == he) + if (!gasmix_distance(&cyl->gasmix, &mix)) return true; } qDebug("too many gases"); @@ -540,8 +547,8 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he, //Default to the first defined gas, if we got one. cylinder_t *cyl = &stagingDive->cylinder[0]; if (cyl) { - o2 = cyl->gasmix.o2.permille; - he = cyl->gasmix.he.permille; + o2 = get_o2(&cyl->gasmix); + he = get_he(&cyl->gasmix); } } if (o2 != -1) @@ -661,7 +668,7 @@ QVector<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d) for (int i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = &d->cylinder[i]; if (!cylinder_nodata(cyl)) - l.push_back(qMakePair(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)); + l.push_back(qMakePair(get_o2(&cyl->gasmix), get_he(&cyl->gasmix))); } return l; } @@ -761,7 +768,7 @@ void DivePlannerPointsModel::createTemporaryPlan() for (int i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = &stagingDive->cylinder[i]; if (cyl->depth.mm) { - dp = create_dp(0, cyl->depth.mm, cyl->gasmix.o2.permille, cyl->gasmix.he.permille, 0); + dp = create_dp(0, cyl->depth.mm, get_o2(&cyl->gasmix), get_he(&cyl->gasmix), 0); if (diveplan.dp) { dp->next = diveplan.dp->next; diveplan.dp->next = dp; |