We had hardcoded the exact translation of the event numbers. They
haven't changed (although we did have what appears to be a spurious
entry for "non stop time" at the end that libdivecomputer doesn't have
an enum for).
Instead, use an explicit array index initializer array, so that it's
obvious that the two match up (and if the sample event numbers ever
change, we should cope with it gracefully).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
New libdivecomputer versions use DC_SAMPLE_GASMIX to indicate a gas
change (which contains the cylinder index we're changing to) rather than
SAMPLE_EVENT_GASCHANGE*.
Unlike the old GASCHANGE model, and despite the name, DC_SAMPLE_GASMIX
does not actually say what the mix is, it only specifies a cylinder
index. We had already extended SAMPLE_EVENT_GASCHANGE2 to have the
cylinder index in the otherwise unused "flags" field, so this is not all
that different from what we used to do.
And subsurface internally already had the logic that "if we know what
the cylinder index is, take the gas mix from the cylinder data", so
we've already been able to transparently use _either_ the actual gas mix
or the cylinder index to show the event.
But we do want to make it an event rather than some sample data, because
we want to show it as such in the profile. But because we are happy
with just the cylinder index, we'll just translate the DC_SAMPLE_GASMIX
thing to the SAMPLE_EVENT_GASCHANGE2 event, and nothing really changes
for subsurface.
libdivecomputer has made other changes, like indicating the initial
cylinder index with an early DC_SAMPLE_GASMIX report, but we've seen
that before too (in the form of early SAMPLE_EVENT_GASCHANGE events), so
that doesn't really end up changing anything for us either.
HOWEVER, one thing that is worth noticing: do *not* apply this patch and
then use an old libdivecomputer library that sends both the
DC_SAMPLE_GASMIX samples _and_ the deprecated SAMPLE_EVENT_GASCHANGE
events. It will all *work*, but since subsurface will take either,
you'll then get duplicate gas mix events.
It's not like that is in any way fatal, but it might be a bit confusing.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Modify formluas for gas use to take into account the
compressibility correction for real gases. This introduces
also the inverse formula to compute the pressure for a given
amount of gas.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Our attempt to skip any white space after the comma causes an ASSERT (strangely
only on Macs).
This closes#158
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds tooltips for the equipment tab for each cylinder, showing the
amount of gas used.
When you mouse over the size and working pressure fields, the tooltip will
show the amount of gas used (along with start and end gas volumes). And
when you mouse over the start and end pressures, it will show the start
and end gas volumes, and the Z factor used.
I started doing this because of the gas volume questions in the last day
or two (and a few from a few weeks ago). When even Robert Helling starts
wondering about the effects of compressibility on the SAC calculation, our
numbers are clearly too opaque.
With these tooltips, at least you can see what went into the used gas
calculations, instead of having to add debugging options to print out Z
factors.
[ This patch also adds a "rint()" to get the rounding right in the
gas_volume() function. Although rounding to the nearst milliliter
really doesn't matter, it's the right thing to do after doing FP
calculations ;^]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Instead of creating the individual parsers, and keeping track of their
arguments, this just uses the "new" dc_parser_new2 function ment for
buffer parsing.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
This removes our own declaration of dc_descriptor_t and all our accesses
to its internals, and switches to use the libdivecomputer functions to
access those instead.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
This is to avoid confusion with planner.display_deco_mode.
When accessing the "current deco mode" use the decoMode()
helper function.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
We have two prefernces determining the deco_mode (BUEHLMANN vs VPMB
vs RECREATIONAL): One for the planner (deco_mode) and one for
displaying dives (display_deco_mode). The former is set in the planner
settings while the latter is set in the preferences.
This patch clears up a confusion which of the two to use by introducing
a helper function that selects the correct variable.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This starts using the newly lifted out get_descriptor in configure dive
computer, instead of previously hard-coded out of date
switch-statements.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This renames and cleans up ostc_get_data_descriptor into get_descriptor,
for more generic use.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is for later reuse of that function in other source files.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I don't know how those arose in the first place, but an
empty QByteArray is never a valid hash value for an image. So
we should not store those in our translation tables and also
get rid of them when loading the tables from disk.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch fixes two bugs:
1) It first computes the effective gradient factors and then
composes the notes with the diveplan rather than the other way
around.
2) It does not try to fit a line through a single point.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For each stop, this computes an effective gradient factor
that gives the same ceiling. Then, it does linear regression
to find values for GFlow and GFhigh that give a similar deco
profile.
Note that this optimises the average gradient factor. The
runtime however depends strongly at the gradient factor at
the last depth. So we don't necessarily to get the runtime
right.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is central information when planning a dive but often
scrolled out of the window for longer plans. So print it on
the top.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Upon importing dives, the average depth can be undefined which we store as 0.
This zero should not contribute when computing the average depth for
the (yearly) statistics, only dives with average depth set now contribute.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This fixes a copy-paste error made by me that caused
tempSensorOffset to first be set the wrong way and then overridden by
pressureSensorOffset.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We had (in the wrong place, imo) a new feature that
should differentiate the different deco_modes, you could
plan your dive in buelhman and see it in vpm-b, for instance
but both of them accessed the same pref.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove a few uneeded lines and add more loading code for
the preferences.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch fixes all the cases that I didn't checked for
the default prefs.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Those macros are nice because they take into consideration
the default preferences.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Date loading was incorrect, this unittest + fix deals with that.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Calculate gfline using the gradient factor that is set by the planner
preferences when in the planner, and by the general prefs when not in the
planner. This is achieved by doing the gradient factor calculation in dive.c,
where buehlmann_config is defined.
Previously, the gfline was calculated using the general preferences gfhigh and
gflow, even when in the planner.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fixes a couple of issues with the tests.
Also, a type in prefs.h is "short" while it's actually
a boolean, this made me write the wrong testcase for this.
Fixed this by setting the Qt wrapper to bool, but I didn't
changed the c implementation because I tought I could break
something.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When merging dives, this will skip the gas change event if both dives
use same gas.
Fixes#1099
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
... as those are needed for the heatmap and not only
for Buehlmann ceilings.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Separate the VPM-B conservatism preference into diveplan.vpmb_conservatism for
planning dives and prefs.vpmb_conservatism for profile ceiling display of
saved dives.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
While Linux can set the locale from the language text, Windows needs the
correct locale value (which makes more sense to use, anyway - that's why
we save it).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Linus pointed out that it might be another call site (and looking at his
proposed patch I noticed a logic error in my earlier attempt)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds a simple cp2130 userspace driver. Its probably unusable in the
real world but its a great base to build upon.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The set_halfduplex function takes a unsigned int, not a int.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This rewrites the custom serial code to use the new api which I
implemented in the Subsurface-branch of libdivecomputer.
This is a bit to big patch but I haven't had the time to break it down
into more sensible patches.
This rewrite enables us to support more ftdi based divecomputer
communication and is tested with both a OSTC3, OSTC2N and a Suunto
Vyper, all over the libftdi driver.
The bluetooth code paths are tested to, and should work as before.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When editing adive in Subsurface-mobile we can only handle one buddy
due to the limitations of the combobox. To prevent loss of data when editing
a dive with more than one buddy we display "Multiple Buddies" in the buddy
field. This creates a special case where no changes are written to the buddy field
unless the user changes buddy for that dive.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
... and not just for Buehlmann. This makes the saturation
graphs meaningful for VPM-B.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Change runtime table string from ZHL-16B to ZHL-16C to reflect he fact
that we use 5min as half-time for the fastest compartment rather than
4min.
Further more trade pow(2.0, ...) for exp().
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This removes 'fixup_dc_cylinder_index()', which was added to fix up the
pressure sensor indexes from the Atomic Cobalt dive computer.
Even for the Cobalt it really shouldn't matter, because the
libdivecomputer backend for the Cobalt actually tries to do the right
thing. See for example commit 8853a1ccd422 ("Associate the pressure
samples with the primary tank.") in libdivecomputer.
Some historical digging shows that the subsurface sample pressure index
code came in from commit e32ba4d6d8 ("Improve tank handling for
Cobalt"), dated Tue Oct 28 13:48:15 2014.
And the libdivecomputer "use the right cylinder" code was around the
same time (Fri Oct 10 20:29:17 2014 +0200).
So I suspect that subsurface needed the fixup based on an older version
of libdivecomputer. Jef's patch is a couple of weeks before, but we may
not have tracked libdivecomputer religiously.
The reason to remove this code is because it can (and does) mess up the
sensor index when it is actually reliable, like in the multi-sensor case
of the Suunto EON Steel.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds the option to select a cylinder when adding or editing a dive.
Due to limited screen size we restrict the editing to the first cylinder only.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
With the recent setting cleanup, gradient factors were set to bool, so were
saved as 1/1, rather than say 50/80. This commit fixes that.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
No, they don't make sense. We should normally not have multiple samples
that are on the same second. But they seem to happen on the EON Steel
under some circumstances, and instead of dividing by zero when trying to
interpolate across such a sample, do something sane.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We used to clear the 'dc_tank_t' for each dive, but then only clear the
volume field in between each cylinder. That means that if the
libdivecomputer back-end does not touch a field, it might contain the
stale value from the previous tank information.
I'm not sure this is actually much of an issue, since I'd expect
back-ends do seem to initialize the fields fully (at least the EON Steel
back-end does). But it's inconsistent.
Also, the code was actually buggy because of the odd indentation: it
would only ask for new tank information up to 'ntanks' tanks, but
because of the final fixup that was done outside of the conditional, it
would actually update the cylinder begin/end pressure data *beyond*
'ntanks', and just re-use the last libdivecomputer data for the rest of
the cylinders.
Again, in practice, that probably never really happened, but it is a
real bug.
The fixed-up code actually looks better too, imho, and is one line
shorter because of the initialization now being done in one place rather
than two.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In subsurface, we only have one cylinder pressure per sample (well,
technically two: we have a separate o2 pressure for rebreather diving).
Which makes things "interesting" if the dive computer can actually have
multiple pressure sensors, and can report them all concurrently. Like
the Suunto EON Steel.
We used to just take the last one (each sensor reading would just
overwrite any previous ones), and this quick hack just changes the logic
to prefer the "current" cylinder instead.
It's wrong, and it's stupid, but it's the best we can do without major
surgery.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There's one function named uiLanguage() that should return
the current uiLanguage() that subsurface is running, but
it actually sets a whole lot of preferences, I think
that the general idea of that function is okay, but it seems
broken for me.
still, I used it to load the correct language from the preferences
since it's what this function is currently doing right now.
Also, a lot of missing groups where added.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Only set the settings if it actually changes, when the user
clicked on the save button on the preferences, the code would
run in every dialog saving each preferences on disk, but this
is uneeded if the value didn't changed.
Also, while doing that, I found a couple of places where I
used the wrong field, which are now fixed.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In commit b76c1846bb ("Settings update: Simplify Update Manager")
the logic for when to show the UpdateManger question to the user got
broken. Unintuitively, a boolean setting actually has three possible
values. True, False, and Unset. This patch fixes things to work as
designed again.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Move Preferences sync / initialization out of the planner
widget prerferences to the ObjectWrapper.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For some reason, the dive computer settings weren't in the
settings prefs. This moves it, makes the boilerplate on Settings
ObjectWrapper and make things compile.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
So, prefs.save_userid_local is being set outside of
a preferences set (it's set to true and false while
loading the files via xml or git) and because of that
I had to bypass a few method calls.
When something triggers a preferences change, the
application will be notified that the preferences
changed, thing that I couldn't do while reading the
xml or git because that should be local-only.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We have the serial number and firmware version fields in "struct
divecomputer", but we don't actually fill them in when loading the data
from git or xml, because we save all that information in the separate
device table instead.
But in order to always have the serial number associated with a device,
let's make sure to fill those fields in. It won't hurt, and this way we
have the information available whether we just loaded the dive from a
file, or imported it from the dive computer. One less semantic
difference to worry about.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The authentication count was a static counter in the authentication
callback, which gets incremented until we consider the authentication to
have failed.
The problem with that is that it doesn't get incremented for just _one_
authentication operation, it gets incremented each time you try to load
or save, so eventually the code considers authentication to have failed
even if nothing ever went wrong.
This fixes it by making it static to the whole git-access file, and have
each operation clear it before starting a new remote access.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Having only the last 2 digits of the year is somewhat confusing as one
can easily think that to be the day. Thus it is more clear to use full
year for the trip header.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Windows Server 2008 seems to be missing the heavy dash in Courier New.
This replaces the symbol by an ordinary dash.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Subsurface uses "local time" which in particular means we never
display time zone information to the user. The user (and our file
format) only sees times like 5pm or 17:00. A better name than
local time (which could mean "local at the dive spot) would
be "watch time", the time displayed by the diver's watch when
she entered the water.
Internally, we store times as time_t, seconds since Jan 1 1970 0:00
UTC. Our convention for conversion between 5pm and time_t as always
been to treat 5pm as if it were UTC.
Then confusion arose since Qt's QDateTime (which is tied to UI elements
like QTimeEdit and similar) is time zone aware and by default assumes
the system time zone. So when we set a QDateTime to 5pm and then later
convert it to time_t we have to take care about the difference between
UTC and the system time zone.
This patch unifies our solution to this problem: With it, we set all
QDateTime's time zone to UTC. This means we don't have to correct for
a time zone anymore when converting to time_t (note, however, the
signedness issue: Qt's idea of time_t is broken since it assumes it
to be unsigned thus not allowing for dates before 1970. Better use the
millisecont variants).
We only need to be careful about time zones when using the current time.
With this convention, when assigning the current time to a QDateTime, we
need to shift for the time zone since its value in UTC should actually be
the watch time of the user who is most likely used to the system time zone.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
to allow grantlee to access individual fields of the cylinder_t struct
rather than a string representation of the whole cylinder info using a
grantlee structure like this one:
<table class="table_class">
<tr>
<td>Cylinder</td>
<td>Start press.</td>
<td>End press.</td>
<td>Gas mix</td>
</tr>
{% for cylinderObject in dive.cylinderObjects %}
<tr>
<td>{{ cylinderObject.description }}</td>
<td>{{ cylinderObject.startPressure }}</td>
<td>{{ cylinderObject.endPressure }}</td>
<td>{{ cylinderObject.gasMix }}</td>
</tr>
{% endfor %}
</table>
Signed-off-by: Tim Wootton <tim@tee-jay.org.uk>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When stuck in areas with really bad internet 5 seconds may not be enough,
but making the timeout longer in general seems the wrong way to go. So
keep the default 5 seconds but allow the user to override that with
subsurface --cloud-timeout=NN
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There are a lot more places all over Subsurface where this needs to be
cleaned up. The converstion of the preferences system has been a complete
mess.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Commit b1ed04a means that DivePlannerPointsModel::rememberTanks() and related
functions and variables are no longer required
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This way they display correctly when accessed from grantlee template
Fixes#1085
Signed-off-by: Tim Wootton <tim@tee-jay.org.uk>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of having fixed numbers and trying to translate them into
strings, a dive computer could just give us the string directly. Like
the new EON Steel backend does.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The cylinder use field was not merged when dives were merged. This is
normally not noticeable, since hopefully the cylinder use should be the
same anyway, but when re-downloading the dives from the EON Steel after
updating it to also get cylinder use data, the dive merging threw the
data away again since the original dive lacked it.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This uses the extended tank type information to fill in the cylinder use
(OC gas, CC Diluent or CC O2) from libdivecomputer when available.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The imperial and metric unit formats already had this, but the
personalized one missed the newline at the end.
It shouldn't really matter, since it's the last line of the file, but it
is not right.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It makes no sense to keep trying. Maybe we need a UI to force it online
again, but for now this works much better when using cloud storage while
actually offline.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add option to calculate the best mix portion of O2 and He for the dive's max
depth if the user enters * in the MOD and MND cylinder fields. Gas portions
are automatically recalculated if the max depth of the dive changes.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Determining the correct cylinder index from a known gas mix can be
complicated, but it is trivial to look up the gasmix from the cylinder_t
structure.
It makes sense to remember which cylinder is being used. This simplifies
handling changing a cylinder's gas mix, either directly by the user, or
indirectly in the planner. It also permits tracking of multiple cylinders of
the same mix, e.g. independent twins / sidemount.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We have two different models for setting the deviceid associated with a
dive computer: either take the value from the libdivecomputer 'devinfo'
field (from the DC_EVENT_DEVINFO event), or generate the device ID by
just hashing the serial number string.
The one thing we do *not* want to have, is to use both methods, so that
the same device generates different device IDs. Because then we'll
think we have two different dive computers even though they are one and
the same.
Usually, this is not an issue, because libdivecomputer either sends the
DEVINFO event or gives us the serial number string, and we'll always
just pick one or the other.
However, in the case of at least the Suunto EON Steel, I intentionally
did *not* send the DC_EVENT_DEVINFO event, because it gives no useful
information. We used the serial number string to generate a device ID,
and everything was fine.
However, in commit d40cdb4755ee ("Add the devinfo event") in the
libdivecomputer tree, Jeff started generating those DC_EVENT_DEVINFO
events for the EON Steel too, and suddenly subsurface would start using
a device ID based on that instead.
The situation is inherently ambiguous - for the EON Steel, we want to
use the hash of the serial number (because that is what we've
historically done), but other dive computers might want to use the
DEVINFO data (because that is what _those_ backends have historically
done, even if they might also implement the new serial string model).
This commit makes subsurface resolve this ambiguity by simply preferring
whatever previous device ID it has associated with that particular
serial number string. If you have no previous device IDs, it doesn't
matter which one you pick.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There might be some spurious setpoint changes at t=0 without
an actual value (I have no idea where those come from). In
any case, those do not indicate that the dive is a CCR dive.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There were two problems in the calculation of tissue pre-
saturation from previous dives: We added the surface interval after
the dive rather than before and when also took dives into accout
that were in the future of the dive considerd.
Reported-by: Timothy Massey
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We could create a plot_info data that didn't contain all the time slots
for the events fromt he dive computer, which would terminally confuse
the plotting of the event profile widgets because it couldn't match up
the event with the dive plot data model.
So for example, in DiveEventItem::recalculatePos(), when the code tries
to figure out the spot in the data model, it could fail, and then try to
hide the event (because without the data model information it doesn't
know where it should go). But that hiding would then not match the
logic in DiveEventItem::shouldBeHidden(), and the event would end up
being shown in the upper left-hand corner of the profile after all.
The reason the plot_info data wouldn't contain the time slots is that
the slots are allocated primarily for the sample data, and then the
events would be added in between sample data in populate_plot_entries().
But since we'd only add the event pointer *between* samples, that would
mean that events after the last samples would not get plot-info points
allocated to them.
That issue was exacerbated by how we also truncate uninteresting samples
at the end when some dive computers end up giving a long stream
(possibly several minutes) of "at the surface" events before they
finally turn off logging.
This makes sure that we take the event timestamps into account for the
"maxtime" calculation, and also that we finish populating the plot_info
data with any final event timestamps.
Now all the events will have a matching plot_info entry.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I missed the fact that not only did we skip importing surface events
from the dive computer, we had also made our xml parser ignore them when
loading an xml file. All part of our historical "let's ignore surface
events because dive computers are being very annoying about it".
Signed-off-by: Linus Torvalds <torvalds@linux-foundtion.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There are cases where we actually want to keep them, as exemplified by
this situation from Richard Yorke:
"I have just come across a situation when ignoring the surface marker
is a disadvantage. I have just had a problem with my BC feed
seeping, slowly filling my BC and as I control my buoyancy on the
bottom using the air in my drysuit, I did not notice, so that when I
came to ascend the expanding air in my BC caused a loss of control.
Fortunately not from a great depth and no untoward consequences.
However, the Subsurface profile only shows me rising to 4m and
descending to 5.5m for my safety stop. However I actually broke the
surface and descented to 5.5 but the frequency of recording depth was
not fast enough to show this as it was so brief"
so remove the code that ignores the surface events entirely.
I think we'll have to come up with some smarter filtering model for
showing them, but that is predicated on getting these events to come
through in the first place.
Reported-by: Richard Yorke <yorke.richard@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Our primary dive computer really is special, not just because it's the
first one: it's directly embedded in the "struct dive", and so if you
just walk the divecomputer list, you'll miss it, because it's not _on_
the list, it is the very head _of_ the list.
We had that bug in copy_dive(), and it turns out we have it in
clear_dive() too: clear_dive() would free all the dive computers on the
list, but not the actual primary one.
This is a minor memory leak, no more, so it's not exactly critial, but
let's just do it right.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
A few basic rules for gas validation:
We can't have <0%, or >100% of either O2 or He
O2 + He must not be >100%
Switch depth can't be <0%
This places limits on user-input values
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For starters, let's just state that this dive was downloaded from
Shearwater. However, once we have information how model numbers map to
names, we can use that info for the models we know about.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The previous patch (Planner: add best mix EAD preference) used the term EAD
(equivalent air depth) in variable names and strings, when it should have been
END (equivalent narcotic depth).
They're not the same thing and shouldn't be confused.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add best mix EAD preference and UI, along with a tooltip describing what it
does
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Best mix O2 calculated based on planner Bottom O2 preference
Best mix He calculated based on EAD of 30m (should be made user-configurable)
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds autocompleting text input fields for suit, buddy and
divemaster.
[Dirk Hohndel: some whitespace cleanup]
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This generated the QStringLists needed to populate the combobxes
in DiveDetailsEdit.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This will parse the date and time information on CSV import if the file
name matches the one used by APD log viewer (date and time are available
in the file name). Hard coding the year to 20?? is a bit unfortunate,
but as there is only 2 digits in the year, we have to invent something.
And it would be quite optimistic to assume this will bite us back any
time soon :D
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Printed command line can be used to manually test the import function,
allowing faster testing of XSLT changes, and showing debug prints that
are discarded by Subsurface.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
No point in having it defined in each main program's .cpp. Especially
since the unit tests don't define them.
Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Otherwise we keep downloading the same image multiple times instead
of new images.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Not sure why we claimed that this was successful when clearly it wasn't.
There's a risk that this could break something on the desktop, but it
makes no sense to me why that would be the right thing to do.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is a feature that many people have asked for. This implementation is
somewhat simplistic because we simply use a different name for the
program settings - but interestingly enough this appears to be enough to
capture a lot of the core functionality that people are looking for in
multi-user support.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Otherwise we step on our own feet when downloading several images,
like after import from divelogs.de with many linked images.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This seems to work around the crazy QDateTime::fromTime_t() problem in Qt.
It is *very* lightly tested. In fact, the only test is that "test0.xml"
change that is part of this patch.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It turns out that we are starting to have users that have logs that go
back that far. It won't be common, but let's get it right anyway.
NOTE! With us now supporting dates earlier in 1900, this also makes
"utc_mktime()" always add the "1900" to the year field. That way we
avoid ever using the fairly ambiguous two-digit shorthand.
It didn't use to be all that ambiguous when we knew that any two-digit
number less than 70 had to be 2000+. Now that we support going back to
earlier in the last centiry, that certainty is eroding.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
So far we didn't do that at all, we either relied on the user manually
creating a local repo, or we cloned a remote repo.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If we have incorrect cloud credentials, we need to return an error on
git authentication call back in order to avoid endless authentication
loop. This might well happen e.g. when changing the password on desktop
and then on laptop Subsurface still thinks the credentials are validated
and ends up in the authentication loop.
The authentication call back on libgit is intended to be used to ask for
user credentials, and as we handle credentials elsewhere, we just need
to fail the authentication attempts. (The threshold for bail out could
have been 1 attempt...)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This allows us to parse the DL7 profile data (skipping the header and
footer)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Make them use indices into the plot-info, fix calculation of average
depth, and fix and add comments.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Qt 5.6.0 is broken when it comes to using CoreLocationService on iOS.
It doesn't even check if the location service is enabled. My patches fix
that and make Qt set an error code right after service creation. Having
the service creation fail is actually the wrong thing to do because then
Qt switches over to GeoClue and that really isn't helpful for our needs
here.
Additionally, Qt 5.6.0 without my patches doesn't follow the REQUIRED
flow of using the location service as it does not check the access
permissions before accessing the GPS service - without doing so the
GPS service will not run in the background.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If the GPS source returns an error that could be an indication that the
user hasn't given us permission to use it, so switch our status to NOGPS.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Initially we don't know if we have a source. After that we may think
that we have one, or not have one (but that can actually change while
the program is running if the user, for example, turns the source off
or switches to airplane mode).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I couldn't figure out how to break this down into small, useful commits.
Part of the problem is that I kept going while working on this and as you
can see from looking at the commit, diff tries so hard to find small code
fragments that moved around, that the diff overall becomes quite
unreadable and it seemed impossible to recreate the sequence of steps
after the fact.
It all started with adding the parsing for the GPS coordinates. But while
testing that code I found several issues with the rest of the function.
Most importantly it seemed ridiculous that we carefully tried to match the
texts that the DiveObjectHelper would create for the various fields,
instead of just using the DiveObjectHelper to do just that. And once I had
converted that I once again realized just how long and hard to understand
that function was getting and decided to break out some of the more
complex parts into their own helper functions.
But of course all this didn't happen in this logical, structured, ordered
way. Instead I did all of these things at the same time, testing,
rearranging, etc.
So in the end I went with one BIG commit that does all of this in one fell
swoop.
This adds four helper functions to deal with start time/date, duration,
location and gps coordinates, and depth of the dive.
To avoid mistakes when dealing with the GPS coordinates, there's another
helper to encapsulate the creation of the dive site and we switched to a
current GPS location.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If we want to keep the selected dive "close" to where it was before an
operation (whether a delete, or a reload, or something like that), then
the most intuitive thing to do appears to be to select either the same
dive again (if it still exists), or one very close to it in time. This
helper allows us to identify the dive in the current dive list that is
closest to the given time.
We do this in the C code to ensure that we look at all dives in the
dive_table - based on the id that is returned the UI can then figure out
where this dive is currently shown.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The variables that control each CVA iteration should be declared at the start
of each loop so that the values are carried over from one iteration to the
next.
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
In our verision of VPM-B for real dives, we take as the deco time the
difference between the time of the deepest ceiling and the time when the
ceiling clears.
When the display of ceilings was set to multiples of 3m this was confused, as
the maximum finder had issues: First of all, it updated the time when the ceiling
was the same (which was almost always the case for stepped ceilings) but changing
>= to > was not enough, since then the first time a deepest stepped ceiling was
reached was used.
This patch uses the actual ceiling (not rounded to the next integer multiple of 3m)
for this calculation to get rid of this problem.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
We first check the sha to see if we want to load at all. But at that
point we already have the repository and the branch and we have synced
with the remote. So when we decide that we need to reload from storage,
we don't need to repeat those steps, instead we can go directly to the
git load.
For that to work we need to pass the repository pointer and the branch
name back to the caller so that we can directly call git_load_dives().
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
With Linus' changes to the tree creation saving the dives is no longer
the dominant part of that process, so simplify the output (which also
removes the hacky buggy code to show the percentages that is of course
totally bogus).
(apparently a couple of white space cleanups snuck into this patch)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
John Van Ostrand reports that when he dives using two cylinders using
sidemounts, the per-cylinder SAC rate display is very misleading.
What happens is that since the two cylinders are used together (but
without a manifold), John is alternating between the two but not
actually adding gas switches in the profile. As a result, the profile
looks like only one cylinder is used, even though clearly the other
cylinder gets breathed down too.
The per-cylinder SAC rate calculations would entirely ignore the
cylinder that didn't have gas switch events to it, and looking at the
info window it would look like John had a truly exceptional SAC rate.
But then in the general statistics panel that actually takes the whole
gas use into account, the very different real SAC rate would show up.
The basic issue is that if we don't have full use information for the
different cylinders, we would account the whole dive to just a partial
set. We did have a special case for this, but that special case only
really worked if the first cylinder truly was the only cylinder used.
This patch makes us see the difference between "only one cylinder was
used, and I can use the overall mean depth for it" and "more than one
cylinder was used, but I don't know what the mean depths might be".
Reported-by: John Van Ostrand <john@vanostrand.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It's good that this is unused, because it does the calculations wrong.
Due to the gas compressibility the gas use calculations should subtract
the gas_volume() values at the differing pressures, not the pressures
themselves.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In commit df4e26c875 ("Start sanitizing gaschange event information")
back about a year and a half ago, I started sanitizing the gas switch
event data, allowing gas switches to be associated with a particular
cylinder index rather than just the gas mix that is switched to.
But that initial step only _allowed_ a gas switch event to be associated
with a particular cylinder, the primary model was still to just specify
the mix.
This finally takes the next step, and *always* associates a gas switch
event with a particular cylinder. Instead of then looking up the
cylinder by trying to match gas mixes at runtime, subsurface now looks
it up when loading the dive initially as part of the dive fixup code.
The switch event still has an a separate gas mix associated with it, but
this patch also starts preparing for entirely relying on the gas mix in
the cylinder itself, by starting to pass in not just the event but also
the dive pointer to the routines that look up gas mix details.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Some of the gas mix cleanups I'm doing are in code that uses const
pointers, and wants to use this.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The gas switch event handling is somewhat fragile, mostly because the
legacy event encoding for gas switches is odd. It's also limited to
whole percentages, unlike our internal gas mix model.
In addition, it also ends up comparing the values to the raw permille
values, which is wrong for air, and wouldn't match our O2_IN_AIR which
is 209 permille (closest approximation to 20.946%).
So handle air separately, since "21" really is a valid oxygen value for
air, and should match 20.9%. And use the proper accessor functions to
get the gasmix values.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Dirk says that divinglog hasn't been doing the linear pressure
interpolation for a long while, so we're doing extra dive fixups that
really aren't needed any more.
Also, the code is actually buggy: it only ever worked on the first
cylinder anyway (because only the first cylinder pressure_delta[] would
be initialized). That was probably perfectly fine in practice, since
it's unlikely that many tech divers used old versions of divinglog
anyway, so the bug per se isn't a reason to remove it - but it is a sign
that the code was a bit hard to read, so let's get rid of it if there is
no reason to maintain it or fix it.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.
And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.
This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>