phidgets 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +3 -0
  3. data/README.rdoc +32 -43
  4. data/Rakefile +4 -2
  5. data/bin/phidget +18 -72
  6. data/ext/phidgets/extconf.rb +5 -8
  7. data/ext/phidgets/phidgets.c +708 -173
  8. data/ext/phidgets/phidgets.h +54 -35
  9. data/ext/phidgets/phidgets_accelerometer.c +193 -109
  10. data/ext/phidgets/phidgets_bldc_motor.c +529 -0
  11. data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
  12. data/ext/phidgets/phidgets_common.c +570 -315
  13. data/ext/phidgets/phidgets_current_input.c +229 -0
  14. data/ext/phidgets/phidgets_dc_motor.c +562 -0
  15. data/ext/phidgets/phidgets_dictionary.c +154 -213
  16. data/ext/phidgets/phidgets_digital_input.c +127 -0
  17. data/ext/phidgets/phidgets_digital_output.c +288 -0
  18. data/ext/phidgets/phidgets_distance_sensor.c +295 -0
  19. data/ext/phidgets/phidgets_encoder.c +211 -192
  20. data/ext/phidgets/phidgets_frequency_counter.c +310 -177
  21. data/ext/phidgets/phidgets_gps.c +226 -164
  22. data/ext/phidgets/phidgets_gyroscope.c +195 -0
  23. data/ext/phidgets/phidgets_hub.c +39 -0
  24. data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
  25. data/ext/phidgets/phidgets_ir.c +211 -171
  26. data/ext/phidgets/phidgets_lcd.c +512 -0
  27. data/ext/phidgets/phidgets_light_sensor.c +200 -0
  28. data/ext/phidgets/phidgets_log.c +263 -0
  29. data/ext/phidgets/phidgets_magnetometer.c +279 -0
  30. data/ext/phidgets/phidgets_manager.c +86 -297
  31. data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
  32. data/ext/phidgets/phidgets_phsensor.c +200 -152
  33. data/ext/phidgets/phidgets_power_guard.c +144 -0
  34. data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
  35. data/ext/phidgets/phidgets_rc_servo.c +672 -0
  36. data/ext/phidgets/phidgets_resistance_input.c +227 -0
  37. data/ext/phidgets/phidgets_rfid.c +107 -221
  38. data/ext/phidgets/phidgets_sound_sensor.c +284 -0
  39. data/ext/phidgets/phidgets_spatial.c +124 -318
  40. data/ext/phidgets/phidgets_stepper.c +457 -430
  41. data/ext/phidgets/phidgets_temp_sensor.c +223 -228
  42. data/ext/phidgets/phidgets_voltage_input.c +428 -0
  43. data/ext/phidgets/phidgets_voltage_output.c +167 -0
  44. data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
  45. data/lib/phidgets.rb +21 -14
  46. data/lib/phidgets/accelerometer.rb +11 -15
  47. data/lib/phidgets/bldc_motor.rb +45 -0
  48. data/lib/phidgets/capacitive_touch.rb +33 -0
  49. data/lib/phidgets/common.rb +40 -69
  50. data/lib/phidgets/current_input.rb +21 -0
  51. data/lib/phidgets/dc_motor.rb +45 -0
  52. data/lib/phidgets/dictionary.rb +30 -39
  53. data/lib/phidgets/digital_input.rb +21 -0
  54. data/lib/phidgets/digital_output.rb +56 -0
  55. data/lib/phidgets/distance_sensor.rb +33 -0
  56. data/lib/phidgets/encoder.rb +1 -29
  57. data/lib/phidgets/frequency_counter.rb +23 -14
  58. data/lib/phidgets/gps.rb +34 -26
  59. data/lib/phidgets/gyroscope.rb +21 -0
  60. data/lib/phidgets/humidity_sensor.rb +21 -0
  61. data/lib/phidgets/ir.rb +34 -39
  62. data/lib/phidgets/light_sensor.rb +21 -0
  63. data/lib/phidgets/magnetometer.rb +21 -0
  64. data/lib/phidgets/manager.rb +18 -66
  65. data/lib/phidgets/motor_position_controller.rb +45 -0
  66. data/lib/phidgets/ph_sensor.rb +2 -6
  67. data/lib/phidgets/pressure_sensor.rb +21 -0
  68. data/lib/phidgets/rc_servo.rb +58 -0
  69. data/lib/phidgets/resistance_input.rb +21 -0
  70. data/lib/phidgets/rfid.rb +22 -38
  71. data/lib/phidgets/sound_sensor.rb +21 -0
  72. data/lib/phidgets/spatial.rb +11 -15
  73. data/lib/phidgets/stepper.rb +48 -50
  74. data/lib/phidgets/temperature_sensor.rb +11 -15
  75. data/lib/phidgets/version.rb +5 -0
  76. data/lib/phidgets/voltage_input.rb +34 -0
  77. data/lib/phidgets/voltage_output.rb +23 -0
  78. data/lib/phidgets/voltage_ratio_input.rb +34 -0
  79. data/phidgets.gemspec +3 -22
  80. data/test/test_accelerometer.rb +42 -23
  81. data/test/test_bldc_motor.rb +134 -0
  82. data/test/test_capacitive_touch.rb +82 -0
  83. data/test/test_common.rb +125 -108
  84. data/test/test_current_input.rb +62 -0
  85. data/test/test_dc_motor.rb +146 -0
  86. data/test/test_dictionary.rb +22 -54
  87. data/test/test_digital_input.rb +30 -0
  88. data/test/test_digital_output.rb +70 -0
  89. data/test/test_distance_sensor.rb +76 -0
  90. data/test/test_encoder.rb +45 -38
  91. data/test/test_frequency_counter.rb +71 -36
  92. data/test/test_gps.rb +29 -38
  93. data/test/test_gyroscope.rb +54 -0
  94. data/test/test_helper.rb +0 -1
  95. data/test/test_hub.rb +14 -0
  96. data/test/test_humidity_sensor.rb +58 -0
  97. data/test/test_ir.rb +34 -34
  98. data/test/test_lcd.rb +146 -0
  99. data/test/test_light_sensor.rb +58 -0
  100. data/test/test_magnetometer.rb +78 -0
  101. data/test/test_manager.rb +10 -79
  102. data/test/test_motor_control.rb +146 -108
  103. data/test/test_phidgets.rb +2 -14
  104. data/test/test_phsensor.rb +46 -34
  105. data/test/test_power_guard.rb +42 -0
  106. data/test/test_pressure_sensor.rb +58 -0
  107. data/test/test_rc_servo.rb +174 -0
  108. data/test/test_resistance_input.rb +66 -0
  109. data/test/test_rfid.rb +15 -54
  110. data/test/test_sound_sensor.rb +78 -0
  111. data/test/test_spatial.rb +19 -85
  112. data/test/test_stepper.rb +89 -98
  113. data/test/test_temp_sensor.rb +42 -47
  114. data/test/test_voltage_input.rb +102 -0
  115. data/test/test_voltage_output.rb +46 -0
  116. data/test/test_voltage_ratio_input.rb +102 -0
  117. metadata +72 -89
  118. data/ext/phidgets/phidgets_advanced_servo.c +0 -567
  119. data/ext/phidgets/phidgets_analog.c +0 -139
  120. data/ext/phidgets/phidgets_bridge.c +0 -263
  121. data/ext/phidgets/phidgets_interface_kit.c +0 -340
  122. data/ext/phidgets/phidgets_led.c +0 -178
  123. data/ext/phidgets/phidgets_motor_control.c +0 -642
  124. data/ext/phidgets/phidgets_servo.c +0 -276
  125. data/ext/phidgets/phidgets_text_lcd.c +0 -381
  126. data/ext/phidgets/phidgets_text_led.c +0 -107
  127. data/ext/phidgets/phidgets_weight_sensor.c +0 -113
  128. data/lib/phidgets/advanced_servo.rb +0 -49
  129. data/lib/phidgets/analog.rb +0 -8
  130. data/lib/phidgets/bridge.rb +0 -25
  131. data/lib/phidgets/interfacekit.rb +0 -49
  132. data/lib/phidgets/led.rb +0 -8
  133. data/lib/phidgets/motor_control.rb +0 -110
  134. data/lib/phidgets/servo.rb +0 -23
  135. data/lib/phidgets/text_lcd.rb +0 -8
  136. data/lib/phidgets/text_led.rb +0 -8
  137. data/lib/phidgets/weight_sensor.rb +0 -25
  138. data/test/test_advanced_servo.rb +0 -152
  139. data/test/test_analog.rb +0 -45
  140. data/test/test_bridge.rb +0 -77
  141. data/test/test_interfacekit.rb +0 -97
  142. data/test/test_led.rb +0 -55
  143. data/test/test_servo.rb +0 -67
  144. data/test/test_text_lcd.rb +0 -115
  145. data/test/test_text_led.rb +0 -35
  146. data/test/test_weight_sensor.rb +0 -32
@@ -0,0 +1,302 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+ #define CAP_TOUCH_TOUCH_END_CALLBACK 0
5
+ #define CAP_TOUCH_TOUCH_CALLBACK 1
6
+
7
+
8
+ VALUE ph_capacitive_touch_init(VALUE self) {
9
+ ph_data_t *ph = get_ph_data(self);
10
+ ph_raise(PhidgetCapacitiveTouch_create((PhidgetCapacitiveTouchHandle *)(&(ph->handle))));
11
+ return self;
12
+ }
13
+
14
+ VALUE ph_capacitive_touch_get_data_interval(VALUE self) {
15
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetCapacitiveTouch_getDataInterval);
16
+ }
17
+
18
+ VALUE ph_capacitive_touch_set_data_interval(VALUE self, VALUE interval) {
19
+ ph_raise(PhidgetCapacitiveTouch_setDataInterval((PhidgetCapacitiveTouchHandle)get_ph_handle(self), NUM2UINT(interval)));
20
+ return Qnil;
21
+ }
22
+
23
+ VALUE ph_capacitive_touch_get_min_data_interval(VALUE self) {
24
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetCapacitiveTouch_getMinDataInterval);
25
+ }
26
+
27
+ VALUE ph_capacitive_touch_get_max_data_interval(VALUE self) {
28
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetCapacitiveTouch_getMaxDataInterval);
29
+ }
30
+
31
+ VALUE ph_capacitive_touch_get_is_touched(VALUE self) {
32
+ return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetCapacitiveTouch_getIsTouched);
33
+ }
34
+
35
+ VALUE ph_capacitive_touch_get_sensitivity(VALUE self) {
36
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getSensitivity);
37
+ }
38
+
39
+ VALUE ph_capacitive_touch_set_sensitivity(VALUE self, VALUE sensitivity) {
40
+ ph_raise(PhidgetCapacitiveTouch_setSensitivity((PhidgetCapacitiveTouchHandle)get_ph_handle(self), NUM2DBL(sensitivity)));
41
+ return Qnil;
42
+ }
43
+
44
+ VALUE ph_capacitive_touch_get_min_sensitivity(VALUE self) {
45
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getMinSensitivity);
46
+ }
47
+
48
+ VALUE ph_capacitive_touch_get_max_sensitivity(VALUE self) {
49
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getMaxSensitivity);
50
+ }
51
+
52
+ VALUE ph_capacitive_touch_get_touch_value(VALUE self) {
53
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getTouchValue);
54
+ }
55
+
56
+ VALUE ph_capacitive_touch_get_min_touch_value(VALUE self) {
57
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getMinTouchValue);
58
+ }
59
+
60
+ VALUE ph_capacitive_touch_get_max_touch_value(VALUE self) {
61
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getMaxTouchValue);
62
+ }
63
+
64
+ VALUE ph_capacitive_touch_get_touch_value_change_trigger(VALUE self) {
65
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getTouchValueChangeTrigger);
66
+ }
67
+
68
+ VALUE ph_capacitive_touch_set_touch_value_change_trigger(VALUE self, VALUE trigger) {
69
+ ph_raise(PhidgetCapacitiveTouch_setTouchValueChangeTrigger((PhidgetCapacitiveTouchHandle)get_ph_handle(self), NUM2DBL(trigger)));
70
+ return Qnil;
71
+ }
72
+
73
+ VALUE ph_capacitive_touch_get_min_touch_value_change_trigger(VALUE self) {
74
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getMinTouchValueChangeTrigger);
75
+ }
76
+
77
+ VALUE ph_capacitive_touch_get_max_touch_value_change_trigger(VALUE self) {
78
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCapacitiveTouch_getMaxTouchValueChangeTrigger);
79
+ }
80
+
81
+
82
+ void CCONV ph_capacitive_touch_on_touch_end(PhidgetCapacitiveTouchHandle phid, void *userPtr) {
83
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
84
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
85
+ callback_data->arg1 = Qnil;
86
+ callback_data->arg2 = Qnil;
87
+ callback_data->arg3 = Qnil;
88
+ callback_data->arg4 = Qnil;
89
+ sem_post(&callback_data->callback_called);
90
+ }
91
+
92
+
93
+ VALUE ph_capacitive_touch_set_on_touch_end_handler(VALUE self, VALUE handler) {
94
+ ph_data_t *ph = get_ph_data(self);
95
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[CAP_TOUCH_TOUCH_END_CALLBACK];
96
+ if( TYPE(handler) == T_NIL ) {
97
+ callback_data->callback = T_NIL;
98
+ callback_data->exit = true;
99
+ ph_raise(PhidgetCapacitiveTouch_setOnTouchEndHandler((PhidgetCapacitiveTouchHandle)ph->handle, NULL, (void *)NULL));
100
+ sem_post(&callback_data->callback_called);
101
+ } else {
102
+ callback_data->exit = false;
103
+ callback_data->phidget = self;
104
+ callback_data->callback = handler;
105
+ ph_raise(PhidgetCapacitiveTouch_setOnTouchEndHandler((PhidgetCapacitiveTouchHandle)ph->handle, ph_capacitive_touch_on_touch_end, (void *)callback_data));
106
+ ph_callback_thread(callback_data);
107
+ }
108
+ return Qnil;
109
+ }
110
+
111
+
112
+ void CCONV ph_capacitive_touch_on_touch(PhidgetCapacitiveTouchHandle phid, void *userPtr, double touch_value) {
113
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
114
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
115
+ callback_data->arg1 = DBL2NUM(touch_value);
116
+ callback_data->arg2 = Qnil;
117
+ callback_data->arg3 = Qnil;
118
+ callback_data->arg4 = Qnil;
119
+ sem_post(&callback_data->callback_called);
120
+ }
121
+
122
+
123
+ VALUE ph_capacitive_touch_set_on_touch_handler(VALUE self, VALUE handler) {
124
+ ph_data_t *ph = get_ph_data(self);
125
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[CAP_TOUCH_TOUCH_CALLBACK];
126
+ if( TYPE(handler) == T_NIL ) {
127
+ callback_data->callback = T_NIL;
128
+ callback_data->exit = true;
129
+ ph_raise(PhidgetCapacitiveTouch_setOnTouchHandler((PhidgetCapacitiveTouchHandle)ph->handle, NULL, (void *)NULL));
130
+ sem_post(&callback_data->callback_called);
131
+ } else {
132
+ callback_data->exit = false;
133
+ callback_data->phidget = self;
134
+ callback_data->callback = handler;
135
+ ph_raise(PhidgetCapacitiveTouch_setOnTouchHandler((PhidgetCapacitiveTouchHandle)ph->handle, ph_capacitive_touch_on_touch, (void *)callback_data));
136
+ ph_callback_thread(callback_data);
137
+ }
138
+ return Qnil;
139
+ }
140
+
141
+
142
+
143
+ void Init_capacitive_touch() {
144
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
145
+ VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
146
+ VALUE ph_capacitive_touch = rb_define_class_under(ph_module, "CapacitiveTouch", ph_common);
147
+
148
+
149
+
150
+ /* Document-method: new
151
+ * call-seq: new
152
+ *
153
+ * Creates a Phidget CapacitiveTouch object.
154
+ */
155
+ rb_define_method(ph_capacitive_touch, "initialize", ph_capacitive_touch_init, 0);
156
+
157
+ /* Document-method: getDataInterval
158
+ * call-seq: getDataInterval -> interval
159
+ *
160
+ * The DataInterval is the time that must elapse before the channel will fire another Touch event.
161
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
162
+ * The timing between Touch events can also affected by the TouchValueChangeTrigger.
163
+ */
164
+ rb_define_method(ph_capacitive_touch, "getDataInterval", ph_capacitive_touch_get_data_interval, 0);
165
+ rb_define_alias(ph_capacitive_touch, "data_interval", "getDataInterval");
166
+
167
+ /* Document-method: setDataInterval
168
+ * call-seq: setDataInterval(interval)
169
+ *
170
+ * The DataInterval is the time that must elapse before the channel will fire another Touch event.
171
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
172
+ * The timing between Touch events can also affected by the TouchValueChangeTrigger.
173
+ */
174
+ rb_define_method(ph_capacitive_touch, "setDataInterval", ph_capacitive_touch_set_data_interval, 1);
175
+ rb_define_alias(ph_capacitive_touch, "data_interval=", "setDataInterval");
176
+
177
+ /* Document-method: getMinDataInterval
178
+ * call-seq: getMinDataInterval -> interval
179
+ *
180
+ * The minimum value that DataInterval can be set to.
181
+ */
182
+ rb_define_method(ph_capacitive_touch, "getMinDataInterval", ph_capacitive_touch_get_min_data_interval, 0);
183
+ rb_define_alias(ph_capacitive_touch, "min_data_interval", "getMinDataInterval");
184
+
185
+ /* Document-method: getMaxDataInterval
186
+ * call-seq: getMaxDataInterval -> interval
187
+ *
188
+ * The maximum value that DataInterval can be set to.
189
+ */
190
+ rb_define_method(ph_capacitive_touch, "getMaxDataInterval", ph_capacitive_touch_get_max_data_interval, 0);
191
+ rb_define_alias(ph_capacitive_touch, "max_data_interval", "getMaxDataInterval");
192
+
193
+ /* Document-method: getIsTouched
194
+ * call-seq: getIsTouched -> true or false
195
+ *
196
+ * The most recent touch state that the channel has reported.
197
+ */
198
+ rb_define_method(ph_capacitive_touch, "getIsTouched", ph_capacitive_touch_get_is_touched, 0);
199
+ rb_define_alias(ph_capacitive_touch, "is_touched?", "getIsTouched");
200
+
201
+ /* Document-method: getSensitivity
202
+ * call-seq: getSensitivity -> sensitivity
203
+ *
204
+ * Determines the sensitivity of all capacitive regions on the device.
205
+ * Higher values result in greater touch sensitivity.
206
+ * The sensitivity value is bounded by MinSensitivity and MaxSensitivity.
207
+ */
208
+ rb_define_method(ph_capacitive_touch, "getSensitivity", ph_capacitive_touch_get_sensitivity, 0);
209
+ rb_define_alias(ph_capacitive_touch, "sensitivity", "getSensitivity");
210
+
211
+ /* Document-method: setSensitivity
212
+ * call-seq: setSensitivity(sensitivity)
213
+ *
214
+ * Determines the sensitivity of all capacitive regions on the device.
215
+ * Higher values result in greater touch sensitivity.
216
+ * The sensitivity value is bounded by MinSensitivity and MaxSensitivity.
217
+ */
218
+ rb_define_method(ph_capacitive_touch, "setSensitivity", ph_capacitive_touch_set_sensitivity, 1);
219
+ rb_define_alias(ph_capacitive_touch, "sensitivity=", "setSensitivity");
220
+
221
+ /* Document-method: getMinSensitivity
222
+ * call-seq: getMinSensitivity -> sensitivity
223
+ *
224
+ * The minimum value that Sensitivity can be set to.
225
+ */
226
+ rb_define_method(ph_capacitive_touch, "getMinSensitivity", ph_capacitive_touch_get_min_sensitivity, 0);
227
+ rb_define_alias(ph_capacitive_touch, "min_sensitivity", "getMinSensitivity");
228
+
229
+ /* Document-method: getMaxSensitivity
230
+ * call-seq: getMaxSensitivity -> sensitivity
231
+ *
232
+ * The maximum value that Sensitivity can be set to.
233
+ */
234
+ rb_define_method(ph_capacitive_touch, "getMaxSensitivity", ph_capacitive_touch_get_max_sensitivity, 0);
235
+ rb_define_alias(ph_capacitive_touch, "max_sensitivity", "getMaxSensitivity");
236
+
237
+ /* Document-method: getTouchValue
238
+ * call-seq: getTouchValue -> touch_value
239
+ *
240
+ * The most recent touch value that the channel has reported.
241
+ * This will be 0 or 1 for button-type inputs, or a ratio between 0-1 for axis-type inputs.
242
+ * This value is bounded by MinTouchValue and MaxTouchValue
243
+ * The value is not reset when the touch ends.
244
+ */
245
+ rb_define_method(ph_capacitive_touch, "getTouchValue", ph_capacitive_touch_get_touch_value, 0);
246
+ rb_define_alias(ph_capacitive_touch, "touch_value", "getTouchValue");
247
+
248
+ /* Document-method: getMinTouchValue
249
+ * call-seq: getMinTouchValue -> touch_value
250
+ *
251
+ * The minimum value the Touch event will report.
252
+ */
253
+ rb_define_method(ph_capacitive_touch, "getMinTouchValue", ph_capacitive_touch_get_min_touch_value, 0);
254
+ rb_define_alias(ph_capacitive_touch, "min_touch_value", "getMinTouchValue");
255
+
256
+ /* Document-method: getMaxTouchValue
257
+ * call-seq: getMaxTouchValue -> touch_value
258
+ *
259
+ * The maximum value the Touch event will report.
260
+ */
261
+ rb_define_method(ph_capacitive_touch, "getMaxTouchValue", ph_capacitive_touch_get_max_touch_value, 0);
262
+ rb_define_alias(ph_capacitive_touch, "max_touch_value", "getMaxTouchValue");
263
+
264
+ /* Document-method: getTouchValueChangeTrigger
265
+ * call-seq: getTouchValueChangeTrigger -> trigger
266
+ *
267
+ * The channel will not issue a Touch event until the touch value has changed by the amount specified by the TouchValueChangeTrigger.
268
+ * Setting the TouchValueChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
269
+ */
270
+ rb_define_method(ph_capacitive_touch, "getTouchValueChangeTrigger", ph_capacitive_touch_get_touch_value_change_trigger, 0);
271
+ rb_define_alias(ph_capacitive_touch, "touch_value_change_trigger", "getTouchValueChangeTrigger");
272
+
273
+ /* Document-method: setTouchValueChangeTrigger
274
+ * call-seq: setTouchValueChangeTrigger(trigger)
275
+ *
276
+ * The channel will not issue a Touch event until the touch value has changed by the amount specified by the TouchValueChangeTrigger.
277
+ * Setting the TouchValueChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
278
+ */
279
+ rb_define_method(ph_capacitive_touch, "setTouchValueChangeTrigger", ph_capacitive_touch_set_touch_value_change_trigger, 1);
280
+ rb_define_alias(ph_capacitive_touch, "touch_value_change_trigger=", "setTouchValueChangeTrigger");
281
+
282
+ /* Document-method: getMinTouchValueChangeTrigger
283
+ * call-seq: getMinTouchValueChangeTrigger -> trigger
284
+ *
285
+ * The minimum value that TouchValueChangeTrigger can be set to.
286
+ */
287
+ rb_define_method(ph_capacitive_touch, "getMinTouchValueChangeTrigger", ph_capacitive_touch_get_min_touch_value_change_trigger, 0);
288
+ rb_define_alias(ph_capacitive_touch, "min_touch_value_change_trigger", "getMinTouchValueChangeTrigger");
289
+
290
+ /* Document-method: getMaxTouchValueChangeTrigger
291
+ * call-seq: getMaxTouchValueChangeTrigger -> trigger
292
+ *
293
+ * The maximum value that TouchValueChangeTrigger can be set to.
294
+ */
295
+ rb_define_method(ph_capacitive_touch, "getMaxTouchValueChangeTrigger", ph_capacitive_touch_get_max_touch_value_change_trigger, 0);
296
+ rb_define_alias(ph_capacitive_touch, "max_touch_value_change_trigger", "getMaxTouchValueChangeTrigger");
297
+
298
+
299
+ rb_define_private_method(ph_capacitive_touch, "ext_setOnTouchEndHandler", ph_capacitive_touch_set_on_touch_end_handler, 1);
300
+ rb_define_private_method(ph_capacitive_touch, "ext_setOnTouchHandler", ph_capacitive_touch_set_on_touch_handler, 1);
301
+ }
302
+
@@ -2,370 +2,287 @@
2
2
  #include "phidgets.h"
3
3
 
4
4
 
5
- VALUE ph_common_allocate(VALUE klass);
6
- void ph_common_free(ph_data_t *ph);
7
- VALUE ph_common_open(VALUE self, VALUE serial_number);
8
- VALUE ph_common_open_label(VALUE self, VALUE label);
9
- VALUE ph_common_open_remote(VALUE self, VALUE serial_number, VALUE server_id, VALUE password);
10
- VALUE ph_common_open_label_remote(VALUE self, VALUE label, VALUE server_id, VALUE password);
11
- VALUE ph_common_open_remote_ip(VALUE self, VALUE serial_number, VALUE address, VALUE port, VALUE password);
12
- VALUE ph_common_open_label_remote_ip(VALUE self, VALUE label, VALUE address, VALUE port, VALUE password);
13
- VALUE ph_common_wait_for_attachment(VALUE self, VALUE milliseconds);
14
- VALUE ph_common_close(VALUE self);
15
- VALUE ph_common_get_device_class(VALUE self);
16
- VALUE ph_common_get_device_id(VALUE self);
17
- VALUE ph_common_get_device_type(VALUE self);
18
- VALUE ph_common_get_device_name(VALUE self);
19
- VALUE ph_common_get_serial_number(VALUE self);
20
- VALUE ph_common_get_device_version(VALUE self);
21
- VALUE ph_common_get_device_status(VALUE self);
22
- VALUE ph_common_get_device_label(VALUE self);
23
- VALUE ph_common_set_device_label(VALUE self, VALUE label);
24
- VALUE ph_common_get_server_id(VALUE self);
25
- VALUE ph_common_get_server_address(VALUE self);
26
- VALUE ph_common_get_server_status(VALUE self);
27
-
28
- #ifdef PH_CALLBACK
29
- VALUE ph_common_set_on_attach_handler(VALUE self, VALUE handler);
30
- VALUE ph_common_set_on_detach_handler(VALUE self, VALUE handler);
31
- VALUE ph_common_set_on_server_connect_handler(VALUE self, VALUE handler);
32
- VALUE ph_common_set_on_server_disconnect_handler(VALUE self, VALUE handler);
33
- int ph_common_on_attach(CPhidgetHandle phid, void *userPtr);
34
- int ph_common_on_detach(CPhidgetHandle phid, void *userPtr);
35
- int ph_common_on_server_connect(CPhidgetHandle phid, void *userPtr);
36
- int ph_common_on_server_disconnect(CPhidgetHandle phid, void *userPtr);
37
- #endif
5
+ void ph_common_free(ph_data_t *ph) {
6
+ if (ph && ph->handle) {
7
+ Phidget_close(ph->handle);
8
+ Phidget_delete(&ph->handle);
9
+ ph->handle = NULL;
10
+ }
11
+ if(ph) {
12
+ sem_destroy(&ph->attach_callback.handler_ready);
13
+ sem_destroy(&ph->attach_callback.callback_called);
14
+ sem_destroy(&ph->detach_callback.handler_ready);
15
+ sem_destroy(&ph->detach_callback.callback_called);
16
+ sem_destroy(&ph->error_callback.handler_ready);
17
+ sem_destroy(&ph->error_callback.callback_called);
18
+ sem_destroy(&ph->property_change_callback.handler_ready);
19
+ sem_destroy(&ph->property_change_callback.callback_called);
20
+ sem_destroy(&ph->dev_callbacks[0].handler_ready);
21
+ sem_destroy(&ph->dev_callbacks[0].callback_called);
22
+ sem_destroy(&ph->dev_callbacks[1].handler_ready);
23
+ sem_destroy(&ph->dev_callbacks[1].callback_called);
24
+ sem_destroy(&ph->dev_callbacks[2].handler_ready);
25
+ sem_destroy(&ph->dev_callbacks[2].callback_called);
26
+ sem_destroy(&ph->dev_callbacks[3].handler_ready);
27
+ sem_destroy(&ph->dev_callbacks[3].callback_called);
28
+ xfree(ph);
29
+ }
30
+ }
38
31
 
39
32
 
40
- void Init_common() {
41
- VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
42
- VALUE ph_common = rb_define_class_under(ph_module, "Common", rb_cObject);
43
- rb_define_alloc_func(ph_common, ph_common_allocate);
44
- rb_define_private_method(ph_common, "ext_open", ph_common_open, 1);
33
+ VALUE ph_common_allocate(VALUE klass) {
34
+ ph_data_t *ph;
35
+ VALUE self = Data_Make_Struct(klass, ph_data_t, 0, ph_common_free, ph);
36
+ memset(ph, 0, sizeof(ph_data_t));
37
+ sem_init(&ph->attach_callback.handler_ready, 0, 0);
38
+ sem_init(&ph->attach_callback.callback_called, 0, 0);
39
+ sem_init(&ph->detach_callback.handler_ready, 0, 0);
40
+ sem_init(&ph->detach_callback.callback_called, 0, 0);
41
+ sem_init(&ph->error_callback.handler_ready, 0, 0);
42
+ sem_init(&ph->error_callback.callback_called, 0, 0);
43
+ sem_init(&ph->property_change_callback.handler_ready, 0, 0);
44
+ sem_init(&ph->property_change_callback.callback_called, 0, 0);
45
+ sem_init(&ph->dev_callbacks[0].handler_ready, 0, 0);
46
+ sem_init(&ph->dev_callbacks[0].callback_called, 0, 0);
47
+ sem_init(&ph->dev_callbacks[1].handler_ready, 0, 0);
48
+ sem_init(&ph->dev_callbacks[1].callback_called, 0, 0);
49
+ sem_init(&ph->dev_callbacks[2].handler_ready, 0, 0);
50
+ sem_init(&ph->dev_callbacks[2].callback_called, 0, 0);
51
+ sem_init(&ph->dev_callbacks[3].handler_ready, 0, 0);
52
+ sem_init(&ph->dev_callbacks[3].callback_called, 0, 0);
53
+ return self;
54
+ }
45
55
 
46
- /* Document-method: openLabel
47
- * call-seq: openLabel(label)
48
- *
49
- * Opens a Phidget by label.
50
- */
51
- rb_define_method(ph_common, "openLabel", ph_common_open_label, 1);
52
56
 
53
- /* Document-method: openRemote
54
- * call-seq: openRemote(serial, server_id, password)
55
- *
56
- * Opens a Phidget remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
57
- */
58
- rb_define_method(ph_common, "openRemote", ph_common_open_remote, 3);
57
+ VALUE ph_common_open(VALUE self) {
58
+ ph_raise(Phidget_open(get_ph_handle(self)));
59
+ return Qnil;
60
+ }
59
61
 
60
- /* Document-method: openLabelRemote
61
- * call-seq: openLabelRemote(label, server_id, password)
62
- *
63
- * Opens a Phidget remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
64
- */
65
- rb_define_method(ph_common, "openLabelRemote", ph_common_open_label_remote, 3);
62
+ VALUE ph_common_open_wait_for_attachment(VALUE self, VALUE milliseconds) {
63
+ ph_raise(Phidget_openWaitForAttachment(get_ph_handle(self), NUM2UINT(milliseconds)));
64
+ return Qnil;
65
+ }
66
66
 
67
- /* Document-method: openRemoteIP
68
- * call-seq: openRemoteIP(serial, address, port, password)
69
- *
70
- * Opens a Phidget remotely by address and port, with optional serial number.
71
- */
72
- rb_define_method(ph_common, "openRemoteIP", ph_common_open_remote_ip, 4);
67
+ VALUE ph_common_get_attached(VALUE self) {
68
+ return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)Phidget_getAttached);
69
+ }
73
70
 
74
- /* Document-method: openLabelRemoteIP
75
- * call-seq: openLabelRemoteIP(label, address, port, password)
76
- *
77
- * Opens a Phidget remotely by address and port, with optional label.
78
- */
79
- rb_define_method(ph_common, "openLabelRemoteIP", ph_common_open_label_remote_ip, 4);
71
+ VALUE ph_common_close(VALUE self) {
72
+ ph_raise(Phidget_close(get_ph_handle(self)));
73
+ return Qnil;
74
+ }
80
75
 
81
- /* Document-method: waitForAttachment
82
- * call-seq: waitForAttachment(milliseconds)
83
- *
84
- * Waits for attachment to happen. This can be called right after calling open, as an alternative to using the attach handler.
85
- */
86
- rb_define_method(ph_common, "waitForAttachment", ph_common_wait_for_attachment, 1);
76
+ VALUE ph_common_get_device_channel_count(VALUE self, VALUE channel_class) {
77
+ uint32_t count;
78
+ ph_raise(Phidget_getDeviceChannelCount(get_ph_handle(self), NUM2INT(channel_class), &count));
79
+ return UINT2NUM(count);
80
+ }
87
81
 
88
- /* Document-method: close
89
- * call-seq: close
90
- *
91
- * Closes a Phidget.
92
- */
93
- rb_define_method(ph_common, "close", ph_common_close, 0);
82
+ VALUE ph_common_get_device_class(VALUE self) {
83
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)Phidget_getDeviceClass);
84
+ }
94
85
 
95
- /* Document-method: getDeviceClass
96
- * call-seq: getDeviceClass -> device_class
97
- *
98
- * Gets the class of a Phidget.
99
- */
100
- rb_define_method(ph_common, "getDeviceClass", ph_common_get_device_class, 0);
86
+ VALUE ph_common_get_device_class_name(VALUE self) {
87
+ return ph_get_string(get_ph_handle(self), (phidget_get_string_func)Phidget_getDeviceClassName);
88
+ }
101
89
 
102
- /* Document-method: getDeviceID
103
- * call-seq: getDeviceID -> device_id
104
- *
105
- * Gets the device ID of a Phidget.
106
- */
107
- rb_define_method(ph_common, "getDeviceID", ph_common_get_device_id, 0);
90
+ VALUE ph_common_get_device_id(VALUE self) {
91
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)Phidget_getDeviceID);
92
+ }
108
93
 
109
- /* Document-method: getDeviceType
110
- * call-seq: getDeviceType -> device_type
111
- *
112
- * Gets the type (class) of a Phidget.
113
- */
114
- rb_define_method(ph_common, "getDeviceType", ph_common_get_device_type, 0);
94
+ VALUE ph_common_get_device_name(VALUE self) {
95
+ return ph_get_string(get_ph_handle(self), Phidget_getDeviceName);
96
+ }
115
97
 
116
- /* Document-method: getDeviceName
117
- * call-seq: getDeviceName -> device_name
118
- *
119
- * Gets the specific name of a Phidget.
120
- */
121
- rb_define_method(ph_common, "getDeviceName", ph_common_get_device_name, 0);
98
+ VALUE ph_common_get_device_serial_number(VALUE self) {
99
+ return ph_get_int(get_ph_handle(self), Phidget_getDeviceSerialNumber);
100
+ }
122
101
 
123
- /* Document-method: getSerialNumber
124
- * call-seq: getSerialNumber -> serial_number
125
- *
126
- * Gets the serial number of a Phidget.
127
- */
128
- rb_define_method(ph_common, "getSerialNumber", ph_common_get_serial_number, 0);
102
+ VALUE ph_common_set_device_serial_number(VALUE self, VALUE serial_number) {
103
+ ph_raise(Phidget_setDeviceSerialNumber(get_ph_handle(self), NUM2INT(serial_number)));
104
+ return Qnil;
105
+ }
129
106
 
130
- /* Document-method: getDeviceVersion
131
- * call-seq: getDeviceVersion -> version
132
- *
133
- * Gets the firmware version of a Phidget.
134
- */
135
- rb_define_method(ph_common, "getDeviceVersion", ph_common_get_device_version, 0);
107
+ VALUE ph_common_get_device_sku(VALUE self) {
108
+ return ph_get_string(get_ph_handle(self), Phidget_getDeviceSKU);
109
+ }
136
110
 
137
- /* Document-method: getDeviceStatus
138
- * call-seq: getDeviceStatus -> status
139
- *
140
- * Gets the attached status of a Phidget.
141
- */
142
- rb_define_method(ph_common, "getDeviceStatus", ph_common_get_device_status, 0);
111
+ VALUE ph_common_get_device_version(VALUE self) {
112
+ return ph_get_int(get_ph_handle(self), Phidget_getDeviceVersion);
113
+ }
143
114
 
144
- /* Document-method: getDeviceLabel
145
- * call-seq: getDeviceLabel -> label
146
- *
147
- * Gets the label of a Phidget.
148
- */
149
- rb_define_method(ph_common, "getDeviceLabel", ph_common_get_device_label, 0);
115
+ VALUE ph_common_get_device_label(VALUE self) {
116
+ return ph_get_string(get_ph_handle(self), Phidget_getDeviceLabel);
117
+ }
150
118
 
151
- /* Document-method: setDeviceLabel
152
- * call-seq: setDeviceLabel(label)
153
- *
154
- * Sets the label of a Phidget. Note that this is not supported on very old Phidgets, and not yet supported in Windows.
155
- */
156
- rb_define_method(ph_common, "setDeviceLabel", ph_common_set_device_label, 1);
119
+ VALUE ph_common_set_device_label(VALUE self, VALUE label) {
120
+ ph_raise(Phidget_setDeviceLabel(get_ph_handle(self), StringValueCStr(label)));
121
+ return Qnil;
122
+ }
157
123
 
158
- /* Document-method: getServerID
159
- * call-seq: getServerID -> server_id
160
- *
161
- * Gets the server ID of a remotely opened Phidget. This will fail if the Phidget was opened locally.
162
- */
163
- rb_define_method(ph_common, "getServerID", ph_common_get_server_id, 0);
124
+ VALUE ph_common_write_device_label(VALUE self, VALUE label) {
125
+ ph_raise(Phidget_writeDeviceLabel(get_ph_handle(self), StringValueCStr(label)));
126
+ return Qnil;
127
+ }
164
128
 
165
- /* Document-method: getServerAddress
166
- * call-seq: getServerAddress -> [address, port]
167
- *
168
- * Gets the address and port of a remotely opened Phidget. This will fail if the Phidget was opened locally.
169
- */
170
- rb_define_method(ph_common, "getServerAddress", ph_common_get_server_address, 0);
129
+ VALUE ph_common_get_channel(VALUE self) {
130
+ return ph_get_int(get_ph_handle(self), Phidget_getChannel);
131
+ }
171
132
 
172
- /* Document-method: getServerStatus
173
- * call-seq: getServerStatus -> status
174
- *
175
- * Gets the connected to server status of a remotely opened Phidget. This will fail if the Phidget was opened locally.
176
- */
177
- rb_define_method(ph_common, "getServerStatus", ph_common_get_server_status, 0);
133
+ VALUE ph_common_set_channel(VALUE self, VALUE channel) {
134
+ ph_raise(Phidget_setChannel(get_ph_handle(self), NUM2INT(channel)));
135
+ return Qnil;
136
+ }
178
137
 
179
- #ifdef PH_CALLBACK
180
- rb_define_private_method(ph_common, "ext_setOnAttachHandler", ph_common_set_on_attach_handler, 1);
181
- rb_define_private_method(ph_common, "ext_setOnDetachHandler", ph_common_set_on_detach_handler, 1);
182
- rb_define_private_method(ph_common, "ext_setOnServerConnectHandler", ph_common_set_on_server_connect_handler, 1);
183
- rb_define_private_method(ph_common, "ext_setOnServerDisconnectHandler", ph_common_set_on_server_disconnect_handler, 1);
184
- #endif
185
-
186
- rb_define_alias(ph_common, "open_label", "openLabel");
187
- rb_define_alias(ph_common, "open_remote", "openRemote");
188
- rb_define_alias(ph_common, "open_label_remote", "openLabelRemote");
189
- rb_define_alias(ph_common, "open_remote_ip", "openRemoteIP");
190
- rb_define_alias(ph_common, "open_label_remote_ip", "openLabelRemoteIP");
191
- rb_define_alias(ph_common, "wait_for_attachment", "waitForAttachment");
192
- rb_define_alias(ph_common, "device_class", "getDeviceClass");
193
- rb_define_alias(ph_common, "device_id", "getDeviceID");
194
- rb_define_alias(ph_common, "device_type", "getDeviceType");
195
- rb_define_alias(ph_common, "device_name", "getDeviceName");
196
- rb_define_alias(ph_common, "serial_number", "getSerialNumber");
197
- rb_define_alias(ph_common, "device_version", "getDeviceVersion");
198
- rb_define_alias(ph_common, "device_status", "getDeviceStatus");
199
- rb_define_alias(ph_common, "device_label", "getDeviceLabel");
200
- rb_define_alias(ph_common, "device_label=", "setDeviceLabel");
201
- rb_define_alias(ph_common, "server_id", "getServerID");
202
- rb_define_alias(ph_common, "server_address", "getServerAddress");
203
- rb_define_alias(ph_common, "server_status", "getServerStatus");
138
+ VALUE ph_common_get_channel_name(VALUE self) {
139
+ return ph_get_string(get_ph_handle(self), Phidget_getChannelName);
204
140
  }
205
141
 
142
+ VALUE ph_common_get_channel_class(VALUE self) {
143
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)Phidget_getChannelClass);
144
+ }
206
145
 
146
+ VALUE ph_common_get_channel_class_name(VALUE self) {
147
+ return ph_get_string(get_ph_handle(self), Phidget_getChannelClassName);
148
+ }
207
149
 
208
- VALUE ph_common_allocate(VALUE klass) {
209
- ph_data_t *ph;
210
- VALUE self = Data_Make_Struct(klass, ph_data_t, 0, ph_common_free, ph);
211
- memset(ph, 0, sizeof(ph_data_t));
212
- return self;
150
+ VALUE ph_common_get_channel_subclass(VALUE self) {
151
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)Phidget_getChannelSubclass);
213
152
  }
214
153
 
215
- void ph_common_free(ph_data_t *ph) {
216
- if (ph && ph->handle) {
217
- CPhidget_close(ph->handle);
218
- CPhidget_delete(ph->handle);
219
- ph->handle = NULL;
220
- }
221
- if(ph) xfree(ph);
154
+ VALUE ph_common_get_data_interval(VALUE self) {
155
+ return ph_get_uint(get_ph_handle(self), Phidget_getDataInterval);
222
156
  }
223
157
 
224
- VALUE ph_common_open(VALUE self, VALUE serial_number) {
225
- CPhidgetHandle handle = get_ph_handle(self);
226
- ph_raise(CPhidget_open(handle, FIX2INT(serial_number)));
158
+ VALUE ph_common_set_data_interval(VALUE self, VALUE interval) {
159
+ ph_raise(Phidget_setDataInterval(get_ph_handle(self), NUM2UINT(interval)));
227
160
  return Qnil;
228
161
  }
229
162
 
230
- VALUE ph_common_open_label(VALUE self, VALUE label) {
231
- CPhidgetHandle handle = get_ph_handle(self);
232
- ph_raise(CPhidget_openLabel(handle, StringValueCStr(label)));
233
- return Qnil;
163
+ VALUE ph_common_get_hub_port(VALUE self) {
164
+ return ph_get_int(get_ph_handle(self), Phidget_getHubPort);
234
165
  }
235
166
 
236
- VALUE ph_common_open_remote(VALUE self, VALUE serial_number, VALUE server_id, VALUE password) {
237
- CPhidgetHandle handle = get_ph_handle(self);
238
- ph_raise(CPhidget_openRemote(handle, FIX2INT(serial_number), StringValueCStr(server_id), StringValueCStr(password)));
167
+ VALUE ph_common_set_hub_port(VALUE self, VALUE hub_port) {
168
+ ph_raise(Phidget_setHubPort(get_ph_handle(self), NUM2INT(hub_port)));
239
169
  return Qnil;
240
170
  }
241
171
 
242
- VALUE ph_common_open_label_remote(VALUE self, VALUE label, VALUE server_id, VALUE password) {
243
- CPhidgetHandle handle = get_ph_handle(self);
244
- ph_raise(CPhidget_openLabelRemote(handle, StringValueCStr(label), StringValueCStr(server_id), StringValueCStr(password)));
245
- return Qnil;
172
+ VALUE ph_common_get_hub_port_count(VALUE self) {
173
+ return ph_get_int(get_ph_handle(self), Phidget_getHubPortCount);
246
174
  }
247
175
 
248
- VALUE ph_common_open_remote_ip(VALUE self, VALUE serial_number, VALUE address, VALUE port, VALUE password) {
249
- CPhidgetHandle handle = get_ph_handle(self);
250
- ph_raise(CPhidget_openRemoteIP(handle, FIX2INT(serial_number), StringValueCStr(address), FIX2INT(port), StringValueCStr(password)));
251
- return Qnil;
176
+ VALUE ph_common_get_is_channel(VALUE self) {
177
+ return ph_get_bool(get_ph_handle(self), Phidget_getIsChannel);
252
178
  }
253
179
 
254
- VALUE ph_common_open_label_remote_ip(VALUE self, VALUE label, VALUE address, VALUE port, VALUE password) {
255
- CPhidgetHandle handle = get_ph_handle(self);
256
- ph_raise(CPhidget_openLabelRemoteIP(handle, StringValueCStr(label), StringValueCStr(address), FIX2INT(port), StringValueCStr(password)));
257
- return Qnil;
180
+ VALUE ph_common_get_is_hub_port_device(VALUE self) {
181
+ return ph_get_bool(get_ph_handle(self), Phidget_getIsHubPortDevice);
258
182
  }
259
183
 
260
- VALUE ph_common_wait_for_attachment(VALUE self, VALUE milliseconds) {
261
- CPhidgetHandle handle = get_ph_handle(self);
262
- ph_raise(CPhidget_waitForAttachment(handle, FIX2INT(milliseconds)));
184
+ VALUE ph_common_set_is_hub_port_device(VALUE self, VALUE is_hub_port_device) {
185
+ ph_raise(Phidget_setIsHubPortDevice(get_ph_handle(self), TYPE(is_hub_port_device) == T_TRUE ? PTRUE : PFALSE));
263
186
  return Qnil;
264
187
  }
265
188
 
266
- VALUE ph_common_close(VALUE self) {
267
- CPhidgetHandle handle = get_ph_handle(self);
268
- ph_raise(CPhidget_close(handle));
269
- return Qnil;
189
+ VALUE ph_common_get_is_local(VALUE self) {
190
+ return ph_get_bool(get_ph_handle(self), Phidget_getIsLocal);
270
191
  }
271
192
 
272
- VALUE ph_common_get_device_class(VALUE self) {
273
- CPhidgetHandle handle = get_ph_handle(self);
274
- CPhidget_DeviceClass device_class;
275
- ph_raise(CPhidget_getDeviceClass(handle, &device_class));
276
- return INT2FIX(device_class);
193
+ VALUE ph_common_set_is_local(VALUE self, VALUE is_local) {
194
+ ph_raise(Phidget_setIsLocal(get_ph_handle(self), TYPE(is_local) == T_TRUE ? PTRUE : PFALSE));
195
+ return Qnil;
277
196
  }
278
197
 
279
- VALUE ph_common_get_device_id(VALUE self) {
280
- CPhidgetHandle handle = get_ph_handle(self);
281
- CPhidget_DeviceID device_id;
282
- ph_raise(CPhidget_getDeviceID(handle, &device_id));
283
- return INT2FIX(device_id);
198
+ VALUE ph_common_get_is_remote(VALUE self) {
199
+ return ph_get_bool(get_ph_handle(self), Phidget_getIsRemote);
284
200
  }
285
201
 
286
- VALUE ph_common_get_device_type(VALUE self) {
287
- CPhidgetHandle handle = get_ph_handle(self);
288
- const char *device_type;
289
- ph_raise(CPhidget_getDeviceType(handle, &device_type));
290
- return rb_str_new2(device_type);
202
+ VALUE ph_common_set_is_remote(VALUE self, VALUE is_remote) {
203
+ ph_raise(Phidget_setIsRemote(get_ph_handle(self), TYPE(is_remote) == T_TRUE ? PTRUE : PFALSE));
204
+ return Qnil;
291
205
  }
292
206
 
293
- VALUE ph_common_get_device_name(VALUE self) {
294
- CPhidgetHandle handle = get_ph_handle(self);
295
- const char *device_name;
296
- ph_raise(CPhidget_getDeviceName(handle, &device_name));
297
- return rb_str_new2(device_name);
207
+ VALUE ph_common_get_server_hostname(VALUE self) {
208
+ return ph_get_string(get_ph_handle(self), Phidget_getServerHostname);
298
209
  }
299
210
 
300
- VALUE ph_common_get_serial_number(VALUE self) {
301
- CPhidgetHandle handle = get_ph_handle(self);
302
- int serial;
303
- ph_raise(CPhidget_getSerialNumber(handle, &serial));
304
- return INT2FIX(serial);
211
+ VALUE ph_common_get_server_name(VALUE self) {
212
+ return ph_get_string(get_ph_handle(self), Phidget_getServerName);
305
213
  }
306
214
 
307
- VALUE ph_common_get_device_version(VALUE self) {
308
- CPhidgetHandle handle = get_ph_handle(self);
309
- int device_version;
310
- ph_raise(CPhidget_getDeviceVersion(handle, &device_version));
311
- return INT2FIX(device_version);
215
+ VALUE ph_common_set_server_name(VALUE self, VALUE server_name) {
216
+ ph_raise(Phidget_setServerName(get_ph_handle(self), StringValueCStr(server_name)));
217
+ return Qnil;
312
218
  }
313
219
 
314
- VALUE ph_common_get_device_status(VALUE self) {
315
- CPhidgetHandle handle = get_ph_handle(self);
316
- int device_status;
317
- ph_raise(CPhidget_getDeviceStatus(handle, &device_status));
318
- return INT2FIX(device_status);
220
+ VALUE ph_common_get_server_peer_name(VALUE self) {
221
+ return ph_get_string(get_ph_handle(self), Phidget_getServerPeerName);
319
222
  }
320
223
 
321
- VALUE ph_common_get_device_label(VALUE self) {
322
- CPhidgetHandle handle = get_ph_handle(self);
323
- const char *device_label;
324
- ph_raise(CPhidget_getDeviceLabel(handle, &device_label));
325
- return rb_str_new2(device_label);
224
+ VALUE ph_common_get_server_unique_name(VALUE self) {
225
+ return ph_get_string(get_ph_handle(self), Phidget_getServerUniqueName);
326
226
  }
327
227
 
328
- VALUE ph_common_set_device_label(VALUE self, VALUE label) {
329
- CPhidgetHandle handle = get_ph_handle(self);
330
- ph_raise(CPhidget_setDeviceLabel(handle, StringValueCStr(label)));
331
- return Qnil;
228
+
229
+ void CCONV ph_common_on_attach(PhidgetHandle phid, void *userPtr) {
230
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
231
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
232
+ callback_data->arg1 = Qnil;
233
+ callback_data->arg2 = Qnil;
234
+ callback_data->arg3 = Qnil;
235
+ callback_data->arg4 = Qnil;
236
+ sem_post(&callback_data->callback_called);
332
237
  }
333
238
 
334
- VALUE ph_common_get_server_id(VALUE self) {
335
- CPhidgetHandle handle = get_ph_handle(self);
336
- const char *server_id;
337
- ph_raise(CPhidget_getServerID(handle, &server_id));
338
- return rb_str_new2(server_id);
239
+
240
+ void CCONV ph_common_on_detach(PhidgetHandle phid, void *userPtr) {
241
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
242
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
243
+ callback_data->arg1 = Qnil;
244
+ callback_data->arg2 = Qnil;
245
+ callback_data->arg3 = Qnil;
246
+ callback_data->arg4 = Qnil;
247
+ sem_post(&callback_data->callback_called);
339
248
  }
340
249
 
341
- VALUE ph_common_get_server_address(VALUE self) {
342
- CPhidgetHandle handle = get_ph_handle(self);
343
- const char *address;
344
- int port;
345
- ph_raise(CPhidget_getServerAddress(handle, &address, &port));
346
- return rb_ary_new3(2, rb_str_new2(address), INT2FIX(port));
250
+
251
+ void CCONV ph_common_on_error(PhidgetHandle phid, void *userPtr, Phidget_ErrorEventCode code, const char* description) {
252
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
253
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
254
+ callback_data->arg1 = INT2NUM(code);
255
+ callback_data->arg2 = rb_str_new2(description);
256
+ callback_data->arg3 = Qnil;
257
+ callback_data->arg4 = Qnil;
258
+ sem_post(&callback_data->callback_called);
347
259
  }
348
260
 
349
- VALUE ph_common_get_server_status(VALUE self) {
350
- CPhidgetHandle handle = get_ph_handle(self);
351
- int server_status;
352
- ph_raise(CPhidget_getServerStatus(handle, &server_status));
353
- return INT2FIX(server_status);
261
+
262
+ void CCONV ph_common_on_property_change(PhidgetHandle phid, void *userPtr, const char *propertyName) {
263
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
264
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
265
+ callback_data->arg1 = rb_str_new2(propertyName);
266
+ callback_data->arg2 = Qnil;
267
+ callback_data->arg3 = Qnil;
268
+ callback_data->arg4 = Qnil;
269
+ sem_post(&callback_data->callback_called);
354
270
  }
355
271
 
356
- #ifdef PH_CALLBACK
272
+
357
273
  VALUE ph_common_set_on_attach_handler(VALUE self, VALUE handler) {
358
274
  ph_data_t *ph = get_ph_data(self);
359
275
  ph_callback_data_t *callback_data = &ph->attach_callback;
360
276
  if( TYPE(handler) == T_NIL ) {
277
+ callback_data->callback = T_NIL;
361
278
  callback_data->exit = true;
362
- ph_raise(CPhidget_set_OnAttach_Handler(ph->handle, NULL, (void *)NULL));
279
+ ph_raise(Phidget_setOnAttachHandler(ph->handle, NULL, (void *)NULL));
280
+ sem_post(&callback_data->callback_called);
363
281
  } else {
364
- callback_data->called = false;
365
282
  callback_data->exit = false;
366
283
  callback_data->phidget = self;
367
284
  callback_data->callback = handler;
368
- ph_raise(CPhidget_set_OnAttach_Handler(ph->handle, ph_common_on_attach, (void *)callback_data));
285
+ ph_raise(Phidget_setOnAttachHandler(ph->handle, ph_common_on_attach, (void *)callback_data));
369
286
  ph_callback_thread(callback_data);
370
287
  }
371
288
  return Qnil;
@@ -375,79 +292,417 @@ VALUE ph_common_set_on_detach_handler(VALUE self, VALUE handler) {
375
292
  ph_data_t *ph = get_ph_data(self);
376
293
  ph_callback_data_t *callback_data = &ph->detach_callback;
377
294
  if( TYPE(handler) == T_NIL ) {
295
+ callback_data->callback = T_NIL;
378
296
  callback_data->exit = true;
379
- ph_raise(CPhidget_set_OnDetach_Handler(ph->handle, NULL, (void *)NULL));
297
+ ph_raise(Phidget_setOnDetachHandler(ph->handle, NULL, (void *)NULL));
298
+ sem_post(&callback_data->callback_called);
380
299
  } else {
381
- callback_data->called = false;
382
300
  callback_data->exit = false;
383
301
  callback_data->phidget = self;
384
302
  callback_data->callback = handler;
385
- ph_raise(CPhidget_set_OnDetach_Handler(ph->handle, ph_common_on_detach, (void *)callback_data));
303
+ ph_raise(Phidget_setOnDetachHandler(ph->handle, ph_common_on_detach, (void *)callback_data));
386
304
  ph_callback_thread(callback_data);
387
305
  }
388
306
  return Qnil;
389
307
  }
390
308
 
391
- VALUE ph_common_set_on_server_connect_handler(VALUE self, VALUE handler) {
309
+ VALUE ph_common_set_on_error_handler(VALUE self, VALUE handler) {
392
310
  ph_data_t *ph = get_ph_data(self);
393
- ph_callback_data_t *callback_data = &ph->server_connect_callback;
311
+ ph_callback_data_t *callback_data = &ph->error_callback;
394
312
  if( TYPE(handler) == T_NIL ) {
313
+ callback_data->callback = T_NIL;
395
314
  callback_data->exit = true;
396
- ph_raise(CPhidget_set_OnServerConnect_Handler(ph->handle, NULL, (void *)NULL));
315
+ ph_raise(Phidget_setOnErrorHandler(ph->handle, NULL, (void *)NULL));
316
+ sem_post(&callback_data->callback_called);
397
317
  } else {
398
- callback_data->called = false;
399
318
  callback_data->exit = false;
400
319
  callback_data->phidget = self;
401
320
  callback_data->callback = handler;
402
- ph_raise(CPhidget_set_OnServerConnect_Handler(ph->handle, ph_common_on_server_connect, (void *)callback_data));
321
+ ph_raise(Phidget_setOnErrorHandler(ph->handle, ph_common_on_error, (void *)callback_data));
403
322
  ph_callback_thread(callback_data);
404
323
  }
405
324
  return Qnil;
406
325
  }
407
326
 
408
- VALUE ph_common_set_on_server_disconnect_handler(VALUE self, VALUE handler) {
327
+ VALUE ph_common_set_on_property_change_handler(VALUE self, VALUE handler) {
409
328
  ph_data_t *ph = get_ph_data(self);
410
- ph_callback_data_t *callback_data = &ph->server_disconnect_callback;
329
+ ph_callback_data_t *callback_data = &ph->property_change_callback;
411
330
  if( TYPE(handler) == T_NIL ) {
331
+ callback_data->callback = T_NIL;
412
332
  callback_data->exit = true;
413
- ph_raise(CPhidget_set_OnServerDisconnect_Handler(ph->handle, NULL, (void *)NULL));
333
+ ph_raise(Phidget_setOnPropertyChangeHandler(ph->handle, NULL, (void *)NULL));
334
+ sem_post(&callback_data->callback_called);
414
335
  } else {
415
- callback_data->called = false;
416
336
  callback_data->exit = false;
417
337
  callback_data->phidget = self;
418
338
  callback_data->callback = handler;
419
- ph_raise(CPhidget_set_OnServerDisconnect_Handler(ph->handle, ph_common_on_server_disconnect, (void *)callback_data));
339
+ ph_raise(Phidget_setOnPropertyChangeHandler(ph->handle, ph_common_on_property_change, (void *)callback_data));
420
340
  ph_callback_thread(callback_data);
421
341
  }
422
342
  return Qnil;
423
343
  }
424
344
 
425
345
 
426
- int ph_common_on_attach(CPhidgetHandle phid, void *userPtr) {
427
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
428
- callback_data->called = true;
429
- return EPHIDGET_OK;
430
- }
346
+ void Init_common() {
347
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
348
+ VALUE ph_common = rb_define_class_under(ph_module, "Common", rb_cObject);
349
+ rb_define_alloc_func(ph_common, ph_common_allocate);
431
350
 
351
+ /* Document-method: open
352
+ * call-seq: open
353
+ *
354
+ * Opens the Phidget channel. The specific channel to be opened can be specified by setting any of the following properties:
355
+ * DeviceSerialNumber
356
+ * DeviceLabel
357
+ * Channel
358
+ * HubPort
359
+ * IsHubPortDevice
360
+ * ServerName
361
+ * IsLocal
362
+ * IsRemote
363
+ *
364
+ * open will return immediately, with the attachment process proceeding asynchronously. Use the Attach event or Attached property to determine when the channel is ready to use.
365
+ */
366
+ rb_define_method(ph_common, "open", ph_common_open, 0);
432
367
 
433
- int ph_common_on_detach(CPhidgetHandle phid, void *userPtr) {
434
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
435
- callback_data->called = true;
436
- return EPHIDGET_OK;
437
- }
368
+ /* Document-method: openWaitForAttachment
369
+ * call-seq: openWaitForAttachment(milliseconds)
370
+ *
371
+ * Opens the Phidget channel and waits a defined amount of time for the device to attach.The specific channel to be opened can be specified by setting any of the following properties:
372
+ * DeviceSerialNumber
373
+ * DeviceLabel
374
+ * Channel
375
+ * HubPort
376
+ * IsHubPortDevice
377
+ * ServerName
378
+ * IsLocal
379
+ * IsRemote
380
+ *
381
+ * openWaitForAttachment will block until the channel is attached or a timeout occurs. A timeout value of 0 will wait forever.
382
+ */
383
+ rb_define_method(ph_common, "openWaitForAttachment", ph_common_open_wait_for_attachment, 1);
384
+ rb_define_alias(ph_common, "open_wait_for_attachment", "openWaitForAttachment");
438
385
 
386
+ /* Document-method: getAttached
387
+ * call-seq: getAttached -> status
388
+ *
389
+ * Gets the attached status of channel. A Phidget is attached after it has been opened and the Phidget library finds and connects to the corresponding hardware device.
390
+ */
391
+ rb_define_method(ph_common, "getAttached", ph_common_get_attached, 0);
392
+ rb_define_alias(ph_common, "attached?", "getAttached");
439
393
 
440
- int ph_common_on_server_connect(CPhidgetHandle phid, void *userPtr) {
441
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
442
- callback_data->called = true;
443
- return EPHIDGET_OK;
444
- }
394
+ /* Document-method: close
395
+ * call-seq: close
396
+ *
397
+ * Closes a Phidget channel that has been opened.
398
+ */
399
+ rb_define_method(ph_common, "close", ph_common_close, 0);
445
400
 
401
+ /* Document-method: getDeviceChannelCount
402
+ * call-seq: getDeviceChannelCount(channel_class) -> channel_count
403
+ *
404
+ * Gets the number of channels of the specified channel class on the device. Pass Phidgets::CHCLASS_NOTHING to get the total number of channels.
405
+ */
406
+ rb_define_method(ph_common, "getDeviceChannelCount", ph_common_get_device_channel_count, 1);
407
+ rb_define_alias(ph_common, "device_channel_count", "getDeviceChannelCount");
446
408
 
447
- int ph_common_on_server_disconnect(CPhidgetHandle phid, void *userPtr) {
448
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
449
- callback_data->called = true;
450
- return EPHIDGET_OK;
409
+ /* Document-method: getDeviceClass
410
+ * call-seq: getDeviceClass -> device_class
411
+ *
412
+ * Gets the device class for the Phidget which this channel is a part of.
413
+ */
414
+ rb_define_method(ph_common, "getDeviceClass", ph_common_get_device_class, 0);
415
+ rb_define_alias(ph_common, "device_class", "getDeviceClass");
416
+
417
+ /* Document-method: getDeviceClassName
418
+ * call-seq: getDeviceClassName -> device_class_name
419
+ *
420
+ * Gets the name of the device class for the Phidget which this channel is a part of.
421
+ */
422
+ rb_define_method(ph_common, "getDeviceClassName", ph_common_get_device_class_name, 0);
423
+ rb_define_alias(ph_common, "device_class_name", "getDeviceClassName");
424
+
425
+ /* Document-method: getDeviceID
426
+ * call-seq: getDeviceID -> device_id
427
+ *
428
+ * Gets the DeviceID for the Phidget which this channel is a part of.
429
+ */
430
+ rb_define_method(ph_common, "getDeviceID", ph_common_get_device_id, 0);
431
+ rb_define_alias(ph_common, "device_id", "getDeviceID");
432
+
433
+ /* Document-method: getDeviceName
434
+ * call-seq: getDeviceName -> device_name
435
+ *
436
+ * Gets the name of the Phidget which this channel is a part of.
437
+ */
438
+ rb_define_method(ph_common, "getDeviceName", ph_common_get_device_name, 0);
439
+ rb_define_alias(ph_common, "device_name", "getDeviceName");
440
+
441
+ /* Document-method: getDeviceSerialNumber
442
+ * call-seq: getDeviceSerialNumber -> serial_number
443
+ *
444
+ * Gets the serial number of the Phidget which this channel is a part of.
445
+ * If the channel is part of a VINT device, this will be the serial number of the VINT Hub the device is attached to.
446
+ */
447
+ rb_define_method(ph_common, "getDeviceSerialNumber", ph_common_get_device_serial_number, 0);
448
+ rb_define_alias(ph_common, "device_serial_number", "getDeviceSerialNumber");
449
+
450
+ /* Document-method: setDeviceSerialNumber
451
+ * call-seq: setDeviceSerialNumber(serial_number)
452
+ *
453
+ * Specifies the serial number of the Phidget to be opened. Leave un-set, or set to Phidgets::SERIALNUMBER_ANY to open any serial number.
454
+ * If the channel is part of a VINT device, this will be the serial number of the VINT Hub the device is attached to.
455
+ *
456
+ * If setting this property, it must be set before the channel is opened. The behaviour of setting this property while the channel is open is undefined.
457
+ */
458
+ rb_define_method(ph_common, "setDeviceSerialNumber", ph_common_set_device_serial_number, 1);
459
+ rb_define_alias(ph_common, "device_serial_number=", "setDeviceSerialNumber");
460
+
461
+ /* Document-method: getDeviceSKU
462
+ * call-seq: getDeviceSKU -> device_sku
463
+ *
464
+ * Gets the SKU (part number) of the Phidget which this channel is a part of.
465
+ */
466
+ rb_define_method(ph_common, "getDeviceSKU", ph_common_get_device_sku, 0);
467
+ rb_define_alias(ph_common, "device_sku", "getDeviceSKU");
468
+
469
+ /* Document-method: getDeviceVersion
470
+ * call-seq: getDeviceVersion -> version
471
+ *
472
+ * Gets the firmware version of the Phidget which this channel is a part of.
473
+ */
474
+ rb_define_method(ph_common, "getDeviceVersion", ph_common_get_device_version, 0);
475
+ rb_define_alias(ph_common, "device_version", "getDeviceVersion");
476
+
477
+ /* Document-method: getDeviceLabel
478
+ * call-seq: getDeviceLabel -> label
479
+ *
480
+ * Gets the label of the Phidget which this channel is a part of. A device label is a custom string used to more easily identify a Phidget.
481
+ * Labels are written to a Phidget using writeDeviceLabel().
482
+ */
483
+ rb_define_method(ph_common, "getDeviceLabel", ph_common_get_device_label, 0);
484
+ rb_define_alias(ph_common, "device_label", "getDeviceLabel");
485
+
486
+ /* Document-method: setDeviceLabel
487
+ * call-seq: setDeviceLabel(label)
488
+ *
489
+ * Specifies the label of the Phidget to be opened. Leave un-set to open any label. A device label is a custom string used to more easily identify a Phidget.
490
+ * Labels are written to a Phidget using writeDeviceLabel().
491
+ */
492
+ rb_define_method(ph_common, "setDeviceLabel", ph_common_write_device_label, 1);
493
+ rb_define_alias(ph_common, "device_label=", "setDeviceLabel");
494
+
495
+ /* Document-method: writeDeviceLabel
496
+ * call-seq: writeDeviceLabel(label)
497
+ *
498
+ * Writes a label to the device in the form of a string in the device flash memory. This label can then be used to identify the device, and will persist across power cycles.
499
+ */
500
+ rb_define_method(ph_common, "writeDeviceLabel", ph_common_write_device_label, 1);
501
+ rb_define_alias(ph_common, "write_device_label", "writeDeviceLabel");
502
+
503
+ /* Document-method: getChannel
504
+ * call-seq: getChannel -> channel
505
+ *
506
+ * Gets the channel index of the channel on the device.
507
+ */
508
+ rb_define_method(ph_common, "getChannel", ph_common_get_channel, 0);
509
+ rb_define_alias(ph_common, "channel", "getChannel");
510
+
511
+ /* Document-method: setChannel
512
+ * call-seq: setChannel(channel)
513
+ *
514
+ * Specifies the channel index to be opened. The default channel is 0. Set to PHIDGET_CHANNEL_ANY to open any channel on the specified device.
515
+ * If setting this property, it must be set before the channel is opened. The behaviour of setting this property while the channel is open is undefined.
516
+ */
517
+ rb_define_method(ph_common, "setChannel", ph_common_set_channel, 1);
518
+ rb_define_alias(ph_common, "channel=", "setChannel");
519
+
520
+ /* Document-method: getChannelName
521
+ * call-seq: getChannelName -> channel_name
522
+ *
523
+ * Gets the channel's name. This name serves as a description of the specific nature of the channel.
524
+ */
525
+ rb_define_method(ph_common, "getChannelName", ph_common_get_channel_name, 0);
526
+ rb_define_alias(ph_common, "channel_name", "getChannelName");
527
+
528
+ /* Document-method: getChannelClass
529
+ * call-seq: getChannelClass -> channel_class
530
+ *
531
+ * Gets the channel class of the channel.
532
+ */
533
+ rb_define_method(ph_common, "getChannelClass", ph_common_get_channel_class, 0);
534
+ rb_define_alias(ph_common, "channel_class", "getChannelClass");
535
+
536
+ /* Document-method: getChannelClassName
537
+ * call-seq: getChannelClassName -> channel_class_name
538
+ *
539
+ * Gets the name of the channel class the channel belongs to.
540
+ */
541
+ rb_define_method(ph_common, "getChannelClassName", ph_common_get_channel_class_name, 0);
542
+ rb_define_alias(ph_common, "channel_class_name", "getChannelClassName");
543
+
544
+ /* Document-method: getChannelSubclass
545
+ * call-seq: getChannelSubclass -> channel_subclass
546
+ *
547
+ * Gets the subclass for this channel. Allows for identifying channels with specific characteristics without needing to know the exact device and channel index.
548
+ */
549
+ rb_define_method(ph_common, "getChannelSubclass", ph_common_get_channel_subclass, 0);
550
+ rb_define_alias(ph_common, "channel_subclass", "getChannelSubclass");
551
+
552
+ /* Document-method: getDataInterval
553
+ * call-seq: getDataInterval -> data_interval
554
+ *
555
+ * Gets the data interval for any channel that supports one.
556
+ * The DataInterval is the time that must elapse before the channel will fire another data event.
557
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
558
+ * The timing between data events can also be affected by the specific change trigger for the channel.
559
+ */
560
+ rb_define_method(ph_common, "getDataInterval", ph_common_get_data_interval, 0);
561
+ rb_define_alias(ph_common, "data_interval", "getDataInterval");
562
+
563
+ /* Document-method: setDataInterval
564
+ * call-seq: setDataInterval(data_interval)
565
+ *
566
+ * Sets the data interval for any channel that supports one.
567
+ * The DataInterval is the time that must elapse before the channel will fire another data event.
568
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
569
+ * The timing between data events can also be affected by the specific change trigger for the channel.
570
+ */
571
+ rb_define_method(ph_common, "setDataInterval", ph_common_set_data_interval, 1);
572
+ rb_define_alias(ph_common, "data_interval=", "setDataInterval");
573
+
574
+ /* Document-method: getHubPort
575
+ * call-seq: getHubPort -> hub_port
576
+ *
577
+ * Gets the hub port index of the VINT Hub port that the channel is attached to.
578
+ */
579
+ rb_define_method(ph_common, "getHubPort", ph_common_get_hub_port, 0);
580
+ rb_define_alias(ph_common, "hub_port", "getHubPort");
581
+
582
+ /* Document-method: setHubPort
583
+ * call-seq: setHubPort(hub_port)
584
+ *
585
+ * Specifies the hub port index of the VINT Hub port to open this channel on. Leave un-set, or set to Phidgets::HUBPORT_ANY to open the channel on any VINT Hub port.
586
+ */
587
+ rb_define_method(ph_common, "setHubPort", ph_common_set_hub_port, 1);
588
+ rb_define_alias(ph_common, "hub_port=", "setHubPort");
589
+
590
+ /* Document-method: getHubPortCount
591
+ * call-seq: getHubPortCount -> hub_port_count
592
+ *
593
+ * Gets the number of VINT ports present on the VINT Hub that the channel is attached to.
594
+ */
595
+ rb_define_method(ph_common, "getHubPortCount", ph_common_get_hub_port_count, 0);
596
+ rb_define_alias(ph_common, "hub_port_count", "getHubPortCount");
597
+
598
+ /* Document-method: getIsChannel
599
+ * call-seq: getIsChannel -> is_channel
600
+ *
601
+ * Returns true if it is a channel. Mostly for use alongside getParent() to distinguish channel handles from device handles.
602
+ */
603
+ rb_define_method(ph_common, "getIsChannel", ph_common_get_is_channel, 0);
604
+ rb_define_alias(ph_common, "is_channel?", "getIsChannel");
605
+
606
+ /* Document-method: getIsHubPortDevice
607
+ * call-seq: getIsHubPortDevice -> is_hub_port_device
608
+ *
609
+ * Gets whether this channel is a VINT Hub port channel, or part of a VINT device attached to a hub port.
610
+ */
611
+ rb_define_method(ph_common, "getIsHubPortDevice", ph_common_get_is_hub_port_device, 0);
612
+ rb_define_alias(ph_common, "is_hub_port_device?", "getIsHubPortDevice");
613
+
614
+ /* Document-method: setIsHubPortDevice
615
+ * call-seq: setIsHubPortDevice(is_hub_port_device)
616
+ *
617
+ * Specifies whether this channel should be opened on a VINT Hub port directly, or on a VINT device attached to a hub port.
618
+ */
619
+ rb_define_method(ph_common, "setIsHubPortDevice", ph_common_set_is_hub_port_device, 1);
620
+ rb_define_alias(ph_common, "is_hub_port_device=", "setIsHubPortDevice");
621
+
622
+ /* Document-method: getIsLocal
623
+ * call-seq: getIsLocal -> is_local
624
+ *
625
+ * Returns true when this channel is attached directly on the local machine, or false otherwise.
626
+ */
627
+ rb_define_method(ph_common, "getIsLocal", ph_common_get_is_local, 0);
628
+ rb_define_alias(ph_common, "is_local?", "getIsLocal");
629
+
630
+ /* Document-method: setIsLocal
631
+ * call-seq: setIsLocal(is_local)
632
+ *
633
+ * Set to true if the channel is to be opened locally, and not over a network. If both this and IsRemote are set to False (the default),
634
+ * the channel will be opened either locally or remotely, on whichever matching channel is found first.
635
+ */
636
+ rb_define_method(ph_common, "setIsLocal", ph_common_set_is_local, 1);
637
+ rb_define_alias(ph_common, "is_local=", "setIsLocal");
638
+
639
+ /* Document-method: getIsRemote
640
+ * call-seq: getIsRemote -> is_remote
641
+ *
642
+ * Returns true when this channel is attached via a Phidget network server, or false otherwise.
643
+ */
644
+ rb_define_method(ph_common, "getIsRemote", ph_common_get_is_remote, 0);
645
+ rb_define_alias(ph_common, "is_remote?", "getIsRemote");
646
+
647
+ /* Document-method: setIsRemote
648
+ * call-seq: setIsRemote(is_remote)
649
+ *
650
+ * Set to true if the channel is to be opened remotely, rather than locally. If both this and IsLocal are set to False (the default),
651
+ * the channel will be opened either locally or remotely, on whichever matching channel is found first.
652
+ */
653
+ rb_define_method(ph_common, "setIsRemote", ph_common_set_is_remote, 1);
654
+ rb_define_alias(ph_common, "is_remote=", "setIsRemote");
655
+
656
+ /* Document-method: getServerHostname
657
+ * call-seq: getServerHostname -> server_hostname
658
+ *
659
+ * Gets the hostname of the Phidget network server for network attached Phidgets.
660
+ * Fails if the channel is not connected to a Phidget network server.
661
+ */
662
+ rb_define_method(ph_common, "getServerHostname", ph_common_get_server_hostname, 0);
663
+ rb_define_alias(ph_common, "server_hostname", "getServerHostname");
664
+
665
+ /* Document-method: getServerName
666
+ * call-seq: getServerName -> server_name
667
+ *
668
+ * Gets the name of the Phidget network server the channel is attached to, if any.
669
+ * Fails if the channel is not connected to a Phidget network server.
670
+ */
671
+ rb_define_method(ph_common, "getServerName", ph_common_get_server_name, 0);
672
+ rb_define_alias(ph_common, "server_name", "getServerName");
673
+
674
+ /* Document-method: setServerName
675
+ * call-seq: setServerName(server_name)
676
+ *
677
+ * Specifies that this channel will be opened remotely, on a Phidget network server with this name.
678
+ * This function should only be used if you want your Phidget to be found on a specific server, and does not need to be specified if the Phidget can be on any any available server.
679
+ * In order for your program to have access to remote Phidgets, you must use the Networking API to EnableServerDiscovery or AddServer.
680
+ * If setting this property, it must be set before the channel is opened. The behaviour of setting this property while the channel is open is undefined.
681
+ */
682
+ rb_define_method(ph_common, "setServerName", ph_common_set_server_name, 1);
683
+ rb_define_alias(ph_common, "server_name=", "setServerName");
684
+
685
+ /* Document-method: getServerPeerName
686
+ * call-seq: getServerPeerName -> peer_name
687
+ *
688
+ * Gets the peer name (address and port) of the Phidget server for network attached Phidgets, formatted as: address:port
689
+ * Fails if the channel is not connected to a Phidget network server.
690
+ */
691
+ rb_define_method(ph_common, "getServerPeerName", ph_common_get_server_peer_name, 0);
692
+ rb_define_alias(ph_common, "server_peer_name", "getServerPeerName");
693
+
694
+ /* Document-method: getServerUniqueName
695
+ * call-seq: getServerUniqueName -> unique_name
696
+ *
697
+ * Gets the unique name for the server the channel is attached to, if any. This is either a unique mDNS name, or the name specified in addServer
698
+ * Fails if the channel is not connected to a Phidget network server.
699
+ */
700
+ rb_define_method(ph_common, "getServerUniqueName", ph_common_get_server_unique_name, 0);
701
+ rb_define_alias(ph_common, "server_unique_name", "getServerUniqueName");
702
+
703
+ rb_define_private_method(ph_common, "ext_setOnAttachHandler", ph_common_set_on_attach_handler, 1);
704
+ rb_define_private_method(ph_common, "ext_setOnDetachHandler", ph_common_set_on_detach_handler, 1);
705
+ rb_define_private_method(ph_common, "ext_setOnErrorHandler", ph_common_set_on_error_handler, 1);
706
+ rb_define_private_method(ph_common, "ext_setOnPropertyChangeHandler", ph_common_set_on_property_change_handler, 1);
451
707
  }
452
- #endif
453
708