summaryrefslogtreecommitdiffstats
path: root/core/load-git.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/load-git.c')
-rw-r--r--core/load-git.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/core/load-git.c b/core/load-git.c
index 87f6ecb25..6a3cc75ce 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -354,6 +354,7 @@ static char *parse_keyvalue_entry(void (*fn)(void *, const char *, const char *)
}
static int cylinder_index, weightsystem_index;
+static int o2pressure_sensor;
static void parse_cylinder_keyvalue(void *_cylinder, const char *key, const char *value)
{
@@ -397,7 +398,6 @@ static void parse_dive_cylinder(char *line, struct membuffer *str, void *_dive)
struct dive *dive = _dive;
cylinder_t *cylinder = dive->cylinder + cylinder_index;
- cylinder_index++;
cylinder->type.description = get_utf8(str);
for (;;) {
char c;
@@ -407,6 +407,9 @@ static void parse_dive_cylinder(char *line, struct membuffer *str, void *_dive)
break;
line = parse_keyvalue_entry(parse_cylinder_keyvalue, cylinder, line);
}
+ if (cylinder->cylinder_use == OXYGEN)
+ o2pressure_sensor = cylinder_index;
+ cylinder_index++;
}
static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char *value)
@@ -540,11 +543,6 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va
}
if (!strcmp(key, "o2pressure")) {
pressure_t p = get_pressure(value);
- //
- // FIXME!!! What's the O2 cylinder index?
- // get_cylinder_idx_by_use(dive, OXYGEN)
- //
- sample->sensor[1] = 1;
sample->pressure[1].mbar = p.mbar;
return;
}
@@ -599,6 +597,13 @@ static char *parse_sample_unit(struct sample *sample, double val, char *unit)
* missing sample pressure doesn't mean "same as last
* time", but "interpolate". We clear those ones
* explicitly.
+ *
+ * NOTE! We default sensor use to 0, 1 respetively for
+ * the two sensors, but for CCR dives with explicit
+ * OXYGEN bottles we set the secondary sensor to that.
+ * Then the primary sensor will be either the first
+ * or the second cylinder depending on what isn't an
+ * oxygen cylinder.
*/
static struct sample *new_sample(struct divecomputer *dc)
{
@@ -606,6 +611,10 @@ static struct sample *new_sample(struct divecomputer *dc)
if (sample != dc->sample) {
memcpy(sample, sample-1, sizeof(struct sample));
sample->pressure[0].mbar = 0;
+ sample->pressure[1].mbar = 0;
+ } else {
+ sample->sensor[0] = !o2pressure_sensor;
+ sample->sensor[1] = o2pressure_sensor;
}
return sample;
}
@@ -1502,6 +1511,7 @@ static int parse_dive_entry(git_repository *repo, const git_tree_entry *entry, c
if (*suffix)
dive->number = atoi(suffix+1);
cylinder_index = weightsystem_index = 0;
+ o2pressure_sensor = 1;
for_each_line(blob, dive_parser, active_dive);
git_blob_free(blob);
return 0;