phidgetik.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <cob_phidgets/phidgetik.h>
19 
20 PhidgetIK::PhidgetIK(SensingMode mode) : Phidget((CPhidgetHandle*) &_iKitHandle, mode), _iKitHandle(0)
21 {
22  _last_error = CPhidgetInterfaceKit_create(&_iKitHandle);
23 
24  if (!_last_error) {
25  CPhidget_set_OnAttach_Handler((CPhidgetHandle) _iKitHandle,
27  CPhidgetInterfaceKit_set_OnOutputChange_Handler(_iKitHandle,
29 
31  {
32  CPhidgetInterfaceKit_set_OnInputChange_Handler(_iKitHandle,
34  _last_error = CPhidgetInterfaceKit_set_OnSensorChange_Handler(
35  _iKitHandle, PhidgetIK::sensorChangeDelegate, this);
36  }
37  }
38 }
39 
41 {
42 }
43 
44 auto PhidgetIK::init(int serial_number) -> int
45 {
46  return (_last_error = open(serial_number));
47 }
48 
50 {
51  int count = -1;
52 
53  _last_error = CPhidgetInterfaceKit_getInputCount(_iKitHandle, &count);
54 
55  return count;
56 }
57 
58 auto PhidgetIK::getInputState(int index) -> int
59 {
60  int state = -1;
61 
62  _last_error = CPhidgetInterfaceKit_getInputState(_iKitHandle, index,
63  &state);
64 
65  return state;
66 }
67 
69 {
70  int count = -1;
71 
72  _last_error = CPhidgetInterfaceKit_getOutputCount(_iKitHandle, &count);
73 
74  return count;
75 }
76 
77 auto PhidgetIK::getOutputState(int index) -> int
78 {
79  int state = -1;
80 
81  _last_error = CPhidgetInterfaceKit_getOutputState(_iKitHandle, index,
82  &state);
83 
84  return state;
85 }
86 
87 auto PhidgetIK::setOutputState(int index, int state) -> int
88 {
89  return (_last_error = CPhidgetInterfaceKit_setOutputState(_iKitHandle,
90  index, state));
91 }
92 
94 {
95  int count = -1;
96 
97  _last_error = CPhidgetInterfaceKit_getSensorCount(_iKitHandle, &count);
98 
99  return count;
100 }
101 
102 auto PhidgetIK::getSensorValue(int index) -> int
103 {
104  int value = -1;
105 
106  _last_error = CPhidgetInterfaceKit_getSensorValue(_iKitHandle, index, &value);
107 
108  return value;
109 }
110 
111 auto PhidgetIK::getSensorRawValue(int index) -> int
112 {
113  int value = -1;
114 
115  _last_error = CPhidgetInterfaceKit_getSensorRawValue(_iKitHandle, index, &value);
116 
117  return value;
118 }
119 
120 auto PhidgetIK::getSensorChangeTrigger(int index) -> int
121 {
122  int trigger = -1;
123 
124  _last_error = CPhidgetInterfaceKit_getSensorChangeTrigger(_iKitHandle, index, &trigger);
125 
126  return trigger;
127 }
128 
129 auto PhidgetIK::setSensorChangeTrigger(int index, int trigger) -> int
130 {
131  return (_last_error = CPhidgetInterfaceKit_setSensorChangeTrigger(_iKitHandle, index, trigger));
132 }
133 
135 {
136  int ratiometric = -1;
137 
138  _last_error = CPhidgetInterfaceKit_getRatiometric(_iKitHandle,
139  &ratiometric);
140 
141  return ratiometric;
142 }
143 
144 auto PhidgetIK::setRatiometric(int ratiometric) -> int
145 {
146  return (_last_error = CPhidgetInterfaceKit_setRatiometric(_iKitHandle,
147  ratiometric));
148 }
149 
150 auto PhidgetIK::getDataRate(int index) -> int
151 {
152  int datarate = -1;
153 
154  _last_error = CPhidgetInterfaceKit_getDataRate(_iKitHandle, index, &datarate);
155 
156  return datarate;
157 }
158 
159 auto PhidgetIK::setDataRate(int index, int datarate) -> int
160 {
161  return (_last_error = CPhidgetInterfaceKit_setDataRate(_iKitHandle, index, datarate));
162 }
163 
164 auto PhidgetIK::getDataRateMax(int index) -> int
165 {
166  int max = -1;
167 
168  _last_error = CPhidgetInterfaceKit_getDataRateMax(_iKitHandle, index, &max);
169 
170  return max;
171 }
172 
173 auto PhidgetIK::getDataRateMin(int index) -> int
174 {
175  int min = -1;
176 
177  _last_error = CPhidgetInterfaceKit_getDataRateMin(_iKitHandle, index, &min);
178 
179  return min;
180 }
181 
182 auto PhidgetIK::getError() -> int
183 {
184  return _last_error;
185 }
186 
188 {
189  int serialNo, version, numInputs, numOutputs;
190  int numSensors, triggerVal, ratiometric, i;
191  const char *ptr, *name;
192 
193  CPhidget_getDeviceName((CPhidgetHandle)_iKitHandle, &name);
194  CPhidget_getDeviceType((CPhidgetHandle)_iKitHandle, &ptr);
195  CPhidget_getSerialNumber((CPhidgetHandle)_iKitHandle, &serialNo);
196  CPhidget_getDeviceVersion((CPhidgetHandle)_iKitHandle, &version);
197 
198  CPhidgetInterfaceKit_getInputCount(_iKitHandle, &numInputs);
199  CPhidgetInterfaceKit_getOutputCount(_iKitHandle, &numOutputs);
200  CPhidgetInterfaceKit_getSensorCount(_iKitHandle, &numSensors);
201  CPhidgetInterfaceKit_getRatiometric(_iKitHandle, &ratiometric);
202 
203  printf("%s %d attached!\n", name, serialNo);
204 
205  printf("%s", ptr);
206  printf("Serial Number: %d\tVersion: %d\n", serialNo, version);
207  printf("Num Digital Inputs: %d\tNum Digital Outputs: %d\n", numInputs, numOutputs);
208  printf("Num Sensors: %d\n", numSensors);
209  printf("Ratiometric: %d\n", ratiometric);
210 
211  for(i = 0; i < numSensors; i++)
212  {
213  CPhidgetInterfaceKit_getSensorChangeTrigger (_iKitHandle, i, &triggerVal);
214 
215  printf("Sensor#: %d > Sensitivity Trigger: %d\n", i, triggerVal);
216  }
217 
218  return 0;
219 }
220 
222 {
223  int serial_number;
224  const char *device_name;
225 
226  CPhidget_getDeviceName ((CPhidgetHandle)_iKitHandle, &device_name);
227  CPhidget_getSerialNumber((CPhidgetHandle)_iKitHandle, &serial_number);
228  printf("%s Serial number %d detached!\n", device_name, serial_number);
229  return 0;
230 }
231 
232 auto PhidgetIK::inputChangeHandler(int index, int inputState) -> int
233 {
234  return 0;
235 }
236 
237 auto PhidgetIK::outputChangeHandler(int index, int outputState) -> int
238 {
239  return 0;
240 }
241 
242 auto PhidgetIK::sensorChangeHandler(int index, int sensorValue) -> int
243 {
244  return 0;
245 }
246 
247 auto PhidgetIK::attachDelegate(CPhidgetHandle phid, void *userptr) -> int
248 {
249  return ((PhidgetIK*) userptr)->attachHandler();
250 }
251 
252 auto PhidgetIK::inputChangeDelegate(CPhidgetInterfaceKitHandle phid,
253  void *userPtr, int index, int inputState) -> int
254 {
255  return ((PhidgetIK*) userPtr)->inputChangeHandler(index, inputState);
256 }
257 
258 auto PhidgetIK::outputChangeDelegate(CPhidgetInterfaceKitHandle phid,
259  void *userPtr, int index, int outputState) -> int
260 {
261  return ((PhidgetIK*) userPtr)->outputChangeHandler(index, outputState);
262 }
263 
264 auto PhidgetIK::sensorChangeDelegate(CPhidgetInterfaceKitHandle phid,
265  void *userPtr, int index, int sensorValue) -> int
266 {
267  return ((PhidgetIK*) userPtr)->sensorChangeHandler(index, sensorValue);
268 }
269 
270 auto PhidgetIK::update()-> void
271 {
272  printf("PhidgetIK::update()");
273 }
auto getInputCount() -> int
Definition: phidgetik.cpp:49
auto setSensorChangeTrigger(int index, int trigger) -> int
Definition: phidgetik.cpp:129
virtual int detachHandler()
Definition: phidgetik.cpp:221
auto getDataRateMax(int index) -> int
Definition: phidgetik.cpp:164
auto getOutputState(int index) -> int
Definition: phidgetik.cpp:77
virtual int attachHandler()
Definition: phidgetik.cpp:187
virtual int inputChangeHandler(int index, int inputState)
Definition: phidgetik.cpp:232
CPhidgetInterfaceKitHandle _iKitHandle
Definition: phidgetik.h:60
auto open(int serial_number) -> int
Definition: phidget.cpp:34
auto getDataRate(int index) -> int
Definition: phidgetik.cpp:150
auto getSensorValue(int index) -> int
Definition: phidgetik.cpp:102
SensingMode
Definition: phidget.h:27
auto getRatiometric() -> int
Definition: phidgetik.cpp:134
auto setRatiometric(int ratiometric) -> int
Definition: phidgetik.cpp:144
static auto sensorChangeDelegate(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int sensorValue) -> int
Definition: phidgetik.cpp:264
auto getDataRateMin(int index) -> int
Definition: phidgetik.cpp:173
auto getOutputCount() -> int
Definition: phidgetik.cpp:68
virtual int outputChangeHandler(int index, int outputState)
Definition: phidgetik.cpp:237
auto getSensorChangeTrigger(int index) -> int
Definition: phidgetik.cpp:120
auto getSensorRawValue(int index) -> int
Definition: phidgetik.cpp:111
int i
Definition: tablet_leer.c:27
auto getSensorCount() -> int
Definition: phidgetik.cpp:93
int _last_error
Definition: phidget.h:48
auto setDataRate(int index, int datarate) -> int
Definition: phidgetik.cpp:159
static auto attachDelegate(CPhidgetHandle phid, void *userptr) -> int
Definition: phidgetik.cpp:247
auto init(int serial_number) -> int
Definition: phidgetik.cpp:44
SensingMode _sensMode
Definition: phidget.h:49
PhidgetIK(SensingMode mode)
Definition: phidgetik.cpp:20
auto getError() -> int
Definition: phidgetik.cpp:182
static auto inputChangeDelegate(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int inputState) -> int
Definition: phidgetik.cpp:252
auto setOutputState(int index, int state) -> int
Definition: phidgetik.cpp:87
virtual auto update() -> void
Definition: phidgetik.cpp:270
static auto outputChangeDelegate(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int outputState) -> int
Definition: phidgetik.cpp:258
auto getInputState(int index) -> int
Definition: phidgetik.cpp:58
virtual int sensorChangeHandler(int index, int sensorValue)
Definition: phidgetik.cpp:242


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Wed Apr 7 2021 02:11:43