diff options
-rw-r--r-- | dive.c | 4 | ||||
-rw-r--r-- | dive.h | 3 | ||||
-rw-r--r-- | planner.c | 62 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 27 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.cpp | 5 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.h | 2 | ||||
-rw-r--r-- | qt-ui/models.cpp | 4 |
7 files changed, 59 insertions, 48 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; } @@ -478,7 +480,6 @@ static unsigned int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, return stoplevels; } -#if DO_WE_WANT_THIS_IN_QT static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive) { char buffer[20000]; @@ -491,10 +492,10 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive) return; snprintf(buffer, sizeof(buffer), translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %.0f and GFhigh = %.0f\n\n"), - disclaimer, plangflow * 100, plangfhigh * 100); + disclaimer, diveplan->gflow * 100, diveplan->gfhigh * 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]; @@ -564,17 +565,18 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive) double volume; const char *unit; char gas[64]; + if (dive->cylinder[gasidx].type.size.mliter) + dive->cylinder[gasidx].end.mbar = dive->cylinder[gasidx].start.mbar - consumption[gasidx] / dive->cylinder[gasidx].type.size.mliter / 1000; if (consumption[gasidx] == 0) 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); } -#endif int ascend_velocity(int depth, int avg_depth, int bottom_time) { @@ -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) { @@ -705,8 +707,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); @@ -767,9 +769,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b goto error_exit; record_dive(dive); -#if DO_WE_WANT_THIS_IN_QT add_plan_to_notes(diveplan, dive); -#endif error_exit: free(stoplevels); diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 9edaac56a..c26aa9569 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -81,8 +81,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) @@ -120,7 +120,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; @@ -441,13 +441,13 @@ DivePlannerPointsModel *DivePlannerPointsModel::instance() void DivePlannerPointsModel::setBottomSac(int sac) { - diveplan.bottomsac = sac; + diveplan.bottomsac = sac * 1000; emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); } void DivePlannerPointsModel::setDecoSac(int sac) { - diveplan.decosac = sac; + diveplan.decosac = sac * 1000; emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1)); } @@ -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; diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index 681b0d20c..71f428b14 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -72,7 +72,6 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : if (default_dive_computer_product) ui.product->setCurrentIndex(ui.product->findText(default_dive_computer_product)); } - connect(ui.product, SIGNAL(currentIndexChanged(int)), this, SLOT(on_product_currentIndexChanged()), Qt::UniqueConnection); if (default_dive_computer_device) ui.device->setEditText(default_dive_computer_device); @@ -190,11 +189,11 @@ void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor) //currentModel->deleteLater(); } -void DownloadFromDCWidget::on_product_currentIndexChanged() +void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &product) { // Set up the DC descriptor dc_descriptor_t *descriptor = NULL; - descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()]; + descriptor = descriptorLookup[ui.vendor->currentText() + product]; // call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL if (dc_descriptor_get_transport(descriptor) == DC_TRANSPORT_SERIAL) { diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h index 955322232..3de102bfd 100644 --- a/qt-ui/downloadfromdivecomputer.h +++ b/qt-ui/downloadfromdivecomputer.h @@ -42,7 +42,7 @@ slots: void on_cancel_clicked(); void on_search_clicked(); void on_vendor_currentIndexChanged(const QString &vendor); - void on_product_currentIndexChanged(); + void on_product_currentIndexChanged(const QString &product); void onDownloadThreadFinished(); void updateProgressBar(); diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 5efcf5a34..4d9e19190 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -249,7 +249,9 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in case O2: if (CHANGED()) { cyl->gasmix.o2 = string_to_fraction(vString.toUtf8().data()); - cyl->depth.mm = 1600 * 1000 / cyl->gasmix.o2.permille * 10 - 10000; + pressure_t modppO2; + modppO2.mbar = 1600; + cyl->depth = gas_mod(&cyl->gasmix, modppO2); changed = true; } break; |