1
0
Fork 0

Add a debug property to make devices print out incoming events on the console.

This commit is contained in:
torsten 2009-08-12 06:08:12 +00:00 committed by Tim Moore
parent 3231561e5a
commit 8cf74b8f2d
3 changed files with 14 additions and 11 deletions

View file

@ -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<SGPropertyNode_ptr>::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]

View file

@ -164,7 +164,7 @@ typedef class SGSharedPtr<FGInputEvent> 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<string,FGInputEvent_ptr> 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> FGInputDevice_ptr;

View file

@ -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()