core: pass depth_t to get_depth_units()

Commit is longer than expected, because a few of the callers
were converted to use depth_t instead of int.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-12-14 22:09:23 +01:00
parent 50c5d49d93
commit 388bd8f330
21 changed files with 82 additions and 84 deletions

View file

@ -180,8 +180,8 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
dive->mintemp.mkelvin ? put_format(&buf, "\\def\\%smintemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->mintemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%ssrfmintemp{}\n", ssrf); dive->mintemp.mkelvin ? put_format(&buf, "\\def\\%smintemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->mintemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%ssrfmintemp{}\n", ssrf);
dive->watertemp.mkelvin ? put_format(&buf, "\\def\\%swatertemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->watertemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%swatertemp{}\n", ssrf); dive->watertemp.mkelvin ? put_format(&buf, "\\def\\%swatertemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->watertemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%swatertemp{}\n", ssrf);
dive->airtemp.mkelvin ? put_format(&buf, "\\def\\%sairtemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->airtemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%sairtemp{}\n", ssrf); dive->airtemp.mkelvin ? put_format(&buf, "\\def\\%sairtemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->airtemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%sairtemp{}\n", ssrf);
dive->maxdepth.mm ? put_format(&buf, "\\def\\%smaximumdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smaximumdepth{}\n", ssrf); dive->maxdepth.mm ? put_format(&buf, "\\def\\%smaximumdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smaximumdepth{}\n", ssrf);
dive->meandepth.mm ? put_format(&buf, "\\def\\%smeandepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->meandepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smeandepth{}\n", ssrf); dive->meandepth.mm ? put_format(&buf, "\\def\\%smeandepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->meandepth, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smeandepth{}\n", ssrf);
std::string tags = taglist_get_tagstring(dive->tags); std::string tags = taglist_get_tagstring(dive->tags);
put_format(&buf, "\\def\\%stype{%s}\n", ssrf, tags.c_str()); put_format(&buf, "\\def\\%stype{%s}\n", ssrf, tags.c_str());
@ -242,7 +242,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
put_format(&buf, "\\def\\%sspot{}\n", ssrf); put_format(&buf, "\\def\\%sspot{}\n", ssrf);
put_format(&buf, "\\def\\%sentrance{}\n", ssrf); put_format(&buf, "\\def\\%sentrance{}\n", ssrf);
put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name.c_str() : ""); put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name.c_str() : "");
dive->maxdepth.mm ? put_format(&buf, "\\def\\%sdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%sdepth{}\n", ssrf); dive->maxdepth.mm ? put_format(&buf, "\\def\\%sdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%sdepth{}\n", ssrf);
put_format(&buf, "\\%spage\n", ssrf); put_format(&buf, "\\%spage\n", ssrf);
} }
@ -280,7 +280,7 @@ void export_depths(const char *filename, bool selected_only)
break; break;
depth = s.depth; depth = s.depth;
} }
put_format(&buf, "%s\t%.1f", picture.filename.c_str(), get_depth_units(depth.mm, NULL, &unit)); put_format(&buf, "%s\t%.1f", picture.filename.c_str(), get_depth_units(depth, NULL, &unit));
put_format(&buf, "%s\n", unit); put_format(&buf, "%s\n", unit);
} }
} }

View file

@ -154,7 +154,7 @@ void PlannerShared::set_decopo2(double value)
int PlannerShared::bestmixend() int PlannerShared::bestmixend()
{ {
return lrint(get_depth_units(prefs.bestmixend.mm, NULL, NULL)); return lrint(get_depth_units(prefs.bestmixend, NULL, NULL));
} }
void PlannerShared::set_bestmixend(int value) void PlannerShared::set_bestmixend(int value)
{ {

View file

@ -169,7 +169,7 @@ bool ConfigureDiveComputer::saveXMLBackup(const QString &fileName, const DeviceD
writer.writeStartElement("AlarmDepth"); writer.writeStartElement("AlarmDepth");
writer.writeAttribute("enabled", QString::number(details.alarmDepthEnabled)); writer.writeAttribute("enabled", QString::number(details.alarmDepthEnabled));
writer.writeCharacters(QString::number(details.alarmDepth)); writer.writeCharacters(QString::number(details.alarmDepth.mm));
writer.writeEndElement(); writer.writeEndElement();
writer.writeEndElement(); writer.writeEndElement();
@ -474,7 +474,7 @@ bool ConfigureDiveComputer::restoreXMLBackup(const QString &fileName, DeviceDeta
if (settingName == "AlarmDepth") { if (settingName == "AlarmDepth") {
if (attributes.hasAttribute("enabled")) if (attributes.hasAttribute("enabled"))
details.alarmDepthEnabled = attributes.value("enabled").toString().toInt(); details.alarmDepthEnabled = attributes.value("enabled").toString().toInt();
details.alarmDepth = keyString.toInt(); details.alarmDepth.mm = keyString.toInt();
} }
if (settingName == "AlarmTime") { if (settingName == "AlarmTime") {

View file

@ -176,7 +176,7 @@ static dc_status_t read_suunto_vyper_settings(dc_device_t *device, DeviceDetails
return rc; return rc;
// in ft * 128.0 // in ft * 128.0
int depth = feet_to_mm(data[0] << 8 ^ data[1]) / 128; int depth = feet_to_mm(data[0] << 8 ^ data[1]) / 128;
deviceDetails.maxDepth = depth; deviceDetails.maxDepth.mm = depth;
EMIT_PROGRESS(); EMIT_PROGRESS();
rc = dc_device_read(device, SUUNTO_VYPER_TOTAL_TIME, data, 2); rc = dc_device_read(device, SUUNTO_VYPER_TOTAL_TIME, data, 2);
@ -272,7 +272,7 @@ static dc_status_t read_suunto_vyper_settings(dc_device_t *device, DeviceDetails
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
depth = feet_to_mm(data[0] << 8 ^ data[1]) / 128; depth = feet_to_mm(data[0] << 8 ^ data[1]) / 128;
deviceDetails.alarmDepth = depth; deviceDetails.alarmDepth.mm = depth;
EMIT_PROGRESS(); EMIT_PROGRESS();
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
@ -354,8 +354,8 @@ static dc_status_t write_suunto_vyper_settings(dc_device_t *device, DeviceDetail
return rc; return rc;
EMIT_PROGRESS(); EMIT_PROGRESS();
data2[0] = (int)(mm_to_feet(deviceDetails.alarmDepth) * 128) >> 8; data2[0] = (int)(mm_to_feet(deviceDetails.alarmDepth.mm) * 128) >> 8;
data2[1] = (int)(mm_to_feet(deviceDetails.alarmDepth) * 128) & 0x0FF; data2[1] = (int)(mm_to_feet(deviceDetails.alarmDepth.mm) * 128) & 0x0FF;
rc = dc_device_write(device, SUUNTO_VYPER_ALARM_DEPTH, data2, 2); rc = dc_device_write(device, SUUNTO_VYPER_ALARM_DEPTH, data2, 2);
EMIT_PROGRESS(); EMIT_PROGRESS();
return rc; return rc;

View file

@ -41,7 +41,6 @@ DeviceDetails::DeviceDetails() :
pressureSensorOffset(0), pressureSensorOffset(0),
flipScreen(0), flipScreen(0),
safetyStop(0), safetyStop(0),
maxDepth(0),
totalTime(0), totalTime(0),
numberOfDives(0), numberOfDives(0),
altitude(0), altitude(0),
@ -52,7 +51,6 @@ DeviceDetails::DeviceDetails() :
alarmTimeEnabled(false), alarmTimeEnabled(false),
alarmTime(0), alarmTime(0),
alarmDepthEnabled(false), alarmDepthEnabled(false),
alarmDepth(0),
leftButtonSensitivity(0), leftButtonSensitivity(0),
rightButtonSensitivity(0), rightButtonSensitivity(0),
buttonSensitivity(0), buttonSensitivity(0),

View file

@ -5,6 +5,7 @@
#include <QObject> #include <QObject>
#include <QDateTime> #include <QDateTime>
#include "libdivecomputer.h" #include "libdivecomputer.h"
#include "units.h"
struct gas { struct gas {
unsigned char oxygen; unsigned char oxygen;
@ -73,7 +74,7 @@ public:
int pressureSensorOffset; int pressureSensorOffset;
bool flipScreen; bool flipScreen;
bool safetyStop; bool safetyStop;
int maxDepth; depth_t maxDepth;
int totalTime; int totalTime;
int numberOfDives; int numberOfDives;
int altitude; int altitude;
@ -84,7 +85,7 @@ public:
bool alarmTimeEnabled; bool alarmTimeEnabled;
int alarmTime; int alarmTime;
bool alarmDepthEnabled; bool alarmDepthEnabled;
int alarmDepth; depth_t alarmDepth;
int leftButtonSensitivity; int leftButtonSensitivity;
int rightButtonSensitivity; int rightButtonSensitivity;
int buttonSensitivity; int buttonSensitivity;

View file

@ -456,17 +456,17 @@ static std::vector<depth_t> sort_stops(const std::vector<depth_t> &dstops, size_
return stoplevels; return stoplevels;
} }
int ascent_velocity(depth_t depth, int avg_depth, int) int ascent_velocity(depth_t depth, depth_t avg_depth, int)
{ {
/* We need to make this configurable */ /* We need to make this configurable */
/* As an example (and possibly reasonable default) this is the Tech 1 provedure according /* As an example (and possibly reasonable default) this is the Tech 1 provedure according
* to http://www.globalunderwaterexplorers.org/files/Standards_and_Procedures/SOP_Manual_Ver2.0.2.pdf */ * to http://www.globalunderwaterexplorers.org/files/Standards_and_Procedures/SOP_Manual_Ver2.0.2.pdf */
if (depth.mm * 4 > avg_depth * 3) { if (depth.mm * 4 > avg_depth.mm * 3) {
return prefs.ascrate75; return prefs.ascrate75;
} else { } else {
if (depth.mm * 2 > avg_depth) { if (depth.mm * 2 > avg_depth.mm) {
return prefs.ascrate50; return prefs.ascrate50;
} else { } else {
if (depth.mm > 6000) if (depth.mm > 6000)
@ -477,7 +477,7 @@ int ascent_velocity(depth_t depth, int avg_depth, int)
} }
} }
static void track_ascent_gas(depth_t depth, struct dive *dive, int cylinder_id, int avg_depth, int bottom_time, bool safety_stop, enum divemode_t divemode) static void track_ascent_gas(depth_t depth, struct dive *dive, int cylinder_id, depth_t avg_depth, int bottom_time, bool safety_stop, enum divemode_t divemode)
{ {
cylinder_t *cylinder = dive->get_cylinder(cylinder_id); cylinder_t *cylinder = dive->get_cylinder(cylinder_id);
while (depth.mm > 0) { while (depth.mm > 0) {
@ -494,7 +494,7 @@ static void track_ascent_gas(depth_t depth, struct dive *dive, int cylinder_id,
} }
// Determine whether ascending to the next stop will break the ceiling. Return true if the ascent is ok, false if it isn't. // Determine whether ascending to the next stop will break the ceiling. Return true if the ascent is ok, false if it isn't.
static bool trial_ascent(struct deco_state *ds, int wait_time, depth_t trial_depth, depth_t stoplevel, int avg_depth, int bottom_time, struct gasmix gasmix, int po2, double surface_pressure, struct dive *dive, enum divemode_t divemode) static bool trial_ascent(struct deco_state *ds, int wait_time, depth_t trial_depth, depth_t stoplevel, depth_t avg_depth, int bottom_time, struct gasmix gasmix, int po2, double surface_pressure, struct dive *dive, enum divemode_t divemode)
{ {
bool clear_to_ascend = true; bool clear_to_ascend = true;
@ -562,7 +562,7 @@ static bool enough_gas(const struct dive *dive, int current_cylinder)
* leap is a guess for the maximum but there is no guarantee that leap is an upper limit. * leap is a guess for the maximum but there is no guarantee that leap is an upper limit.
* So we always test at the upper bundary, not in the middle! * So we always test at the upper bundary, not in the middle!
*/ */
static int wait_until(struct deco_state *ds, struct dive *dive, int clock, int min, int leap, int stepsize, depth_t depth, depth_t target_depth, int avg_depth, int bottom_time, struct gasmix gasmix, int po2, double surface_pressure, enum divemode_t divemode) static int wait_until(struct deco_state *ds, struct dive *dive, int clock, int min, int leap, int stepsize, depth_t depth, depth_t target_depth, depth_t avg_depth, int bottom_time, struct gasmix gasmix, int po2, double surface_pressure, enum divemode_t divemode)
{ {
// When a deco stop exceeds two days, there is something wrong... // When a deco stop exceeds two days, there is something wrong...
if (min >= 48 * 3600) if (min >= 48 * 3600)
@ -579,28 +579,26 @@ static int wait_until(struct deco_state *ds, struct dive *dive, int clock, int m
return wait_until(ds, dive, clock, min, leap / 2, stepsize, depth, target_depth, avg_depth, bottom_time, gasmix, po2, surface_pressure, divemode); return wait_until(ds, dive, clock, min, leap / 2, stepsize, depth, target_depth, avg_depth, bottom_time, gasmix, po2, surface_pressure, divemode);
} }
static void average_max_depth(const struct diveplan &dive, int *avg_depth, int *max_depth) // returns an (average_depth, maximum_depth) pair
static std::pair<depth_t, depth_t> average_max_depth(const struct diveplan &dive)
{ {
int integral = 0; depth_t integral; // Strictly speaking not a depth, but depth × time. Might want to define a custom time for that.
depth_t last_depth, max_depth;
int last_time = 0; int last_time = 0;
int last_depth = 0;
*max_depth = 0;
for (auto &dp: dive.dp) { for (auto &dp: dive.dp) {
if (dp.time) { if (dp.time) {
/* Ignore gas indication samples */ /* Ignore gas indication samples */
integral += (dp.depth.mm + last_depth) * (dp.time - last_time) / 2; integral += (dp.depth + last_depth) * (dp.time - last_time) / 2;
last_time = dp.time; last_time = dp.time;
last_depth = dp.depth.mm; last_depth = dp.depth;
if (dp.depth.mm > *max_depth) if (dp.depth.mm > max_depth.mm)
*max_depth = dp.depth.mm; max_depth = dp.depth;
} }
} }
if (last_time) if (last_time)
*avg_depth = integral / last_time; return { integral / last_time, max_depth };
else return { 0_m, 0_m };
*avg_depth = *max_depth = 0;
} }
std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, int dcNr, int timestep, deco_state_cache &cache, bool is_planner, bool show_disclaimer) std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, int dcNr, int timestep, deco_state_cache &cache, bool is_planner, bool show_disclaimer)
@ -619,7 +617,6 @@ std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, str
bool stopping = false; bool stopping = false;
bool pendinggaschange = false; bool pendinggaschange = false;
int clock, previous_point_time; int clock, previous_point_time;
int avg_depth, max_depth;
int last_ascend_rate; int last_ascend_rate;
int best_first_ascend_cylinder = -1; int best_first_ascend_cylinder = -1;
struct gasmix gas, bottom_gas; struct gasmix gas, bottom_gas;
@ -678,7 +675,7 @@ std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, str
po2 = sample.setpoint.mbar; po2 = sample.setpoint.mbar;
depth_t depth = sample.depth; depth_t depth = sample.depth;
average_max_depth(diveplan, &avg_depth, &max_depth); auto [avg_depth, max_depth] = average_max_depth(diveplan);
last_ascend_rate = ascent_velocity(depth, avg_depth, bottom_time); last_ascend_rate = ascent_velocity(depth, avg_depth, bottom_time);
/* if all we wanted was the dive just get us back to the surface */ /* if all we wanted was the dive just get us back to the surface */
@ -723,7 +720,7 @@ std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, str
nuclear_regeneration(ds, clock); nuclear_regeneration(ds, clock);
vpmb_start_gradient(ds); vpmb_start_gradient(ds);
if (decoMode(true) == RECREATIONAL) { if (decoMode(true) == RECREATIONAL) {
bool safety_stop = prefs.safetystop && max_depth >= 10000; bool safety_stop = prefs.safetystop && max_depth.mm >= 10000;
track_ascent_gas(depth, dive, current_cylinder, avg_depth, bottom_time, safety_stop, divemode); track_ascent_gas(depth, dive, current_cylinder, avg_depth, bottom_time, safety_stop, divemode);
// How long can we stay at the current depth and still directly ascent to the surface? // How long can we stay at the current depth and still directly ascent to the surface?
do { do {

View file

@ -58,7 +58,7 @@ struct diveplan {
struct deco_state_cache; struct deco_state_cache;
extern int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_t time); extern int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_t time);
extern int ascent_velocity(depth_t depth, int avg_depth, int); extern int ascent_velocity(depth_t depth, depth_t avg_depth, int);
extern const char *get_planner_disclaimer(); extern const char *get_planner_disclaimer();
void plan_add_segment(struct diveplan &diveplan, int duration, depth_t depth, int cylinderid, int po2, bool entered, enum divemode_t divemode); void plan_add_segment(struct diveplan &diveplan, int duration, depth_t depth, int cylinderid, int po2, bool entered, enum divemode_t divemode);

View file

@ -202,7 +202,7 @@ void diveplan::add_plan_to_notes(struct dive &dive, bool show_disclaimer, planne
if (dp->time == 0) if (dp->time == 0)
continue; continue;
gasmix = dive.get_cylinder(dp->cylinderid)->gasmix; gasmix = dive.get_cylinder(dp->cylinderid)->gasmix;
depthvalue = get_depth_units(dp->depth.mm, &decimals, &depth_unit); depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
/* analyze the dive points ahead */ /* analyze the dive points ahead */
while (nextdp != this->dp.end() && nextdp->time == 0) while (nextdp != this->dp.end() && nextdp->time == 0)
++nextdp; ++nextdp;
@ -443,7 +443,7 @@ void diveplan::add_plan_to_notes(struct dive &dive, bool show_disclaimer, planne
{ {
const char *depth_unit; const char *depth_unit;
int altitude = (int) get_depth_units(pressure_to_altitude(surface_pressure).mm, NULL, &depth_unit); int altitude = (int) get_depth_units(pressure_to_altitude(surface_pressure), NULL, &depth_unit);
buf += casprintf_loc(translate("gettextFromC", "ATM pressure: %dmbar (%d%s)<br/>\n</div>\n"), surface_pressure, altitude, depth_unit); buf += casprintf_loc(translate("gettextFromC", "ATM pressure: %dmbar (%d%s)<br/>\n</div>\n"), surface_pressure, altitude, depth_unit);
} }
@ -519,7 +519,7 @@ void diveplan::add_plan_to_notes(struct dive &dive, bool show_disclaimer, planne
mingas_volume = get_volume_units(mingasv.mliter, NULL, &unit); mingas_volume = get_volume_units(mingasv.mliter, NULL, &unit);
mingas_pressure = get_pressure_units(lastbottomdp->minimum_gas.mbar, &pressure_unit); mingas_pressure = get_pressure_units(lastbottomdp->minimum_gas.mbar, &pressure_unit);
mingas_d_pressure = get_pressure_units(lrint((double)cyl.end.mbar + deco_pressure_mbar - lastbottomdp->minimum_gas.mbar), &pressure_unit); mingas_d_pressure = get_pressure_units(lrint((double)cyl.end.mbar + deco_pressure_mbar - lastbottomdp->minimum_gas.mbar), &pressure_unit);
mingas_depth = get_depth_units(lastbottomdp->depth.mm, NULL, &depth_unit); mingas_depth = get_depth_units(lastbottomdp->depth, NULL, &depth_unit);
/* Print it to results */ /* Print it to results */
if (cyl.start.mbar > lastbottomdp->minimum_gas.mbar) { if (cyl.start.mbar > lastbottomdp->minimum_gas.mbar) {
mingas = casprintf_loc("<br/>\n&nbsp;&mdash; <span style='color: %s;'>%s</span> (%s %.1fx%s/+%d%s@%.0f%s): " mingas = casprintf_loc("<br/>\n&nbsp;&mdash; <span style='color: %s;'>%s</span> (%s %.1fx%s/+%d%s@%.0f%s): "
@ -595,7 +595,7 @@ void diveplan::add_plan_to_notes(struct dive &dive, bool show_disclaimer, planne
if (pressures.o2 > (dp.entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) { if (pressures.o2 > (dp.entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) {
const char *depth_unit; const char *depth_unit;
int decimals; int decimals;
double depth_value = get_depth_units(dp.depth.mm, &decimals, &depth_unit); double depth_value = get_depth_units(dp.depth, &decimals, &depth_unit);
if (!o2warning_exist) if (!o2warning_exist)
buf += "<div>\n"; buf += "<div>\n";
o2warning_exist = true; o2warning_exist = true;
@ -605,7 +605,7 @@ void diveplan::add_plan_to_notes(struct dive &dive, bool show_disclaimer, planne
} else if (pressures.o2 < 0.16) { } else if (pressures.o2 < 0.16) {
const char *depth_unit; const char *depth_unit;
int decimals; int decimals;
double depth_value = get_depth_units(dp.depth.mm, &decimals, &depth_unit); double depth_value = get_depth_units(dp.depth, &decimals, &depth_unit);
if (!o2warning_exist) if (!o2warning_exist)
buf += "<div>"; buf += "<div>";
o2warning_exist = true; o2warning_exist = true;

View file

@ -326,7 +326,7 @@ static void insert_entry(struct plot_info &pi, int time, depth_t depth, int sac)
entry = prev; entry = prev;
entry.sec = time; entry.sec = time;
entry.depth = depth; entry.depth = depth;
entry.running_sum = prev.running_sum + (time - prev.sec) * (depth + prev.depth).mm / 2; entry.running_sum = prev.running_sum + (depth + prev.depth) * (time - prev.sec) / 2;
entry.sac = sac; entry.sac = sac;
entry.ndl = -1; entry.ndl = -1;
entry.bearing = -1; entry.bearing = -1;
@ -401,7 +401,7 @@ static void populate_plot_entries(const struct dive *dive, const struct divecomp
entry.sec = time; entry.sec = time;
entry.depth = sample.depth; entry.depth = sample.depth;
entry.running_sum = prev.running_sum + (time - prev.sec) * (sample.depth.mm + prev.depth.mm) / 2; entry.running_sum = prev.running_sum + (sample.depth + prev.depth) * (time - prev.sec) / 2;
entry.stopdepth = sample.stopdepth; entry.stopdepth = sample.stopdepth;
entry.stoptime = sample.stoptime.seconds; entry.stoptime = sample.stoptime.seconds;
entry.ndl = sample.ndl.seconds; entry.ndl = sample.ndl.seconds;
@ -1268,7 +1268,7 @@ static std::vector<std::string> plot_string(const struct dive *d, const struct p
const struct plot_data &entry = pi.entry[idx]; const struct plot_data &entry = pi.entry[idx];
std::vector<std::string> res; std::vector<std::string> res;
depthvalue = get_depth_units(entry.depth.mm, NULL, &depth_unit); depthvalue = get_depth_units(entry.depth, NULL, &depth_unit);
res.push_back(casprintf_loc(translate("gettextFromC", "@: %d:%02d"), FRACTION_TUPLE(entry.sec, 60))); res.push_back(casprintf_loc(translate("gettextFromC", "@: %d:%02d"), FRACTION_TUPLE(entry.sec, 60)));
res.push_back(casprintf_loc(translate("gettextFromC", "D: %.1f%s"), depthvalue, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "D: %.1f%s"), depthvalue, depth_unit));
for (cyl = 0; cyl < pi.nr_cylinders; cyl++) { for (cyl = 0; cyl < pi.nr_cylinders; cyl++) {
@ -1303,23 +1303,23 @@ static std::vector<std::string> plot_string(const struct dive *d, const struct p
if (prefs.pp_graphs.phe && entry.pressures.he > 0) if (prefs.pp_graphs.phe && entry.pressures.he > 0)
res.push_back(casprintf_loc(translate("gettextFromC", "pHe: %.2fbar"), entry.pressures.he)); res.push_back(casprintf_loc(translate("gettextFromC", "pHe: %.2fbar"), entry.pressures.he));
if (prefs.mod && entry.mod.mm > 0) { if (prefs.mod && entry.mod.mm > 0) {
mod.mm = lrint(get_depth_units(entry.mod.mm, NULL, &depth_unit)); mod.mm = lrint(get_depth_units(entry.mod, NULL, &depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "MOD: %d%s"), mod.mm, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "MOD: %d%s"), mod.mm, depth_unit));
} }
eadd.mm = lrint(get_depth_units(entry.eadd.mm, NULL, &depth_unit)); eadd.mm = lrint(get_depth_units(entry.eadd, NULL, &depth_unit));
if (prefs.ead) { if (prefs.ead) {
switch (pi.dive_type) { switch (pi.dive_type) {
case plot_info::NITROX: case plot_info::NITROX:
if (entry.ead.mm > 0) { if (entry.ead.mm > 0) {
ead.mm = lrint(get_depth_units(entry.ead.mm, NULL, &depth_unit)); ead.mm = lrint(get_depth_units(entry.ead, NULL, &depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "EAD: %d%s"), ead.mm, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "EAD: %d%s"), ead.mm, depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd.mm, depth_unit, entry.density)); res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd.mm, depth_unit, entry.density));
break; break;
} }
case plot_info::TRIMIX: case plot_info::TRIMIX:
if (entry.end.mm > 0) { if (entry.end.mm > 0) {
end.mm = lrint(get_depth_units(entry.end.mm, NULL, &depth_unit)); end.mm = lrint(get_depth_units(entry.end, NULL, &depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "END: %d%s"), end.mm, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "END: %d%s"), end.mm, depth_unit));
res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd.mm, depth_unit, entry.density)); res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/"), eadd.mm, depth_unit, entry.density));
break; break;
@ -1334,7 +1334,7 @@ static std::vector<std::string> plot_string(const struct dive *d, const struct p
} }
} }
if (entry.stopdepth.mm > 0) { if (entry.stopdepth.mm > 0) {
depthvalue = get_depth_units(entry.stopdepth.mm, NULL, &depth_unit); depthvalue = get_depth_units(entry.stopdepth, NULL, &depth_unit);
if (entry.ndl > 0) { if (entry.ndl > 0) {
/* this is a safety stop as we still have ndl */ /* this is a safety stop as we still have ndl */
if (entry.stoptime) if (entry.stoptime)
@ -1360,7 +1360,7 @@ static std::vector<std::string> plot_string(const struct dive *d, const struct p
if (entry.tts) if (entry.tts)
res.push_back(casprintf_loc(translate("gettextFromC", "TTS: %umin"), div_up(entry.tts, 60))); res.push_back(casprintf_loc(translate("gettextFromC", "TTS: %umin"), div_up(entry.tts, 60)));
if (entry.stopdepth_calc.mm > 0 && entry.stoptime_calc) { if (entry.stopdepth_calc.mm > 0 && entry.stoptime_calc) {
depthvalue = get_depth_units(entry.stopdepth_calc.mm, NULL, &depth_unit); depthvalue = get_depth_units(entry.stopdepth_calc, NULL, &depth_unit);
res.push_back(casprintf_loc(translate("gettextFromC", "Deco: %umin @ %.0f%s (calc)"), div_up(entry.stoptime_calc, 60), res.push_back(casprintf_loc(translate("gettextFromC", "Deco: %umin @ %.0f%s (calc)"), div_up(entry.stoptime_calc, 60),
depthvalue, depth_unit)); depthvalue, depth_unit));
} else if (entry.in_deco_calc) { } else if (entry.in_deco_calc) {
@ -1390,13 +1390,13 @@ static std::vector<std::string> plot_string(const struct dive *d, const struct p
if (entry.surface_gf > 0.0) if (entry.surface_gf > 0.0)
res.push_back(casprintf_loc(translate("gettextFromC", "Surface GF %.0f%%"), entry.surface_gf)); res.push_back(casprintf_loc(translate("gettextFromC", "Surface GF %.0f%%"), entry.surface_gf));
if (entry.ceiling.mm > 0) { if (entry.ceiling.mm > 0) {
depthvalue = get_depth_units(entry.ceiling.mm, NULL, &depth_unit); depthvalue = get_depth_units(entry.ceiling, NULL, &depth_unit);
res.push_back(casprintf_loc(translate("gettextFromC", "Calculated ceiling %.1f%s"), depthvalue, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "Calculated ceiling %.1f%s"), depthvalue, depth_unit));
if (prefs.calcalltissues) { if (prefs.calcalltissues) {
int k; int k;
for (k = 0; k < 16; k++) { for (k = 0; k < 16; k++) {
if (entry.ceilings[k].mm > 0) { if (entry.ceilings[k].mm > 0) {
depthvalue = get_depth_units(entry.ceilings[k].mm, NULL, &depth_unit); depthvalue = get_depth_units(entry.ceilings[k], NULL, &depth_unit);
res.push_back(casprintf_loc(translate("gettextFromC", "Tissue %.0fmin: %.1f%s"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "Tissue %.0fmin: %.1f%s"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit));
} }
} }
@ -1409,7 +1409,7 @@ static std::vector<std::string> plot_string(const struct dive *d, const struct p
res.push_back(casprintf_loc(translate("gettextFromC", "heart rate: %d"), entry.heartbeat)); res.push_back(casprintf_loc(translate("gettextFromC", "heart rate: %d"), entry.heartbeat));
if (entry.bearing >= 0) if (entry.bearing >= 0)
res.push_back(casprintf_loc(translate("gettextFromC", "bearing: %d"), entry.bearing)); res.push_back(casprintf_loc(translate("gettextFromC", "bearing: %d"), entry.bearing));
if (entry.running_sum) { if (entry.running_sum.mm > 0) {
depthvalue = get_depth_units(entry.running_sum / entry.sec, NULL, &depth_unit); depthvalue = get_depth_units(entry.running_sum / entry.sec, NULL, &depth_unit);
res.push_back(casprintf_loc(translate("gettextFromC", "mean depth to here %.1f%s"), depthvalue, depth_unit)); res.push_back(casprintf_loc(translate("gettextFromC", "mean depth to here %.1f%s"), depthvalue, depth_unit));
} }
@ -1458,7 +1458,8 @@ std::vector<std::string> compare_samples(const struct dive *d, const struct plot
int max_asc_speed = 0; int max_asc_speed = 0;
int max_desc_speed = 0; int max_desc_speed = 0;
int delta_depth = abs(start.depth.mm - stop.depth.mm); depth_t delta_depth = start.depth - stop.depth;
delta_depth.mm = std::abs(delta_depth.mm);
int delta_time = abs(start.sec - stop.sec); int delta_time = abs(start.sec - stop.sec);
depth_t avg_depth; depth_t avg_depth;
depth_t max_depth; depth_t max_depth;
@ -1527,13 +1528,13 @@ std::vector<std::string> compare_samples(const struct dive *d, const struct plot
depthvalue = get_depth_units(delta_depth, NULL, &depth_unit); depthvalue = get_depth_units(delta_depth, NULL, &depth_unit);
l += space + casprintf_loc(translate("gettextFromC", "ΔD:%.1f%s"), depthvalue, depth_unit); l += space + casprintf_loc(translate("gettextFromC", "ΔD:%.1f%s"), depthvalue, depth_unit);
depthvalue = get_depth_units(min_depth.mm, NULL, &depth_unit); depthvalue = get_depth_units(min_depth, NULL, &depth_unit);
l += space + casprintf_loc(translate("gettextFromC", "↓D:%.1f%s"), depthvalue, depth_unit); l += space + casprintf_loc(translate("gettextFromC", "↓D:%.1f%s"), depthvalue, depth_unit);
depthvalue = get_depth_units(max_depth.mm, NULL, &depth_unit); depthvalue = get_depth_units(max_depth, NULL, &depth_unit);
l += space + casprintf_loc(translate("gettextFromC", "↑D:%.1f%s"), depthvalue, depth_unit); l += space + casprintf_loc(translate("gettextFromC", "↑D:%.1f%s"), depthvalue, depth_unit);
depthvalue = get_depth_units(avg_depth.mm, NULL, &depth_unit); depthvalue = get_depth_units(avg_depth, NULL, &depth_unit);
l += space + casprintf_loc(translate("gettextFromC", "øD:%.1f%s"), depthvalue, depth_unit); l += space + casprintf_loc(translate("gettextFromC", "øD:%.1f%s"), depthvalue, depth_unit);
res.push_back(l); res.push_back(l);

View file

@ -53,7 +53,7 @@ struct plot_data {
int cns = 0; int cns = 0;
depth_t smoothed; depth_t smoothed;
int sac = 0; int sac = 0;
int running_sum = 0; depth_t running_sum; // strictly speaking not a depth, but depth × time. Might define a custom type for that based on a longer integer.
struct gas_pressures pressures; struct gas_pressures pressures;
// TODO: make pressure_t default to 0 // TODO: make pressure_t default to 0
pressure_t o2pressure; // for rebreathers, this is consensus measured po2, or setpoint otherwise. 0 for OC. pressure_t o2pressure; // for rebreathers, this is consensus measured po2, or setpoint otherwise. 0 for OC.

View file

@ -281,7 +281,7 @@ void put_HTML_depth(struct membuffer *b, const struct dive &dive, const char *pr
put_format(b, "%s--%s", pre, post); put_format(b, "%s--%s", pre, post);
return; return;
} }
value = get_depth_units(dive.maxdepth.mm, NULL, &unit); value = get_depth_units(dive.maxdepth, NULL, &unit);
switch (units_p->length) { switch (units_p->length) {
case units::METERS: case units::METERS:

View file

@ -83,7 +83,7 @@ static void put_pd(struct membuffer *b, const struct plot_info &pi, int idx)
put_int(b, entry.cns); put_int(b, entry.cns);
put_int(b, entry.smoothed.mm); put_int(b, entry.smoothed.mm);
put_int(b, entry.sac); put_int(b, entry.sac);
put_int(b, entry.running_sum); put_int(b, entry.running_sum.mm);
put_double(b, entry.pressures.o2); put_double(b, entry.pressures.o2);
put_double(b, entry.pressures.n2); put_double(b, entry.pressures.n2);
put_double(b, entry.pressures.he); put_double(b, entry.pressures.he);
@ -199,7 +199,7 @@ static std::string format_st_event(const plot_data &entry, const plot_data &next
std::string format_string = prefs.subtitles_format_string; std::string format_string = prefs.subtitles_format_string;
replace_all(format_string, "[time]", format_string_std("%d:%02d", FRACTION_TUPLE(entry.sec, 60))); replace_all(format_string, "[time]", format_string_std("%d:%02d", FRACTION_TUPLE(entry.sec, 60)));
value = get_depth_units(entry.depth.mm, &decimals, &unit); value = get_depth_units(entry.depth, &decimals, &unit);
replace_all(format_string, "[depth]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[depth]", format_string_std("%02.2f %s", value, unit));
if (entry.temperature) { if (entry.temperature) {
@ -210,7 +210,7 @@ static std::string format_st_event(const plot_data &entry, const plot_data &next
} }
if (entry.ceiling.mm > 0) { if (entry.ceiling.mm > 0) {
value = get_depth_units(entry.ceiling.mm, &decimals, &unit); value = get_depth_units(entry.ceiling, &decimals, &unit);
replace_all(format_string,"[ceiling]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string,"[ceiling]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[ceiling]", ""); replace_all(format_string, "[ceiling]", "");
@ -245,7 +245,7 @@ static std::string format_st_event(const plot_data &entry, const plot_data &next
} }
if (entry.stopdepth.mm > 0) { if (entry.stopdepth.mm > 0) {
value = get_depth_units(entry.stopdepth.mm, &decimals, &unit); value = get_depth_units(entry.stopdepth, &decimals, &unit);
replace_all(format_string, "[stopdepth]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[stopdepth]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[stopdepth]", ""); replace_all(format_string, "[stopdepth]", "");
@ -297,28 +297,28 @@ static std::string format_st_event(const plot_data &entry, const plot_data &next
} }
if (entry.mod.mm > 0) { if (entry.mod.mm > 0) {
value = get_depth_units(entry.mod.mm, &decimals, &unit); value = get_depth_units(entry.mod, &decimals, &unit);
replace_all(format_string, "[mod]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[mod]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[mod]", ""); replace_all(format_string, "[mod]", "");
} }
if (entry.ead.mm > 0) { if (entry.ead.mm > 0) {
value = get_depth_units(entry.ead.mm, &decimals, &unit); value = get_depth_units(entry.ead, &decimals, &unit);
replace_all(format_string, "[ead]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[ead]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[ead]", ""); replace_all(format_string, "[ead]", "");
} }
if (entry.end.mm > 0) { if (entry.end.mm > 0) {
value = get_depth_units(entry.end.mm, &decimals, &unit); value = get_depth_units(entry.end, &decimals, &unit);
replace_all(format_string, "[end]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[end]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[end]", ""); replace_all(format_string, "[end]", "");
} }
if (entry.eadd.mm > 0) { if (entry.eadd.mm > 0) {
value = get_depth_units(entry.eadd.mm, &decimals, &unit); value = get_depth_units(entry.eadd, &decimals, &unit);
replace_all(format_string, "[eadd]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[eadd]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[eadd]", ""); replace_all(format_string, "[eadd]", "");
@ -359,7 +359,7 @@ static std::string format_st_event(const plot_data &entry, const plot_data &next
} }
if (entry.stopdepth_calc.mm > 0) { if (entry.stopdepth_calc.mm > 0) {
value = get_depth_units(entry.stopdepth_calc.mm, &decimals, &unit); value = get_depth_units(entry.stopdepth_calc, &decimals, &unit);
replace_all(format_string, "[stopdepth_calc]", format_string_std("%02.2f %s", value, unit)); replace_all(format_string, "[stopdepth_calc]", format_string_std("%02.2f %s", value, unit));
} else { } else {
replace_all(format_string, "[stopdepth_calc]", ""); replace_all(format_string, "[stopdepth_calc]", "");

View file

@ -95,7 +95,7 @@ depth_t units_to_depth(double depth)
return internaldepth; return internaldepth;
} }
double get_depth_units(int mm, int *frac, const char **units) double get_depth_units(depth_t depth, int *frac, const char **units)
{ {
int decimals; int decimals;
double d; double d;
@ -105,12 +105,12 @@ double get_depth_units(int mm, int *frac, const char **units)
switch (units_p->length) { switch (units_p->length) {
case units::METERS: case units::METERS:
default: default:
d = mm / 1000.0; d = depth.mm / 1000.0;
unit = translate("gettextFromC", "m"); unit = translate("gettextFromC", "m");
decimals = d < 20; decimals = d < 20;
break; break;
case units::FEET: case units::FEET:
d = mm_to_feet(mm); d = mm_to_feet(depth.mm);
unit = translate("gettextFromC", "ft"); unit = translate("gettextFromC", "ft");
decimals = 0; decimals = 0;
break; break;

View file

@ -498,7 +498,7 @@ extern const struct units SI_units, IMPERIAL_units;
extern const struct units *get_units(); extern const struct units *get_units();
extern int get_pressure_units(int mb, const char **units); extern int get_pressure_units(int mb, const char **units);
extern double get_depth_units(int mm, int *frac, const char **units); extern double get_depth_units(depth_t mm, int *frac, const char **units);
extern double get_volume_units(unsigned int ml, int *frac, const char **units); extern double get_volume_units(unsigned int ml, int *frac, const char **units);
extern double get_temp_units(unsigned int mk, const char **units); extern double get_temp_units(unsigned int mk, const char **units);
extern double get_weight_units(unsigned int grams, int *frac, const char **units); extern double get_weight_units(unsigned int grams, int *frac, const char **units);

View file

@ -753,7 +753,7 @@ void ConfigureDiveComputerDialog::populateDeviceDetailsSuuntoVyper()
deviceDetails.lightEnabled = ui.lightCheckBox->isChecked(); deviceDetails.lightEnabled = ui.lightCheckBox->isChecked();
deviceDetails.light = ui.lightSpinBox->value(); deviceDetails.light = ui.lightSpinBox->value();
deviceDetails.alarmDepthEnabled = ui.alarmDepthCheckBox->isChecked(); deviceDetails.alarmDepthEnabled = ui.alarmDepthCheckBox->isChecked();
deviceDetails.alarmDepth = units_to_depth(ui.alarmDepthDoubleSpinBox->value()).mm; deviceDetails.alarmDepth = units_to_depth(ui.alarmDepthDoubleSpinBox->value());
deviceDetails.alarmTimeEnabled = ui.alarmTimeCheckBox->isChecked(); deviceDetails.alarmTimeEnabled = ui.alarmTimeCheckBox->isChecked();
deviceDetails.alarmTime = ui.alarmTimeSpinBox->value(); deviceDetails.alarmTime = ui.alarmTimeSpinBox->value();
} }

View file

@ -163,7 +163,7 @@ void DivePlannerWidget::settingsChanged()
} }
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DEPTH, new SpinBoxDelegate(0, maxDepth, 1, this)); ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DEPTH, new SpinBoxDelegate(0, maxDepth, 1, this));
ui.atmHeight->blockSignals(true); ui.atmHeight->blockSignals(true);
ui.atmHeight->setValue((int) get_depth_units(pressure_to_altitude(DivePlannerPointsModel::instance()->getSurfacePressure()).mm, NULL, NULL)); ui.atmHeight->setValue((int) get_depth_units(pressure_to_altitude(DivePlannerPointsModel::instance()->getSurfacePressure()), NULL, NULL));
ui.atmHeight->blockSignals(false); ui.atmHeight->blockSignals(false);
ui.dateEdit->setDisplayFormat(QString::fromStdString(prefs.date_format)); ui.dateEdit->setDisplayFormat(QString::fromStdString(prefs.date_format));
@ -175,7 +175,7 @@ void DivePlannerWidget::atmPressureChanged(int pressure_in_mbar)
pressure_t pressure { .mbar = pressure_in_mbar }; pressure_t pressure { .mbar = pressure_in_mbar };
DivePlannerPointsModel::instance()->setSurfacePressure(pressure); DivePlannerPointsModel::instance()->setSurfacePressure(pressure);
ui.atmHeight->blockSignals(true); ui.atmHeight->blockSignals(true);
ui.atmHeight->setValue((int) get_depth_units(pressure_to_altitude(pressure).mm, NULL, NULL)); ui.atmHeight->setValue((int) get_depth_units(pressure_to_altitude(pressure), NULL, NULL));
ui.atmHeight->blockSignals(false); ui.atmHeight->blockSignals(false);
} }
@ -457,7 +457,7 @@ void PlannerSettingsWidget::updateUnitsUI()
ui.ascRateStops->setValue(plannerModel->ascratestopsDisplay()); ui.ascRateStops->setValue(plannerModel->ascratestopsDisplay());
ui.ascRateLast6m->setValue(plannerModel->ascratelast6mDisplay()); ui.ascRateLast6m->setValue(plannerModel->ascratelast6mDisplay());
ui.descRate->setValue(lrint(plannerModel->descrateDisplay())); ui.descRate->setValue(lrint(plannerModel->descrateDisplay()));
ui.bestmixEND->setValue(lrint(get_depth_units(prefs.bestmixend.mm, NULL, NULL))); ui.bestmixEND->setValue(lrint(get_depth_units(prefs.bestmixend, NULL, NULL)));
} }
PlannerSettingsWidget::~PlannerSettingsWidget() PlannerSettingsWidget::~PlannerSettingsWidget()

View file

@ -142,7 +142,8 @@ void DiveEventItem::setupToolTipString(struct gasmix lastgasmix)
name += QString(": %1bar").arg((double)value / 1000, 0, 'f', 1); name += QString(": %1bar").arg((double)value / 1000, 0, 'f', 1);
} else if (type == SAMPLE_EVENT_CEILING && ev.name == "planned waypoint above ceiling") { } else if (type == SAMPLE_EVENT_CEILING && ev.name == "planned waypoint above ceiling") {
const char *depth_unit; const char *depth_unit;
double depth_value = get_depth_units(value*1000, NULL, &depth_unit); depth_t depth { .mm = value * 1000 };
double depth_value = get_depth_units(depth, NULL, &depth_unit);
name += QString(": %1%2").arg((int) round(depth_value)).arg(depth_unit); name += QString(": %1%2").arg((int) round(depth_value)).arg(depth_unit);
} else { } else {
name += QString(": %1").arg(value); name += QString(": %1").arg(value);

View file

@ -450,9 +450,9 @@ std::pair<double,double> DiveMeanDepthItem::getMeanDepth(int i) const
{ {
for ( ; i >= 0; --i) { for ( ; i >= 0; --i) {
const plot_data &entry = pInfo.entry[i]; const plot_data &entry = pInfo.entry[i];
if (entry.running_sum > 0) if (entry.running_sum.mm > 0)
return { static_cast<double>(entry.sec), return { static_cast<double>(entry.sec),
static_cast<double>(entry.running_sum) / entry.sec }; static_cast<double>(entry.running_sum.mm) / entry.sec };
} }
return { 0.0, 0.0 }; return { 0.0, 0.0 };
} }
@ -462,9 +462,9 @@ std::pair<double,double> DiveMeanDepthItem::getNextMeanDepth(int first) const
int last = pInfo.nr; int last = pInfo.nr;
for (int i = first + 1; i < last; ++i) { for (int i = first + 1; i < last; ++i) {
const plot_data &entry = pInfo.entry[i]; const plot_data &entry = pInfo.entry[i];
if (entry.running_sum > 0) if (entry.running_sum.mm > 0)
return { static_cast<double>(entry.sec), return { static_cast<double>(entry.sec),
static_cast<double>(entry.running_sum) / entry.sec }; static_cast<double>(entry.running_sum.mm) / entry.sec };
} }
return getMeanDepth(first); return getMeanDepth(first);
} }

View file

@ -117,7 +117,7 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) :
[](const plot_data &item) { return (double)item.temperature; }, [](const plot_data &item) { return (double)item.temperature; },
1, dpr)), 1, dpr)),
meanDepthItem(createItem<DiveMeanDepthItem>(*profileYAxis, meanDepthItem(createItem<DiveMeanDepthItem>(*profileYAxis,
[](const plot_data &item) { return (double)item.running_sum; }, [](const plot_data &item) { return (double)item.running_sum.mm; },
1, dpr)), 1, dpr)),
gasPressureItem(createItem<DiveGasPressureItem>(*cylinderPressureAxis, gasPressureItem(createItem<DiveGasPressureItem>(*cylinderPressureAxis,
[](const plot_data &item) { return 0.0; }, // unused [](const plot_data &item) { return 0.0; }, // unused

View file

@ -296,7 +296,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const
case CCSETPOINT: case CCSETPOINT:
return (divemode == CCR) ? (double)(p.setpoint / 1000.0) : QVariant(); return (divemode == CCR) ? (double)(p.setpoint / 1000.0) : QVariant();
case DEPTH: case DEPTH:
return int_cast<int>(get_depth_units(p.depth.mm, NULL, NULL)); return int_cast<int>(get_depth_units(p.depth, NULL, NULL));
case RUNTIME: case RUNTIME:
return p.time / 60; return p.time / 60;
case DURATION: case DURATION: