diff options
-rw-r--r-- | dive.h | 19 | ||||
-rw-r--r-- | libdivecomputer.c | 2 | ||||
-rw-r--r-- | parse-xml.c | 2 | ||||
-rw-r--r-- | save-xml.c | 2 | ||||
-rw-r--r-- | uemis.c | 4 |
5 files changed, 15 insertions, 14 deletions
@@ -11,13 +11,14 @@ #include <libxml/tree.h> #include <openssl/sha.h> -#define O2_IN_AIR 209 // permille -#define N2_IN_AIR 781 -#define O2_DENSITY 1429 // mg/Liter -#define N2_DENSITY 1251 -#define HE_DENSITY 179 -#define SURFACE_PRESSURE 1013 // mbar +#define O2_IN_AIR 209 // permille +#define N2_IN_AIR 781 +#define O2_DENSITY 1429 // mg/Liter +#define N2_DENSITY 1251 +#define HE_DENSITY 179 +#define SURFACE_PRESSURE 1013 // mbar #define SURFACE_PRESSURE_STRING "1013" +#define ZERO_C_IN_MKELVIN 273150 // mKelvin /* @@ -161,7 +162,7 @@ static inline int to_feet(depth_t depth) static inline double mkelvin_to_C(int mkelvin) { - return (mkelvin - 273150) / 1000.0; + return (mkelvin - ZERO_C_IN_MKELVIN) / 1000.0; } static inline double mkelvin_to_F(int mkelvin) @@ -171,12 +172,12 @@ static inline double mkelvin_to_F(int mkelvin) static inline unsigned long F_to_mkelvin(double f) { - return (f-32) * 1000 / 1.8 + 273150.5; + return (f-32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN + 0.5; } static inline unsigned long C_to_mkelvin(double c) { - return c * 1000 + 273150.5; + return c * 1000 + ZERO_C_IN_MKELVIN + 0.5; } static inline double psi_to_bar(double psi) diff --git a/libdivecomputer.c b/libdivecomputer.c index 8345c859f..3a32c5d97 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -214,7 +214,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata) sample->cylinderpressure.mbar = value.pressure.value * 1000 + 0.5; break; case DC_SAMPLE_TEMPERATURE: - sample->temperature.mkelvin = (value.temperature + 273.15) * 1000 + 0.5; + sample->temperature.mkelvin = value.temperature * 1000 + ZERO_C_IN_MKELVIN + 0.5; break; case DC_SAMPLE_EVENT: handle_event(dc, sample, value); diff --git a/parse-xml.c b/parse-xml.c index 55b37a9c4..8128f25ee 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -348,7 +348,7 @@ static void temperature(char *buffer, void *_temperature) temperature->mkelvin = val.fp * 1000; break; case CELSIUS: - temperature->mkelvin = (val.fp + 273.15) * 1000 + 0.5; + temperature->mkelvin = val.fp * 1000 + ZERO_C_IN_MKELVIN + 0.5; break; case FAHRENHEIT: temperature->mkelvin = (val.fp + 459.67) * 5000/9; diff --git a/save-xml.c b/save-xml.c index afee34da5..6e33cd5e6 100644 --- a/save-xml.c +++ b/save-xml.c @@ -37,7 +37,7 @@ static void show_milli(FILE *f, const char *pre, int value, const char *unit, co static void show_temperature(FILE *f, temperature_t temp, const char *pre, const char *post) { if (temp.mkelvin) - show_milli(f, pre, temp.mkelvin - 273150, " C", post); + show_milli(f, pre, temp.mkelvin - ZERO_C_IN_MKELVIN, " C", post); } static void show_depth(FILE *f, depth_t depth, const char *pre, const char *post) @@ -297,7 +297,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { datalen = uemis_convert_base64(base64, &data); - dive->dc.airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + 273150; + dive->dc.airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + ZERO_C_IN_MKELVIN; dive->dc.surface_pressure.mbar = *(uint16_t *)(data + 43); if (*(uint8_t *)(data + 19)) dive->dc.salinity = 10300; /* avg grams per 10l sea water */ @@ -355,7 +355,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { sample = prepare_sample(dc); sample->time.seconds = u_sample->dive_time; sample->depth.mm = rel_mbar_to_depth(u_sample->water_pressure, dive); - sample->temperature.mkelvin = (u_sample->dive_temperature * 100) + 273150; + sample->temperature.mkelvin = (u_sample->dive_temperature * 100) + ZERO_C_IN_MKELVIN; sample->sensor = active; sample->cylinderpressure.mbar = (u_sample->tank_pressure_high * 256 + u_sample->tank_pressure_low) * 10; |