Index: trunk/FACT++/src/smartfact.cc
===================================================================
--- trunk/FACT++/src/smartfact.cc	(revision 13702)
+++ trunk/FACT++/src/smartfact.cc	(revision 13704)
@@ -82,4 +82,6 @@
     float  fDriveControlTrackingDev;
     string fDriveControlSourceName;
+
+    int64_t fFadControlNumEvents;
 
     float  fFtmControlTriggerRateCam;
@@ -192,4 +194,7 @@
     DimStampedInfo fDimBiasControlCurrent;
 
+    DimStampedInfo fDimFadConnections;
+    DimStampedInfo fDimFadEvents;
+
     DimStampedInfo fDimFtmControlTriggerRates;
     DimStampedInfo fDimFtmControlStaticData;
@@ -454,5 +459,5 @@
     void HandleFeedbackDeviation(const DimData &d)
     {
-        if (!CheckDataSize(d, "Feedback:Deviation", 2*4*416+2))
+        if (!CheckDataSize(d, "Feedback:Deviation", 2*4*416+8))
             return;
 
@@ -467,5 +472,5 @@
 
         // Write the 160 patch values to a file
-        WriteBinary("feedback-deviation", dev, 2000, -1000);
+        WriteBinary("feedback-deviation", dev, 1);
 
         const Statistics stat(dev, 3);
@@ -480,5 +485,5 @@
         out << kHtmlWhite << '\t' << stat.avg << '\n';
         out << kHtmlWhite << '\t' << stat.max << '\n';
-        ofstream("www/feedback.txt") << out.str();
+        ofstream(fPath+"/feedback.txt") << out.str();
     }
 
@@ -603,4 +608,64 @@
     }
 
+    void HandleFadEvents(const DimData &d)
+    {
+        if (!CheckDataSize(d, "FadControl:Events", 4*4))
+        {
+            fFadControlNumEvents = -1;
+            return;
+        }
+
+        fFadControlNumEvents = d.get<uint32_t>();
+    }
+
+    void HandleFadConnections(const DimData &d)
+    {
+        if (!CheckDataSize(d, "FadControl:Connections", 41))
+        {
+            //fStatusEventBuilderLabel->setText("Offline");
+            return;
+        }
+
+        string rc(40, '-'); // orange/red [45]
+
+        const uint8_t *ptr = d.ptr<uint8_t>();
+
+        int c[4] = { '.', '.', '.', '.' };
+
+        for (int i=0; i<40; i++)
+        {
+            const uint8_t stat1 = ptr[i]&3;
+            const uint8_t stat2 = ptr[i]>>3;
+
+            if (stat1==0 && stat2==0)
+                rc[i] = '.'; // gray [46]
+            else
+                if (stat1>=2 && stat2==8)
+                    rc[i] = stat1==2?'+':'*';  // green [43] : check [42]
+
+            if (rc[i]<c[i/10])
+                c[i/10] = rc[i];
+        }
+
+        string col[4];
+        for (int i=0; i<4; i++)
+            switch (c[i])
+            {
+            case '.': col[i]=kHtmlWhite;  break;
+            case '-': col[i]=kHtmlRed;    break;
+            case '+': col[i]=kHtmlYellow; break;
+            case '*': col[i]=kHtmlGreen;  break;
+            }
+
+        ostringstream out;
+        out << setprecision(3);
+        out << d.time.JavaDate() << '\n';
+        out << col[0] << '\t' << rc.substr( 0, 10) << '\n';
+        out << col[1] << '\t' << rc.substr(10, 10) << '\n';
+        out << col[2] << '\t' << rc.substr(20, 10) << '\n';
+        out << col[3] << '\t' << rc.substr(30, 10) << '\n';
+        ofstream(fPath+"/fad.txt") << out.str();
+    }
+
     void HandleFtmControlTriggerRates(const DimData &d)
     {
@@ -829,4 +894,8 @@
             return;
         if (HandleService(curr, fDimBiasControlCurrent,     &StateMachineSmartFACT::HandleBiasControlCurrent))
+            return;
+        if (HandleService(curr, fDimFadConnections,         &StateMachineSmartFACT::HandleFadConnections))
+            return;
+        if (HandleService(curr, fDimFadEvents,              &StateMachineSmartFACT::HandleFadEvents))
             return;
         if (HandleService(curr, fDimFtmControlTriggerRates, &StateMachineSmartFACT::HandleFtmControlTriggerRates))
@@ -953,5 +1022,10 @@
                 out << " [";
             if (fMcpConfigurationMaxEvents>0)
-                out << fMcpConfigurationMaxEvents;
+            {
+                if (fFadControlNumEvents>0 && fMcpConfigurationState==12)
+                    out << fMcpConfigurationMaxEvents-fFadControlNumEvents;
+                else
+                    out << fMcpConfigurationMaxEvents;
+            }
             if (fMcpConfigurationMaxEvents>0 && (fMcpConfigurationMaxTime>0 || fMcpConfigurationState==12))
                 out << '/';
@@ -968,5 +1042,5 @@
                 }
                 else
-                    out << "[" << fMcpConfigurationMaxTime << "s]";
+                    out << fMcpConfigurationMaxTime << 's';
             }
             else
@@ -1081,6 +1155,6 @@
             // and Bias not in "data-taking state' => Red
             if (fDimMcp.state()>5 &&
-                (fDimBiasControl.state()==BIAS::kVoltageOn ||
-                 fDimBiasControl.state()==BIAS::kVoltageOff))
+                fDimBiasControl.state()!=BIAS::kVoltageOn &&
+                fDimBiasControl.state()!=BIAS::kVoltageOff)
                 col = kHtmlRed;
 
@@ -1183,4 +1257,7 @@
         fDimBiasControlCurrent    ("BIAS_CONTROL/CURRENT",            (void*)NULL, 0, this),
         //---
+        fDimFadConnections        ("FAD_CONTROL/CONNECTIONS",         (void*)NULL, 0, this),
+        fDimFadEvents             ("FAD_CONTROL/EVENTS",              (void*)NULL, 0, this),
+        //---
         fDimFtmControlTriggerRates("FTM_CONTROL/TRIGGER_RATES",       (void*)NULL, 0, this),
         fDimFtmControlStaticData  ("FTM_CONTROL/STATIC_DATA",         (void*)NULL, 0, this),
@@ -1243,6 +1320,6 @@
     po::options_description control("Smart FACT");
     control.add_options()
-        ("pixel-map-file", var<string>("FACTmapV5a.txt"), "Pixel mapping file. Used here to get the default reference voltage")
-        ("path",           var<string>("www/smartfact"),  "Output path for the data-files")
+        ("pixel-map-file", var<string>("FACTmapV5a.txt"),     "Pixel mapping file. Used here to get the default reference voltage")
+        ("path",           var<string>("www/smartfact/data"), "Output path for the data-files")
         ;
 
