Index: /trunk/FACT++/scripts/Main.js
===================================================================
--- /trunk/FACT++/scripts/Main.js	(revision 17355)
+++ /trunk/FACT++/scripts/Main.js	(revision 17356)
@@ -179,4 +179,10 @@
     if (isOpen)
     {
+        if (dim.state("FTM_CONTROL").name=="TriggerOn")
+        {
+            dim.send("FTM_CONTROL/STOP_TRIGGER");
+            dim.wait("FTM_CONTROL", "Valid", 3000);
+        }
+
         dim.log("Closing lid.");
         dim.send("LID_CONTROL/CLOSE");
@@ -511,4 +517,5 @@
          "FTM_CONTROL/STATIC_DATA",
          "FTM_CONTROL/TRIGGER_RATES",
+         "GPS_CONTROL/NEMA",
          "LID_CONTROL/DATA",
          "MAGIC_LIDAR/DATA",
@@ -684,5 +691,27 @@
 var system_on;  // undefined
 
-while (!irq)
+function processIrq()
+{
+    if (!irq)
+        return false;
+
+    if (irq.toUpperCase()=="OFF")
+    {
+        service_feedback.voltageOff();
+        dim.send("FAD_CONTROL/CLOSE_OPEN_FILES");
+        return true;
+    }
+
+    if (irq.toUpperCase()=="SHUTDOWN")
+    {
+        Shutdown();
+        return true;
+    }
+
+    console.log("IRQ "+irq+" unhandled... stopping script.");
+    return true;
+}
+
+while (!processIrq())
 {
     // Check if observation position is still valid
@@ -821,4 +850,5 @@
          [ "RATE_SCAN",       [ "Connected"                ] ],
          [ "RATE_CONTROL",    [ "Connected", "GlobalThresholdSet", "InProgress"  ] ],
+         [ "GPS_CONTROL",     [ "Locked"  ] ],
         ];
 
@@ -1154,7 +1184,4 @@
 dim.log("Left main loop [irq="+irq+"]");
 
-if (irq.toUpperCase()=="SHUTDOWN")
-    Shutdown();
-
 // ================================================================
 // Comments and ToDo goes here
