Commit graph

1903 commits

Author SHA1 Message Date
Dirk Hohndel
40d05ed768 Show two decimal digits in pO2, pN2 and pHe in the tooltip
Tec divers seem to like a little bit more precision - and the dive
computers certainly provide it (or we can calculate it).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-08 13:58:14 -08:00
Dirk Hohndel
3b425b4c13 Plot pO2 graph based on sample information, if available
This should give closed circuit divers with a supported dive computer
correct partial pressure plots.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 21:05:21 -08:00
Dirk Hohndel
9d80e7bfe4 Add CNS and pO2 tracking in the samples
This adds the new members to the sample structure and fills them from
supported dive computers (Uemis SDA and OSTC / Shearwater Predator,
assuming you have libdivecomputer 0.3).

Save relvant values of this to the XML file and load it back. Handle the
new fields when merging dives.

At this stage we don't DO anything with this, all we do is extract them
from the dive computer, save them to the XML file and load them back.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 21:03:39 -08:00
Dirk Hohndel
a72597189d Initialize helper structure to 0s
We check the pointers that are part of this structure for NULL before
accessing them - but that means we need to zero out the structure for this
to work.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 20:06:07 -08:00
Dirk Hohndel
dad93c425e Fix potential uninitialized read
When analyzing the buffer that is handed to the first_object_id function
we carefully check to make sure that we don't read past the end of the
input buffer but there was still one code path that could have us do just
that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 20:02:14 -08:00
Dirk Hohndel
0fcdd011f5 Fix off by one error
We increment i twice - which causes us to access memory past the end of
the allocated array.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 20:01:05 -08:00
Dirk Hohndel
407d4dd4aa Fix embarrassing cut and paste bugs
The previous commit 871d7ae0cdf5 "Add option to make ceiling visually
stand out more in the profile" contained not one but two stupid cut and
paste bugs. I cannot begin to explain how this could have worked when I
first tested it.

Reported-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 12:55:11 -08:00
Dirk Hohndel
a0f28aa422 Add option to make ceiling visually stand out more in the profile
While having the background "come down" seemed like a good visualization
of the ceiling, some divers appear to prefer something more dramatic. This
adds an option to the Tec Settings to have the ceiling shown in red
instead of the default background color.

Suggested-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 11:39:15 -08:00
Dirk Hohndel
982abb5596 Move partial pressure plots up slightly
This way they don't clash with the dive computer model information that
was added by commit a23ec27ca7bb "Add dive computer name to the dive
plot".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 10:49:02 -08:00
Linus Torvalds
0d1f396f3a Move 'plot_info' into 'struct graphics_context'
.. and then allocate just the plot-info entry array dynamically.

We want to have a longer lifetime for the basic plot_info data
structure, because we want to do computer selection and maximum
time/depth/temperature computations *before* we start plotting anything,
and before we allocate the plot entry array.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 10:31:26 -08:00
Linus Torvalds
22aa6fa4ef Add dive computer name to the dive plot
I want to have some way to show multiple dive computers, so start off by
adding the name of the current one.  So if we change dive computers,
we'll see it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 10:31:22 -08:00
Linus Torvalds
3a7f3ba880 Tune the dive joining surface event insert code
From 178a3f0d6d5112f76943fec5f8c1c1f3b173a7f4 Mon Sep 17 00:00:00 2001
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Fri, 7 Dec 2012 09:34:18 -0800
Subject: [PATCH 2/2] Tune the dive joining surface event insert code

So this makes us do surface events only if the samples are more than one
minute apart, and are shallow enough (randomly selected at 5m).

We can add more heuristics.  Maybe we should compare the 1-minute sample
time limit of the previous sample to the time to the sample before that:
if some computer (or manually entered dive) has a long time between
*all* samples, we'd make the cut-off time longer.

Baby steps.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 10:18:48 -08:00
Linus Torvalds
59fc674e01 When merging downloaded dives, strive to keep old dive in 'a'
This doesn't really change the logic of the merging, but it does mean
that the end result tends to be less unexpected: when downloading dives
that end up being merged with pre-existing dives (because you have
multiple dive computers, for example), the newly downloaded dive data
will tend to be appended to the old dive data, rather than showing up
first.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 10:18:30 -08:00
Dirk Hohndel
3d80d9283d Sort the divecomputers alphabetically and have fixed width dropdown
Instead of just taking the vendors and products for the supported
divecomputers in the order libdivecomputer provides them to us we sort
them as we add them to our list of lists. While doing this we also track
the longest product name and try to make sure that the combobox for the
product is set to a fixed width that's wider then the longest product
name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 10:12:10 -08:00
Dirk Hohndel
c796c16115 Add two test dives that triggered the bug fixed in the previous commit
Loading these two XML files created a divelist with two trips that each
started at the same time but that were NOT linked together (because the
code in insert_trip detected that they started at the same time). Since
the trips were not linked together, trying to then merge those two trips
from the UI got us into an infinite loop, trying to move a dive from one
trip into the same trip (as the code couldn't find the trip that wasn't
linked into the dive_trip_list).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-06 13:06:16 -08:00
Dirk Hohndel
936d289cb7 Fix insert_trip to correctly deal with trips that start at the same time
The existing code did not move the dives that are part of the second trip
to the first trip (and forgot to keep the 'better' notes as well).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-06 13:04:37 -08:00
Linus Torvalds
5ac5408bb0 Fix SIGSEGV when joining dives without dive computer information
Handle the case where we have no divecomputer information.

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-06 11:00:52 -08:00
Dirk Hohndel
d5da3c9a95 Prevent crash when no default device is set
We were dereferencing the default device, even if not set.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 21:19:30 -08:00
Dirk Hohndel
9904272d2f Split dive computer selection into seperate vendor and product combo boxes
The length of that combo box got increasingly insane as libdivecomputer
supported more and more models. To make this more scalable we now have two
combo boxes. One with just the vendors and a second one with the products
depending on the vendor selected.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 21:05:30 -08:00
Dirk Hohndel
c1aacc05d1 Fix deco/ndl support for libdivecomputer
Several blatant mistakes prevented this from ever working.
Now we correctly record ndl / stoptime / stopdepth in every sample and no
longer issue bogus events.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 14:39:13 -08:00
Dirk Hohndel
afb53e387b Fix retrieval of object_id value in Uemis downloader
The existing code could read past the end of the buffer that was handed to
it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 13:43:36 -08:00
Dirk Hohndel
240442cec9 Improve reading of extra dive data for Uemis
When starting from the first dive on the dive computer we called getDive
for every dive starting with id 0 instead of figuring out which id is
actually the first one that we downloaded.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 12:34:43 -08:00
Dirk Hohndel
a012ce0515 Fix saving of salinity
Several things were wrong.
- we saved it as floating point (that was stupid, given the locale issue
  with that and given the fact that the precision was really artificial)
- we always saved it when set (we should only save it if the value is
  different from our default of 1030g/l == salt water)
- most embarrassing - the unit we assigned was wrong. That's g/l, not
  kg/l...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 12:31:31 -08:00
Dirk Hohndel
d00be63c86 Change Uemis code to use locale indepent floating point parsing
I clearly forgot about not using atof... now we use the locale safe
g_ascii_strtod instead.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 11:54:15 -08:00
Linus Torvalds
5e5e3460ac Turn latitude and longitude into integer micro-degree values
This actually makes us internally use 'micro-degrees' for latitude and
longitude, and we never turn them into floating point either at parse
time or save time.

That said, the Uemis downloader internally does still use atof() when
converting things, which is likely a bug (locale issues and all that),
but I'll ask Dirk to check it out.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 10:34:02 -08:00
Linus Torvalds
708df33539 Save latitude/longitude using integer math
I hate using floating point, this tries to at least make parts of it be
integer logic, and avoid the whole locale issue.  This still keeps the
latitude and longitude internally as a floating point value, and parses
it that way, but I'm slowly moving towards less and less FP use.

We're going to use micro-degrees for location information: that's
sufficient to about a tenth of a meter precision, and it fits in a
32-bit integer.

If you specify dive sites with more precision than that, you may have
OCD.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 10:33:58 -08:00
Dirk Hohndel
1e074f3fb2 Pick up dive numbers from Uemis SDA when starting with empty data file
This is improving a bit more on commit d2dd0eb39efe "When starting with an
empty data file and downloading dives, number them" by providing a better
starting number when a user downloads dives from a Uemis SDA into an empty
data file.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 10:24:21 -08:00
Dirk Hohndel
0141b69d0a When starting with an empty data file and downloading dives, number them
We have been very careful not to mess with the numbering that a user may
intend - but one obvious case where we should automatically number the
dives appears to be the first time download from a dive computer. Right
now all dives show up with number '0' and that's just really ugly and a
bad experience for a first time user.

With this change if a user starts with an empty data file and downloads
dives from a computer for the first time, Subsurface will give them
numbers starting with '1'.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 09:34:00 -08:00
Dirk Hohndel
10e64f0e17 Make it easier to pass macro definitions from make
This small change to the Makefile allows you to call

	make CLCFLAGS=-DDEBUG

or some other define directly from the command line. It gets added to the
CFLAGS without overwriting the CFLAGS.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 09:30:29 -08:00
Lubomir I. Ivanov
b435166dc3 Merge trips without modifying the GTK tree
This patch does 4 small divelist.c changes in the following
order of importance:

1) In find_trip_by_time() now there is a check if a trip is actually found
before looking at the "when" flag.

2) Make remember_tree_state() slighly safer. If for example we have recently
deleted a trip from the linked list, it may still exist in the GTK tree model,
thus we want to check when calling find_trip_by_time() if there is an actual
match before setting the "expanded" flag for a trip.

3) When merging two trips in merge_trips_cb(), only use the tree model
to retrieve the timestamps (DIVE_DATE) and then find matching trips with
find_matching_trip(). Once we have pointers to the two trips to be merged,
move dives from one to another iterating with add_dive_to_trip().

4) In merge_trips_cb() - remember the tree state, repopulate the tree and
restore tree state, since now we are not adding/removing rows directly.
tesdsad

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:21:28 -08:00
Linus Torvalds
fb0d728973 Improve automatic dive merging logic
This tunes the heuristics for when to merge two dives together into a
single dive. We used to just look at the date, and say "if they're
within one minute of each other, try to merge". This looks at the
actual dive data, and tries to see just how much sense it makes to
merge the dive.

It also checks if the dives to be merged use different dive computers,
and if so relaxes the one minute to five, since most people aren't
quite as OCD as I am, and don't tend to set their dive computers quite
that exactly to the same time and date.

I'm sure people can come up with other heuristics, but this should
make that easier too.

NOTE! If you have things like wrong timezones etc, and the
divecomputer dates are thus off by hours rather than by a couple of
minutes, this will still not merge them. For that kind of situation,
we'd need some kind of manual merge option. Note that that is *not*
the same as the current "merge two adjacent dives" together, which
joins two separate dives into one *longer* dive with a surface
interval in between.

That kind of manual merge UI makes sense, but is independent of this
partical change.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:19:02 -08:00
Dirk Hohndel
ebd27b798a Support the new NDL / deco code in the Uemis downloader
This also replaces the old heuristic for when we are in deco with the
(hopefully correct) bits in the sample flags.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:06:54 -08:00
Dirk Hohndel
dcb6574dc4 Improve deco handling and add NDL support
This commit changes the code that was recently introduced to deal with
deco ceilings. Instead of handling these through events we now store the
ceiling (which in reality is the deepest deco stop with all known dive
computers) and the stop time at that ceiling in the samples.

This also adds support for NDL (non stop dive limit) which both dive
computers that appear to give us ceiling / deco information appear to
give us as well (when the diver isn't in deco).

If the mouse hovers over the profile we now add support for displaying the
NDL, the current deco obligation and (if we are able to tell from the
data) whether we are at a safety stop.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:05:26 -08:00
Dirk Hohndel
7383f7fe0a Change Uemis debug code to test for bit values
This way individual pieces can be turned on and off.
The commit also adds code to read from a disk image (instead of the SDA)
without all the long timeouts.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:05:26 -08:00
Dirk Hohndel
8562364bd9 Small cosmetic cleanups of Uemis downloader code
Just improving the messages a user gets.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-01 13:32:33 -08:00
Dirk Hohndel
96091e8238 Fix stupid error in last minute cleanup of Uemis rewrite
Never make trivial changes without testing them. This was missung a '!'
before the strcmp - so the wrong code got executed when trying to get the
DeviceId and everything afterwards failed without a valid DeviceId.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-01 13:31:18 -08:00
Dirk Hohndel
79c2b00212 Make more uemis functions static
These are no longer called from other parts of the code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-30 14:30:24 -07:00
Dirk Hohndel
15edba9ab0 Remove the hack to mark parsed XML files as downloaded
This was necessary for the Uemis downloader when we used the SDA file
format as intermediary data format and imported that as XML buffer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-30 13:56:10 -07:00
Dirk Hohndel
1bc4aba8e7 Remove the ability to import Uemis SDA files
The downloader has been integrated into Subsurface for a while and with
the recent change to no longer have it create the old style SDA files as
intermediary format there is no need anymore to support that format in the
XML parser.

This deletes almost 300 lines of code. Yay!

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-30 13:50:54 -07:00
Dirk Hohndel
4c4dff7683 Convert Uemis downloader to directly create dives
The initial downloader reused the XML parsing of SDA files that was
implemented early in order to support the information extracted from the
SDA with the java applet. But creating this intermediary XML file and
handing it off to the XML import function always seemed like an ugly way
to do things. This became even more obvious when adding more features to
the Uemis downloader.

This commit completely changes the downloader to instead create dives and
record them directly.

This also adds support for divespots (which are stored in a seperate
database that needs to be queried after the divelog and dive entries have
been combined - the Uemis firmware clearly was written by monkeys on
crack - oh wait: I'm trusting these same people to get the deco right?).

This commit leaves the SDA import capability in the XML parser intact.
I'll remove that later. Because of this it actually adds a few lines of
code, but the overall change will be a substantial code deletion.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-30 13:41:58 -07:00
Dirk Hohndel
a79b74ed36 Track Uemis last dive downloaded on a per data-file basis
Actually, it's even better than that. Thanks to the new divecomputer
datastructure we can now simply look up in the dive_table which dives have
been downloaded from this specific Uemis SDA.

This patch removes the old gconf based code - which leads to one
unfortunate problem: the first time a Uemis SDA owner runs this version of
Subsurface against their data file ALL dives will be downloaded again
(which may not be a bad thing as we have improved a few other details of
Uemis support so now they get their deco information, surface pressure and
other data that we have started to support since 2.1). Still, this is not
ideal. But I didn't want to keep the legacy code around since this new
solution is so much cleaner.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-28 22:02:03 -07:00
Dirk Hohndel
10fac7a6af Updating events for libdivecomputer 0.3 (and tracking uemis support)
I was a little too eager to add the deco feature to Subsurface. Jef and I
went back and forth a few more times and the definition of those events
changed. I guess I shouldn't have commited that code until the
corresponding libdivecomputer code had been pushed.

This commit now brings us in sync with the current master of
libdivecomputer (but should compile with 0.2 as well - only deco events
won't work then).

One issue that I see is that deco / ndl aren't really a good fit for the
event model. I actually disabled the drawing of the little yellow
triangles for ndl events as for example on the Uemis those events are
created whenever the remaining non stop time changes - and that can be
every few seconds.

The correct solution may be to treat this as a function of the samples,
but for now this works and is tested with both OSTC and Uemis SDA.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-28 21:13:21 -07:00
Miika Turkia
7259cf5bb6 Count the actual decimal digits for import
Apply the decimal time conversion hack for JDiveLog import if there are
less than 2 digits in the decimal part (and value is less than 60).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-28 20:49:44 -07:00
Miika Turkia
2ee26caba4 JDiveLog import fallback for 1 digit numbers
Use the decimal time format fallback also for one digit numbers as
Linus suggested. Thus 1.1 min would result in 1 min 6 sec.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:46:04 -07:00
Linus Torvalds
df3671390d Fix dive computer event handling if there are no samples
This actually triggers for one of our insane test dives (test15): it has
no samples, so we created a fake dive computer entry with the a fake
profile in it, but we didn't copy the events over.

Having a dive with no samples, yet having events from the dive computer,
sounds pretty bogus.  But that test-case did show that when that bogus
situation happens, we had two independent buglets: (a) we didn't insert
the entries in the fake dive computer entry we used and (b) we would
then mix up the events of the fake dive computer entry with the first
dive computer of a dive.

Fix this, just to make test15 happy again.  And eventually, when we
actually plot the information for multiple dive computers, fixing case
(b) would become necessary even for real dives.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:45:38 -07:00
Linus Torvalds
6fe52ee19e Simplify tripflags: remove tripflag_names[]
This removes the tripflag name array, since it's not actually useful.
The only information we ever save in the XML file is whether a dive is
explicitly not supposed to ever be grouped with a trip ("NOTRIP"), and
everything else is implicit.

I'm going to simplify the trip flags further (possibly removing it
entirely - like I did for dive trips already), and don't like having to
maintain the tripflag_names[] array logic.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:44:51 -07:00
Linus Torvalds
3f197336aa Remove 'tripflag' from dive trips
Both dives and dive trips have the same 'tripflag' thing, but they are
used very differently.  In particular, for dive trips, the only case
that has any meaning is the TF_AUTOGEN case, so instead of having that
trip flag, replace it with a bitfield that says whether the trip was
auto-generated or not.

And make the one-bit bitfields explicitly unsigned.  Signed bitfields
are almost always a mistake, and can be confusing.

Also remove a few now stale macros that are no longer needed now that we
don't do the GList thing for dive list handling, and our autogen logic
has been simplified.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:44:04 -07:00
Miika Turkia
e544ca5f6a Handle seconds in decimal notation (from JDiveLog)
This is a hack to convert time stored in decimal notation to proper
seconds. When using metric units the default way of JDiveLog to store
seconds is to have the amount of seconds after decimal point (1.20 is 1
minute 20 seconds). In some odd case it is reportedly possible that the
seconds are actually 100 based, thus we need to convert that to seconds
(1.33333 will become 1 minute 20 seconds).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 11:14:58 -08:00
Linus Torvalds
ffa3fd551c Clarify (and fix) dive trip auto-generation
This makes the dive trip auto-generation a separate pass from the
showing of the dive trips, which makes things much more understandable.
It simplifies the code a lot too, because it's much more natural to
generate the automatic trip data by walking the dives from oldest to
newest (while the tree model wants to walk the other way).

It gets rid of the most annoying part of using the gtk tree model for
dive trip management, but some still remains.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:30:27 -08:00
Linus Torvalds
85f0749c85 Remove 'when_from_file' field from dive trip
It had become a write-only field (apart from some now useless debugging)
when simplifying the remove_autogen_trips() function.

So remove it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:28:34 -08:00