OSSIA
Open Scenario System for Interactive Application
phidgets_parameter_data.hpp
1 #pragma once
2 #if defined(__APPLE__)
3 #include <Phidget22/phidget22.h>
4 #else
5 #include <phidget22.h>
6 #endif
7 #include <ossia/detail/hash.hpp>
8 
9 #include <string>
10 namespace ossia
11 {
12 struct phidget_handle_t
13 {
14  PhidgetHandle phid;
15  phidget_handle_t(PhidgetHandle h)
16  : phid{h}
17  {
18  }
19 
20  int32_t get_serial() const
21  {
22  int32_t sn;
23  Phidget_getDeviceSerialNumber(phid, &sn);
24  return sn;
25  }
26 
27  operator PhidgetHandle() const { return phid; }
28 
29  phidget_handle_t get_parent() const
30  {
31  PhidgetHandle par;
32  Phidget_getParent(phid, &par);
33  return par;
34  }
35  auto get_device_class() const
36  {
37  Phidget_DeviceClass dc;
38  Phidget_getDeviceClass(phid, &dc);
39  return dc;
40  }
41  auto get_channel() const
42  {
43  int dc;
44  Phidget_getChannel(phid, &dc);
45  return dc;
46  }
47  auto get_channel_class() const
48  {
49  Phidget_ChannelClass dc;
50  Phidget_getChannelClass(phid, &dc);
51  return dc;
52  }
53  auto get_channel_subclass() const
54  {
55  Phidget_ChannelSubclass dc;
56  Phidget_getChannelSubclass(phid, &dc);
57  return dc;
58  }
59  auto get_device_id() const
60  {
61  Phidget_DeviceID dc;
62  Phidget_getDeviceID(phid, &dc);
63  return dc;
64  }
65  auto get_hub_port() const
66  {
67  int dc;
68  Phidget_getHubPort(phid, &dc);
69  return dc;
70  }
71  auto get_hub_port_count() const
72  {
73  int dc;
74  Phidget_getHubPortCount(phid, &dc);
75  return dc;
76  }
77  bool is_attached() const
78  {
79  int dc;
80  Phidget_getAttached(phid, &dc);
81  return dc;
82  }
83  bool is_hub_port_device() const
84  {
85  int dc;
86  Phidget_getIsHubPortDevice(phid, &dc);
87  return dc;
88  }
89  bool is_channel() const
90  {
91  int dc;
92  Phidget_getIsChannel(phid, &dc);
93  return dc;
94  }
95 
96  std::string get_device_classname() { return phidget_name(get_device_class()); }
97  std::string get_channel_classname() { return phidget_name(get_channel_class()); }
98  std::string get_channel_subclassname() { return phidget_name(get_channel_subclass()); }
99  std::string get_device_id_name() { return phidget_id(get_device_id()); }
100 
101  const char* phidget_id(Phidget_DeviceID cls)
102  {
103  switch(cls)
104  {
105  case PHIDID_NOTHING:
106  return "PHIDID_NOTHING";
107  case PHIDID_INTERFACEKIT_4_8_8:
108  return "PHIDID_INTERFACEKIT_4_8_8";
109  case PHIDID_1000:
110  return "PHIDID_1000";
111  case PHIDID_1001:
112  return "PHIDID_1001";
113  case PHIDID_1002:
114  return "PHIDID_1002";
115  case PHIDID_1008:
116  return "PHIDID_1008";
117  case PHIDID_1010_1013_1018_1019:
118  return "PHIDID_1010_1013_1018_1019";
119  case PHIDID_1011:
120  return "PHIDID_1011";
121  case PHIDID_1012:
122  return "PHIDID_1012";
123  case PHIDID_1014:
124  return "PHIDID_1014";
125  case PHIDID_1015:
126  return "PHIDID_1015";
127  case PHIDID_1016:
128  return "PHIDID_1016";
129  case PHIDID_1017:
130  return "PHIDID_1017";
131  case PHIDID_1023:
132  return "PHIDID_1023";
133  case PHIDID_1024:
134  return "PHIDID_1024";
135  case PHIDID_1030:
136  return "PHIDID_1030";
137  case PHIDID_1031:
138  return "PHIDID_1031";
139  case PHIDID_1032:
140  return "PHIDID_1032";
141  case PHIDID_1040:
142  return "PHIDID_1040";
143  case PHIDID_1041:
144  return "PHIDID_1041";
145  case PHIDID_1042:
146  return "PHIDID_1042";
147  case PHIDID_1043:
148  return "PHIDID_1043";
149  case PHIDID_1044:
150  return "PHIDID_1044";
151  case PHIDID_1045:
152  return "PHIDID_1045";
153  case PHIDID_1046:
154  return "PHIDID_1046";
155  case PHIDID_1047:
156  return "PHIDID_1047";
157  case PHIDID_1048:
158  return "PHIDID_1048";
159  case PHIDID_1049:
160  return "PHIDID_1049";
161  case PHIDID_1051:
162  return "PHIDID_1051";
163  case PHIDID_1052:
164  return "PHIDID_1052";
165  case PHIDID_1053:
166  return "PHIDID_1053";
167  case PHIDID_1054:
168  return "PHIDID_1054";
169  case PHIDID_1055:
170  return "PHIDID_1055";
171  case PHIDID_1056:
172  return "PHIDID_1056";
173  case PHIDID_1057:
174  return "PHIDID_1057";
175  case PHIDID_1058:
176  return "PHIDID_1058";
177  case PHIDID_1059:
178  return "PHIDID_1059";
179  case PHIDID_1060:
180  return "PHIDID_1060";
181  case PHIDID_1061:
182  return "PHIDID_1061";
183  case PHIDID_1062:
184  return "PHIDID_1062";
185  case PHIDID_1063:
186  return "PHIDID_1063";
187  case PHIDID_1064:
188  return "PHIDID_1064";
189  case PHIDID_1065:
190  return "PHIDID_1065";
191  case PHIDID_1066:
192  return "PHIDID_1066";
193  case PHIDID_1067:
194  return "PHIDID_1067";
195  case PHIDID_1202_1203:
196  return "PHIDID_1202_1203";
197  case PHIDID_1204:
198  return "PHIDID_1204";
199  case PHIDID_1215__1218:
200  return "PHIDID_1215__1218";
201  case PHIDID_1219__1222:
202  return "PHIDID_1219__1222";
203  case PHIDID_ADP1000:
204  return "PHIDID_ADP1000";
205  case PHIDID_ADP1001:
206  return "PHIDID_ADP1001";
207  case PHIDID_DAQ1000:
208  return "PHIDID_DAQ1000";
209  case PHIDID_DAQ1200:
210  return "PHIDID_DAQ1200";
211  case PHIDID_DAQ1300:
212  return "PHIDID_DAQ1300";
213  case PHIDID_DAQ1301:
214  return "PHIDID_DAQ1301";
215  case PHIDID_DAQ1400:
216  return "PHIDID_DAQ1400";
217  case PHIDID_DAQ1500:
218  return "PHIDID_DAQ1500";
219  case PHIDID_DCC1000:
220  return "PHIDID_DCC1000";
221  case PHIDID_DST1000:
222  return "PHIDID_DST1000";
223  case PHIDID_DST1200:
224  return "PHIDID_DST1200";
225  case PHIDID_ENC1000:
226  return "PHIDID_ENC1000";
227  case PHIDID_HIN1000:
228  return "PHIDID_HIN1000";
229  case PHIDID_HIN1001:
230  return "PHIDID_HIN1001";
231  case PHIDID_HIN1100:
232  return "PHIDID_HIN1100";
233  case PHIDID_HUB0000:
234  return "PHIDID_HUB0000";
235  case PHIDID_HUB0001:
236  return "PHIDID_HUB0001";
237  case PHIDID_HUB0002:
238  return "PHIDID_HUB0002";
239  case PHIDID_HUB0004:
240  return "PHIDID_HUB0004";
241  case PHIDID_HUB0005:
242  return "PHIDID_HUB0005";
243  case PHIDID_HUM1000:
244  return "PHIDID_HUM1000";
245  case PHIDID_LCD1100:
246  return "PHIDID_LCD1100";
247  case PHIDID_LED1000:
248  return "PHIDID_LED1000";
249  case PHIDID_LUX1000:
250  return "PHIDID_LUX1000";
251  case PHIDID_MOT1100:
252  return "PHIDID_MOT1100";
253  case PHIDID_MOT1101:
254  return "PHIDID_MOT1101";
255  case PHIDID_OUT1000:
256  return "PHIDID_OUT1000";
257  case PHIDID_OUT1001:
258  return "PHIDID_OUT1001";
259  case PHIDID_OUT1002:
260  return "PHIDID_OUT1002";
261  case PHIDID_OUT1100:
262  return "PHIDID_OUT1100";
263  case PHIDID_PRE1000:
264  return "PHIDID_PRE1000";
265  case PHIDID_RCC1000:
266  return "PHIDID_RCC1000";
267  case PHIDID_REL1000:
268  return "PHIDID_REL1000";
269  case PHIDID_REL1100:
270  return "PHIDID_REL1100";
271  case PHIDID_REL1101:
272  return "PHIDID_REL1101";
273  case PHIDID_SAF1000:
274  return "PHIDID_SAF1000";
275  case PHIDID_SND1000:
276  return "PHIDID_SND1000";
277  case PHIDID_STC1000:
278  return "PHIDID_STC1000";
279  case PHIDID_TMP1000:
280  return "PHIDID_TMP1000";
281  case PHIDID_TMP1100:
282  return "PHIDID_TMP1100";
283  case PHIDID_TMP1101:
284  return "PHIDID_TMP1101";
285  case PHIDID_TMP1200:
286  return "PHIDID_TMP1200";
287  case PHIDID_TMP1300:
288  return "PHIDID_TMP1300";
289  case PHIDID_VCP1000:
290  return "PHIDID_VCP1000";
291  case PHIDID_VCP1001:
292  return "PHIDID_VCP1001";
293  case PHIDID_VCP1002:
294  return "PHIDID_VCP1002";
295  case PHIDID_DIGITALINPUT_PORT:
296  return "PHIDID_DIGITALINPUT_PORT";
297  case PHIDID_DIGITALOUTPUT_PORT:
298  return "PHIDID_DIGITALOUTPUT_PORT";
299  case PHIDID_VOLTAGEINPUT_PORT:
300  return "PHIDID_VOLTAGEINPUT_PORT";
301  case PHIDID_VOLTAGERATIOINPUT_PORT:
302  return "PHIDID_VOLTAGERATIOINPUT_PORT";
303  case PHIDID_GENERICUSB:
304  return "PHIDID_GENERICUSB";
305  case PHIDID_GENERICVINT:
306  return "PHIDID_GENERICVINT";
307  case PHIDID_FIRMWARE_UPGRADE_USB:
308  return "PHIDID_FIRMWARE_UPGRADE_USB";
309  case PHIDID_FIRMWARE_UPGRADE_STM32F0:
310  return "PHIDID_FIRMWARE_UPGRADE_STM32F0";
311  case PHIDID_FIRMWARE_UPGRADE_STM8S:
312  return "PHIDID_FIRMWARE_UPGRADE_STM8S";
313  case PHIDID_FIRMWARE_UPGRADE_SPI:
314  return "PHIDID_FIRMWARE_UPGRADE_SPI";
315  case PHIDID_VCP1100:
316  return "PHIDID_VCP1100";
317  case PHIDID_DCC1100:
318  return "PHIDID_DCC1100";
319  case PHIDID_HIN1101:
320  return "PHIDID_HIN1101";
321  case PHIDID_DCC1001:
322  return "PHIDID_DCC1001";
323  case PHIDID_DICTIONARY:
324  return "PHIDID_DICTIONARY";
325  case PHIDID_STC1001:
326  return "PHIDID_STC1001";
327  case PHIDID_USBSWITCH:
328  return "PHIDID_USBSWITCH";
329  }
330  return "NONE";
331  }
332 
333  const char* phidget_name(Phidget_DeviceClass cls)
334  {
335  switch(cls)
336  {
337  case PHIDCLASS_ACCELEROMETER:
338  return "ACCELEROMETER";
339  case PHIDCLASS_ADVANCEDSERVO:
340  return "ADVANCEDSERVO";
341  case PHIDCLASS_ANALOG:
342  return "ANALOG";
343  case PHIDCLASS_BRIDGE:
344  return "BRIDGE";
345  case PHIDCLASS_ENCODER:
346  return "ENCODER";
347  case PHIDCLASS_FREQUENCYCOUNTER:
348  return "FREQUENCYCOUNTER";
349  case PHIDCLASS_GPS:
350  return "GPS";
351  case PHIDCLASS_HUB:
352  return "HUB";
353  case PHIDCLASS_INTERFACEKIT:
354  return "INTERFACEKIT";
355  case PHIDCLASS_IR:
356  return "IR";
357  case PHIDCLASS_LED:
358  return "LED";
359  case PHIDCLASS_MESHDONGLE:
360  return "MESHDONGLE";
361  case PHIDCLASS_MOTORCONTROL:
362  return "MOTORCONTROL";
363  case PHIDCLASS_PHSENSOR:
364  return "PHSENSOR";
365  case PHIDCLASS_RFID:
366  return "RFID";
367  case PHIDCLASS_SERVO:
368  return "SERVO";
369  case PHIDCLASS_SPATIAL:
370  return "SPATIAL";
371  case PHIDCLASS_STEPPER:
372  return "STEPPER";
373  case PHIDCLASS_TEMPERATURESENSOR:
374  return "TEMPERATURESENSOR";
375  case PHIDCLASS_TEXTLCD:
376  return "TEXTLCD";
377  case PHIDCLASS_VINT:
378  return "VINT";
379  case PHIDCLASS_GENERIC:
380  return "GENERIC";
381  case PHIDCLASS_FIRMWAREUPGRADE:
382  return "FIRMWAREUPGRADE";
383  case PHIDCLASS_DICTIONARY:
384  return "DICTIONARY";
385  case PHIDCLASS_NOTHING:
386  return "NOTHING";
387  }
388  return "none";
389  }
390 
391  const char* phidget_name(Phidget_ChannelClass cls)
392  {
393  switch(cls)
394  {
395  case PHIDCHCLASS_NOTHING:
396  return "NOTHING";
397  case PHIDCHCLASS_ACCELEROMETER:
398  return "ACCELEROMETER";
399  case PHIDCHCLASS_CURRENTINPUT:
400  return "CURRENTINPUT";
401  case PHIDCHCLASS_DATAADAPTER:
402  return "DATAADAPTER";
403  case PHIDCHCLASS_DCMOTOR:
404  return "DCMOTOR";
405  case PHIDCHCLASS_DIGITALINPUT:
406  return "DIGITALINPUT";
407  case PHIDCHCLASS_DIGITALOUTPUT:
408  return "DIGITALOUTPUT";
409  case PHIDCHCLASS_DISTANCESENSOR:
410  return "DISTANCESENSOR";
411  case PHIDCHCLASS_ENCODER:
412  return "ENCODER";
413  case PHIDCHCLASS_FREQUENCYCOUNTER:
414  return "FREQUENCYCOUNTER";
415  case PHIDCHCLASS_GPS:
416  return "GPS";
417  case PHIDCHCLASS_LCD:
418  return "LCD";
419  case PHIDCHCLASS_GYROSCOPE:
420  return "GYROSCOPE";
421  case PHIDCHCLASS_HUB:
422  return "HUB";
423  case PHIDCHCLASS_CAPACITIVETOUCH:
424  return "CAPACITIVETOUCH";
425  case PHIDCHCLASS_HUMIDITYSENSOR:
426  return "HUMIDITYSENSOR";
427  case PHIDCHCLASS_IR:
428  return "IR";
429  case PHIDCHCLASS_LIGHTSENSOR:
430  return "LIGHTSENSOR";
431  case PHIDCHCLASS_MAGNETOMETER:
432  return "MAGNETOMETER";
433  case PHIDCHCLASS_MESHDONGLE:
434  return "MESHDONGLE";
435  case PHIDCHCLASS_PHSENSOR:
436  return "PHSENSOR";
437  case PHIDCHCLASS_POWERGUARD:
438  return "POWERGUARD";
439  case PHIDCHCLASS_PRESSURESENSOR:
440  return "PRESSURESENSOR";
441  case PHIDCHCLASS_RCSERVO:
442  return "RCSERVO";
443  case PHIDCHCLASS_RESISTANCEINPUT:
444  return "RESISTANCEINPUT";
445  case PHIDCHCLASS_RFID:
446  return "RFID";
447  case PHIDCHCLASS_SOUNDSENSOR:
448  return "SOUNDSENSOR";
449  case PHIDCHCLASS_SPATIAL:
450  return "SPATIAL";
451  case PHIDCHCLASS_STEPPER:
452  return "STEPPER";
453  case PHIDCHCLASS_TEMPERATURESENSOR:
454  return "TEMPERATURESENSOR";
455  case PHIDCHCLASS_VOLTAGEINPUT:
456  return "VOLTAGEINPUT";
457  case PHIDCHCLASS_VOLTAGEOUTPUT:
458  return "VOLTAGEOUTPUT";
459  case PHIDCHCLASS_VOLTAGERATIOINPUT:
460  return "VOLTAGERATIOINPUT";
461  case PHIDCHCLASS_FIRMWAREUPGRADE:
462  return "FIRMWAREUPGRADE";
463  case PHIDCHCLASS_GENERIC:
464  return "GENERIC";
465  case PHIDCHCLASS_MOTORPOSITIONCONTROLLER:
466  return "MOTORPOSITIONCONTROLLER";
467  case PHIDCHCLASS_BLDCMOTOR:
468  return "BLDCMOTOR";
469  case PHIDCHCLASS_DICTIONARY:
470  return "DICTIONARY";
471  }
472  return "none";
473  }
474 
475  const char* phidget_name(Phidget_ChannelSubclass cls)
476  {
477  switch(cls)
478  {
479  case PHIDCHSUBCLASS_NONE:
480  return "NONE";
481  case PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE:
482  return "DIGITALOUTPUT_DUTY_CYCLE";
483  case PHIDCHSUBCLASS_DIGITALOUTPUT_LED_DRIVER:
484  return "DIGITALOUTPUT_LED_DRIVER";
485  case PHIDCHSUBCLASS_TEMPERATURESENSOR_RTD:
486  return "TEMPERATURESENSOR_RTD";
487  case PHIDCHSUBCLASS_TEMPERATURESENSOR_THERMOCOUPLE:
488  return "TEMPERATURESENSOR_THERMOCOUPLE";
489  case PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT:
490  return "VOLTAGEINPUT_SENSOR_PORT";
491  case PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT:
492  return "VOLTAGERATIOINPUT_SENSOR_PORT";
493  case PHIDCHSUBCLASS_VOLTAGERATIOINPUT_BRIDGE:
494  return "VOLTAGERATIOINPUT_BRIDGE";
495  case PHIDCHSUBCLASS_LCD_GRAPHIC:
496  return "LCD_GRAPHIC";
497  case PHIDCHSUBCLASS_LCD_TEXT:
498  return "LCD_TEXT";
499  case PHIDCHSUBCLASS_ENCODER_MODE_SETTABLE:
500  return "ENCODER_MODE_SETTABLE";
501  }
502  return "none";
503  }
504 };
505 
506 struct phidget_id
507 {
508  phidget_id() = default;
509  phidget_id(ossia::phidget_handle_t);
510  int serialNumber;
511  int hubPort;
512  int channel;
513  int isHubPort;
514 };
515 inline bool operator==(phidget_id lhs, phidget_id rhs)
516 {
517  return lhs.serialNumber == rhs.serialNumber && lhs.hubPort == rhs.hubPort
518  && lhs.channel == rhs.channel && lhs.isHubPort == rhs.isHubPort;
519 }
520 }
521 
522 namespace std
523 {
524 template <>
525 class hash<ossia::phidget_id>
526 {
527 public:
528  std::size_t operator()(const ossia::phidget_id& id)
529  {
530  std::size_t s = 0;
531  ossia::hash_combine(s, id.serialNumber);
532  ossia::hash_combine(s, id.hubPort);
533  ossia::hash_combine(s, id.channel);
534  ossia::hash_combine(s, id.isHubPort);
535  return s;
536  }
537 };
538 }
Definition: git_info.h:7