changeset 128:44140fb96102 main

Tidy up the front-facing sonar controls.
author Bob Cook <bob@bobcookdev.com>
date Thu, 15 Dec 2011 10:04:56 -0800
parents f1944fbcf419
children 336ea92dbee9
files main/robots/odr-sim/ControllerStatus.cpp main/robots/odr-sim/SimDisplay.cpp main/robots/odr-sim/SonarFrontStatus.cpp main/robots/odr-sim/SonarFrontStatus.h
diffstat 4 files changed, 48 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/main/robots/odr-sim/ControllerStatus.cpp	Thu Dec 15 06:59:06 2011 -0800
+++ b/main/robots/odr-sim/ControllerStatus.cpp	Thu Dec 15 10:04:56 2011 -0800
@@ -156,7 +156,7 @@
             // nothing to do, but don't stop the thread
         }
 
-        if ( m_quitEvent.tryWait( 1000 ) ) // 1000 ms == 1s
+        if ( m_quitEvent.tryWait( 2500 ) ) // 2500 ms == 2.5s
         {
             return;
         }
--- a/main/robots/odr-sim/SimDisplay.cpp	Thu Dec 15 06:59:06 2011 -0800
+++ b/main/robots/odr-sim/SimDisplay.cpp	Thu Dec 15 10:04:56 2011 -0800
@@ -528,14 +528,7 @@
    
     if ( m_boxMgrHeartbeat )
     {
-        if ( m_boxMgrHeartbeat->color() == FL_GREEN )
-        {
-            m_boxMgrHeartbeat->color( FL_WHITE );
-        }
-        else
-        {
-            m_boxMgrHeartbeat->color( FL_GREEN );
-        }
+        m_boxMgrHeartbeat->color( FL_GREEN );
         m_boxMgrHeartbeat->redraw();
     }
 
@@ -602,7 +595,7 @@
 void SimDisplay::updateSonarFrontState( bool enabled )
 {
     Fl::lock();
-  
+
     if ( m_boxSonarFrontState )
     {
         if ( enabled )
--- a/main/robots/odr-sim/SonarFrontStatus.cpp	Thu Dec 15 06:59:06 2011 -0800
+++ b/main/robots/odr-sim/SonarFrontStatus.cpp	Thu Dec 15 10:04:56 2011 -0800
@@ -40,6 +40,31 @@
 // ----------------------------------------------------------------------------------------
 
 Poco::RWLock SonarFrontStatus::sm_rwLock;
+bool         SonarFrontStatus::sm_isEnabled = false;
+
+// ----------------------------------------------------------------------------------------
+
+bool SonarFrontStatus::isSonarFrontEnabled()
+{
+    Poco::RWLock::ScopedReadLock lock( sm_rwLock );
+    return sm_isEnabled;
+}
+
+// ----------------------------------------------------------------------------------------
+
+void SonarFrontStatus::setSonarFrontEnabled()
+{
+    Poco::RWLock::ScopedWriteLock lock( sm_rwLock );
+    sm_isEnabled = true;
+}
+
+// ----------------------------------------------------------------------------------------
+
+void SonarFrontStatus::setSonarFrontDisabled()
+{
+    Poco::RWLock::ScopedWriteLock lock( sm_rwLock );
+    sm_isEnabled = false;
+}
 
 // ----------------------------------------------------------------------------------------
 
@@ -76,23 +101,30 @@
     {
         try
         {
-            uint32_t msgid = can_build_message_id( can_node_odr_sonar_front,
-                                                   can_node_broadcast,
-                                                   can_dataid_heartbeat );
+            uint32_t msgid;
 
-            uint32_t data = can_heartbeat_data;
+            if ( SonarFrontStatus::isSonarFrontEnabled() )
+            {
+                msgid = can_build_message_id( can_node_odr_sonar_front,
+                                              can_node_broadcast,
+                                              can_dataid_sonar_front_state_enabled );
+            }
+            else
+            {
+                msgid = can_build_message_id( can_node_odr_sonar_front,
+                                              can_node_broadcast,
+                                              can_dataid_sonar_front_state_disabled );
+            }
 
-            CANMessage::QueueToSend(
-                new CANMessage( msgid,
-                                reinterpret_cast< uint8_t* >( &data ),
-                                sizeof( data ) ) );
+            CANMessage::QueueToSend( new CANMessage( msgid ) );
+
         }
         catch ( ... )
         {
             // nothing to do, but don't stop the thread
         }
 
-        if ( m_quitEvent.tryWait( 1000 ) ) // 1000 ms == 1s
+        if ( m_quitEvent.tryWait( 2500 ) ) // 2500 ms == 2.5s
         {
             return;
         }
--- a/main/robots/odr-sim/SonarFrontStatus.h	Thu Dec 15 06:59:06 2011 -0800
+++ b/main/robots/odr-sim/SonarFrontStatus.h	Thu Dec 15 10:04:56 2011 -0800
@@ -41,6 +41,9 @@
 class SonarFrontStatus : public Poco::Runnable
 {
     public:
+        static bool isSonarFrontEnabled();
+        static void setSonarFrontEnabled();
+        static void setSonarFrontDisabled();
         //static void setSonarFrontLeft( uint16_t value );
 
     public:
@@ -54,6 +57,7 @@
 
     private:
         static Poco::RWLock sm_rwLock;
+        static bool         sm_isEnabled;
 
     private:
         Poco::Event m_quitEvent;