From b2f2a865eb55f13fb20313eaa7b7785e019a58f7 Mon Sep 17 00:00:00 2001
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Mon, 18 Jul 2016 16:18:17 +0900
Subject: [PATCH] Get the cylinder use data from libdivecomputer if provided

This uses the extended tank type information to fill in the cylinder use
(OC gas, CC Diluent or CC O2) from libdivecomputer when available.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
---
 core/libdivecomputer.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index a949e582e..70917cf53 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -16,6 +16,18 @@
 #include <libdivecomputer/version.h>
 #include "libdivecomputer.h"
 
+//
+// If we have an old libdivecomputer, it doesn't
+// have the new DC_TANKINFO bits, but just volume
+// type information.
+//
+#ifndef DC_TANKINFO_METRIC
+#define DC_TANKINFO_METRIC	DC_TANKVOLUME_METRIC
+#define DC_TANKINFO_IMPERIAL	DC_TANKVOLUME_IMPERIAL
+#define DC_TANKINFO_CC_O2	0
+#define DC_TANKINFO_CC_DILUENT	0
+#endif
+
 /* Christ. Libdivecomputer has the worst configuration system ever. */
 #ifdef HW_FROG_H
 #define NOT_FROG , 0
@@ -127,9 +139,18 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
 		if (i < ntanks) {
 			rc = dc_parser_get_field(parser, DC_FIELD_TANK, i, &tank);
 			if (rc == DC_STATUS_SUCCESS) {
-				if (tank.type == DC_TANKVOLUME_IMPERIAL) {
-					dive->cylinder[i].type.size.mliter = rint(tank.volume * 1000);
-					dive->cylinder[i].type.workingpressure.mbar = rint(tank.workpressure * 1000);
+				cylinder_t *cyl = dive->cylinder + i;
+
+				cyl->type.size.mliter = rint(tank.volume * 1000);
+				cyl->type.workingpressure.mbar = rint(tank.workpressure * 1000);
+
+				cyl->cylinder_use = OC_GAS;
+				if (tank.type & DC_TANKINFO_CC_O2)
+					cyl->cylinder_use = OXYGEN;
+				if (tank.type & DC_TANKINFO_CC_DILUENT)
+					cyl->cylinder_use = DILUENT;
+
+				if (tank.type & DC_TANKINFO_IMPERIAL) {
 					if (same_string(devdata->model, "Suunto EON Steel")) {
 						/* Suunto EON Steele gets this wrong. Badly.
 						 * but on the plus side it only supports a few imperial sizes,
@@ -163,8 +184,6 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
 						dive->cylinder[i].type.size.mliter = cuft_to_l(rounded_size) * 1000 /
 										     mbar_to_atm(dive->cylinder[i].type.workingpressure.mbar);
 					}
-				} else if (tank.type == DC_TANKVOLUME_METRIC) {
-					dive->cylinder[i].type.size.mliter = rint(tank.volume * 1000);
 				}
 				if (tank.gasmix != i) { // we don't handle this, yet
 					shown_warning = true;