00001 00011 #include <phidgetspp.hh> 00012 00014 00018 class PhidgetIK : public Phidget 00019 { 00020 public: 00022 00023 PhidgetIK() : 00024 Phidget((CPhidgetHandle*)&ik_handle_), 00025 ik_handle_(0) 00026 { 00027 last_error_ = CPhidgetInterfaceKit_create(&ik_handle_); 00028 00029 if (!last_error_) 00030 { 00031 CPhidget_set_OnAttach_Handler((CPhidgetHandle)ik_handle_, PhidgetIK::attachDelegate, this); 00032 CPhidgetInterfaceKit_set_OnInputChange_Handler(ik_handle_, PhidgetIK::inputChangeDelegate, this); 00033 CPhidgetInterfaceKit_set_OnOutputChange_Handler(ik_handle_, PhidgetIK::outputChangeDelegate, this); 00034 last_error_ = CPhidgetInterfaceKit_set_OnSensorChange_Handler(ik_handle_, PhidgetIK::sensorChangeDelegate, this); 00035 } 00036 } 00037 00039 00041 int init(int serial_number) 00042 { 00043 return (last_error_ = open(serial_number)); 00044 } 00045 00047 int getInputCount() 00048 { 00049 int count=-1; 00050 00051 last_error_ = CPhidgetInterfaceKit_getInputCount(ik_handle_, &count); 00052 00053 return count; 00054 } 00055 00057 int getInputState(int index) 00058 { 00059 int state=-1; 00060 00061 last_error_ = CPhidgetInterfaceKit_getInputState(ik_handle_, index, &state); 00062 00063 return state; 00064 } 00065 00067 int getOutputCount() 00068 { 00069 int count=-1; 00070 00071 last_error_ = CPhidgetInterfaceKit_getOutputCount(ik_handle_, &count); 00072 00073 return count; 00074 } 00075 00077 int getOutputState(int index) 00078 { 00079 int state=-1; 00080 00081 last_error_ = CPhidgetInterfaceKit_getOutputState(ik_handle_, index, &state); 00082 00083 return state; 00084 } 00085 00087 int setOutputState(int index, int state) 00088 { 00089 return (last_error_ = CPhidgetInterfaceKit_setOutputState(ik_handle_, index, state)); 00090 } 00091 00093 int getSensorCount() 00094 { 00095 int count=-1; 00096 00097 last_error_ = CPhidgetInterfaceKit_getSensorCount(ik_handle_, &count); 00098 00099 return count; 00100 } 00101 00103 int getSensorValue(int index) 00104 { 00105 int value=-1; 00106 00107 last_error_ = CPhidgetInterfaceKit_getSensorValue(ik_handle_, index, &value); 00108 00109 return value; 00110 } 00111 00113 int getSensorRawValue(int index) 00114 { 00115 int value=-1; 00116 00117 last_error_ = CPhidgetInterfaceKit_getSensorRawValue(ik_handle_, index, &value); 00118 00119 return value; 00120 } 00121 00123 int getSensorChangeTrigger(int index) 00124 { 00125 int trigger=-1; 00126 00127 last_error_ = CPhidgetInterfaceKit_getSensorChangeTrigger(ik_handle_, index, &trigger); 00128 00129 return trigger; 00130 } 00131 00133 int setSensorChangeTrigger(int index, int trigger) 00134 { 00135 return (last_error_ = CPhidgetInterfaceKit_setSensorChangeTrigger(ik_handle_, index, trigger)); 00136 } 00137 00139 int getRatiometric() 00140 { 00141 int ratiometric=-1; 00142 00143 last_error_ = CPhidgetInterfaceKit_getRatiometric(ik_handle_, &ratiometric); 00144 00145 return ratiometric; 00146 } 00147 00149 int setRatiometric(int ratiometric) 00150 { 00151 return (last_error_ = CPhidgetInterfaceKit_setRatiometric(ik_handle_, ratiometric)); 00152 } 00153 00155 int getDataRate(int index) 00156 { 00157 int datarate=-1; 00158 00159 last_error_ = CPhidgetInterfaceKit_getDataRate(ik_handle_, index, &datarate); 00160 00161 return datarate; 00162 } 00163 00165 int setDataRate(int index, int datarate) 00166 { 00167 return (last_error_ = CPhidgetInterfaceKit_setDataRate(ik_handle_, index, datarate)); 00168 } 00169 00171 int getDataRateMax(int index) 00172 { 00173 int max=-1; 00174 00175 last_error_ = CPhidgetInterfaceKit_getDataRateMax(ik_handle_, index, &max); 00176 00177 return max; 00178 } 00179 00181 int getDataRateMin(int index) 00182 { 00183 int min=-1; 00184 00185 last_error_ = CPhidgetInterfaceKit_getDataRateMin(ik_handle_, index, &min); 00186 00187 return min; 00188 } 00189 00191 int getLastError() 00192 { 00193 return last_error_; 00194 } 00195 00196 protected: 00198 CPhidgetInterfaceKitHandle ik_handle_; 00199 00201 int last_error_; 00202 00204 00205 virtual int attachHandler() 00206 { 00207 return 0; 00208 }; 00209 00211 00212 virtual int inputChangeHandler(int index, int inputState) 00213 { 00214 return 0; 00215 } 00216 00218 00219 virtual int outputChangeHandler(int index, int outputState) 00220 { 00221 return 0; 00222 } 00223 00225 00226 virtual int sensorChangeHandler(int index, int sensorValue) 00227 { 00228 return 0; 00229 } 00230 00231 private: 00233 static int attachDelegate(CPhidgetHandle phid, void *userptr) 00234 { 00235 return ((PhidgetIK*)userptr)->attachHandler(); 00236 }; 00237 00239 static int inputChangeDelegate(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int inputState) 00240 { 00241 return ((PhidgetIK*)userPtr)->inputChangeHandler(index, inputState); 00242 } 00243 00245 static int outputChangeDelegate(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int outputState) 00246 { 00247 return ((PhidgetIK*)userPtr)->outputChangeHandler(index, outputState); 00248 } 00249 00251 static int sensorChangeDelegate(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int sensorValue) 00252 { 00253 return ((PhidgetIK*)userPtr)->sensorChangeHandler(index, sensorValue); 00254 } 00255 };