OSSIA
Open Scenario System for Interactive Application
sensors.hpp
1 #pragma once
2 #include <phidget22.h>
3 
4 #include <functional>
5 #include <iostream>
6 #include <mutex>
7 namespace ppp
8 {
9 /*
10 struct interface_kit
11 {
12 public:
13  interface_kit(int serial)
14  {
15  PhidgetInterfaceKit_create(&m_handle);
16 
17  PhidgetInterfaceKit_set_OnInputChange_Handler(
18  m_handle,
19  [](PhidgetInterfaceKitHandle, void* userPtr, int index,
20  int st) -> int {
21  auto& self = *(interface_kit*)(userPtr);
22  if (self.onInputChange)
23  self.onInputChange(index, st);
24  return EPHIDGET_OK;
25  },
26  this);
27  PhidgetInterfaceKit_set_OnOutputChange_Handler(
28  m_handle,
29  [](PhidgetInterfaceKitHandle, void* userPtr, int index,
30  int st) -> int {
31  auto& self = *(interface_kit*)(userPtr);
32  if (self.onOutputChange)
33  self.onOutputChange(index, st);
34  return EPHIDGET_OK;
35  },
36  this);
37  PhidgetInterfaceKit_set_OnSensorChange_Handler(
38  m_handle,
39  [](PhidgetInterfaceKitHandle, void* userPtr, int index,
40  int sensorValue) -> int {
41  auto& self = *(interface_kit*)(userPtr);
42 
43  std::lock_guard<std::mutex> l{self.m_ioMutex};
44  if (self.m_sensorChange)
45  self.m_sensorChange(index, sensorValue);
46  return EPHIDGET_OK;
47  },
48  this);
49 
50  Phidget_open((PhidgetHandle)m_handle, serial);
51  }
52 
53  ~interface_kit()
54  {
55  Phidget_close((PhidgetHandle)m_handle);
56  Phidget_delete((PhidgetHandle)m_handle);
57  }
58 
59  PhidgetHandle get_base_handle() const
60  {
61  return (PhidgetHandle)m_handle;
62  }
63 
64  int get_sensor_count() const
65  {
66  int c;
67  PhidgetInterfaceKit_getSensorCount(m_handle, &c);
68  return c;
69  }
70 
71  int get_sensor_value(int idx) const
72  {
73  int c;
74  PhidgetInterfaceKit_getSensorValue(m_handle, idx, &c);
75  return c;
76  }
77 
78  int get_sensor_raw_value(int idx) const
79  {
80  int c;
81  PhidgetInterfaceKit_getSensorRawValue(m_handle, idx, &c);
82  return c;
83  }
84 
85  int get_data_rate(int idx)
86  {
87  int ms;
88  PhidgetInterfaceKit_getDataRate(m_handle, idx, &ms);
89  return ms;
90  }
91 
92  void set_data_rate(int idx, int ms)
93  {
94  PhidgetInterfaceKit_setDataRate(m_handle, idx, ms);
95  }
96 
97  int inputs() const
98  {
99  int m;
100  PhidgetInterfaceKit_getInputCount(m_handle, &m);
101  return m;
102  }
103 
104  int outputs() const
105  {
106  int m;
107  PhidgetInterfaceKit_getOutputCount(m_handle, &m);
108  return m;
109  }
110 
111  std::function<void(int, int)> onInputChange;
112  std::function<void(int, int)> onOutputChange;
113 
114  void set_sensor_change(std::function<void(int, int)> m)
115  {
116  std::lock_guard<std::mutex> l{m_ioMutex};
117  m_sensorChange = std::move(m);
118  }
119 
120 private:
121  PhidgetInterfaceKitHandle m_handle;
122  std::function<void(int, int)> m_sensorChange;
123  std::mutex m_ioMutex;
124 };
125 
126 struct accelerometer
127 {
128 public:
129  accelerometer(PhidgetAccelerometerHandle h) : m_handle{h}
130  {
131  }
132 
133 private:
134  PhidgetAccelerometerHandle m_handle;
135 };
136 
137 struct advanced_servo
138 {
139 public:
140  advanced_servo(PhidgetAdvancedServoHandle h) : m_handle{h}
141  {
142  }
143 
144 private:
145  PhidgetAdvancedServoHandle m_handle;
146 };
147 
148 struct bridge
149 {
150 public:
151  bridge(PhidgetBridgeHandle h) : m_handle{h}
152  {
153  }
154 
155 private:
156  PhidgetBridgeHandle m_handle;
157 };
158 
159 struct frequency_counter
160 {
161 public:
162  frequency_counter(PhidgetFrequencyCounterHandle h) : m_handle{h}
163  {
164  }
165 
166 private:
167  PhidgetFrequencyCounterHandle m_handle;
168 };
169 
170 struct gps
171 {
172 public:
173  gps(PhidgetGPSHandle h) : m_handle{h}
174  {
175  }
176 
177 private:
178  PhidgetGPSHandle m_handle;
179 };
180 
181 struct ir
182 {
183 public:
184  ir(PhidgetIRHandle h) : m_handle{h}
185  {
186  }
187 
188 private:
189  PhidgetIRHandle m_handle;
190 };
191 
192 struct led
193 {
194 public:
195  led(PhidgetLEDHandle h) : m_handle{h}
196  {
197  }
198 
199 private:
200  PhidgetLEDHandle m_handle;
201 };
202 
203 struct motor_control
204 {
205 public:
206  motor_control(PhidgetMotorControlHandle h) : m_handle{h}
207  {
208  }
209 
210 private:
211  PhidgetMotorControlHandle m_handle;
212 };
213 
214 struct ph_sensor
215 {
216 public:
217  ph_sensor(PhidgetPHSensorHandle h) : m_handle{h}
218  {
219  }
220 
221 private:
222  PhidgetPHSensorHandle m_handle;
223 };
224 
225 struct rfid
226 {
227 public:
228  rfid(PhidgetRFIDHandle h) : m_handle{h}
229  {
230  }
231 
232 private:
233  PhidgetRFIDHandle m_handle;
234 };
235 
236 struct servo
237 {
238 public:
239  servo(PhidgetServoHandle h) : m_handle{h}
240  {
241  }
242 
243 private:
244  PhidgetServoHandle m_handle;
245 };
246 
247 struct spatial
248 {
249 public:
250  spatial(PhidgetSpatialHandle h) : m_handle{h}
251  {
252  }
253 
254 private:
255  PhidgetSpatialHandle m_handle;
256 };
257 
258 struct stepper
259 {
260 public:
261  stepper(PhidgetStepperHandle h) : m_handle{h}
262  {
263  }
264 
265 private:
266  PhidgetStepperHandle m_handle;
267 };
268 
269 struct temperature_sensor
270 {
271 public:
272  temperature_sensor(PhidgetTemperatureSensorHandle h) : m_handle{h}
273  {
274  }
275 
276 private:
277  PhidgetTemperatureSensorHandle m_handle;
278 };
279 
280 struct text_lcd
281 {
282 public:
283  text_lcd(PhidgetTextLCDHandle h) : m_handle{h}
284  {
285  }
286 
287 private:
288  PhidgetTextLCDHandle m_handle;
289 };
290 
291 struct text_led
292 {
293 public:
294  text_led(PhidgetTextLEDHandle h) : m_handle{h}
295  {
296  }
297 
298 private:
299  PhidgetTextLEDHandle m_handle;
300 };
301 
302 struct weight_sensor
303 {
304 public:
305  weight_sensor(PhidgetWeightSensorHandle h) : m_handle{h}
306  {
307  }
308 
309 private:
310  PhidgetWeightSensorHandle m_handle;
311 };
312 */
313 }