Commit graph

72 commits

Author SHA1 Message Date
Dirk Hohndel
1d02ba12a3 Separate Gtk related code from core logic: planner
Relatively straight forward, just a handful of places where we call
show_error() (a UI function) from the logic code. In the process I noticed
a few places where error returns weren't dealt with correctly.

Added a new planner.h files for the necessary declarations.

This should make no difference to functionality.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-07 20:22:41 -07:00
Robert C. Helling
c083ec45a9 Make relative times default in planner 2
In planning you usually plan lengths of segments rather than runtimes to
leave a level.

This patch superseeds a previous one with a similar name and (even more)
broken spacing.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-26 19:30:38 -07:00
Dirk Hohndel
8a5792d473 Manually add gas changes to a dive
Create a little widget that lists all the gases / tanks we know about and
allow the user to pick one of them.

Turns out that add_event only added events at the end of the list - but we
treat that list as chronologically sorted. So I fixed that little
mis-feature as well.

This does raise the question whether we need the inverse operation
(removing a gas change). And if there are other things that we should be
able to manually edit, now that we have the infrastructure for this neat
little context menu...

See #60 -- this doesn't address all of the issues mentioned there, but at
least deals with the 'headline' of the feature request...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-17 20:04:25 -07:00
Lubomir I. Ivanov
4401132836 Fix potentially broken white space truncation on certain Windows versions
Testing the Planner in Subsurface on a Windows XP SP3 installation,
shows corrupted UTF-8 strings in the case of Cyrillic locales, but
possibly others as well. Instead limited to the Planner, this affects
the entire application.

After some examination it appears that <ctype>'s isspace() in MSVC
on the tested version of Windows is broken for some UTF-8 characters,
after enabling the user locale using: setlocale(LC_ALL, "");

For example, characters such as the Cyrillic capital "BE" are defined as:
0xD091, where isspace() for the first byte returns 0x08, which is the
bytemask for C1_SPACE and the character is treated as space.
After a byte is treated as space, it is usually discarded from a UTF-8
character/string, where if only one byte left, corrupting the entire
string.

In Subsurface, usages of string trimming are present in multiple
locations, so to make this work try to use GLib's g_ascii_isspace(),
which is a locale agnostic version of isspace().

Affected versions of Windows could be everything up to XP SP3,
but not apparently Vista.

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-07 12:01:47 -08:00
Dirk Hohndel
d2f9ee8d45 Planner: don't use the planned dive for relative start time
The existing code has an embarrassing error in its logic. It picked the
last dive in the table and made sure that the relative start time was
either N minutes after 'now' or N minutes after the last dive ends,
whichever is later.

But once the planned dive has been added to the dive list (so once we have
a first depth and time entry, that last dive now is the planned dive. And
every time focus left the start time field the start time would be
recalculated relative to the end of the dive we are currently planning.

With this patch we instead simply remember the number of the last dive
just as we create the dive plan and use that to look up the end time of
previous dive. I could have just stored that end time but I figured maybe
there could be other reasons to go back to the last dive before the
planned dive, so this seemed cleaner.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-27 10:22:51 -08:00
Lubomir I. Ivanov
97a43003c4 Planner: use time.h and utc_mktime() to retrive the current time (no TZ)
This should do the same as the GTimeZone variant.
Also works on Windows.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-27 09:58:53 -08:00
Robert C. Helling
e5b73d9cb7 Planner: fix wait time calculations
The problem is that when we reach the gas change depth and compute the
stop time, no gas change event is created yet but time_at_last_depth tries
to determine the gas for the stop from events.

So instead we pass o2 and he as parameters of that function and calculate
the wait time based on that information.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-23 16:15:18 -08:00
Dirk Hohndel
ac38aa0243 Planner: fix incorrect gas change event
We stored the He permille instead of the He percentage. But for most
casual testing this was hidden by the previous bug.

Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19 15:10:01 -08:00
Dirk Hohndel
8527720794 Planner: Start calculations with gas 0 instead of air
The planner had a fatal flaw in that it ALWAYS started with AIR, even when
clearly claiming to use the correct gas. We only picked up correct gases
from events, but not at the beginning of the dive (where there is no
event).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19 14:28:07 -08:00
Dirk Hohndel
6b458ad7fa Ensure that planner warnings get shown before calculations are run
Linus pointed out that the warning wasn't shown until the main loop got
control back, so even a gtk_widget_show_all() doesn't really help to make
sure that things are shown right then.

This commit adds a little loop to handle all pending gtk_events before
exiting the show_error() function. Now the warning should be shown BEFORE
a potentially slow calculation gets started.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-14 07:51:25 -08:00
Dirk Hohndel
d1ee250524 Make planner.c warning consistent
Just a tiny change to make them look more consistent.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-13 23:14:55 -08:00
Dirk Hohndel
fd703f3ca0 Support deeper stops and longer dive notes in planner
Since we now support dives all the way down to 400m we should also support
deeper stops. And of course this can create insanely long dive plans, so
make sure there is plenty of space for those.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-13 23:02:05 -08:00
Dirk Hohndel
0cde0eff10 Rewriting the error handling in planner.c
Printf is not a way to issue warnings and errors. This is a very late
addition but seems necessary for a viable release of the planner.

This also adds one artificial limit and two warnings:

a) no dives deeper than 400m
b) warning of potentially very long calculation times for dives longer
   than 3h (180min) before the ascent and dives deeper than 150m

It also creates quite a number of new strings that need to be translated
(and marks a few existing ones for translation as well).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-13 23:02:00 -08:00
Dirk Hohndel
5a540fb9d1 Remove rounded O2 in air
To quote Linus, gentle as always:

 Stuff like this is just BS.

 Don't do it. You already fixed the bug with matching gas change events,
 so adding this idiotic workaround no longer fixes anything, and its
 confusing and actively misleading.

 It's not even percent. It's still permille, just rounded. So it's a
 nonsensical number and a misleading name. Just delete it as the abortion
 it is. It is only going to cause more problems later.

 Just use the correct value.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-12 22:28:31 -08:00
Dirk Hohndel
5e93469f35 Fix gas handling in planner
Two separate bugs.

a) Air cylinders were created with o2=209 and no other value set.
sanitize_gasmix() turned that into o2=0 which meant that this cylinder was
now identified as "nodata", i.e., unset.
We now set a fake cylinder name to deal with that issue.

b) the gaschange event is inherited from libdivecomputer and therefore
only supports 1 percent granularity for o2 and h2. Since we didn't round
when assigning the value we ended up with air being stored as o2=20 he=0
which of course then didn't match air anymore (which we have defined as
208 <= o2 <= 210).
We now use o2=210 for air in the planner and carefully round the permille
values whenever we convert into percent - and compare gases with percent
granularity as well.

A better fix for b) would be to change the Subsurface event to not simply
copy the libdivecomputer behavior and use percent granularity but support
permille instead. But this closely before the 3.0 release that seemed like
a far too invasive change to make - the changes to the planner should have
no impact outside the planner module.

Reported-by: Chris Lewis <chrislewis915@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-12 21:12:17 -08:00
Dirk Hohndel
9d9eff718b Hopefully last change to po files
While this is a pain for everyone, I decided not to edit out the code
reference noise - after all this is supposed to help translators find
where the text is used in case it's unclear how to translate something.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 10:39:11 -08:00
Linus Torvalds
926fcef2a1 Do more dive fixup for each dive computer
In commit b6c9301e58 ("Move more dive computer filled data to the
divecomputer structure") we moved the fields that get filled in by the
dive computers to be per-divecomputer data structures.

This patch re-creates some of those fields back in the "struct dive",
but now the fields are initialized to be a reasonable average from the
dive computer data.  We already did some of this for the temperature
min/max fields for the statistics, so this just continues that trend.

The goal is to make it easy to look at "dive values" without having to
iterate over dive computers every time you do.  Just do it once in
"fixup_dive()" instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 18:22:30 -08:00
Dirk Hohndel
61861d2611 Clean up the handling of surface pressure
There are two ways to look at surface pressure. One is to say "what was
the surface pressure during that dive?" - in that case we now return an
average over the pressure reported by the different divecomputers (or the
standard 1013mbar if none reported any).

Or you want to do specific calculations for a specific divecomputer - in
which case we access only the pressure reported by THAT divecomputer, if
present (and fall back to the previous case, otherwise).

We still have lots of places in Subsurface that only act on the first
divecomputer. As a side effect of this change we now make this more
obvious as we in those cases pass a pointer to the first divecomputer
explicitly to the calculations.

Either way, this commit should prevent us from ever mistakenly basing our
calculations on a surface pressure of 0 (which is the initial bug in
deco.c that triggered all this).

Similar changes need to be made for other elements that we currently only
use from the first divecomputer, i.e., salinity.

Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 08:01:59 +11:00
Dirk Hohndel
79e55b019b Add a more stronly worded warning / disclaimer for dive planning
This is a late string change, but I think this may be a valid exception of
the string freeze...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 22:53:42 +11:00
Sergey Starosek
5cc6e21064 Increase the buffer for the gas text in planner
UTF-8 strings could create more characters.

Signed-off-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03 21:27:25 +11:00
Dirk Hohndel
de0cdf28b2 Merge branch 'po-files'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>

Conflicts:
	po/nb_NO.po
	po/ru_RU.po
2013-02-03 18:08:26 +11:00
Dirk Hohndel
7f59026dbf Distinguish the two uses of "Gas Used" for translation purposes
One is about the amount, the other about the specific type of gar that was
used.

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03 18:03:10 +11:00
Dirk Hohndel
3e426283b4 Increase the buffer for the gas text in planner
Translations that use UTF-8 could easily create more characters than I had
initially specified.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03 08:44:51 +11:00
Jan Schubert
99dbd667bf Fixing SP handling in planner, adding event
This moves some double/floating handling for po2 to plain integer. There
are still non int values around (also for phe and po2) in the plot area.

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03 07:07:12 +11:00
Jan Schubert
59cfa5c427 Fixing SP handling in planner, adding event
Fixing the SP change event and introducing a bailout scenario.

I decided not to use a event showing SP=0.0 nor using a gaschange event as
is in fact there is no gas change related to bailing out itself. If there
is also a gaschange for the event it will be displayed anyway.

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03 07:06:38 +11:00
Jan Schubert
057253c4eb Fixing SP handling in planner, adding event
Fixes bug in planner which prevents from bailing out (setpoint = 0).

Also introduces events for changing setpoints in planner.
It also makes the eventtype for gaschange slightly more consistent by
changing it from SAMPLE_EVENT_GASCHANGE (O2 only) to
SAMPLE_EVENT_GASCHANGE2 (O2/He). But Subsurface treats them both the same
(the distinction comes from libdivecomputer).

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03 07:05:16 +11:00
Lubomir I. Ivanov
60f9c338e9 planner.c: Use g_time_zone_find_interval()
current_time_notz():
Attempt to use g_time_zone_find_interval() to retrieve a
timezone interval, which is then passed to g_time_zone_get_offset()

Reported and tested-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-02 00:05:03 +11:00
Dirk Hohndel
aa55bda944 Don't allow to plan dives out of order
The planned dive always has to be the last dive in the dive list. To make
sure of that we interpret the relative start time to be relative to either
the current time or the end of the last dive, whichever is later.

This fixes a bug where we would delete the wrong dive and get our data
structures confused by planning multiple dives out of order.

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31 23:50:35 +11:00
Dirk Hohndel
e3a8ed5183 Massive cleanup
Mostly coding style and whitespace changes plus making lots of functions
static that have no need to be extern. This also helped find a bit of code
that is actually no longer used.

This should have absolutely no functional impact - all changes should be
purely cosmetic. But it removes a bunch of lines of code and makes the
rest easier to read.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30 08:31:53 +11:00
Dirk Hohndel
a61877d1d4 Add missing strings for translations
Mostly in new code, but some of them are strings in older code that have
been missed in the past.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-29 20:32:56 +11:00
Dirk Hohndel
55b3fd12a8 Make dive planner more useful for closed circuit diving
Add a sample at time 0 to allow for a pO2 from the start of the dive.
Remember the last pO2 so it doesn't have to be repeated (and the right
thing happens for the planned part of the dive).

This still doesn't allow us to change the setpoint at a certain depth
(which would be analogous to being able to switch to a certain gas at a
certain depth in OC plans), but with this commit it's already usable.

This commit also fixes a couple of small bugs in commit b8ee3de870fa
("Dive planning for closed circuit rebreather") where a pO2 of 1.1 was
hardcoded in one place, throwing off all plan calculations and integer
math was used to calculate a floating point value (leading to most pO2
values actually used being 1.0).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 21:39:25 -08:00
Jan Schubert
9df9fc088d Dive planning for closed circuit rebreather
This misses a single issue to be used as a base for further discussion:
The CC setpoint is used for the next segment, not the one specified for. I
also have in mind to modify the existing code to use setpoints specified
in mbar and plain integer instead of float values.

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 18:31:30 -08:00
Linus Torvalds
77ece3fccb Clean up gtk combo box handling
This cleans up our handling of combo boxes and all the duplicated
completion logic, and simplifies the code.

In particular, we get rid of the deprecated GtkComboBoxEntry.  While it
made some things easier, it made other things harder.  Just using
GtkComboBox and setting that up correctly ends up being simpler, and
also makes the logic work with gtk-3.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 13:17:44 -08:00
Henrik Brautaset Aronsen
d1262848d8 Fix compile error in planner.c
Linus seems to have been too eager in the dc refactoring: a diveplan
doesn't have a divecomputer.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 08:47:34 -08:00
Linus Torvalds
b6c9301e58 Move more dive computer filled data to the divecomputer structure
This moves the fields 'duration', 'surfacetime', 'maxdepth',
'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure'
to the per-divecomputer data structure.  They are filled in by the dive
computer, and normally not edited.

NOTE! All actual *use* of this data was then changed from dive->field to
dive->dc.field programmatically with a shell-script and sed, and the
result then edited for details.  So while the XML save and restore code
has been updated, all the displaying etc will currently always just show
the first dive computer entry.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23 12:55:33 -08:00
Dirk Hohndel
aa3eb364bc Add GFlow/GFhigh settings in dive planner
The planner interactively responds to changes to the GFlow and GFhigh in
the dialog and calculates an appropriate profile. If there is a previous
dive within the 48 hours prior to this dive then its saturation is
correctly taken into account if the gradient factors are changed - so if
they are aggressively lowered it is possible to start the dive with
already an existing ceiling (simply increase the surface interval to 'fix'
that).

Once the plan is accepted the GF values are reset to the current
preferences. This can cause the ceiling in the plot to change and the deco
stops to no longer match the ceiling - but that's a logical consequence of
the ability to change a temporary copy of GFlow/GFhigh during the planning
process and not the actual preferences (which would be counter intuitive,
I think).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-16 15:40:38 -08:00
Dirk Hohndel
2cee400ad1 Correctly mark divelist changed after accepting dive plan
Commit 293126257b20 ("Mark divelist as changed if user accepts planned
dive") had the correct commit message but an incorrect implementation.

This moves the mark_divelist_changed() call into the GTK_RESPONSE_ACCEPT
clause where it belongs.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-16 14:44:11 -08:00
Dirk Hohndel
348c590ac6 Mark divelist as changed if user accepts planned dive
When the user clicks OK in the dive planner and the dive is added to the
divelist the divelist needs to be marked as changed so Subsurface prompts
the user to save the file before quitting.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 17:35:29 -08:00
Dirk Hohndel
db8de4233d Calculate the gas used during the planned dive
This works on the assumption that the diver uses the deco SAC rate while
on a calculated deco stop and the bottom SAC rate during the rest of the
dive (including the time they move from deco stop to deco stop).

This is making the planning function mostly useful for open circuit
diving.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 17:35:14 -08:00
Dirk Hohndel
c3a08ff056 Add diveplan to the dive notes
This makes it easy to print out a dive plan - it's simply stored in the
notes of the simulated dive we create.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 17:34:51 -08:00
Dirk Hohndel
189cba7fd2 Add code to enter SAC rates for dive planning
This just provides the infrastructure to enter the data, nothing is
calculated, yet.

This adds a new get_thousandths() helper function so we can enter
information of the 'mili-' type as decimal values. So things like
"14.5 l/min" or "0.75 cuft/min" are parsed correctly and converted
into a ml value.

In the process of implementing that I also fixed a bug introduced in
commit ab7aecf16e ("Simplify dive planning code") which broke the
get_tenth() function.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 17:31:27 -08:00
Dirk Hohndel
417391a801 Add small helper function to make planner gui function easier to read
This is just preparation for the next set of changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 17:31:03 -08:00
Jan Schubert
322410a845 Trivial pressure related fixes
This patch removes the need for the "string" pressurebuf in planner.c.

It also adds a unit to the partial pressures displayed in the mouse
overlay which are always displayed in bar.

BTW: Has anyone seen a pO2 shown in PSI?

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 10:13:33 -08:00
Dirk Hohndel
3b7d68c091 Correct the start time of planned dives
Subsurface follows the lead of most divecomputers to use times without
timezone - so all times are implicitly assumed to be local time of the
dive location; so in order to give the current time in that way we
actually need to add the timezone offset.

Instead of relying on OS specific members of struct tm we use the glib
timezone functions to get the timezone offset for us. Of course, the
function used to do this is only in glib 2.26 or newer, which once again
means that Debian stable won't be supported. But since that doesn't build
other parts of Subsurface, either, I think I'll live with that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 10:09:42 -08:00
Jan Schubert
90d3c5614a Centralising and redefining values as integers
This patch centralizes the definition for surface pressure, oxygen in
air, (re)defines all such values as plain integers and adapts calculations.

It eliminates 11 (!) occurrences of definitions for surface pressure and
also a few for oxygen in air.

It also rewrites the calculation for EAD, END and EADD using the new
definitons, harmonizing it for OC and CC and fixes a bug for EADD OC
calculation.

And finally it removes the unneeded variable entry_ead in gtk-gui.c.

Jan

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14 20:12:40 -08:00
Dirk Hohndel
1ea445102e Correctly show the planned dive in the divelist
Previously we would simply show the first dive in the divelist - which
worked fine in the default sort by trip setting and assuming that there
are no dives from the future in the divelist.

With this commit we actually find the correct dive in the divelist and
select it instead. If you sort by depth you will see the dive move around
in the divelist, but it will stay selected and visible in the profile.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13 21:01:52 -08:00
Linus Torvalds
868a2cc090 Split up preference data structure definition into 'pref.h'
.. and rename the badly named 'output_units/input_units' variables.

We used to have this confusing thing where we had two different units
(input vs output) that *look* like they are mirror images, but in fact
"output_units" was the user units, and "input_units" are the XML parsing
units.

So this renames them to be clearer.  "output_units" is now just "units"
(it's the units a user would ever see), and "input_units" is now
"xml_parsing_units" and set by the XML file parsers to reflect the units
of the parsed file.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10 20:30:32 -08:00
Linus Torvalds
88313f1077 Clean up duplicated depth interpolation
We have several places where we interpolate the depth based on two
samples and the time between them. Some of them use floating point, some
of them don't, some of them meant to do it but didn't.

Just use a common helper function for it. I seriously doubt the floating
point here really matters, since doing it in integers is not going to
overflow unless we're interpolating between two samples that are hours
apart at hundreds of meters of depth, but hey, it gives that rounding to
the nearest millimeter. Which I'm sure matters.

Anyway, we can probably just get rid of the rounding and the floating
point math, but it won't really hurt either, so at least do it
consistently.

The interpolation could be for other things than just depth, but we
probably don't have anything else we'd want to interpolate. But make the
function naming generic just in case.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09 16:17:57 -08:00
Dirk Hohndel
c0ce218df4 Add support to planner to use additional gases during the ascent
This change ended up being quite a bit bigger than expected as it
uncovered a number of bugs in the existing code.

The planner now handles gas changes correctly by creating (and later
parsing) events in the simulated divecomputer. At the end of the dive
specified in the input form the algorithm starts with the deepest
interesting depth: either the first stop below our ceiling or the deepest
depth at which we can change gases. It then traverses all the stop and all
the gas change depth and at each stage ensures that we are allowed to
ascend further before going on.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09 16:01:15 -08:00
Dirk Hohndel
fbea5e31ca Allow special entries in diveplan for available gases
An entry with no time is considered special and not considered when
constructing the profile.

This should allow us to add support for two different ways of adding
information about available gas:

changedepth 0 gasmix
0 0 gasmix @ po2

The first syntax basically says "during the ascent, switch to this gas at
this depth.
The second one says "switch to this gas once the pO2 allows for it"

Neither of these are implemented, yet, but this commit is necessary in
order for the rest of the code to ignore entries with a time field of 0.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08 15:03:37 -08:00