summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-19 13:32:10 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-19 13:32:10 -0700
commite9d28901341d4cefb4c80a98239daaf81fb3d941 (patch)
tree43f4000d940e8f57fffc2bd7b86a52db107de898
parentde721d98106569ccf74d4bcc35619e281df00e5e (diff)
downloadsubsurface-e9d28901341d4cefb4c80a98239daaf81fb3d941.tar.gz
Start filling in temperature and nitrox data in dive list
Still more to go, but it's slowly fleshing out.. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--dive.h14
-rw-r--r--divelist.c61
2 files changed, 73 insertions, 2 deletions
diff --git a/dive.h b/dive.h
index 6c5dbcc23..bbc5c67ae 100644
--- a/dive.h
+++ b/dive.h
@@ -91,18 +91,28 @@ static inline int to_feet(depth_t depth)
return depth.mm * 0.00328084 + 0.5;
}
+static double mkelvin_to_C(int mkelvin)
+{
+ return (mkelvin - 273150) / 1000.0;
+}
+
+static double mkelvin_to_F(int mkelvin)
+{
+ return mkelvin * 9 / 5000.0 - 459.670;
+}
+
static inline int to_C(temperature_t temp)
{
if (!temp.mkelvin)
return 0;
- return (temp.mkelvin - 273150 + 499) / 1000;
+ return mkelvin_to_C(temp.mkelvin) + 0.5;
}
static inline int to_F(temperature_t temp)
{
if (!temp.mkelvin)
return 0;
- return temp.mkelvin * 9 / 5000.0 - 459.670 + 0.5;
+ return mkelvin_to_F(temp.mkelvin) + 0.5;
}
static inline int to_K(temperature_t temp)
diff --git a/divelist.c b/divelist.c
index e4b381279..5c85e5696 100644
--- a/divelist.c
+++ b/divelist.c
@@ -42,6 +42,49 @@ static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
repaint_dive();
}
+static void get_temp(struct dive *dive, int *val, char **str)
+{
+ int value = dive->watertemp.mkelvin;
+ char buffer[80];
+
+ *val = value;
+ *str = "";
+ if (value) {
+ double deg;
+ switch (output_units.temperature) {
+ case CELSIUS:
+ deg = mkelvin_to_C(value);
+ break;
+ case FAHRENHEIT:
+ deg = mkelvin_to_F(value);
+ break;
+ default:
+ return;
+ }
+ snprintf(buffer, sizeof(buffer), "%.1f", deg);
+ *str = strdup(buffer);
+ }
+}
+
+static void get_nitrox(struct dive *dive, int *val, char **str)
+{
+ int value = dive->cylinder[0].gasmix.o2.permille;
+ char buffer[80];
+
+ *val = value;
+ *str = "";
+ if (value) {
+ snprintf(buffer, sizeof(buffer), "%.1f", value/10.0);
+ *str = strdup(buffer);
+ }
+}
+
+static void get_sac(struct dive *dive, int *val, char **str)
+{
+ *val = 0;
+ *str = "";
+}
+
static gboolean set_one_dive(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
@@ -53,6 +96,8 @@ static gboolean set_one_dive(GtkTreeModel *model,
char buffer[256], *datestr, *depth, *duration;
struct tm *tm;
int integer, frac;
+ int temp, nitrox, sac;
+ char *tempstr, *nitroxstr, *sacstr;
/* Get the dive number */
gtk_tree_model_get_value(model, iter, DIVE_INDEX, &value);
@@ -96,6 +141,10 @@ static gboolean set_one_dive(GtkTreeModel *model,
duration = malloc(len + 1);
memcpy(duration, buffer, len+1);
+ get_temp(dive, &temp, &tempstr);
+ get_nitrox(dive, &nitrox, &nitroxstr);
+ get_sac(dive, &sac, &sacstr);
+
/*
* We only set the fields that changed: the strings.
* The core data itself is unaffected by units
@@ -104,6 +153,12 @@ static gboolean set_one_dive(GtkTreeModel *model,
DIVE_DATESTR, datestr,
DIVE_DEPTHSTR, depth,
DIVE_DURATIONSTR, duration,
+ DIVE_TEMPSTR, tempstr,
+ DIVE_TEMP, temp,
+ DIVE_NITROXSTR, nitroxstr,
+ DIVE_NITROX, nitrox,
+ DIVE_SACSTR, sacstr,
+ DIVE_NITROX, sac,
-1);
return FALSE;
@@ -147,6 +202,12 @@ static void fill_dive_list(struct DiveList *dive_list)
DIVE_DEPTH, dive->maxdepth,
DIVE_DURATIONSTR, "duration",
DIVE_DURATION, dive->duration.seconds,
+ DIVE_TEMPSTR, "temp",
+ DIVE_TEMP, dive->watertemp.mkelvin,
+ DIVE_NITROXSTR, "21.0",
+ DIVE_NITROX, dive->cylinder[0].gasmix.o2,
+ DIVE_SACSTR, "sac",
+ DIVE_SAC, 0,
-1);
}