mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
de721d9810
commit
e9d2890134
2 changed files with 73 additions and 2 deletions
14
dive.h
14
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)
|
||||
|
|
61
divelist.c
61
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue