]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Start filling in temperature and nitrox data in dive list
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 19 Sep 2011 20:32:10 +0000 (13:32 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 19 Sep 2011 20:32:10 +0000 (13:32 -0700)
Still more to go, but it's slowly fleshing out..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
dive.h
divelist.c

diff --git a/dive.h b/dive.h
index 6c5dbcc23496cf0730bb3fc1b701b9f8f66e4a48..bbc5c67ae36413fead1c033f136e7685aa001d6c 100644 (file)
--- 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)
index e4b381279f476f9c7265c1b8b2541361b96d4ff8..5c85e56961150c15dc179a83561f45596f665c50 100644 (file)
@@ -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);
        }