phidgetik.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #include <cob_phidgets/phidgetik.h>
00019 
00020 PhidgetIK::PhidgetIK(SensingMode mode)  : Phidget((CPhidgetHandle*) &_iKitHandle, mode), _iKitHandle(0)
00021 {
00022         _last_error = CPhidgetInterfaceKit_create(&_iKitHandle);
00023 
00024         if (!_last_error) {
00025                 CPhidget_set_OnAttach_Handler((CPhidgetHandle) _iKitHandle,
00026                                 PhidgetIK::attachDelegate, this);
00027                 CPhidgetInterfaceKit_set_OnOutputChange_Handler(_iKitHandle,
00028                                 PhidgetIK::outputChangeDelegate, this);
00029 
00030                 if(_sensMode == SensingMode::EVENT)
00031                 {
00032                         CPhidgetInterfaceKit_set_OnInputChange_Handler(_iKitHandle,
00033                                         PhidgetIK::inputChangeDelegate, this);
00034                         _last_error = CPhidgetInterfaceKit_set_OnSensorChange_Handler(
00035                                         _iKitHandle, PhidgetIK::sensorChangeDelegate, this);
00036                 }
00037         }
00038 }
00039 
00040 PhidgetIK::~PhidgetIK()
00041 {
00042 }
00043 
00044 auto PhidgetIK::init(int serial_number) -> int
00045 {
00046         return (_last_error = open(serial_number));
00047 }
00048 
00049 auto PhidgetIK::getInputCount() -> int
00050 {
00051         int count = -1;
00052 
00053         _last_error = CPhidgetInterfaceKit_getInputCount(_iKitHandle, &count);
00054 
00055         return count;
00056 }
00057 
00058 auto PhidgetIK::getInputState(int index) -> int
00059 {
00060         int state = -1;
00061 
00062          _last_error = CPhidgetInterfaceKit_getInputState(_iKitHandle, index,
00063                         &state);
00064 
00065         return state;
00066 }
00067 
00068 auto PhidgetIK::getOutputCount() -> int
00069 {
00070         int count = -1;
00071 
00072         _last_error = CPhidgetInterfaceKit_getOutputCount(_iKitHandle, &count);
00073 
00074         return count;
00075 }
00076 
00077 auto PhidgetIK::getOutputState(int index) -> int
00078 {
00079         int state = -1;
00080 
00081          _last_error = CPhidgetInterfaceKit_getOutputState(_iKitHandle, index,
00082                         &state);
00083 
00084         return state;
00085 }
00086 
00087 auto PhidgetIK::setOutputState(int index, int state) -> int
00088 {
00089         return (_last_error = CPhidgetInterfaceKit_setOutputState(_iKitHandle,
00090                         index, state));
00091 }
00092 
00093 auto PhidgetIK::getSensorCount() -> int
00094 {
00095         int count = -1;
00096 
00097         _last_error = CPhidgetInterfaceKit_getSensorCount(_iKitHandle, &count);
00098 
00099         return count;
00100 }
00101 
00102 auto PhidgetIK::getSensorValue(int index) -> int
00103 {
00104         int value = -1;
00105 
00106          _last_error = CPhidgetInterfaceKit_getSensorValue(_iKitHandle, index, &value);
00107 
00108         return value;
00109 }
00110 
00111 auto PhidgetIK::getSensorRawValue(int index) -> int
00112 {
00113         int value = -1;
00114 
00115          _last_error = CPhidgetInterfaceKit_getSensorRawValue(_iKitHandle, index, &value);
00116 
00117         return value;
00118 }
00119 
00120 auto PhidgetIK::getSensorChangeTrigger(int index) -> int
00121 {
00122         int trigger = -1;
00123 
00124          _last_error = CPhidgetInterfaceKit_getSensorChangeTrigger(_iKitHandle, index, &trigger);
00125 
00126         return trigger;
00127 }
00128 
00129 auto PhidgetIK::setSensorChangeTrigger(int index, int trigger) -> int
00130 {
00131         return (_last_error = CPhidgetInterfaceKit_setSensorChangeTrigger(_iKitHandle, index, trigger));
00132 }
00133 
00134 auto PhidgetIK::getRatiometric() -> int
00135 {
00136         int ratiometric = -1;
00137 
00138         _last_error = CPhidgetInterfaceKit_getRatiometric(_iKitHandle,
00139                         &ratiometric);
00140 
00141         return ratiometric;
00142 }
00143 
00144 auto PhidgetIK::setRatiometric(int ratiometric) -> int
00145 {
00146         return (_last_error = CPhidgetInterfaceKit_setRatiometric(_iKitHandle,
00147                         ratiometric));
00148 }
00149 
00150 auto PhidgetIK::getDataRate(int index) -> int
00151 {
00152         int datarate = -1;
00153 
00154         _last_error = CPhidgetInterfaceKit_getDataRate(_iKitHandle, index, &datarate);
00155 
00156         return datarate;
00157 }
00158 
00159 auto PhidgetIK::setDataRate(int index, int datarate) -> int
00160 {
00161         return (_last_error = CPhidgetInterfaceKit_setDataRate(_iKitHandle,     index, datarate));
00162 }
00163 
00164 auto PhidgetIK::getDataRateMax(int index) -> int
00165 {
00166         int max = -1;
00167 
00168         _last_error = CPhidgetInterfaceKit_getDataRateMax(_iKitHandle, index, &max);
00169 
00170         return max;
00171 }
00172 
00173 auto PhidgetIK::getDataRateMin(int index) -> int
00174 {
00175         int min = -1;
00176 
00177         _last_error = CPhidgetInterfaceKit_getDataRateMin(_iKitHandle, index, &min);
00178 
00179         return min;
00180 }
00181 
00182 auto PhidgetIK::getError() -> int
00183 {
00184         return _last_error;
00185 }
00186 
00187 auto PhidgetIK::attachHandler() -> int
00188 {
00189         int serialNo, version, numInputs, numOutputs;
00190         int numSensors, triggerVal, ratiometric, i;
00191         const char *ptr, *name;
00192 
00193         CPhidget_getDeviceName((CPhidgetHandle)_iKitHandle, &name);
00194         CPhidget_getDeviceType((CPhidgetHandle)_iKitHandle, &ptr);
00195         CPhidget_getSerialNumber((CPhidgetHandle)_iKitHandle, &serialNo);
00196         CPhidget_getDeviceVersion((CPhidgetHandle)_iKitHandle, &version);
00197 
00198         CPhidgetInterfaceKit_getInputCount(_iKitHandle, &numInputs);
00199         CPhidgetInterfaceKit_getOutputCount(_iKitHandle, &numOutputs);
00200         CPhidgetInterfaceKit_getSensorCount(_iKitHandle, &numSensors);
00201         CPhidgetInterfaceKit_getRatiometric(_iKitHandle, &ratiometric);
00202 
00203         printf("%s %d attached!\n", name, serialNo);
00204 
00205         printf("%s", ptr);
00206         printf("Serial Number: %d\tVersion: %d\n", serialNo, version);
00207         printf("Num Digital Inputs: %d\tNum Digital Outputs: %d\n", numInputs, numOutputs);
00208         printf("Num Sensors: %d\n", numSensors);
00209         printf("Ratiometric: %d\n", ratiometric);
00210 
00211         for(i = 0; i < numSensors; i++)
00212         {
00213                 CPhidgetInterfaceKit_getSensorChangeTrigger (_iKitHandle, i, &triggerVal);
00214 
00215                 printf("Sensor#: %d > Sensitivity Trigger: %d\n", i, triggerVal);
00216         }
00217 
00218         return 0;
00219 }
00220 
00221 auto PhidgetIK::detachHandler() -> int
00222 {
00223         int serial_number;
00224     const char *device_name;
00225 
00226     CPhidget_getDeviceName ((CPhidgetHandle)_iKitHandle, &device_name);
00227     CPhidget_getSerialNumber((CPhidgetHandle)_iKitHandle, &serial_number);
00228     printf("%s Serial number %d detached!\n", device_name, serial_number);
00229     return 0;
00230 }
00231 
00232 auto PhidgetIK::inputChangeHandler(int index, int inputState) -> int
00233 {
00234         return 0;
00235 }
00236 
00237 auto PhidgetIK::outputChangeHandler(int index, int outputState) -> int
00238 {
00239         return 0;
00240 }
00241 
00242 auto PhidgetIK::sensorChangeHandler(int index, int sensorValue) -> int
00243 {
00244         return 0;
00245 }
00246 
00247 auto PhidgetIK::attachDelegate(CPhidgetHandle phid, void *userptr) -> int
00248 {
00249         return ((PhidgetIK*) userptr)->attachHandler();
00250 }
00251 
00252 auto PhidgetIK::inputChangeDelegate(CPhidgetInterfaceKitHandle phid,
00253                 void *userPtr, int index, int inputState) -> int
00254 {
00255         return ((PhidgetIK*) userPtr)->inputChangeHandler(index, inputState);
00256 }
00257 
00258 auto PhidgetIK::outputChangeDelegate(CPhidgetInterfaceKitHandle phid,
00259                 void *userPtr, int index, int outputState) -> int
00260 {
00261         return ((PhidgetIK*) userPtr)->outputChangeHandler(index, outputState);
00262 }
00263 
00264 auto PhidgetIK::sensorChangeDelegate(CPhidgetInterfaceKitHandle phid,
00265                 void *userPtr, int index, int sensorValue) -> int
00266 {
00267         return ((PhidgetIK*) userPtr)->sensorChangeHandler(index, sensorValue);
00268 }
00269 
00270 auto PhidgetIK::update()-> void
00271 {
00272         printf("PhidgetIK::update()");
00273 }


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 21:02:14