Index: /trunk/FACT++/src/ratecontrol.cc
===================================================================
--- /trunk/FACT++/src/ratecontrol.cc	(revision 18605)
+++ /trunk/FACT++/src/ratecontrol.cc	(revision 18606)
@@ -15,4 +15,5 @@
 
 #include "HeadersFTM.h"
+#include "HeadersLid.h"
 #include "HeadersDrive.h"
 #include "HeadersRateScan.h"
@@ -56,4 +57,5 @@
     DimDescribedState fDimFTM;
     DimDescribedState fDimRS;
+    DimDescribedState fDimLid;
     DimDescribedState fDimDrive;
 
@@ -433,5 +435,5 @@
         // Record only currents when the drive is tracking to avoid
         // bias from the movement
-        if (fDimDrive.state()<Drive::State::kTracking)
+        if (fDimDrive.state()<Drive::State::kTracking || fDimLid.state()==Lid::State::kClosed)
             return GetCurrentState();
 
@@ -553,13 +555,4 @@
     int Calibrate()
     {
-        if (!fPhysTriggerEnabled)
-        {
-            Info("Physics trigger not enabled... CALIBRATE command ignored.");
-
-            fTriggerOn = false;
-            fPhysTriggerEnabled = false;
-            return RateControl::State::kGlobalThresholdSet;
-        }
-
         const int32_t val[2] = { -1, fThresholdReference };
         Dim::SendCommandNB("FTM_CONTROL/SET_THRESHOLD", val);
@@ -584,16 +577,4 @@
     int CalibrateByCurrent()
     {
-        if (!fPhysTriggerEnabled)
-        {
-            Info("Physics trigger not enabled... CALIBRATE command ignored.");
-
-            fTriggerOn = false;
-            fPhysTriggerEnabled = false;
-            return RateControl::State::kGlobalThresholdSet;
-        }
-
-        if (fDimDrive.state()<Drive::State::kMoving)
-            Warn("Drive not even moving...");
-
         fCounter = 0;
         fCalibrateByCurrent = true;
@@ -629,4 +610,41 @@
         const config &conf = it->second;
 
+        if (conf.fCalibrationType!=0)
+        {
+
+            if (!fPhysTriggerEnabled)
+            {
+                Info("Calibration requested, but physics trigger not enabled... CALIBRATE command ignored.");
+
+                fTriggerOn = false;
+                fPhysTriggerEnabled = false;
+                return RateControl::State::kGlobalThresholdSet;
+            }
+
+            if (fDimLid.state()==Lid::State::kClosed)
+            {
+                Info("Calibration requested, but lid closed... setting all thresholds to "+to_string(conf.fMinThreshold)+".");
+
+                const int32_t val[2] = { -1, conf.fMinThreshold };
+                Dim::SendCommandNB("FTM_CONTROL/SET_THRESHOLD", val);
+
+                fThresholds.assign(160, conf.fMinThreshold);
+
+                const double mjd = Time().Mjd();
+
+                const RateControl::DimThreshold data = { conf.fMinThreshold, mjd, mjd };
+                fDimThreshold.setQuality(3);
+                fDimThreshold.Update(data);
+
+                fCalibrateByCurrent = true;
+                fTriggerOn = false;
+                fPhysTriggerEnabled = false;
+                return RateControl::State::kSettingGlobalThreshold;
+            }
+
+            if (fDimDrive.state()<Drive::State::kMoving)
+                Warn("Calibration requested, but drive not even moving...");
+        }
+
         switch (conf.fCalibrationType)
         {
@@ -687,4 +705,5 @@
         Out() << fDimFTM << endl;
         Out() << fDimRS << endl;
+        Out() << fDimLid << endl;
         Out() << fDimDrive << endl;
 
@@ -745,4 +764,5 @@
         fDimFTM("FTM_CONTROL"),
         fDimRS("RATE_SCAN"),
+        fDimLid("LID_CONTROL"),
         fDimDrive("DRIVE_CONTROL"),
         fDimThreshold("RATE_CONTROL/THRESHOLD", "S:1;D:1;D:1",
@@ -762,4 +782,5 @@
         fDimFTM.Subscribe(*this);
         fDimRS.Subscribe(*this);
+        fDimLid.Subscribe(*this);
         fDimDrive.Subscribe(*this);
 
