Index: libs/libmythtv/diseqc.cpp
===================================================================
--- libs/libmythtv/diseqc.cpp	(revision 10424)
+++ libs/libmythtv/diseqc.cpp	(working copy)
@@ -72,7 +72,7 @@
 #define LOC     QString("DiSEqCDevTree: ")
 #define LOC_ERR QString("DiSEqCDevTree, Error: ")
 
-static QString TableToString(uint type, const TypeTable *table)
+QString DiSEqCDevDevice::TableToString(uint type, const TypeTable *table)
 {
     for (; !table->name.isEmpty(); table++)
     {
@@ -82,7 +82,7 @@
     return QString::null;
 }
 
-static uint TableFromString(const QString &type, const TypeTable *table)
+uint DiSEqCDevDevice::TableFromString(const QString &type, const TypeTable *table)
 {
     uint first_val = table->value;
     for (; !table->name.isEmpty(); table++)
@@ -428,7 +428,7 @@
  *  \return True if execution completed successfully.
  */
 bool DiSEqCDevTree::Execute(const DiSEqCDevSettings &settings,
-                         const DVBTuning &tuning)
+                            const DVBTuning &tuning)
 {
     if (!m_root)
     {
@@ -572,7 +572,7 @@
  *  \param data Pointer to optional data.
  */
 bool DiSEqCDevTree::SendCommand(uint adr, uint cmd, uint repeats,
-                             uint data_len, unsigned char *data)
+                                uint data_len, unsigned char *data)
 {
     // check payload validity
     if (data_len > 3 || (data_len > 0 && !data))
@@ -691,7 +691,7 @@
 }
 
 bool DiSEqCDevTree::ApplyVoltage(const DiSEqCDevSettings &settings,
-                              const DVBTuning      &tuning)
+                                 const DVBTuning         &tuning)
 {
     uint voltage = SEC_VOLTAGE_18;
 
@@ -707,7 +707,7 @@
  *  \brief Represents a node in a DVB-S device network.
  */
 
-const TypeTable DiSEqCDevDevice::dvbdev_lookup[4] =
+const DiSEqCDevDevice::TypeTable DiSEqCDevDevice::dvbdev_lookup[4] =
 {
     { "switch",      kTypeSwitch },
     { "rotor",       kTypeRotor  },
@@ -795,8 +795,8 @@
 }
 
 DiSEqCDevDevice *DiSEqCDevDevice::CreateByType(DiSEqCDevTree &tree,
-                                         dvbdev_t type,
-                                         uint dev_id)
+                                               dvbdev_t type,
+                                               uint dev_id)
 {
     if (!dev_id)
         dev_id = tree.NextFakeID();
@@ -902,7 +902,7 @@
  *  \brief Switch class, including tone, legacy and DiSEqC switches.
  */
 
-const TypeTable DiSEqCDevSwitch::SwitchTypeTable[7] =
+const DiSEqCDevDevice::TypeTable DiSEqCDevSwitch::SwitchTypeTable[7] =
 {
     { "legacy_sw21",  kTypeLegacySW21        },
     { "legacy_sw42",  kTypeLegacySW42        },
@@ -914,7 +914,7 @@
 };
 
 DiSEqCDevSwitch::DiSEqCDevSwitch(DiSEqCDevTree &tree,
-                           uint devid)
+                                 uint devid)
     : DiSEqCDevDevice(tree, devid),
       m_type(kTypeTone), m_num_ports(2)
 {
@@ -937,7 +937,7 @@
 }
 
 bool DiSEqCDevSwitch::Execute(const DiSEqCDevSettings &settings,
-                           const DVBTuning      &tuning)
+                              const DVBTuning         &tuning)
 {
     bool success = true;
 
@@ -1057,7 +1057,7 @@
 }
 
 uint DiSEqCDevSwitch::GetVoltage(const DiSEqCDevSettings &settings,
-                                        const DVBTuning      &tuning) const
+                                 const DVBTuning         &tuning) const
 {
     uint voltage = SEC_VOLTAGE_18;
     DiSEqCDevDevice *child = GetSelectedChild(settings);
@@ -1310,8 +1310,8 @@
 }
 
 bool DiSEqCDevSwitch::ExecuteTone(const DiSEqCDevSettings &/*settings*/,
-                               const DVBTuning &/*tuning*/,
-                               uint pos)
+                                  const DVBTuning &/*tuning*/,
+                                  uint pos)
 {
     VERBOSE(VB_CHANNEL, LOC + "Changing to Tone switch port " +
             QString("%1/2").arg(pos + 1));
@@ -1324,8 +1324,8 @@
 }
 
 bool DiSEqCDevSwitch::ExecuteDiseqc(const DiSEqCDevSettings &settings,
-                                 const DVBTuning &tuning,
-                                 uint pos)
+                                    const DVBTuning &tuning,
+                                    uint pos)
 {
     // retrieve LNB info
     bool high_band  = false;
@@ -1388,11 +1388,18 @@
 
 //////////////////////////////////////// DiSEqCDevRotor
 
+static double GetCurTimeFloating(void)
+{
+    struct timeval curtime;
+    gettimeofday(&curtime, NULL);
+    return (double)curtime.tv_sec + (((double)curtime.tv_usec) / 1000000);
+}
+
 /** \class DiSEqCDevRotor
  *  \brief Rotor class.
  */
 
-const TypeTable DiSEqCDevRotor::RotorTypeTable[] =
+const DiSEqCDevDevice::TypeTable DiSEqCDevRotor::RotorTypeTable[] =
 {
     { "diseqc_1_2", kTypeDiSEqC_1_2 },
     { "diseqc_1_3", kTypeDiSEqC_1_3 },
@@ -1400,14 +1407,14 @@
 };
 
 DiSEqCDevRotor::DiSEqCDevRotor(DiSEqCDevTree &tree,
-                         uint devid)
+                               uint devid)
     : DiSEqCDevDevice(tree, devid),
       m_type(kTypeDiSEqC_1_3),
       m_speed_hi(2.5),          m_speed_lo(1.9),
-      m_child(NULL),
-      m_last_position(0.0),     m_last_azimuth(0.0),
+      m_child(NULL),            
+      m_last_position(0.0),     m_desired_azimuth(0.0),
       m_reset(true),            m_move_time(0.0),
-      m_last_pos_known(false)
+      m_last_pos_known(false),  m_last_azimuth(0.0)
 {
     Reset();
 }
@@ -1419,7 +1426,7 @@
 }
 
 bool DiSEqCDevRotor::Execute(const DiSEqCDevSettings &settings,
-                          const DVBTuning &tuning)
+                             const DVBTuning &tuning)
 {
     bool success = true;
 
@@ -1498,11 +1505,11 @@
 }
 
 uint DiSEqCDevRotor::GetVoltage(const DiSEqCDevSettings &settings,
-                                       const DVBTuning      &tuning) const
+                                const DVBTuning         &tuning) const
 {
     double position = settings.GetValue(GetDeviceID());
-    bool   moving   = ((GetProgress() < 1.0) || m_reset ||
-                       (position != m_last_position));
+    double completed = GetProgress();
+    bool   moving   = (completed < 1.0) || (position != m_last_position);
 
     // override voltage if the last position is known and the rotor is moving
     if (m_last_pos_known && moving)
@@ -1669,20 +1676,12 @@
     double duration = change / speed;
 
     // determine completion percentage
-    struct timeval curtime;
-    gettimeofday(&curtime, NULL);
-
-    double cursecond       = (curtime.tv_sec +
-                              ((double) curtime.tv_usec / 1000000));
-    double time_since_move = cursecond - m_move_time;
-    double completed       = time_since_move / duration;
-
-    // move completed, finish up
-    if (completed > 1.0)
+    double time_since_move = GetCurTimeFloating() - m_move_time;
+    double completed = time_since_move / duration;
+    if(completed > 1.0)
     {
+        RotationComplete();
         completed = 1.0;
-        m_move_time = 0.0;
-        m_last_pos_known = true;
     }
 
     return completed;
@@ -1720,7 +1719,7 @@
 }
 
 bool DiSEqCDevRotor::ExecuteRotor(const DiSEqCDevSettings&, const DVBTuning&,
-                               double angle)
+                                  double angle)
 {
     // determine stored position from position map
     dbl_to_uint_t::const_iterator it = m_posmap.find(angle);
@@ -1739,7 +1738,7 @@
 }
 
 bool DiSEqCDevRotor::ExecuteUSALS(const DiSEqCDevSettings&, const DVBTuning&,
-                               double angle)
+                                  double angle)
 {
     double azimuth = CalculateAzimuth(angle);
     StartRotorPositionTracking(azimuth);
@@ -1793,14 +1792,19 @@
     m_desired_azimuth = azimuth;
 
     // set last to approximate current position (or worst case if unknown)
-    m_last_azimuth = azimuth > 0.0 ? -75.0 : 75.0;
-    if (m_last_pos_known)
+    if (m_last_pos_known || m_move_time > 0.0)
         m_last_azimuth = GetApproxAzimuth();
+    else
+        m_last_azimuth = azimuth > 0.0 ? -75.0 : 75.0;
 
-    struct timeval curtime;
-    gettimeofday(&curtime, NULL);
+    m_move_time = GetCurTimeFloating();
+}
 
-    m_move_time = curtime.tv_sec + (((double)curtime.tv_usec) / 1000000);
+void DiSEqCDevRotor::RotationComplete(void) const
+{
+    m_move_time = 0.0;
+    m_last_pos_known = true;
+    m_last_azimuth = m_desired_azimuth;
 }
 
 ////////////////////////////////////////
@@ -1835,7 +1840,7 @@
 }
 
 uint DiSEqCDevLNB::GetVoltage(const DiSEqCDevSettings&,
-                                     const DVBTuning &tuning) const
+                              const DVBTuning &tuning) const
 {
     uint voltage = SEC_VOLTAGE_18;
 
Index: libs/libmythtv/diseqc.h
===================================================================
--- libs/libmythtv/diseqc.h	(revision 10424)
+++ libs/libmythtv/diseqc.h	(working copy)
@@ -34,10 +34,6 @@
 typedef QMap<uint, DiSEqCDevTree*> cardid_to_diseqc_tree_t;
 typedef vector<DiSEqCDevDevice*>   dvbdev_vec_t;
 
-typedef struct { QString name; uint value; } TypeTable;
-static QString TableToString(uint type, const TypeTable *table);
-static uint    TableFromString(const QString &type, const TypeTable *table);
-
 class DiSEqCDevSettings
 {
   public:
@@ -149,7 +145,7 @@
     // Gets
     dvbdev_t      GetDeviceType(void)  const { return m_dev_type;    }
     uint          GetDeviceID(void)    const { return m_devid;       }
-    bool          IsRealDeviceID(void) const { return m_devid<4000000000; }
+    bool          IsRealDeviceID(void) const { return m_devid<4000000000u; }
     DiSEqCDevDevice *GetParent(void)   const { return m_parent;      }
     uint          GetOrdinal(void)     const { return m_ordinal;     }
     QString       GetDescription(void) const { return m_desc;        }
@@ -188,6 +184,10 @@
     uint             m_ordinal;
     uint             m_repeat;
 
+    typedef struct { QString name; uint value; } TypeTable;
+    static QString TableToString(uint type, const TypeTable *table);
+    static uint    TableFromString(const QString &type, const TypeTable *table);
+
   private:
     static const TypeTable dvbdev_lookup[4];
 };
@@ -272,6 +272,7 @@
     void   SetHiSpeed(double speed)        { m_speed_hi = speed; }
     void   SetPosMap(const uint_to_dbl_t &posmap);
     virtual bool SetChild(uint ordinal, DiSEqCDevDevice* device);
+    void   RotationComplete(void) const;
 
     // Gets
     dvbdev_rotor_t GetType(void)         const { return m_type;      }
@@ -315,13 +316,13 @@
 
     // state
     double         m_last_position;
-    double         m_last_azimuth;
     double         m_desired_azimuth;
     bool           m_reset;
 
     // rotor position tracking state
     mutable double m_move_time;
     mutable bool   m_last_pos_known;
+    mutable double m_last_azimuth;
 
     // statics
     static const TypeTable RotorTypeTable[3];
