summaryrefslogtreecommitdiffstats
path: root/dive.h
AgeCommit message (Collapse)Author
2013-02-25Take incompressibility of gas into account at higher pressuresGravatar Linus Torvalds
This creates a helper function called "gas_volume()" that takes the cylinder and a particular pressure, and returns the estimated volume of the gas at surface pressure, including proper approximation of the incompressibility of gas. It very much is an approximation, but it's closer to reality than assuming a pure ideal gas. See for example compressibility at http://en.wikipedia.org/wiki/Compressibility_factor Suggested-by: Jukka Lind <jukka.lind@iki.fi> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-25Show a "No Events" label when there are no events in the filter dialogGravatar Lubomir I. Ivanov
Uses profile.c:evn_foreach() to retrieve the number of events, which if zero, no table is added in the dialog and the label is added instead. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24Fix cylinder air size calculationsGravatar Linus Torvalds
Commit 90d3c5614a9c ("Centralising and redefining values as integers") broke SAC-rate calculations. In particular, it changed "to_ATM()": to use the centralized SURFACE_PRESSURE helper define, but in the process it changed a floating point calculation to an integer calculation, and it threw away all the fractional details. Any user of "to_ATM()" basically dropped to an accuracy of a single atmosphere. The good news is that we didn't use to_ATM() for things like depth calculations, but only for cylinder pressures. As a result, the error ends up being relatively small, since the pressures involved are big, and thus the error of rounding to whole atmospheres is usually in the 1% range. The cylinder sizing tends to be off by more than that anyway. But it was wrong, and not intentional. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-22Add correct XSLT search path for WindowsGravatar Dirk Hohndel
And report error if XSLT stylesheet not found Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-18When only a dive trip is selected, select all the dives in the tripGravatar Linus Torvalds
This does a final pass after all the selection logic, and notices if we have dive trips that are selected, but that have no dives in them selected. In that case, we assume that the user wanted to select all dives in that trip. NOTE! This still allows a range selection that selects the dive trip entry and a few dives under the trip. If a trip has any dives selected in it, we leave that manual selection alone. So this new logic really only triggers on the case where somebody selected *just* the trip. Note: unselecting the trip still leaves the dives under it selected, because having a dive trip that isn't selected have all the dives under it be selected is normal, and we can't recognize that as some kind of special event. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-15Get the SHA1 routines from git instead of opensslGravatar Linus Torvalds
..they are of a higher quality anyway, and this way we have one less library to worry about. And this way there is nobody who can claim that openssl is not a system library and thus not compatible with the GPL. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-15Improve the code handling air temperatureGravatar Linus Torvalds
Better helper functions make for easier to understand code. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-14Better handling of manually edited air temperatureGravatar Dirk Hohndel
We now load and save this in the XML file, we do the right thing when merging dives and show the edited air temperature in the Dive Info notebook when a divecomputer doesn't have an air temperature. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-13Rewriting the error handling in planner.cGravatar Dirk Hohndel
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-12Fix gas handling in plannerGravatar Dirk Hohndel
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-09Finish removing accesses to first divecomputer instead of diveGravatar Dirk Hohndel
This adds watertemp and airtemp to the dive, populates them in fixup and uses them elsewhere in the code. WARNING: as a sideeffect we now edit the airtemp in the dive, but we never display this in the DIve Info notebook (as that always displays the data from the specific selected divecomputer). This is likely to cause confusion. It's consistent behavior, but... odd. This brings back the desire to have a view of "best data available" for a dive, in addition to the "per divecomputer" view. This would also allow us to consolidate the different pressure graphs we may be getting from different divecomputers (consider the case where you dive with multiple air integrated computers that are connected to different tanks - now we could have one profile with all the correct tank pressure plots overlayed - and the best available (or edited) data in the corresponding Dive Info notebook. This commit also fixes a few remaining accesses to the first divecomputer that fell through the cracks earlier and does a couple of other related cleanups. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Move duration to dive structure and replace accessor functionGravatar Dirk Hohndel
When starting on this quest to stop using the first divecomputer instead of data for the whole dive in commit eb73b5a528c8 ("Duration of a dive is the maximum duration from all divecomputers") I introduced an accessor function that calculates the dive duration on the fly as the maximum of the durations in the divecomputers. Since then Linus and I have added quite a few of the variables back to the dive data structure and it makes perfect sense to do the same thing for the duration as well and simply do the calculation once during fixup. This commit also replaces accesses to the first divecomputer in likely_same_dive to use the maxdepth and meandepth of the dive (those two slipped through the cracks in the previous commits, it seems). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Add a meandepth to the dive structureGravatar Dirk Hohndel
This is currently only used in one place (in statistics.c), but it certainly is consistent with the other recent changes to avoid using only the first divecomputer when trying to make statements about a dive. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Add maxdepth back to the dive structureGravatar Dirk Hohndel
Populate during dive fixup as the maximum depth shown by all the divecomputers. Use this value (instead of the one in the first divecomputer) in printing, statistics, etc. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Do more dive fixup for each dive computerGravatar Linus Torvalds
In commit b6c9301e5847 ("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-09Clean up the handling of surface pressureGravatar Dirk Hohndel
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-08The 'gasmix' argument to add_segment() is read-onlyGravatar Linus Torvalds
We'll want to use a 'static const' gasmix for the upcoming no-fly-time code, so prepare for it by just marking the read-only gasmix argument as 'const'. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Duration of a dive is the maximum duration from all divecomputersGravatar Dirk Hohndel
So far we always used the duration of the first divecomputer. The same fix needs to be done for some of the other calculations that always use the first divecomputer. This commit also removes some obsolete code from the webservice merging. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-04Get rid of dive->{start,end}Gravatar Linus Torvalds
We had this special logic to not show the end of a dive when a dive computer shows a series of very shallow samples (basically snorkeling back to shore after the dive ended). However, that logic ended up being global per dive, which is very annoying when you have two or more dive computers, and it decides to cut off the second one because the first one surfaces. So get rid of this per-dive state, and just use the plot-info 'maxtime' field for this (we never used the 'start' case anyway). That way we will properly cut off boring surface entries only when they are past the end of the interesting entries of *all* dive computers, and we won't be cutting things short. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Fixing SP handling in planner, adding eventGravatar Jan Schubert
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-02Add 'Save As' entry to context menu shown when right clicking on a diveGravatar Pierre-Yves Chibon
Something which is nice especially when asked on the list to share an interesting dive is the possibility to save just some dives into a file. This commit adds to the context menu shown with right-click the 'Save As' entry. This entry allows to save selected dives. [Dirk Hohndel: clean up white space, commit message and remove unused variables] Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-01Clear the list of events when closing data fileGravatar Dirk Hohndel
When the data file is closed we should reset the events that we offer for filtering. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31Better algorithm to merge gps locations & locations names from webserviceGravatar Dirk Hohndel
This no longer abuses the dive merging code (which would leave stray "dives" behind if a gps fix couldn't be merged with any of the dives) and instead parses the gps fixes into a second table and then walks that table and tries to find matching dives. The code tries to be reasonably smart about this. If we have auto-generated GPS fixes at regular intervals, we look for a fix that is during a dive (that's likely when the boat where the phone is staying dry is more or less above the diver having fun). And if we have named entries (so the user typed in a location name) we try to match them in order to the dives that happened "that day" (where "that day" is about 6h before and after the timestamp of the gps fix). This commit also renames dive_has_location() to dive_has_gps_location() as the difference between if(!dive->location) and if(dives_has_location) is a bit too subtle... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31Allow using two different tables to hold dives and gps locationsGravatar Dirk Hohndel
This only changes the infrastructure and actually loses functionality as it no longer does the simplistic "just treat the locations as dives and merge them". The new code that does something "smart" with the gps_location_table is yet to be written. But now we can use the XML parser to put the gps locations downloaded from the webservice into their own data structure. In the process I noticed that we never used the two delete functions in parse-xml.c and removed them. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Make 'get_dive_by_diveid()' work even for non-primary dive computersGravatar Linus Torvalds
It's only used by the Uemis importer, and Dirk always seems to import his Uemis data first, so it wasn't very noticeable. But if the Uemis data wasn't the first dive computer, it would not find the dive. Side note: just comparing deviceid is not correct. We should pass in the device model too. But again, that will realistically never really matter, since non-Uemis importers will generate complex SHA1 hashes of the dive data for the dive ID, so a collision with the Uemis numbers is very unlikely. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Massive cleanupGravatar Dirk Hohndel
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-28Dive planning for closed circuit rebreatherGravatar Jan Schubert
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-28Pick GPS coordinates of dive location via map widgetGravatar Dirk Hohndel
I have some concerns about the way this is implemented - especially the use of gtk_grab_add to make the map widget work has me worried. But it seems to work and survived some test cases that I threw at it. The GtkButton with the Pixmap looks a little off on my screen, but this way it was easy to implement. Feel free to come up with a better design. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-27UTF8 aware parser for some more GPS formatsGravatar Dirk Hohndel
I'm sure there are better ways to do this, but this appears to grok most rational formats I was able to find. NSEW or positive/negative numbers. Decimal degrees (WGS84) or degrees and decimal minutes (that's what most GPSs seem to provide). I'm sure there are still corner cases that confuse it, but it seemed reasonably robust in testing. I don't really love the ';' as separator but that solves the obvious problem with locales that use a decimal comma. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Centralization for Kelvin and Standardization to milliKelvinGravatar Jan Schubert
This centralizes all occurrences of Kelvin to dive.h and standardizes all usages to milliKelvin. [Dirk Hohndel: renamed the constant plus minor white space cleanup] Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Use actual min and max temperatures in statistics.Gravatar Henrik Brautaset Aronsen
The statistics page only used each dive's "watertemp" attribute, regardless of actual higher/lower temperatures in the samples. By finding the actual max/min temperatures, the statistics page utilize more "real" data, and look better even on single dives. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Remove saving of dive computer nicnames in system configGravatar Linus Torvalds
We save the (more complete) dive computer information in the XML file with serial numbers and firmware version if we know about them, so using a complicated string in the system config was redundant and confusing. So remove that code. NOTE! Since the dive computer nicknames are now only saved if the XML file is saved, we also mark the dive list "changed" when we edit the nicknames. That way we'll be prompted to save things before exiting, even if we don't actually edit any actual dive data. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Save all dive computer nicknames - whether used or notGravatar Linus Torvalds
We used to save dive computer information only if that dive computer was actually used in any of the dives we saved. But we can simplify the code if we just always save any dive computers we know about. And it does allow for some usage cases where you have nicknames for other peoples computers that you may not actively use, but you want to see if you end up loading multiple XML files in one go. So there's just no compelling reason to not just save all the info we have. And this will make it less painful to remove the "use system config for dive computer nicknames", because you can also use this to continue to gather dive computer info in a separate XML file if you want to. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Fix temperature rounding issuesGravatar Linus Torvalds
Temperatures can actually be negative, which means that rounding by adding 0.5 and casting to 'int' is not correct. We could use '(int)(rint(val))' instead, but the only place we care about might as well just print out the floating point representation with a precision of two digits instead. So if you have a dive computer that gives you the precision, you might see '3.5˚C' as the temperature. Remove the helper functions that nobody uses and that get the rounding wrong anyway. Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Move more dive computer filled data to the divecomputer structureGravatar Linus Torvalds
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-16Only offer to show dive on map if we have location informationGravatar Linus Torvalds
This adds the "Show in map" menu entry to the divelist only if we actually have a location to show. Of course, having some way to visually see whether we have a GPS location even before we show the menu would probably be good. Maybe a marker in the "location" string or something. But in the meanwhile, at least we don't have that menu entry if we have nothing to show. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Show single dives in map.Gravatar Henrik Brautaset Aronsen
This adds a "Show in map" entry in the dive list context menu. It will zoom to the dive location if it exists, otherwise the full map will be displayed. I've also switched map tiles from OpenStreetMap to Google Maps just to show off that we can. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Add diveplan to the dive notesGravatar Dirk Hohndel
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-15Add code to enter SAC rates for dive planningGravatar Dirk Hohndel
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 ab7aecf16e96 ("Simplify dive planning code") which broke the get_tenth() function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Added the OS dependent function subsurface_launch_for_uri()Gravatar Lubomir I. Ivanov
Opening URI addresses from Subsurface does not work on Windows using the latest GTK bundle from the Gnome website. The reason lies in GIO and GLib and how it obtains assigned applications for protocols and MIME types. While gtk_show_uri() should be viable for both linux.c and macos.c, in windows.c ShellExecute() is used, which provides proper support for the URI calls. subsurface_launch_for_uri() returns TRUE on success. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14Centralising and redefining values as integersGravatar Jan Schubert
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-13Add support for MOD, EAD, AND and EADD in the mouse over displayGravatar Dirk Hohndel
- MOD: Maximum Operation Depth based on a configurable limit - EAD: Equivalent Air Depth considering N2 and (!) O2 narcotic - END: Equivalent Nitrogen (Narcotic) Depth considering just N2 narcotic (ignoring O2) - EADD: Equivalent Air Density Depth Please note that some people and even diving organisations have opposite definitions for EAD and END. Considering A stands for Air, lets choose the above. And considering N for Nitrogen it also fits in this scheme. This patch moves N2_IN_AIR from deco.c to dive.h as this is already used in several places and might be useful for future use also. It also respecifies N2_IN_AIR to a more correct value of 78,084%, the former one also included all other gases than oxygen appearing in air. If someone needs to use the former value it would be more correct to use 1-O2_IN_AIR instead. Signed-off-by: Jan Schubert / Jan.Schubert@GMX.li Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13Work on a dive localisation tool using GPS coordinatesGravatar Pierre-Yves Chibon
For each dive recorded, place their GPS coordinates onto a map using the OSM-GPS-MAP library. This map is accessible via the "log" menu or the shortcut ctrl+M (M as map). We check for the GPS coordinates "0, 0" which are the default when we do not have real GPS coordinates set. [Dirk Hohndel: fixed int/float math confusion, fixed some whitespace and coding style issues, cleaned up some comments, added a missing cast to prevent a compiler warning] Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr> Signed-Off-By: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-11Add default filename and divelist font to prefs structureGravatar Linus Torvalds
.. and add the usual logic to not save the default values. This also simplifies the initial system-specific setup of both of these: since we have defaults for all the preferences that get set up at startup, we can just initialize those defaults to the system-specific fonts then and there. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10Split up preference data structure definition into 'pref.h'Gravatar Linus Torvalds
.. 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-09Move device_info handling into a new 'device.c' fileGravatar Linus Torvalds
The legacy nickname wrappers (that use the device_info structure) are left in gtk-gui.c. We can slowly start moving away from them, we don't want to start exporting that thing as some kind of generic interface. This isn't a pure code movement - because we leave the legacy interfaces alone, there are a few new interfaces in device.c (like "create a new device_info entry") that were embedded into the legacy "create nickname" code, and needed to be abstracted out. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Clean up duplicated depth interpolationGravatar Linus Torvalds
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-08Rewrite of the deco codeGravatar Robert C. Helling
o) Instead of using gradient factors as means of comparison, I now use pressure (as in: maximal ambient pressure). o) tissue_tolerance_calc() now computes the maximal ambient pressure now respecting gradient factors. For this, it needs to know about the surface pressure (as refernce for GF_high), thus gets *dive as an argument. It is called from add_segment() which this also needs *dive as an additional argument. o) This implies deco_allowed_depth is now mainly a ambient-pressure to depth conversion with decorations to avoid negative depth (i.e. no deco obliation), implementation of quantization (!smooth => multiples of 3m) and explicit setting of last deco depth (e.g. 6m for O2 deco). o) gf_low_pressure_this_dive (slight change of name), the max depth in pressure units is updated in add_segment. I set the minimal value in buehlmann_config to the equivalent of 20m as otherwise good values of GF_low add a lot of deco to shallow dives which do not need deep stops in the first place. o) The bogus loop is gone as well as actual_gradient_limit() and gradient_factor_calculation() and large parts of deco_allowed_depth() although I did not delete the code but put it in comments. o) The meat is in the formula in lines 147-154 of deco.c. Here is the rationale: Without gradient factors, the M-value (i.e the maximal tissue pressure) at a given depth is given by ambient_pressure / buehlmann_b + a. According to "Clearing Up The Confusion About "Deep Stops" by Erik C. Baker (as found via google) the effect of the gradient factors is no replace this by a reduced affine relation (i.e. another line) such that at the surface the difference between M-value and ambient pressure is reduced by a factor GF_high and at the maximal depth by a factor GF_low. That is, we are looking for parameters alpha and beta such that alpha surface + beta = surface + gf_high * (surface/b + a - surface) and alpha max_p + beta = max_p + gf_low * (max_p/b + a - max_p) This can be solved for alpha and beta and then inverted to obtain the max ambient pressure given tissue loadings. The result is the above mentioned formula. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Remove the now obsolete hard coded test_planGravatar Dirk Hohndel
This was just a crutch to get something out there for people to play with. With the ability to input a plan in place this is now obsolete. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Support relative times in diveplanner input "on the fly" modeGravatar Dirk Hohndel
This had gotten lost when updating the profile on the fly. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>