From ec06e567136d66a569d35da0982be33eb0ce7853 Mon Sep 17 00:00:00 2001
From: Tobias Triffterer <tobias@ep1.ruhr-uni-bochum.de>
Date: Tue, 20 Apr 2021 23:14:09 +0200
Subject: [PATCH] Add Conversion from hPa to Torr

The software uses Pascal internally as this is the SI unit, but the old
guide to the real experiment uses Torr, so we add a conversion function
to display both in the GUI.
---
 src/experimentstate.cpp | 5 +++++
 src/experimentstate.h   | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/src/experimentstate.cpp b/src/experimentstate.cpp
index c819c37..c107795 100644
--- a/src/experimentstate.cpp
+++ b/src/experimentstate.cpp
@@ -31,3 +31,8 @@ using namespace Fp311Online;
 ExperimentState::ExperimentState(const uint64_t experimentId)
     : id(experimentId)
 {}
+
+ExperimentState::PressureTorr ExperimentState::convertHectoPascalToTorr(const PressureHectoPascal& pressure)
+{
+    return pressure*76000.0/101325.0;
+}
diff --git a/src/experimentstate.h b/src/experimentstate.h
index 1aa311e..6fe24de 100644
--- a/src/experimentstate.h
+++ b/src/experimentstate.h
@@ -53,6 +53,7 @@ public:
     static const constexpr uint16_t NumberOfAdcChannels = 4096;
 
     using PressureHectoPascal = UInt32BoundedDouble<0, 1500>;
+    using PressureTorr = UInt32BoundedDouble<0, 1130>; // 1500 hPa ≈ 1125 Torr, so 1130 Torr as upper limit should make sure that the conversion from hPa to Torr never fails
     using TargetPositionMilliMeter = UInt32BoundedDouble<14, 200>;
     using AdcConversion = GenericBoundedNumeral<uint16_t, uint16_t, 0, NumberOfAdcChannels - 1>;
 
@@ -63,6 +64,8 @@ public:
     TargetPositionMilliMeter targetPosition = TargetPositionMilliMeter::minimum;
     AdcConversion adcThreshold = AdcConversion::minimum;
 
+    static PressureTorr convertHectoPascalToTorr(const PressureHectoPascal& pressure);
+
     ExperimentState() = default;
     ExperimentState(const uint64_t experimentId);
     ~ExperimentState() = default;
-- 
GitLab