git-svn-id: https://openitg.svn.sourceforge.net/svnroot/openitg@21 83fadc84-e282...
authorMark Cannon <vyhdycokio@gmail.com>
Wed, 13 Feb 2008 18:35:14 +0000 (18:35 +0000)
committerMark Cannon <vyhdycokio@gmail.com>
Wed, 13 Feb 2008 18:35:14 +0000 (18:35 +0000)
src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp
src/io/PIUIO.cpp
src/io/PIUIO.h
src/io/USBDriver.cpp
src/io/USBDriver.h

index 64870a9..ed695f3 100644 (file)
@@ -1,5 +1,6 @@
 #include "global.h"
 #include "RageLog.h"
+#include "RageException.h"
 
 #include "LightsManager.h"
 #include "arch/Lights/LightsDriver_External.h" // needed for g_LightsState
@@ -15,6 +16,7 @@ InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO()
        // device found and set
        if( IOBoard.Open() )
        {
+               LOG->Trace( "Opened I/O board." );
                m_bFoundDevice = true;
 
                InputThread.SetName( "PIUIO thread" );
@@ -22,7 +24,7 @@ InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO()
        }
        else
        {
-               LOG->Warn( "InputHandler_Linux_PIUIO: could not open I/O board." );
+               sm_crash( "InputHandler_Linux_PIUIO: Failed to open PIU I/O board." );
        }
 }
 
@@ -57,9 +59,12 @@ int InputHandler_Linux_PIUIO::InputThread_Start( void *p )
 
 void InputHandler_Linux_PIUIO::InputThreadMain()
 {
-       /* For now, we just want to test lights updates. */
-       UpdateLights();
-       IOBoard.Write( m_iLightData );
+       while( !m_bShutdown )
+       {       
+               /* For now, we just want to test lights updates. */
+               UpdateLights();
+               IOBoard.Write( m_iLightData );
+       }
 }
 
 void InputHandler_Linux_PIUIO::UpdateLights()
index a31bf93..a87d8ff 100644 (file)
@@ -3,16 +3,13 @@
 #include "USBDevice.h"
 #include "PIUIO.h"
 
-PIUIO::PIUIO()
-{
-       Open();
-}
-
 bool PIUIO::Matches( int idVendor, int idProduct )
 {
        if( idVendor == 0x547 && idProduct == 0x1002 )
                return true;
 
+       LOG->Trace( "Not a match. idVendor %u, idProduct %u", idVendor, idProduct );
+
        return false;
 }
 
index e8a8577..340b679 100644 (file)
@@ -7,8 +7,6 @@
 class PIUIO: public USBDriver
 {
 public:
-       PIUIO();
-
        bool Read( uint32_t *pData );
        bool Write( uint32_t iData );
 
index f18e752..cdf35c7 100644 (file)
@@ -6,10 +6,14 @@
 
 USBDriver::USBDriver()
 {
+       LOG->Trace( "USBDriver::USBDriver()" );
+       m_pHandle = NULL; // work around segfault
+       usb_init();
 }
 
 USBDriver::~USBDriver()
 {
+       LOG->Trace( "USBDriver::~USBDriver()" );
        Close();
 }
 
@@ -19,20 +23,28 @@ bool USBDriver::Matches( int idVendor, int idProduct )
        return false;
 }
 
-struct usb_device *USBDriver::FindDevice()
+struct usb_device *USBDriver::FindDevice( usb_bus *usb_busses )
 {
-       for( usb_bus *bus = usb_get_busses(); bus; bus->next )
-               for( struct usb_device *dev = bus->devices; dev; dev->next )
+       LOG->Trace( "USBDriver::FindDevice()." );
+
+       for( usb_bus *bus = usb_busses; bus; bus = bus->next )
+               for( struct usb_device *dev = bus->devices; dev; dev = dev->next )
                        if( Matches(dev->descriptor.idVendor, dev->descriptor.idProduct) )
+                       {
+                               LOG->Trace( "FindDevice() got a match." );
                                return dev;
+                       }
 
        // fall through
+       LOG->Trace( "FindDevice() found no matches." );
        return NULL;
 }
 
 void USBDriver::Close()
 {
-       // already closed
+       LOG->Trace( "USBDriver::Close()" );
+
+       // never opened
        if( m_pHandle == NULL )
                return;
 
@@ -44,9 +56,12 @@ void USBDriver::Close()
 
 bool USBDriver::Open()
 {
+       LOG->Trace( "USBDriver::Open()" );
        Close();
 
+       LOG->Trace( "Attempting to usb_init()." );
        usb_init();
+       LOG->Trace( "USB subsystem successfully initialized." );
 
        if( usb_find_busses() < 0 )
        {
@@ -54,28 +69,29 @@ bool USBDriver::Open()
                return false;
        }
 
+       LOG->Trace( "usb_find_busses successful." );
+
        if( usb_find_devices() < 0 )
        {
                LOG->Warn( "usb_find_devices: %s", usb_strerror() );
                return false;
        }
-       
-       if( !usb_busses )
-       {
-               LOG->Warn( "usb_busses: %s", usb_strerror() );
-               return false;
-       }
+
+       LOG->Trace( "usb_find_devices successful." );
 
        // set the device
-       struct usb_device *device = FindDevice();
+       struct usb_device *device = FindDevice( usb_busses );
+
+       LOG->Trace( "device set." );
 
        if( device == NULL )
        {
                LOG->Warn( "USBDriver: could not set usb_device" );
                return false;
        }
-       
+
        m_pHandle = usb_open( device );
+
        if( m_pHandle == NULL )
        {
                LOG->Warn( "usb_open: %s", usb_strerror() );
index c4b7319..3129698 100644 (file)
@@ -13,7 +13,7 @@ public:
        bool Open();
        void Close();
 protected:
-       struct usb_device *FindDevice();
+       struct usb_device *FindDevice( usb_bus *usb_busses );
 
        virtual bool Matches( int idVendor, int idProduct );