From 8cf74b8f2d1591905fc81cf2b2993c865b6332a0 Mon Sep 17 00:00:00 2001 From: torsten Date: Wed, 12 Aug 2009 06:08:12 +0000 Subject: [PATCH] Add a debug property to make devices print out incoming events on the console. --- src/Input/FGEventInput.cxx | 7 ++++++- src/Input/FGEventInput.hxx | 9 ++++++++- src/Input/FGLinuxEventInput.cxx | 9 --------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Input/FGEventInput.cxx b/src/Input/FGEventInput.cxx index f47a6161a..3acf7b93c 100644 --- a/src/Input/FGEventInput.cxx +++ b/src/Input/FGEventInput.cxx @@ -192,7 +192,10 @@ void FGInputDevice::update( double dt ) void FGInputDevice::HandleEvent( FGEventData & eventData ) { string eventName = TranslateEventName( eventData ); -// cout << GetName() << " has event " << eventName << " modifiers=" << eventData.modifiers << " value=" << eventData.value << endl; + if( debugEvents ) + cout << GetName() << " has event " << + eventName << " modifiers=" << eventData.modifiers << " value=" << eventData.value << endl; + if( handledEvents.count( eventName ) > 0 ) { handledEvents[ eventName ]->fire( eventData ); } @@ -272,6 +275,8 @@ void FGEventInput::AddDevice( FGInputDevice * inputDevice ) for( vector::iterator it = eventNodes.begin(); it != eventNodes.end(); it++ ) inputDevice->AddHandledEvent( FGInputEvent::NewObject( inputDevice, *it ) ); + inputDevice->SetDebugEvents( deviceNode->getBoolValue("debug-events", inputDevice->GetDebugEvents() )); + // TODO: // add nodes for the last event: // last-event/name [string] diff --git a/src/Input/FGEventInput.hxx b/src/Input/FGEventInput.hxx index 7a7323d43..a3896e1d4 100644 --- a/src/Input/FGEventInput.hxx +++ b/src/Input/FGEventInput.hxx @@ -164,7 +164,7 @@ typedef class SGSharedPtr FGInputEvent_ptr; */ class FGInputDevice : public SGReferenced { public: - FGInputDevice() {} + FGInputDevice() : debugEvents(false) {} FGInputDevice( string aName ) : name(aName) {} virtual ~FGInputDevice(); @@ -193,12 +193,19 @@ public: virtual void update( double dt ); + bool GetDebugEvents () const { return debugEvents; } + void SetDebugEvents( bool value ) { debugEvents = value; } + private: // A map of events, this device handles map handledEvents; // the device has a name to be recognized string name; + + // print out events comming in from the device + // if true + bool debugEvents; }; typedef SGSharedPtr FGInputDevice_ptr; diff --git a/src/Input/FGLinuxEventInput.cxx b/src/Input/FGLinuxEventInput.cxx index eb191f524..ec0f23da2 100644 --- a/src/Input/FGLinuxEventInput.cxx +++ b/src/Input/FGLinuxEventInput.cxx @@ -252,15 +252,6 @@ void FGLinuxInputDevice::Open() if( (fd = ::open( devname.c_str(), O_RDWR )) == -1 ) { throw exception(); } -/* - input_event evt; - evt.type=EV_LED; - evt.code = 8; - evt.value = 1; - evt.time.tv_sec = 0; - evt.time.tv_usec = 0; - write( fd, &evt, sizeof(evt) ); -*/ } void FGLinuxInputDevice::Close()