Index: trunk/FACT++/scripts/Main.js
===================================================================
--- trunk/FACT++/scripts/Main.js	(revision 17174)
+++ trunk/FACT++/scripts/Main.js	(revision 17179)
@@ -221,12 +221,15 @@
         return;
 
-
-    this.ok = cnt==0 || (this.last!=undefined && Math.abs(this.last-avg)<0.002);
-
-    console.out("  DeltaUov=%.3f (%.3f) [N(>0.033V)=%d]".$(avg, Math.abs(this.last-avg), cnt));
-
-    this.last = avg;
-}
-
+    this.ok = cnt==0;
+
+    console.out("  DeltaUov=%.3f [N(>0.033V)=%d]".$(avg, cnt));
+}
+
+// DN:  Why is voltageOff() implemented as 
+//      a method of a Subscription to a specific Service
+//      I naively would think of voltageOff() as an unbound function.
+//      I seems to me it has to be a method of a Subscription object, in order
+//      to use the update counting method. But does it have to be
+//      a Subscription to FEEDBACK/DEVIATION, or could it work with other services as well?
 service_feedback.voltageOff = function()
 {
@@ -244,4 +247,6 @@
     {
         dim.log("Switching voltage off.");
+
+        this.ok = undefined;
 
         // Supress the possibility that the bias control is
@@ -255,5 +260,5 @@
     }
 
-    dim.wait("BIAS_CONTROL", "VoltageOff", 60000); // FIXME: 30000?
+    dim.wait("BIAS_CONTROL", "VoltageOff", 60000);
 
     // FEEDBACK stays in CurrentCtrl when Voltage is off but output enabled
@@ -300,8 +305,8 @@
 
     // Wait until voltage on
-    dim.wait("BIAS_CONTROL", "VoltageOn", 60000); // FIXME: 30000?
-
-//    if (isOff)
-//        this.ok = false;
+    dim.wait("BIAS_CONTROL", "VoltageOn", 60000);
+
+    if (isOff)
+        this.ok = false;
 }
 
@@ -319,8 +324,5 @@
     var now = new Date();
 
-    this.last = undefined;
-    this.ok = false;
-    v8.timeout(4*60000, func, this); // FIMXE: Remove 4!
-    this.ok = undefined;
+    v8.timeout(60000, func, this);
 
     if (irq)
@@ -328,4 +330,6 @@
     else
         dim.log("Voltage stable within limits");
+
+    this.ok = undefined;
 }
 
@@ -374,10 +378,9 @@
     //dim.send("FEEDBACK/STOP");
     dim.send("FTM_CONTROL/STOP_TRIGGER");
+    dim.send("BIAS_CONTROL/DISCONNECT");
 
     dim.wait("FTM_CONTROL",  "Valid",        3000);
+    dim.wait("BIAS_CONTROL", "Disconnected", 3000);
     dim.wait("FEEDBACK",     "Calibrated",   3000);
-
-    dim.send("BIAS_CONTROL/DISCONNECT");
-    dim.wait("BIAS_CONTROL", "Disconnected", 3000);
 
     var report = sub.get();
@@ -803,54 +806,6 @@
         while (!irq && !takeRun("single-pe", 10000));
 
-        /*
-        // =================== new feedback ======================
-        dim.log("Switching to new bias calibration and feedback.");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", true);
-        dim.wait("BIAS_CONTROL", "ExpertMode", 3000);
-        dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new2.txt");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", false);
-        dim.wait("BIAS_CONTROL", "VoltageOn", 3000);
-        dim.send("FEEDBACK/STOP");
-        dim.wait("FEEDBACK", "Calibrated", 3000);
-        dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", false);
-        dim.send("FEEDBACK/START", 1.1);
-        dim.wait("FEEDBACK", "InProgress", 45000);
-        service_feedback.voltageOn();
-        service_feedback.waitForVoltageOn();
-
-        v8.sleep(60000);
-        dim.log("Taking single p.e. run.");
-        while (!irq && !takeRun("single-pe", 10000));
-
-        dim.send("FEEDBACK/STOP");
-        dim.wait("FEEDBACK", "Calibrated", 3000);
-        dim.send("FEEDBACK/ENABLE_TEMP_OFFSETS", true);
-        dim.send("FEEDBACK/START", 1.1);
-        dim.wait("FEEDBACK", "InProgress", 45000);
-        service_feedback.voltageOn();
-        service_feedback.waitForVoltageOn();
-
-        v8.sleep(60000);
-        dim.log("Taking single p.e. run.");
-        while (!irq && !takeRun("single-pe", 10000));
-        */
-        // =======================================================
-
         // It is unclear what comes next, so we better switch off the voltage
         service_feedback.voltageOff();
-
-        /*
-        // =============== Switch back to old feedback =============
-        dim.log("Switching to old bias calibration and feedback.");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", true);
-        dim.wait("BIAS_CONTROL", "ExpertMode", 3000);
-        dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new.txt");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", false);
-        dim.wait("BIAS_CONTROL", "VoltageOff", 3000);
-        dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", true);
-        dim.send("FEEDBACK/ENABLE_TEMP_OFFSETS", false);
-        // =========================================================
-        */
-
         system_on = true;
         dim.log("Task finished [STARTUP]");
@@ -954,163 +909,5 @@
         console.out("");
         break; // case "RATESCAN"
-/*
-    case "FEEDBACK-TEST":
-        // ----------------- Enable new feedback ---------------
-        service_feedback.voltageOff();
-        dim.log("Switching to new bias calibration and feedback.");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", true);
-        dim.wait("BIAS_CONTROL", "ExpertMode", 3000);
-        dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new2.txt");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", false);
-        dim.wait("BIAS_CONTROL", "VoltageOff", 3000);
-        dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", false);
-
-        // ---------------- Take single pe run ------------------
-        CloseLid();
-        doDrsCalibration("singlepe");  // will turn voltage off
-        service_feedback.voltageOn();
-        service_feedback.waitForVoltageOn();
-        v8.sleep(15000);
-        dim.log("Taking single p.e. run.");
-        while (!irq && !takeRun("single-pe", 10000));
-
-        dim.send("FEEDBACK/STOP");
-        dim.wait("FEEDBACK", "Calibrated", 3000);
-        dim.send("FEEDBACK/ENABLE_TEMP_OFFSETS", true);
-        dim.send("FEEDBACK/START", 1.1);
-        dim.wait("FEEDBACK", "InProgress", 45000);
-        service_feedback.voltageOn();
-        service_feedback.waitForVoltageOn();
-        v8.sleep(15000);
-        dim.log("Taking single p.e. run.");
-        while (!irq && !takeRun("single-pe", 10000));
-
-        // ------------------ Ratescan --------------------------
-        var tm1 = new Date();
-
-        // This is a workaround to make sure that we really catch
-        // the new OnTrack state later and not the old one
-        dim.send("DRIVE_CONTROL/STOP");
-        dim.wait("DRIVE_CONTROL", "Armed", 15000);
-
-        // The lid must be open
-        OpenLid();
-
-        // The voltage must be switched on
-        service_feedback.voltageOn();
-
-        if (obs.source != undefined)
-        {
-            dim.log("Pointing telescope to '"+obs[cub].source+"'.");
-            dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source);
-        }
-        else
-        {
-            dim.log("Pointing telescope to ra="+obs[sub].ra+" dec="+obs[sub].dec);
-            dim.send("DRIVE_CONTROL/TRACK", obs[sub].ra, obs[sub].dec);
-        }
-
-        dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing
-
-        service_feedback.waitForVoltageOn();
-
-        var tm2 = new Date();
-
-        dim.log("Starting ratescan.");
-
-        // Start rate scan
-        dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
-
-        // Lets wait if the ratescan really starts... this might take a few
-        // seconds because RATE_SCAN configures the ftm and is waiting for
-        // it to be configured.
-        dim.wait("RATE_SCAN", "InProgress", 10000);
-        dim.wait("RATE_SCAN", "Connected", 2700000);
-
-        // this line is actually some kind of hack. 
-        // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
-        // So I decided to put this line here as a kind of patchwork....
-        //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2);
-
-        dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
-
-        // ------------------ Switch back --------------------------
-
-        dim.send("BIAS_CONTROL/EXPERT_MODE", true);
-        dim.wait("BIAS_CONTROL", "ExpertMode", 3000);
-        dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new.txt");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", false);
-        dim.wait("BIAS_CONTROL", "VoltageOn", 3000);
-        dim.send("FEEDBACK/STOP");
-        dim.wait("FEEDBACK", "Calibrated", 3000);
-        dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", true);
-        dim.send("FEEDBACK/ENABLE_TEMP_OFFSETS", false);
-        dim.send("FEEDBACK/START", 1.1);
-        dim.wait("FEEDBACK", "InProgress", 60000);
-
-        dim.log("Starting ratescan.");
-
-        // Start rate scan
-        dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
-
-        // Lets wait if the ratescan really starts... this might take a few
-        // seconds because RATE_SCAN configures the ftm and is waiting for
-        // it to be configured.
-        dim.wait("RATE_SCAN", "InProgress", 10000);
-        dim.wait("RATE_SCAN", "Connected", 2700000);
-
-        // this line is actually some kind of hack. 
-        // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
-        // So I decided to put this line here as a kind of patchwork....
-        //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2);
-
-        dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
-
-        dim.log("Task finished [FEEDBACK-TEST]");
-        console.out("");
-        break;
-
-    case "SINGLEPE-TEST":
-        // ----------------- Enable new feedback ---------------
-        service_feedback.voltageOff();
-        dim.log("Switching to new bias calibration and feedback.");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", true);
-        dim.wait("BIAS_CONTROL", "ExpertMode", 3000);
-        dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new2.txt");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", false);
-        dim.wait("BIAS_CONTROL", "VoltageOff", 3000);
-        dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", false);
-
-        // ---------------- Take single pe run ------------------
-        CloseLid();
-        doDrsCalibration("singlepe");  // will turn voltage off
-        dim.send("FEEDBACK/STOP");
-        dim.wait("FEEDBACK", "Calibrated", 3000);
-        dim.send("FEEDBACK/ENABLE_TEMP_OFFSETS", true);
-        dim.send("FEEDBACK/START", 1.1);
-        dim.wait("FEEDBACK", "InProgress", 45000);
-        service_feedback.voltageOn();
-        service_feedback.waitForVoltageOn();
-        v8.sleep(15000);
-        dim.log("Taking single p.e. run.");
-        while (!irq && !takeRun("single-pe", 10000));
-
-        // ------------------ Switch back --------------------------
-        dim.send("BIAS_CONTROL/EXPERT_MODE", true);
-        dim.wait("BIAS_CONTROL", "ExpertMode", 3000);
-        dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new.txt");
-        dim.send("BIAS_CONTROL/EXPERT_MODE", false);
-        dim.wait("BIAS_CONTROL", "VoltageOn", 3000);
-        dim.send("FEEDBACK/STOP");
-        dim.wait("FEEDBACK", "Calibrated", 3000);
-        dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", true);
-        dim.send("FEEDBACK/ENABLE_TEMP_OFFSETS", false);
-        dim.send("FEEDBACK/START", 1.1);
-        dim.wait("FEEDBACK", "InProgress", 60000);
-
-        dim.log("Task finished [SINGLEPE-TEST]");
-        console.out("");
-        break;
-*/
+
 
     case "DATA":
