diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-02 12:39:55 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-02 12:39:55 -0700 |
commit | 55352a051cfa7ac519e397cd3d18851e5050517b (patch) | |
tree | 8d42a09d66212b84f992c8d3ce6b8e341cdac94a /dive.c | |
parent | e4bfb6597279ca3d9aa3678a617f5f0aef298278 (diff) | |
parent | 619ab9e828d4db7b0c4089018b09892c9d04ece9 (diff) | |
download | subsurface-55352a051cfa7ac519e397cd3d18851e5050517b.tar.gz |
Merge branch 'add-info-stats-page' of git://github.com/dirkhh/subsurface
* 'add-info-stats-page' of git://github.com/dirkhh/subsurface:
Add Info & Stats page to the notebook
Even more places with pressure and volume conversions
Further cleanup of pressure and volume conversions
Use unit functions to get column headers, add unit function for pressure
More consistency improvements
Add new helper function to get temperature and unit
Diffstat (limited to 'dive.c')
-rw-r--r-- | dive.c | 66 |
1 files changed, 66 insertions, 0 deletions
@@ -29,6 +29,72 @@ void add_event(struct dive *dive, int time, int type, int flags, int value, cons remember_event(name); } +int get_pressure_units(unsigned int mb, const char **units) +{ + int pressure; + const char* unit; + + switch (output_units.pressure) { + case PASCAL: + pressure = mb * 100; + unit = "pascal"; + break; + case BAR: + pressure = (mb + 500) / 1000; + unit = "bar"; + break; + case PSI: + pressure = mbar_to_PSI(mb); + unit = "psi"; + break; + } + if (units) + *units = unit; + return pressure; +} + +double get_temp_units(unsigned int mk, const char **units) +{ + double deg; + const char *unit; + + if (output_units.temperature == FAHRENHEIT) { + deg = mkelvin_to_F(mk); + unit = UTF8_DEGREE "F"; + } else { + deg = mkelvin_to_C(mk); + unit = UTF8_DEGREE "C"; + } + if (units) + *units = unit; + return deg; +} + +double get_volume_units(unsigned int ml, int *frac, const char **units) +{ + int decimals; + double vol; + const char *unit; + + switch (output_units.volume) { + case LITER: + vol = ml / 1000.0; + unit = "l"; + decimals = 1; + break; + case CUFT: + vol = ml_to_cuft(ml); + unit = "cuft"; + decimals = 2; + break; + } + if (frac) + *frac = decimals; + if (units) + *units = unit; + return vol; +} + double get_depth_units(unsigned int mm, int *frac, const char **units) { int decimals; |