phidgetik.cpp
Go to the documentation of this file.
00001 
00060 #include <cob_phidgets/phidgetik.h>
00061 
00062 PhidgetIK::PhidgetIK(SensingMode mode)  : Phidget((CPhidgetHandle*) &_iKitHandle, mode), _iKitHandle(0)
00063 {
00064         _last_error = CPhidgetInterfaceKit_create(&_iKitHandle);
00065 
00066         if (!_last_error) {
00067                 CPhidget_set_OnAttach_Handler((CPhidgetHandle) _iKitHandle,
00068                                 PhidgetIK::attachDelegate, this);
00069                 CPhidgetInterfaceKit_set_OnOutputChange_Handler(_iKitHandle,
00070                                 PhidgetIK::outputChangeDelegate, this);
00071 
00072                 if(_sensMode == SensingMode::EVENT)
00073                 {
00074                         CPhidgetInterfaceKit_set_OnInputChange_Handler(_iKitHandle,
00075                                         PhidgetIK::inputChangeDelegate, this);
00076                         _last_error = CPhidgetInterfaceKit_set_OnSensorChange_Handler(
00077                                         _iKitHandle, PhidgetIK::sensorChangeDelegate, this);
00078                 }
00079         }
00080 }
00081 
00082 PhidgetIK::~PhidgetIK()
00083 {
00084 }
00085 
00086 auto PhidgetIK::init(int serial_number) -> int
00087 {
00088         return (_last_error = open(serial_number));
00089 }
00090 
00091 auto PhidgetIK::getInputCount() -> int
00092 {
00093         int count = -1;
00094 
00095         _last_error = CPhidgetInterfaceKit_getInputCount(_iKitHandle, &count);
00096 
00097         return count;
00098 }
00099 
00100 auto PhidgetIK::getInputState(int index) -> int
00101 {
00102         int state = -1;
00103 
00104          _last_error = CPhidgetInterfaceKit_getInputState(_iKitHandle, index,
00105                         &state);
00106 
00107         return state;
00108 }
00109 
00110 auto PhidgetIK::getOutputCount() -> int
00111 {
00112         int count = -1;
00113 
00114         _last_error = CPhidgetInterfaceKit_getOutputCount(_iKitHandle, &count);
00115 
00116         return count;
00117 }
00118 
00119 auto PhidgetIK::getOutputState(int index) -> int
00120 {
00121         int state = -1;
00122 
00123          _last_error = CPhidgetInterfaceKit_getOutputState(_iKitHandle, index,
00124                         &state);
00125 
00126         return state;
00127 }
00128 
00129 auto PhidgetIK::setOutputState(int index, int state) -> int
00130 {
00131         return (_last_error = CPhidgetInterfaceKit_setOutputState(_iKitHandle,
00132                         index, state));
00133 }
00134 
00135 auto PhidgetIK::getSensorCount() -> int
00136 {
00137         int count = -1;
00138 
00139         _last_error = CPhidgetInterfaceKit_getSensorCount(_iKitHandle, &count);
00140 
00141         return count;
00142 }
00143 
00144 auto PhidgetIK::getSensorValue(int index) -> int
00145 {
00146         int value = -1;
00147 
00148          _last_error = CPhidgetInterfaceKit_getSensorValue(_iKitHandle, index, &value);
00149 
00150         return value;
00151 }
00152 
00153 auto PhidgetIK::getSensorRawValue(int index) -> int
00154 {
00155         int value = -1;
00156 
00157          _last_error = CPhidgetInterfaceKit_getSensorRawValue(_iKitHandle, index, &value);
00158 
00159         return value;
00160 }
00161 
00162 auto PhidgetIK::getSensorChangeTrigger(int index) -> int
00163 {
00164         int trigger = -1;
00165 
00166          _last_error = CPhidgetInterfaceKit_getSensorChangeTrigger(_iKitHandle, index, &trigger);
00167 
00168         return trigger;
00169 }
00170 
00171 auto PhidgetIK::setSensorChangeTrigger(int index, int trigger) -> int
00172 {
00173         return (_last_error = CPhidgetInterfaceKit_setSensorChangeTrigger(_iKitHandle, index, trigger));
00174 }
00175 
00176 auto PhidgetIK::getRatiometric() -> int
00177 {
00178         int ratiometric = -1;
00179 
00180         _last_error = CPhidgetInterfaceKit_getRatiometric(_iKitHandle,
00181                         &ratiometric);
00182 
00183         return ratiometric;
00184 }
00185 
00186 auto PhidgetIK::setRatiometric(int ratiometric) -> int
00187 {
00188         return (_last_error = CPhidgetInterfaceKit_setRatiometric(_iKitHandle,
00189                         ratiometric));
00190 }
00191 
00192 auto PhidgetIK::getDataRate(int index) -> int
00193 {
00194         int datarate = -1;
00195 
00196         _last_error = CPhidgetInterfaceKit_getDataRate(_iKitHandle, index, &datarate);
00197 
00198         return datarate;
00199 }
00200 
00201 auto PhidgetIK::setDataRate(int index, int datarate) -> int
00202 {
00203         return (_last_error = CPhidgetInterfaceKit_setDataRate(_iKitHandle,     index, datarate));
00204 }
00205 
00206 auto PhidgetIK::getDataRateMax(int index) -> int
00207 {
00208         int max = -1;
00209 
00210         _last_error = CPhidgetInterfaceKit_getDataRateMax(_iKitHandle, index, &max);
00211 
00212         return max;
00213 }
00214 
00215 auto PhidgetIK::getDataRateMin(int index) -> int
00216 {
00217         int min = -1;
00218 
00219         _last_error = CPhidgetInterfaceKit_getDataRateMin(_iKitHandle, index, &min);
00220 
00221         return min;
00222 }
00223 
00224 auto PhidgetIK::getError() -> int
00225 {
00226         return _last_error;
00227 }
00228 
00229 auto PhidgetIK::attachHandler() -> int
00230 {
00231         int serialNo, version, numInputs, numOutputs;
00232         int numSensors, triggerVal, ratiometric, i;
00233         const char *ptr, *name;
00234 
00235         CPhidget_getDeviceName((CPhidgetHandle)_iKitHandle, &name);
00236         CPhidget_getDeviceType((CPhidgetHandle)_iKitHandle, &ptr);
00237         CPhidget_getSerialNumber((CPhidgetHandle)_iKitHandle, &serialNo);
00238         CPhidget_getDeviceVersion((CPhidgetHandle)_iKitHandle, &version);
00239 
00240         CPhidgetInterfaceKit_getInputCount(_iKitHandle, &numInputs);
00241         CPhidgetInterfaceKit_getOutputCount(_iKitHandle, &numOutputs);
00242         CPhidgetInterfaceKit_getSensorCount(_iKitHandle, &numSensors);
00243         CPhidgetInterfaceKit_getRatiometric(_iKitHandle, &ratiometric);
00244 
00245         printf("%s %d attached!\n", name, serialNo);
00246 
00247         printf("%s", ptr);
00248         printf("Serial Number: %d\tVersion: %d\n", serialNo, version);
00249         printf("Num Digital Inputs: %d\tNum Digital Outputs: %d\n", numInputs, numOutputs);
00250         printf("Num Sensors: %d\n", numSensors);
00251         printf("Ratiometric: %d\n", ratiometric);
00252 
00253         for(i = 0; i < numSensors; i++)
00254         {
00255                 CPhidgetInterfaceKit_getSensorChangeTrigger (_iKitHandle, i, &triggerVal);
00256 
00257                 printf("Sensor#: %d > Sensitivity Trigger: %d\n", i, triggerVal);
00258         }
00259 
00260         return 0;
00261 }
00262 
00263 auto PhidgetIK::detachHandler() -> int
00264 {
00265         int serial_number;
00266     const char *device_name;
00267 
00268     CPhidget_getDeviceName ((CPhidgetHandle)_iKitHandle, &device_name);
00269     CPhidget_getSerialNumber((CPhidgetHandle)_iKitHandle, &serial_number);
00270     printf("%s Serial number %d detached!\n", device_name, serial_number);
00271     return 0;
00272 }
00273 
00274 auto PhidgetIK::inputChangeHandler(int index, int inputState) -> int
00275 {
00276         return 0;
00277 }
00278 
00279 auto PhidgetIK::outputChangeHandler(int index, int outputState) -> int
00280 {
00281         return 0;
00282 }
00283 
00284 auto PhidgetIK::sensorChangeHandler(int index, int sensorValue) -> int
00285 {
00286         return 0;
00287 }
00288 
00289 auto PhidgetIK::attachDelegate(CPhidgetHandle phid, void *userptr) -> int
00290 {
00291         return ((PhidgetIK*) userptr)->attachHandler();
00292 }
00293 
00294 auto PhidgetIK::inputChangeDelegate(CPhidgetInterfaceKitHandle phid,
00295                 void *userPtr, int index, int inputState) -> int
00296 {
00297         return ((PhidgetIK*) userPtr)->inputChangeHandler(index, inputState);
00298 }
00299 
00300 auto PhidgetIK::outputChangeDelegate(CPhidgetInterfaceKitHandle phid,
00301                 void *userPtr, int index, int outputState) -> int
00302 {
00303         return ((PhidgetIK*) userPtr)->outputChangeHandler(index, outputState);
00304 }
00305 
00306 auto PhidgetIK::sensorChangeDelegate(CPhidgetInterfaceKitHandle phid,
00307                 void *userPtr, int index, int sensorValue) -> int
00308 {
00309         return ((PhidgetIK*) userPtr)->sensorChangeHandler(index, sensorValue);
00310 }
00311 
00312 auto PhidgetIK::update()-> void
00313 {
00314         printf("PhidgetIK::update()");
00315 }


cob_phidgets
Author(s): Florian Weisshardt, Benjamin Maidel
autogenerated on Sun Oct 5 2014 23:10:20