00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "inputdevice.h"
00020
00021 #include <QtCore/QDebug>
00022 #include <QtCore/QFile>
00023 #include <QtCore/QMetaObject>
00024 #include <QtCore/QMetaEnum>
00025
00026 #include "absval.h"
00027 #include "inputdeviceprivate.h"
00028 #include "inputbuffer.h"
00029 #include "gluondevices.h"
00030
00031 #include <core/debughelper.h>
00032
00033 using namespace GluonInput;
00034
00035 InputDevice::InputDevice( InputThread* inputThread, QObject* parent )
00036 : QObject( parent )
00037 , d( new InputDevicePrivate )
00038 {
00039 d->inputThread = inputThread;
00040 d->inputThread->setParent( this );
00041 d->inputBuffer = new InputBuffer();
00042 d->inputBuffer->setParent( this );
00043
00044 connect( inputThread, SIGNAL( buttonStateChanged( int, int ) ), SLOT( buttonStateChanged( int, int ) ), Qt::DirectConnection );
00045 }
00046
00047 InputDevice::InputDevice()
00048 {
00049 }
00050
00051 InputDevice::~InputDevice()
00052 {
00053 setEnabled( false );
00054 delete d->inputThread;
00055 delete d->inputBuffer;
00056
00057 qDebug() << "Closed device :" << deviceName();
00058 }
00059
00060 int InputDevice::vendor() const
00061 {
00062 return d->inputThread->vendor();
00063 }
00064
00065 int InputDevice::product() const
00066 {
00067 return d->inputThread->product();
00068 }
00069
00070 int InputDevice::version() const
00071 {
00072 return d->inputThread->version();
00073 }
00074
00075 int InputDevice::bustype() const
00076 {
00077 return d->inputThread->bustype();
00078 }
00079
00080 const QString InputDevice::deviceName() const
00081 {
00082 return d->inputThread->deviceName();
00083 }
00084
00085 GluonInput::DeviceFlag InputDevice::deviceType() const
00086 {
00087 return d->inputThread->deviceType();
00088 }
00089
00090 QList<int> InputDevice::buttonCapabilities() const
00091 {
00092 return d->inputThread->buttonCapabilities();
00093 }
00094
00095 QList<int> InputDevice::absAxisCapabilities() const
00096 {
00097 return d->inputThread->absAxisCapabilities();
00098 }
00099
00100 QList<int> InputDevice::relAxisCapabilities() const
00101 {
00102 return d->inputThread->relAxisCapabilities();
00103 }
00104
00105 AbsVal InputDevice::axisInfo( int axisCode ) const
00106 {
00107 return d->inputThread->axisInfo( axisCode );
00108 }
00109
00110 bool InputDevice::error() const
00111 {
00112 return d->inputThread->error();
00113 }
00114
00115 QString InputDevice::msgError() const
00116 {
00117 return d->inputThread->msgError();
00118 }
00119
00120 bool InputDevice::isEnabled() const
00121 {
00122 return d->inputThread->isEnabled();
00123 }
00124
00125 void InputDevice::setEnabled( bool enable )
00126 {
00127 if( enable && !d->inputThread->isEnabled() )
00128 {
00129 d->inputThread->start();
00130 }
00131 else if( !enable && d->inputThread->isEnabled() )
00132 {
00133 d->inputThread->stop();
00134 }
00135 }
00136
00137 void InputDevice::setInputThread( InputThread* inputThread )
00138 {
00139 d->inputThread->stop();
00140 delete d->inputThread;
00141 d->inputThread = inputThread;
00142 }
00143
00144 InputThread* InputDevice::inputThread() const
00145 {
00146 return d->inputThread;
00147 }
00148
00149 bool InputDevice::buttonPressed( int code ) const
00150 {
00151 return d->inputBuffer->buttonState( code );
00152 }
00153
00154 QString InputDevice::buttonName( int code ) const
00155 {
00156 return GluonButtons::instance()->buttonName( deviceType(), code );
00157 }
00158
00159 QString InputDevice::axisName( int code ) const
00160 {
00161 switch( deviceType() )
00162 {
00163 case MouseDevice:
00164 case JoystickDevice:
00165 return GluonButtons::instance()->axisName( deviceType(), code );
00166 break;
00167 default:
00168 return "Unknown";
00169 break;
00170 }
00171 }
00172
00173 void InputDevice::buttonStateChanged( int code, int value )
00174 {
00175 d->inputBuffer->setButtonState( code, value );
00176 }
00177
00178 #include "inputdevice.moc"