#include <devices.h>
Public Methods | |
Devices () | |
Constructor. More... | |
~Devices () | |
Deconstructor. More... | |
string | addDevicePlugIn (string filename) |
Loads and registers a new device plugin. More... | |
bool | update () |
int | countDevices () |
Returns number of registered devices. More... | |
int | nameToInt (string name) |
Return device number of device name. More... | |
string | getDeviceName (int i) |
Returns name of device number. More... | |
int | getDeviceAxes (int i) |
Returns amount of axes. More... | |
int | getDeviceButtons (int i) |
Returns amount of buttons. More... | |
int | getDeviceSlots (int i) |
Returns amount of slots. More... | |
float | getSlot (int device, int slot) |
Returns value of device slot. More... | |
bool | connect (int device, int deviceslot, DeviceEvent ev) |
Connect device slot to event. More... | |
float | eventStatus (DeviceEvent ev) |
Returns event status. More... | |
Private Types | |
typedef vector<DevicePlugIn*> | CVectorDevicePlugIn |
typedef vector<float> | CEvents |
typedef vector< vector<int> > | CCEvents |
Private Attributes | |
int | registeredDevices |
CVectorDevicePlugIn | devs |
CEvents | events |
CCEvents | cEvents |
Definition at line 33 of file devices.h.
00033 { 00034 public: 00035 00037 Devices (); 00039 ~Devices (); 00040 00042 00046 string addDevicePlugIn (string filename); 00047 00048 bool update (); 00049 00051 00054 int countDevices (); 00055 00057 00061 int nameToInt (string name); 00062 00064 00068 string getDeviceName (int i); 00069 00071 00075 int getDeviceAxes (int i); 00077 00081 int getDeviceButtons (int i); 00082 00084 00088 int getDeviceSlots (int i); 00089 00091 00096 float getSlot (int device, int slot); 00097 00099 00105 bool connect (int device, int deviceslot, DeviceEvent ev); 00106 00108 00112 float eventStatus (DeviceEvent ev); 00113 00114 00115 private: 00116 00117 typedef vector<DevicePlugIn*> CVectorDevicePlugIn; 00118 typedef vector<float> CEvents; 00119 typedef vector< vector<int> > CCEvents; 00120 int registeredDevices; 00121 CVectorDevicePlugIn devs; 00122 CEvents events; 00123 CCEvents cEvents; 00124 }
|
|
|
|
Constructor.
Definition at line 29 of file devices.cpp.
00029 { 00030 registeredDevices = 0; 00031 00032 for (int i = 0; i < DEVICE_EVENTS; i++) { 00033 events.push_back (0.0); 00034 }; 00035 }
|
|
Loads and registers a new device plugin.
filename | the name of the plugin |
Definition at line 60 of file devices.cpp.
00060 { 00061 typedef void* (*pfnPlugIn)(); 00062 pfnPlugIn getPlugIn; 00063 void* handler; 00064 00065 if ((handler = (pfnPlugIn) dlopen (filename.c_str (), RTLD_NOW)) != 0) { 00066 if ((getPlugIn = (pfnPlugIn)dlsym (handler, "GetDevicePlugIn")) != 0) { 00067 devs.push_back ((DevicePlugIn*) getPlugIn ()); 00068 devs.back ()->openDevice (); 00069 00070 vector<int> tmpV; 00071 for (int i = 0; i < (devs.back ()->buttons () + (devs.back ()->axes () * 2)); i++) { 00072 tmpV.push_back (0); 00073 }; 00074 cEvents.push_back (tmpV); 00075 00076 return string (devs.back ()->name ()); 00077 } else { 00078 return "Error: Not a 3Dsia device plugin !"; 00079 }; 00080 } else { 00081 return "Error: Couldn't open device plugin !"; 00082 }; 00083 }
|
Connect device slot to event.
device | device number |
deviceslot | slot number |
ev | event number |
Definition at line 191 of file devices.cpp.
00191 { 00192 if ((device >= 0) && ((CCEvents::size_type)device < cEvents.size ()) && (deviceslot < getDeviceSlots (device))) { 00193 cEvents[device][deviceslot] = ev; 00194 return true; 00195 } else return false; 00196 }
|
Returns number of registered devices.
Definition at line 95 of file devices.cpp.
00095 { 00096 return devs.size (); 00097 }
|
Returns event status.
ev | Event to check |
Definition at line 209 of file devices.cpp.
00209 { 00210 if ((ev >= 0) && ((CEvents::size_type)ev < events.size ())) { 00211 return events[ev]; 00212 } else return 0.0; 00213 }
|
Returns amount of axes.
i | device number |
Definition at line 142 of file devices.cpp.
00142 { 00143 if ((i >= 0) && ((CVectorDevicePlugIn::size_type)i < devs.size ())) { 00144 return devs[i]->axes (); 00145 } else return -1; 00146 }
|
Returns amount of buttons.
i | device number |
Definition at line 158 of file devices.cpp.
00158 { 00159 if ((i >= 0) && ((CVectorDevicePlugIn::size_type)i < devs.size ())) { 00160 return devs[i]->buttons (); 00161 } else return -1; 00162 }
|
Returns name of device number.
i | device number |
Definition at line 126 of file devices.cpp.
00126 { 00127 if ((i >= 0) && ((CVectorDevicePlugIn::size_type)i < devs.size ())) { 00128 return devs[i]->name (); 00129 } else return "no such device"; 00130 }
|
Returns amount of slots.
i | device number |
Definition at line 175 of file devices.cpp.
00175 { 00176 if ((i >= 0) && ((CVectorDevicePlugIn::size_type)i < devs.size ())) { 00177 return (devs[i]->buttons () + (devs[i]->axes () * 2)); 00178 } else return -1; 00179 }
|
Returns value of device slot.
device | The number of the device |
slot | The number of the slot |
Definition at line 234 of file devices.cpp.
00234 { 00235 if ((device >= 0) && ((CVectorDevicePlugIn::size_type)device < devs.size ()) && (slot >= 0) && (slot < getDeviceSlots (device))) { 00236 if (slot < getDeviceButtons (device)) { 00237 if (devs[device]->buttonPressed (slot)) { 00238 return 1.0; 00239 } else { 00240 return 0.0; 00241 }; 00242 } else { 00243 if (((slot - getDeviceButtons (device)) % 2) == 0) { 00244 if (devs[device]->axis ((slot - getDeviceButtons (device)) / 2) < 0) return 0.0; 00245 return (devs[device]->axis ((slot - getDeviceButtons (device)) / 2)) / 32767.0; 00246 } else { 00247 if (devs[device]->axis ((slot - getDeviceButtons (device)) / 2) > 0) return 0.0; 00248 return -(devs[device]->axis ((slot - getDeviceButtons (device)) / 2)) / 32767.0; 00249 }; 00250 }; 00251 } else return 0.0; 00252 }
|
Return device number of device name.
name | returned by addDevicePlugin |
Definition at line 109 of file devices.cpp.
00109 { 00110 for (CVectorDevicePlugIn::size_type i = 0; i < devs.size(); i++) { 00111 if (devs[i]->name () == name) return i; 00112 }; 00113 return -1; 00114 }
|
Definition at line 267 of file devices.cpp.
00267 { 00268 if (devs.size () == 0) return false; 00269 00270 for (CEvents::size_type i = 0; i < events.size (); i++) { 00271 events[i] = 0.0; 00272 }; 00273 00274 for (CVectorDevicePlugIn::size_type i = 0; i < devs.size (); i++) { 00275 devs[i]->update (); 00276 for (CCEvents::size_type k = 0; k < cEvents[i].size (); k++) { 00277 if (events[cEvents[i][k]] == 0.0) events[cEvents[i][k]] = 0.0; 00278 }; 00279 }; 00280 00281 for (CVectorDevicePlugIn::size_type i = 0; i < devs.size (); i++) { 00282 for (CCEvents::size_type k = 0; k < cEvents[i].size (); k++) { 00283 if (events[cEvents[i][k]] == 0.0) events[cEvents[i][k]] += getSlot (i, k); 00284 }; 00285 }; 00286 00287 return true; 00288 }
|
|
|
|