Commit graph

385 commits

Author SHA1 Message Date
willem ferguson
d1c521ce5e CCR patch: adapt code for diluent cylinder pressures (3)
This patch implements the cylinder pressure calculations for diluent
gas in CCR dive computers. This is the third patch for achieving this.
The following were performed:

1) Add two lines to try_to_fill_sample() in parse-xml so that
   diluent cylinder pressures are stored from XML dive log file
   into structures of sample.
2) Add one line to populate_plot_entries() in profile.c so that
   the diluent cylinder pressures are copied from structures of
   sample to structures of plot_info.
3) add three constant #defines in profile.h
4) change populate_pressure_information() in gaspressures.c in
   order to take into account pressure calculations for the
   diluent cylinder, calling subordinate functions in the
   appropriate way.
5) change create_plot_info_new() in profile.c in order to initiate
   the pressure calculations for the diluent cylinder.
6) Implement two debugging functions (one in profile.c, another
   in gaspressures.c). These debugging functions are activated
   by means of #defines.

Two function calls dealing with oxygen pressure are currently commented
out.  They will be activated in the following patch that attends to CCR
oxygen partial pressure calculation.

[Dirk Hohndel: rather massive whitespace cleanup]

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-09-11 08:32:10 -07:00
Willem Ferguson
7575eb44df CCR code: Split profile.c into two files, with gas caluclations separate.
This patch implements a separation of the code for gas pressure
calculations from the rest of the code in profile.c. The latter
file is now split into: profile.c and gaspressures.c. The
details of the transferred functions is given at the top of
gaspressures.c. The following chnages were made:
1) dive.h: The function types of calculate_depth_to_mbar
   and depth_to_mbar were made non-static in order to make them
   available within gaspressures.c.
2) profile.c: Prototypes for the functions in gaspressures.c
   were inserted at the top of profile. Ten functions were
   transferred from profile.c to gaspressures.c
3) gaspressures.c as well as a short header, gaspressures.h
   were created.

For the gas pressure calculations for CCR dives, gaspressures.c
forms the immediate basis for further code development.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-25 13:53:51 -07:00
Anton Lundin
848a5352c7 Add support divecomputer based TTS
Since earlier have we had support for our own calculated TTS. This adds
support for holding TTS values reported by a dive computer.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-09 13:22:00 -07:00
Anton Lundin
537beb319b Only calculate deco stops, TTS and NDL every 30s
This introduces a limiter that we only calculate deco stop, TTS and NDL
with a minimum of 30s intervall and just reused the values from the
previous sample in other cases.

I run my OSTC3 at 2s sample intervall so this is a 15x speedup in that
case.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-29 17:16:43 -07:00
Robert C. Helling
65c5d6815c Make pO2 settings functional in planner
Spin boxes for pO2 are now hooked up to preference values. Adding new
cylinders (or changing their fo2) computes the MOD accordin to the current
value of decopo2. Note that chaning the limits for deco pO2 does _not_
automatically update the switch depth of all cylinders as those might have
been manually entered.

Furthermore, MOD has now to option of rounding to multiples of a given
depth. That is used for the automatic switch depth which are now always
multiples of 3m (so that EAN50 is switched to at 21m rather than 22m).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25 21:07:10 +08:00
Henrik Brautaset Aronsen
630ec88dd4 Be more consistent in partial pressure naming
Lets just use pO₂ instead of PO2, ppO2, ppO₂, PO₂.
They all mean the same, but it's better to be
consistent

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-23 06:48:54 +08:00
Dirk Hohndel
a3ce3221fd Fix incorrect argument order for %.*f
Strangely, *prinf() on Linux appears to do the right thing in either
order (my guess is based on the type of the two values?), but on Windows
things go badly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-09 11:23:05 -07:00
Dirk Hohndel
bbe62f756a Change character for liter in SAC values as well
And fix the bug that in the info overlay SAC was always given in metric
values. And try to reduce the number of places in which we calculate the
unit conversions...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 21:00:56 -07:00
Anton Lundin
f34e6218a0 More tweaks to TTS calculations
Add a lager step value when walking the calculations forward.

[Dirk Hohndel: this was sent ages ago and in all the discussions about the
               implications I apparently never applied this]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-04 13:44:08 -07:00
Linus Torvalds
9874a97ed5 Make bigger steps when calculating TTS
[Dirk Hohndel: this was sent ages ago and in all the discussions about the
               implications I apparently never applied this]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-04 11:05:22 -07:00
Willem Ferguson
eaf6d56487 CCR code: Change to sample structure
1) All the variables in the sample structures are strongly typed
2) Two additional types were declared in units.h:
     o2pressure_t
     bearing_t
3) The following variables were added:
     diluentpressure
     o2setpoint
     o2sensor[3]
4) Changes to a number of files were made to chanf
     sample->po2 to sample->po2.mbar
     bearing to bearring.degrees

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 17:05:25 -07:00
Dirk Hohndel
1a04013453 Encapsulate the horrid gas encoding in gas change events
We should never pass permille values around as integers. And we shouldn't
have to decode the stupid value in more than one place.

This doesn't tackle all the places where we access O2 and He "too early"
and should instead keep passing around a gaxmix. But it's a first step.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 12:07:29 -07:00
Dirk Hohndel
56395b3894 Don't assume that pressures are always positive
When planning a dive, the dive could use more gas than is in the cylinder.
So getting a negative end pressure is a useful indication to the user that
there plan might not be a good one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-29 13:18:13 -07:00
Anton Lundin
ff966f2c1a Move mod calculations to a separate helper
We use mod calculations on multiple places, so make a separate helper
from it with proper types.

The "clumsiness" of defining a local variable to pass into the function
and out from it comes from the discrepancies in how c and c++ handles
initializations of variables in a struct.

Thanks goes to Tiago and Linus for pointing me in the right direction.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-25 06:20:52 -07:00
Tomaz Canabrava
c86d055db7 Do not check for null before free.
C specs says that we can safelly free a NULL pointer, so there's no reason
to check if it's null before freeing it.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-13 09:26:50 +09:00
Anton Lundin
08df5e7e87 Use enum name instead of its int value.
SAMPLE_EVENT_GASCHANGE2 is the libdivecomputer name of the event.
Compare with that instead of its int value.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 14:58:04 -07:00
Miika Turkia
e5ce55ed6c Set minpressure from manually added cylinders
This includes minimum pressure from manually added cylinders to be taken
into account on scaling. Without this, manually added cylinders might
lead to pressure dropping below the Y axis 0 line (e.g. when first
"computerized" cylinder is 220->140 and second, manually added cylinder,
200->50 bar).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-28 14:15:08 -07:00
Linus Torvalds
0c5ec1d6db Don't calculate SAC-rates for negative pressure changes
They happen - maybe the cylinder actually warmed up, or maybe the user
entered just a ending pressure without a starting pressure.  Regardless,
just ignore cylinder pressure changes that go up.

Also ignore cylinders with a zero ending pressure: that's really a
*missing* pressure rather than an actual zero pressure.  As Dirk says,
the scuba regulators don't even work without a healthy positive pressure
differential, so even when you breathe down a tank to "empty", it won't
be at zero pressure (this is true even with gauge pressure, where zero
means "atmospheric pressure").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-26 17:24:12 -07:00
Gehad Elrobey
8380f09619 Renaming the prefs struct members to be consistent with the QSettings.
-Renaming prefs members for consistency.
-Changing references of QSettings to the prefs structure instead.
-Removing unused functions in pref.h were left over from an old version.
-Changing the data-type of bool members to short for consistency with other members.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-16 13:09:55 -07:00
Lakshman
6a8d929876 Feature to show or hide heart rate graph
Adds new push button "HR" to the button bar on the dive profile to
toggle display of heart rate.

TODO: New icon for the heart rate button is needed.

Fixes #485

Signed-off-by: Lakshman Anumolu <acrlakshman@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-10 09:21:43 -07:00
Robert C. Helling
61d60f6b1a Exchange EAD and END to align our language with the rest of the world
This needs to be tracked in the documentation as well.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-31 09:48:16 -07:00
Robert C. Helling
907459291d Show EAD/END only for trimix/nitrox dives respectively
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-31 08:58:35 -07:00
Robert C. Helling
374f99af18 Get rid of division by 0 by reshuffling EAD and EAN logic
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-30 16:02:21 -07:00
Dirk Hohndel
cb53049b74 Don't devide by 0 if fO2 is 100%
Fixes #465

Initial-patch-by: Anton Lundin <glance@acc.umu.se>
Better-idea-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-17 20:41:16 -07:00
Linus Torvalds
37794e2e23 Be more careful about dive computer selection
The selection logic was a bit random: some places would return NULL if
the dive computer index was out of range, others would return the
primary dive computer, and actually moving between dive computers would
just blindly increment and decrement the number.

This always selects the primary computer if the index is out of bounds,
and makes sure we stay in bound when switching beteen dive computers
(but switching between dives can then turn an in-bound number into an
out-of-bounds one)

Fixes #464

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-17 10:53:49 -07:00
Tomaz Canabrava
00c97e710f Remove a Lot of Dead Code.
This is just removal of dead code from the old profile, probably there's
still a bit more to remove, but this is a very good cleanup already.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 08:56:06 -08:00
Dirk Hohndel
211ff0e63b Fix theoretical uninitialized read
We should never read cur_pr[cyl] if cyl isn't used during a dive - but for
cylinders that are used cur_pr[cyl] is initialized. But just to catch
errors elsewhere, let's not leave cur_pr[cyl] uninitialized.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 16:16:10 -08:00
Dirk Hohndel
d24d2288f3 Remove pointless assignments
tissue_tolerance wasn't used after it was assigned.
type was overwritten after it was assigned.
serial was overwritten after the last /= 100.
event is assigned in the for loop.
clear isn't used after the assignment

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03 21:40:56 -08:00
Dirk Hohndel
7c535452f9 Whitespace cleanup
Minor change to the perl postprocessing script and resulting changes to
the affected source files.

This deals with two issues:
- "foreach"-like structures were not always treated correctly
- some longer calculations that ended on "+ constant" were reformatted in
  a rather unatractive manner

In one source file (divelist.c) I ended up adding braces to the sources...
trying to cascade the indentation further down without having the block
there seemed a lot more trouble than it's worth.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03 13:29:22 -08:00
Dirk Hohndel
76e6420f6b Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 20:09:57 -08:00
Tomaz Canabrava
8c56b2f45e Store zoomed plot in preferences
This patch makes the 'Zoomed Plot' a preference that can be stored and
retrieved, this way if the user sets the plot to be 'zoomed', this
information will persist even if they closed or opened subsurface again.

Also, added the 'Scale' button on the new profile, but didn't did the glue
code yet.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 10:48:35 -08:00
Andrey Zhdanov
fdc11abe68 Typesetting in profile infobox
There should be a space between the colon and the value in the information
box in the profile.  The vertical speed should have only one digit after
the decimal point.

Fixes #443

Signed-off-by: Andrey Zhdanov <andrjufka@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-26 15:38:46 -08:00
Dirk Hohndel
41abab7253 Calculate minimum and maximum heartrate
And setup the axis accordingly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-23 14:32:25 -08:00
Dirk Hohndel
4c68d4c616 Make sure that there are plot_info entries for events
We use the plot_info as basis for our dataModel in the new profile. In
order to be able to place events at the right spot we need to have a
plot_info entry when the event happens. So let's add interpolated entries
not only based on time but also whenever there's an event between them.

This should address Robert's comment in commit 0474fe70fc ("New profile:
add image pixmaps for image events").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-23 08:36:20 -08:00
Dirk Hohndel
8a4a693cb7 Don't use the same variable for new and old profile
This will make no difference when we remove the old profile, but for now I
worry that this could cause us trouble.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-17 19:50:19 -08:00
Dirk Hohndel
4e5e87c51d Don't return a stack variable
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-17 19:10:35 -08:00
Linus Torvalds
23baf20f56 Use "rint()" instead of rounding manually with "+ 0.5"
rint() is "round to nearest integer", and does a better job than +0.5
(followed by the implicit truncation inherent in integer casting).  We
already used 'rint()' for values that could be negative (where +0.5 is
actively wrong), let's just make it consistent.

Of course, as is usual for the messy C math functions, it depends on the
current rounding mode.  But the default round-to-nearest is what we want
and use, and the functions that explicitly always round to nearest
aren't standard enough to worry about.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12 17:41:49 -08:00
Linus Torvalds
e58f54cac1 Fix ATM-vs-bar confusion
SAC should be calculated in relationship to surface pressure, not "1 bar".

I also realize that we have a few other cases where we do the same
mistake: the partial pressure calculations do things like

    po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);

which is wrong as well - the partial pressure is also relative to
standard atmospheric pressures.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-11 14:05:54 -08:00
Boris Barbulovski
3e41047d41 Fix plot_info calculate_max_limits_new() function return value
The return value(structure) was not fully initialized, thus random data
returned for uninitialized members possibly causing random bahavior.

Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:54:17 -08:00
Linus Torvalds
50424df653 Use 'struct membuffer' for profile info string generation
The profile info was generated using nasty string concatenation that the
membuffers are much better at anyway.  And membuffers don't need those
arbitrarily sized fixed buffers (500 bytes? Why 500 bytes?).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:03:27 -08:00
Linus Torvalds
22f66501ac Add support for heartrate and bearing information in samples
libdivecomputer already supports this, but we didn't save it.

Tested-by: Oscar Isoz <jan.oscar.isoz@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:03:24 -08:00
Tomaz Canabrava
40cb57b202 Adapt the ToolTip to work on the new profile
With this patch the tooltip is ready to work on the new profile, we just
need to actually use it.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-06 06:29:19 -08:00
Tomaz Canabrava
25b0a846af Created a method to check if calculations should take place.
Created a method to check if calculations should take place
taking into consideration what changed on the model. if the
model changes *everything*, them, all calculations should
be done, but if just some of the columns of the model are
changed, only those columns should trigger an visual update
on the items.

In theory this patch looks right, but something is wrong (
calculations are not being made. ), so I'll commit this any
how, and fix on the next commit.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-05 06:30:33 -08:00
Tomaz Canabrava
92446f0009 Always calculate deco data, independent of preferences
This is a better way since we can enable / disable the deco by changing
the preferences later, and that will not need to recalculate everything
just because a polygon was set to invisible.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-29 09:33:45 -08:00
Tomaz Canabrava
c99089e1fa Add settings awareness for the PP graph
This commit is rather big, and I forgot to cut it in pieces.
The first part creates a new 'calculate_gas_information' that will not
fill the profile_info->maxpp member ( that should be removed from it as
soon as the new dialog is finished ). The reason for that is that all of
the profile data will be calculated and the graph needs to update
dynamically, so whenever the settings changes, I ask for the model which
is the biggest graph and replot only the ones we need.

The second part adds a new animation function 'animdelete' to fade-out and
delete the item when it's done. the old function 'hide' did just that but
a hide shouldn't delete anything.

The third part is preferenes awareness for the PP graphs. I created two
new functions that receive the settings key for visibility and use the
QSettings to show / hide them. This also works quite well for the axis;
if no graph is visible, the axis will also hide itself.

The fourth part is colors. The pp graphs now have the correct colors.

And a bit of code cleanup too.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-27 09:15:28 -08:00
Tomaz Canabrava
779c1b6738 Create a version of create_graph_info that doesn't depend on GC.
This version of the create plot info is the same as before, with the
difference that it doesn't depends on the gc.
Also fixed a crash.

The Pressure Index, Information and interpolated seems wrong,
I'm getting only zeroes.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-17 14:04:47 -08:00
Dirk Hohndel
a27f67c026 Whitespace and coding style updates
Another futile attempt to cleanup the code and make coding style and
whitespace consistent. I tried to add a file that describes the key points
of our coding style. I have no illusions that this will help the least
bit...

This commit should ONLY change whitespace

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 11:50:56 +07:00
Tomaz Canabrava
dd64f1792d Reworked the calculate_max_limits and plotted the dive.
Created a new version of calculate_max_limits that doesn't have a
graphics_context and returns a plot_info. The code is basically the same
as the old calculate_max_limits, so there's not much to talk about.

The rest of the code is just boilerplate to plug the Profile
code with the axis and model stuff, to be plotted on screen.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 10:12:31 +07:00
Tomaz Canabrava
7d5cf32501 Added a Model that should handle the Dive Profile
This model encapsulates the plot_info struct and provides
a consistent way to show it using the Qt Model view system
in the C++ and QML way. For a QGraphicsItem that should show
a Profile, this is the start.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 10:12:30 +07:00
Anton Lundin
33391a77e9 Convert the C code to using stdbool and true/false
Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 09:34:50 +07:00