Subject: [PATCH] Show the o2 setpoint graph

When a CCR dive is viewed and the toolbar button for PO2 is activated,
both the PO2 (green line) and the O2 setpoint (red line) are shown.
This allows evaluation of the PO2 in the CCR loop with respect to the
pre-configured O2 setpoint.

I need someone who is conversant with Qt to check this code, Please!

Signed-off-by: willem ferguson <[email protected]>

>From 5f6e8792b8ec8caecd604707b9d5c6fd8d577cb9 Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Sat, 3 Jan 2015 18:25:05 +0200
Subject: [PATCH] Show the o2 setpoint graph

When a CCR dive is viewed and the toolbar button for PO2 is activated,
both the PO2 (green line) and the O2 setpoint (red line) are shown.
This allows evaluation of the PO2 in the loop with respect to the
pre-configured O2 setpoint.

I need someone who is conversant with Qt to check this code, Please!

Signed-off-by: willem ferguson <[email protected]>
---
 profile.c                           |  3 +--
 profile.h                           |  1 +
 qt-ui/graphicsview-common.cpp       |  3 ++-
 qt-ui/graphicsview-common.h         |  1 +
 qt-ui/profile/diveplotdatamodel.cpp |  7 +++++++
 qt-ui/profile/diveplotdatamodel.h   |  1 +
 qt-ui/profile/profilewidget2.cpp    | 11 +++++++++++
 qt-ui/profile/profilewidget2.h      |  1 +
 8 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/profile.c b/profile.c
index 74d4936..54ee84e 100644
--- a/profile.c
+++ b/profile.c
@@ -17,7 +17,6 @@
 #include "libdivecomputer/version.h"
 #include "membuffer.h"
 
-
 //#define DEBUG_GAS 1
 
 int selected_dive = -1; /* careful: 0 is a valid value */
@@ -608,7 +607,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
 		entry->in_deco = sample->in_deco;
 		entry->cns = sample->cns;
 		if (dc->dctype == CCR) {
-			entry->o2pressure.mbar = sample->setpoint.mbar;     // for rebreathers
+			entry->o2pressure.mbar = entry->o2setpoint.mbar = sample->setpoint.mbar;     // for rebreathers
 			entry->o2sensor[0].mbar = sample->o2sensor[0].mbar; // for up to three rebreather O2 sensors
 			entry->o2sensor[1].mbar = sample->o2sensor[1].mbar;
 			entry->o2sensor[2].mbar = sample->o2sensor[2].mbar;
diff --git a/profile.h b/profile.h
index 5c30ca4..0ae9a8f 100644
--- a/profile.h
+++ b/profile.h
@@ -43,6 +43,7 @@ struct plot_data {
 	struct gas_pressures pressures;
 	pressure_t o2pressure;  // for rebreathers, this is consensus measured po2, or setpoint otherwise. 0 for OC.
 	pressure_t o2sensor[3]; //for rebreathers with up to 3 PO2 sensors
+	pressure_t o2setpoint;
 	double mod, ead, end, eadd;
 	velocity_t velocity;
 	int speed;
diff --git a/qt-ui/graphicsview-common.cpp b/qt-ui/graphicsview-common.cpp
index 4beab9d..982cb84 100644
--- a/qt-ui/graphicsview-common.cpp
+++ b/qt-ui/graphicsview-common.cpp
@@ -26,7 +26,8 @@ void fill_profile_color()
 	profile_color[PN2] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
 	profile_color[PN2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
 	profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
-	profile_color[PHE_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
+	profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
+	profile_color[O2SETPOINT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
 	profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS, BLACK1_HIGH_TRANS);
 
 	profile_color[TEXT_BACKGROUND] = COLOR(CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS);
diff --git a/qt-ui/graphicsview-common.h b/qt-ui/graphicsview-common.h
index c223c30..294109d 100644
--- a/qt-ui/graphicsview-common.h
+++ b/qt-ui/graphicsview-common.h
@@ -37,6 +37,7 @@ typedef enum {
 	PN2_ALERT,
 	PHE,
 	PHE_ALERT,
+	O2SETPOINT,
 	PP_LINES,
 
 	/* Other colors */
diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp
index 51aea1b..aff9ebe 100644
--- a/qt-ui/profile/diveplotdatamodel.cpp
+++ b/qt-ui/profile/diveplotdatamodel.cpp
@@ -52,6 +52,11 @@ QVariant DivePlotDataModel::data(const QModelIndex &index, int role) const
 			return item.pressures.he;
 		case PO2:
 			return item.pressures.o2;
+		case O2SETPOINT:
+			if (item.o2setpoint.mbar > 5000)
+				return(0);
+			else
+				return item.o2setpoint.mbar / 1000.0;
 		case HEARTBEAT:
 			return item.heartbeat;
 		case AMBPRESSURE:
@@ -125,6 +130,8 @@ QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation,
 		return tr("pHe");
 	case PO2:
 		return tr("pO₂");
+	case O2SETPOINT:
+		return tr("Setpoint");
 	case AMBPRESSURE:
 		return tr("Ambient pressure");
 	}
diff --git a/qt-ui/profile/diveplotdatamodel.h b/qt-ui/profile/diveplotdatamodel.h
index 416ae69..e178972 100644
--- a/qt-ui/profile/diveplotdatamodel.h
+++ b/qt-ui/profile/diveplotdatamodel.h
@@ -59,6 +59,7 @@ public:
 		PN2,
 		PHE,
 		PO2,
+		O2SETPOINT,
 		HEARTBEAT,
 		AMBPRESSURE,
 		GFLINE,
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index d631e3c..c1bc402 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -93,6 +93,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
 	pn2GasItem(new PartialPressureGasItem()),
 	pheGasItem(new PartialPressureGasItem()),
 	po2GasItem(new PartialPressureGasItem()),
+	o2SetpointGasItem(new PartialPressureGasItem()),
 	heartBeatAxis(new DiveCartesianAxis()),
 	heartBeatItem(new DiveHeartrateItem()),
 	percentageAxis(new DiveCartesianAxis()),
@@ -161,6 +162,7 @@ ProfileWidget2::~ProfileWidget2()
 	delete pn2GasItem;
 	delete pheGasItem;
 	delete po2GasItem;
+	delete o2SetpointGasItem;
 	delete heartBeatAxis;
 	delete heartBeatItem;
 	delete percentageAxis;
@@ -199,6 +201,7 @@ void ProfileWidget2::addItemsToScene()
 	scene()->addItem(pn2GasItem);
 	scene()->addItem(pheGasItem);
 	scene()->addItem(po2GasItem);
+	scene()->addItem(o2SetpointGasItem);
 	scene()->addItem(percentageAxis);
 	scene()->addItem(heartBeatAxis);
 	scene()->addItem(heartBeatItem);
@@ -307,6 +310,7 @@ void ProfileWidget2::setupItemOnScene()
 	CREATE_PP_GAS(pn2GasItem, PN2, PN2, PN2_ALERT, &prefs.pp_graphs.pn2_threshold, "pn2graph");
 	CREATE_PP_GAS(pheGasItem, PHE, PHE, PHE_ALERT, &prefs.pp_graphs.phe_threshold, "phegraph");
 	CREATE_PP_GAS(po2GasItem, PO2, PO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold, "po2graph");
+	CREATE_PP_GAS(o2SetpointGasItem, O2SETPOINT, PO2_ALERT, PO2_ALERT, &prefs.pp_graphs.po2_threshold, "po2graph");
 #undef CREATE_PP_GAS
 
 	temperatureAxis->setTextVisible(false);
@@ -521,6 +525,11 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
 		currentdc = fake_dc(currentdc);
 	}
 
+	if (currentdc->dctype == CCR) {
+		o2SetpointGasItem->setVisible(true);
+	} else {
+		o2SetpointGasItem->setVisible(false);
+	}
 	/* This struct holds all the data that's about to be plotted.
 	 * I'm not sure this is the best approach ( but since we are
 	 * interpolating some points of the Dive, maybe it is... )
@@ -879,6 +888,7 @@ void ProfileWidget2::setEmptyState()
 	tankItem->setVisible(false);
 	pn2GasItem->setVisible(false);
 	po2GasItem->setVisible(false);
+	o2SetpointGasItem->setVisible(false);
 	pheGasItem->setVisible(false);
 	ambPressureItem->setVisible(false);
 	gflineItem->setVisible(false);
@@ -977,6 +987,7 @@ void ProfileWidget2::setProfileState()
 	}
 	pn2GasItem->setVisible(prefs.pp_graphs.pn2);
 	po2GasItem->setVisible(prefs.pp_graphs.po2);
+	o2SetpointGasItem->setVisible(1);
 	pheGasItem->setVisible(prefs.pp_graphs.phe);
 
 	timeAxis->setPos(itemPos.time.pos.on);
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 5a612d9..3dfc503 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -169,6 +169,7 @@ private:
 	PartialPressureGasItem *pn2GasItem;
 	PartialPressureGasItem *pheGasItem;
 	PartialPressureGasItem *po2GasItem;
+	PartialPressureGasItem *o2SetpointGasItem;
 	DiveCartesianAxis *heartBeatAxis;
 	DiveHeartrateItem *heartBeatItem;
 	DiveCartesianAxis *percentageAxis;
-- 
1.9.1

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to