Index: trunk/FACT++/src/smartfact.cc
===================================================================
--- trunk/FACT++/src/smartfact.cc	(revision 14013)
+++ trunk/FACT++/src/smartfact.cc	(revision 14014)
@@ -69,5 +69,5 @@
 // ========================================================================
 
-class Astro
+class Sun
 {
 public:
@@ -89,7 +89,11 @@
 
     bool isday;
+    bool visible;
 
 public:
-    Astro(double lon, double lat, const Time &t=Time()) :  time(t)
+    Sun() : time(Time::none)
+    {
+    }
+    Sun(double lon, double lat, const Time &t=Time()) :  time(t)
     {
 #ifdef HAVE_LIBNOVA
@@ -107,5 +111,4 @@
 
         // Warning: return code of 1 means circumpolar and is not checked!
-        //ln_get_lunar_rst        (JD-0.5, &observer,      &moon);
         ln_get_solar_rst        (JD-0.5, &observer,      &sun_day);
         ln_get_solar_rst_horizon(JD-0.5, &observer, - 6, &sun_civil);
@@ -126,5 +129,4 @@
         const bool is_night = JD>sun_dark.set;
 
-        //ln_get_lunar_rst        (JD+0.5, &observer,      &moon);
         ln_get_solar_rst        (JD+0.5, &observer,      &sun_day);
         ln_get_solar_rst_horizon(JD+0.5, &observer, - 6, &sun_civil);
@@ -151,15 +153,4 @@
         // case 1: sun-rise to sun-set  |  is_day && !is_night | set /rise
         // case 2: sun-set  to midnight |  is_day &&  is_night | rise/set
-        /*
-        if (is_day^is_night)
-        {
-            cout << "SunSet:  " << fSunSetDayTime  << endl;
-            cout << "SunRise: " << fSunRiseDayTime << endl;
-        }
-        else
-        {
-            cout << "SunRise: " << fSunRiseDayTime << endl;
-            cout << "SunSet:  " << fSunSetDayTime  << endl;
-        }*/
 
         isday = is_day^is_night;
@@ -205,4 +196,6 @@
         case 7: case 8:  color = HTML::kGreen;   break;
         }
+
+        visible = state>=3 && state<=5;
 #endif
     }
@@ -212,4 +205,6 @@
 {
 public:
+    Time time;
+
     double ra;
     double dec;
@@ -226,5 +221,7 @@
     string color;
 
-    Time time;
+    Moon() : time(Time::none)
+    {
+    }
 
     Moon(double lon, double lat, const Time &t=Time()) : time(t)
@@ -391,10 +388,36 @@
     deque<float> fRateScanDataHist[41];
 
-    bool fSunIsVisible;
-    bool fMoonIsVisible;
-
-    Time fTimeOfCivilTwilight;
+    Sun   fSun;
+    Moon  fMoon;
+
+    //bool fSunIsVisible;
+    //bool fMoonIsVisible;
+    //Time fTimeOfCivilTwilight;
+    //float fMoonPhase;
+
+    // --------------------------- File header ----------------------------
 
     int fHasError;
+
+    Time   fAudioTime;
+    string fAudioName;
+
+    string Header(const Time &d)
+    {
+        ostringstream msg;
+        msg << d.JavaDate() << '\t' << fAudioTime.JavaDate() << '\t' << fAudioName;
+        return msg.str();
+    }
+
+    string Header(const EventImp &d)
+    {
+        return Header(d.GetTime());
+    }
+
+    void SetAudio(const string &name)
+    {
+        fAudioName = name;
+        fAudioTime = Time();
+    }
 
     // ------------- Initialize variables before the Dim stuff ------------
@@ -531,5 +554,5 @@
         ostringstream out;
         out << setprecision(3);
-        out << d.GetJavaDate() << '\n';
+        out << Header(d) << '\n';
         out << HTML::kWhite << '\t';
 
@@ -562,4 +585,9 @@
         if (d.GetQoS()==-2 && fDimControl.scriptdepth==0)
             fControlMessageHist.clear();
+
+        // Not that this will also "ding" just after program startup
+        // if the dimctrl is still in state -3
+        if (d.GetQoS()==-3 && fDimControl.scriptdepth==0)
+            SetAudio("ding");
 
         if (d.GetQoS()>=0)
@@ -589,4 +617,10 @@
         }
 
+        if (fMcpConfigurationState==MCP::State::kTakingData && d.GetQoS()==MCP::State::kIdle)
+            SetAudio("sound_10");
+
+        if (fMcpConfigurationState==MCP::State::kTriggerOn && d.GetQoS()==MCP::State::kTakingData)
+            SetAudio("losticks");
+
         fMcpConfigurationState     = d.GetQoS();
         fMcpConfigurationMaxTime   = d.Get<uint64_t>();
@@ -594,5 +628,5 @@
         fMcpConfigurationName      = d.Ptr<char>(16);
 
-        if (d.GetQoS()==12)
+        if (d.GetQoS()==MCP::State::kTakingData)
             fMcpConfigurationRunStart = Time();
 
@@ -643,12 +677,12 @@
         //const uint16_t idx = uint16_t(floor(fmod(fMagicWeatherHist[kDir].back()/22.5+360+11.25, 360)/22.5))%16;
 
-        Astro astro(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
-        Moon  moon (-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
+        Sun  sun (-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
+        Moon moon(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
 
         ostringstream out;
         out << d.GetJavaDate() << '\n';
-        out << astro.color << '\t' << astro.description << '\n';
+        out << sun.color << '\t' << sun.description << '\n';
         out << setprecision(2);
-        out << (astro.isday?HTML::kWhite:moon.color) << '\t' << moon.description << '\n';
+        out << (sun.isday?HTML::kWhite:moon.color) << '\t' << moon.description << '\n';
         out << setprecision(3);
         for (int i=0; i<6; i++)
@@ -661,22 +695,20 @@
             out << "\t\n";
 
-        fSunIsVisible = astro.state>=3 && astro.state<=5;
-        fMoonIsVisible = !fSunIsVisible && moon.visible;
-
-        fTimeOfCivilTwilight = astro.fSunSetCivil;
+        fSun  = sun;
+        fMoon = moon;
 
         ofstream(fPath+"/weather.data") << out.str();
 
         out.str("");
-        out << astro.time.JavaDate() << '\n';
-        out << HTML::kWhite << '\t' << astro.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n';
-        out << HTML::kWhite << '\t' << astro.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n';
-        out << HTML::kWhite << '\t' << astro.fSunRiseCivil.GetAsStr("%H:%M") << '\n';
-        out << HTML::kWhite << '\t' << astro.fSunRiseDayTime.GetAsStr("%H:%M") << '\n';
-
-        out << HTML::kWhite << '\t' << astro.fSunSetDayTime.GetAsStr("%H:%M") << '\n';
-        out << HTML::kWhite << '\t' << astro.fSunSetCivil.GetAsStr("%H:%M") << '\n';
-        out << HTML::kWhite << '\t' << astro.fSunSetAstronomical.GetAsStr("%H:%M") << '\n';
-        out << HTML::kWhite << '\t' << astro.fSunSetDarkTime.GetAsStr("%H:%M") << '\n';
+        out << sun.time.JavaDate() << '\n';
+        out << HTML::kWhite << '\t' << sun.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << sun.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << sun.fSunRiseCivil.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << sun.fSunRiseDayTime.GetAsStr("%H:%M") << '\n';
+
+        out << HTML::kWhite << '\t' << sun.fSunSetDayTime.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << sun.fSunSetCivil.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << sun.fSunSetAstronomical.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << sun.fSunSetDarkTime.GetAsStr("%H:%M") << '\n';
 
         out << HTML::kWhite << '\t' << moon.fMoonRise.GetAsStr("%H:%M") << '\n';
@@ -1590,5 +1622,5 @@
         Time now;
         if (now-fLastUpdate<boost::posix_time::seconds(1))
-            return kStateRunning;
+            return fDimDNS.online() ? kStateRunning : kStateDimNetworkNA;
 
         fLastUpdate=now;
@@ -1675,5 +1707,5 @@
 
         ostringstream out;
-        out << now.JavaDate() << '\t' << haserror << '\t' << (fDimControl.state()>-3) << '\n';
+        out << Header(now) << '\t' << haserror << '\t' << (fDimControl.state()>-3) << '\n';
         out << setprecision(3);
         out << HTML::kWhite << '\t' << msg.str() << '\n';
@@ -1690,5 +1722,5 @@
 
         out.str("");
-        out << now.JavaDate() << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
+        out << Header(now) << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
         out << setprecision(3);
 
@@ -1718,5 +1750,5 @@
             const bool other =
                 fDimRateControl.state()==RateControl::State::kSettingGlobalThreshold ||
-                fDimRateScan.state()!=RateScan::State::kInProgress;
+                fDimRateScan.state()==RateScan::State::kInProgress;
 
             if (other)
@@ -1845,14 +1877,21 @@
         else
             out << HTML::kWhite << '\t';
-        if (fSunIsVisible)
-        {
-            out << " &#9788;";
-            if (fTimeOfCivilTwilight.IsValid() && fDimDriveControl.state()<Drive::State::kArmed)
-                out << " [" << fTimeOfCivilTwilight.MinutesTo() << "]";
-        }
-        else
-            if (fMoonIsVisible)
-                out << " &#9790;";
-        out << '\n';
+        if (fSun.time.IsValid() && fMoon.time.IsValid())
+        {
+            if (fSun.visible)
+            {
+                out << " &#9788;";
+                if (fDimDriveControl.state()<Drive::State::kArmed)
+                    out << " [" << fSun.fSunSetCivil.MinutesTo() << "&darr;]";
+            }
+            else
+                if (!fSun.visible && fMoon.visible)
+                {
+                    out << " &#9790;";
+                    if (fDimDriveControl.state()<Drive::State::kArmed)
+                        out << " [" << fMoon.disk << "%]";
+                }
+            out << '\n';
+        }
 
         // ------------------- FSC ------------------
@@ -1976,5 +2015,5 @@
 
         out.str("");
-        out << now.JavaDate() << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
+        out << Header(now) << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
 
         if (!fDimDNS.online())
@@ -2031,7 +2070,4 @@
         fRateScanDataId(0),
         fRateScanBoard(0),
-        fSunIsVisible(true),
-        fMoonIsVisible(false),
-        fTimeOfCivilTwilight(Time::none),
         fHasError(2),
         // ---
