phidgets 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +3 -0
- data/README.rdoc +32 -43
- data/Rakefile +4 -2
- data/bin/phidget +18 -72
- data/ext/phidgets/extconf.rb +5 -8
- data/ext/phidgets/phidgets.c +708 -173
- data/ext/phidgets/phidgets.h +54 -35
- data/ext/phidgets/phidgets_accelerometer.c +193 -109
- data/ext/phidgets/phidgets_bldc_motor.c +529 -0
- data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
- data/ext/phidgets/phidgets_common.c +570 -315
- data/ext/phidgets/phidgets_current_input.c +229 -0
- data/ext/phidgets/phidgets_dc_motor.c +562 -0
- data/ext/phidgets/phidgets_dictionary.c +154 -213
- data/ext/phidgets/phidgets_digital_input.c +127 -0
- data/ext/phidgets/phidgets_digital_output.c +288 -0
- data/ext/phidgets/phidgets_distance_sensor.c +295 -0
- data/ext/phidgets/phidgets_encoder.c +211 -192
- data/ext/phidgets/phidgets_frequency_counter.c +310 -177
- data/ext/phidgets/phidgets_gps.c +226 -164
- data/ext/phidgets/phidgets_gyroscope.c +195 -0
- data/ext/phidgets/phidgets_hub.c +39 -0
- data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
- data/ext/phidgets/phidgets_ir.c +211 -171
- data/ext/phidgets/phidgets_lcd.c +512 -0
- data/ext/phidgets/phidgets_light_sensor.c +200 -0
- data/ext/phidgets/phidgets_log.c +263 -0
- data/ext/phidgets/phidgets_magnetometer.c +279 -0
- data/ext/phidgets/phidgets_manager.c +86 -297
- data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
- data/ext/phidgets/phidgets_phsensor.c +200 -152
- data/ext/phidgets/phidgets_power_guard.c +144 -0
- data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
- data/ext/phidgets/phidgets_rc_servo.c +672 -0
- data/ext/phidgets/phidgets_resistance_input.c +227 -0
- data/ext/phidgets/phidgets_rfid.c +107 -221
- data/ext/phidgets/phidgets_sound_sensor.c +284 -0
- data/ext/phidgets/phidgets_spatial.c +124 -318
- data/ext/phidgets/phidgets_stepper.c +457 -430
- data/ext/phidgets/phidgets_temp_sensor.c +223 -228
- data/ext/phidgets/phidgets_voltage_input.c +428 -0
- data/ext/phidgets/phidgets_voltage_output.c +167 -0
- data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
- data/lib/phidgets.rb +21 -14
- data/lib/phidgets/accelerometer.rb +11 -15
- data/lib/phidgets/bldc_motor.rb +45 -0
- data/lib/phidgets/capacitive_touch.rb +33 -0
- data/lib/phidgets/common.rb +40 -69
- data/lib/phidgets/current_input.rb +21 -0
- data/lib/phidgets/dc_motor.rb +45 -0
- data/lib/phidgets/dictionary.rb +30 -39
- data/lib/phidgets/digital_input.rb +21 -0
- data/lib/phidgets/digital_output.rb +56 -0
- data/lib/phidgets/distance_sensor.rb +33 -0
- data/lib/phidgets/encoder.rb +1 -29
- data/lib/phidgets/frequency_counter.rb +23 -14
- data/lib/phidgets/gps.rb +34 -26
- data/lib/phidgets/gyroscope.rb +21 -0
- data/lib/phidgets/humidity_sensor.rb +21 -0
- data/lib/phidgets/ir.rb +34 -39
- data/lib/phidgets/light_sensor.rb +21 -0
- data/lib/phidgets/magnetometer.rb +21 -0
- data/lib/phidgets/manager.rb +18 -66
- data/lib/phidgets/motor_position_controller.rb +45 -0
- data/lib/phidgets/ph_sensor.rb +2 -6
- data/lib/phidgets/pressure_sensor.rb +21 -0
- data/lib/phidgets/rc_servo.rb +58 -0
- data/lib/phidgets/resistance_input.rb +21 -0
- data/lib/phidgets/rfid.rb +22 -38
- data/lib/phidgets/sound_sensor.rb +21 -0
- data/lib/phidgets/spatial.rb +11 -15
- data/lib/phidgets/stepper.rb +48 -50
- data/lib/phidgets/temperature_sensor.rb +11 -15
- data/lib/phidgets/version.rb +5 -0
- data/lib/phidgets/voltage_input.rb +34 -0
- data/lib/phidgets/voltage_output.rb +23 -0
- data/lib/phidgets/voltage_ratio_input.rb +34 -0
- data/phidgets.gemspec +3 -22
- data/test/test_accelerometer.rb +42 -23
- data/test/test_bldc_motor.rb +134 -0
- data/test/test_capacitive_touch.rb +82 -0
- data/test/test_common.rb +125 -108
- data/test/test_current_input.rb +62 -0
- data/test/test_dc_motor.rb +146 -0
- data/test/test_dictionary.rb +22 -54
- data/test/test_digital_input.rb +30 -0
- data/test/test_digital_output.rb +70 -0
- data/test/test_distance_sensor.rb +76 -0
- data/test/test_encoder.rb +45 -38
- data/test/test_frequency_counter.rb +71 -36
- data/test/test_gps.rb +29 -38
- data/test/test_gyroscope.rb +54 -0
- data/test/test_helper.rb +0 -1
- data/test/test_hub.rb +14 -0
- data/test/test_humidity_sensor.rb +58 -0
- data/test/test_ir.rb +34 -34
- data/test/test_lcd.rb +146 -0
- data/test/test_light_sensor.rb +58 -0
- data/test/test_magnetometer.rb +78 -0
- data/test/test_manager.rb +10 -79
- data/test/test_motor_control.rb +146 -108
- data/test/test_phidgets.rb +2 -14
- data/test/test_phsensor.rb +46 -34
- data/test/test_power_guard.rb +42 -0
- data/test/test_pressure_sensor.rb +58 -0
- data/test/test_rc_servo.rb +174 -0
- data/test/test_resistance_input.rb +66 -0
- data/test/test_rfid.rb +15 -54
- data/test/test_sound_sensor.rb +78 -0
- data/test/test_spatial.rb +19 -85
- data/test/test_stepper.rb +89 -98
- data/test/test_temp_sensor.rb +42 -47
- data/test/test_voltage_input.rb +102 -0
- data/test/test_voltage_output.rb +46 -0
- data/test/test_voltage_ratio_input.rb +102 -0
- metadata +72 -89
- data/ext/phidgets/phidgets_advanced_servo.c +0 -567
- data/ext/phidgets/phidgets_analog.c +0 -139
- data/ext/phidgets/phidgets_bridge.c +0 -263
- data/ext/phidgets/phidgets_interface_kit.c +0 -340
- data/ext/phidgets/phidgets_led.c +0 -178
- data/ext/phidgets/phidgets_motor_control.c +0 -642
- data/ext/phidgets/phidgets_servo.c +0 -276
- data/ext/phidgets/phidgets_text_lcd.c +0 -381
- data/ext/phidgets/phidgets_text_led.c +0 -107
- data/ext/phidgets/phidgets_weight_sensor.c +0 -113
- data/lib/phidgets/advanced_servo.rb +0 -49
- data/lib/phidgets/analog.rb +0 -8
- data/lib/phidgets/bridge.rb +0 -25
- data/lib/phidgets/interfacekit.rb +0 -49
- data/lib/phidgets/led.rb +0 -8
- data/lib/phidgets/motor_control.rb +0 -110
- data/lib/phidgets/servo.rb +0 -23
- data/lib/phidgets/text_lcd.rb +0 -8
- data/lib/phidgets/text_led.rb +0 -8
- data/lib/phidgets/weight_sensor.rb +0 -25
- data/test/test_advanced_servo.rb +0 -152
- data/test/test_analog.rb +0 -45
- data/test/test_bridge.rb +0 -77
- data/test/test_interfacekit.rb +0 -97
- data/test/test_led.rb +0 -55
- data/test/test_servo.rb +0 -67
- data/test/test_text_lcd.rb +0 -115
- data/test/test_text_led.rb +0 -35
- data/test/test_weight_sensor.rb +0 -32
@@ -0,0 +1,284 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
#define SOUND_SENSOR_SPL_CHANGE_CALLBACK 0
|
5
|
+
|
6
|
+
|
7
|
+
VALUE ph_sound_init(VALUE self) {
|
8
|
+
ph_data_t *ph = get_ph_data(self);
|
9
|
+
ph_raise(PhidgetSoundSensor_create((PhidgetSoundSensorHandle *)(&(ph->handle))));
|
10
|
+
return self;
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE ph_sound_get_data_interval(VALUE self) {
|
14
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSoundSensor_getDataInterval);
|
15
|
+
}
|
16
|
+
|
17
|
+
VALUE ph_sound_set_data_interval(VALUE self, VALUE interval) {
|
18
|
+
ph_raise(PhidgetSoundSensor_setDataInterval((PhidgetSoundSensorHandle)get_ph_handle(self), NUM2UINT(interval)));
|
19
|
+
return Qnil;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE ph_sound_get_min_data_interval(VALUE self) {
|
23
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSoundSensor_getMinDataInterval);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE ph_sound_get_max_data_interval(VALUE self) {
|
27
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSoundSensor_getMaxDataInterval);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE ph_sound_get_db(VALUE self) {
|
31
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getdB);
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE ph_sound_get_max_db(VALUE self) {
|
35
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getMaxdB);
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE ph_sound_get_dba(VALUE self) {
|
39
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getdBA);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE ph_sound_get_dbc(VALUE self) {
|
43
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getdBC);
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE ph_sound_get_noise_floor(VALUE self) {
|
47
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getNoiseFloor);
|
48
|
+
}
|
49
|
+
|
50
|
+
VALUE ph_sound_get_octaves(VALUE self) {
|
51
|
+
double octaves[10];
|
52
|
+
ph_raise(PhidgetSoundSensor_getOctaves((PhidgetSoundSensorHandle)get_ph_handle(self), &octaves));
|
53
|
+
return rb_ary_new3(10, DBL2NUM(octaves[0]), DBL2NUM(octaves[1]), DBL2NUM(octaves[2]), DBL2NUM(octaves[3]), DBL2NUM(octaves[4]), DBL2NUM(octaves[5]), DBL2NUM(octaves[6]), DBL2NUM(octaves[7]), DBL2NUM(octaves[8]), DBL2NUM(octaves[9]));
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE ph_sound_get_spl_change_trigger(VALUE self) {
|
57
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getSPLChangeTrigger);
|
58
|
+
}
|
59
|
+
|
60
|
+
VALUE ph_sound_set_spl_change_trigger(VALUE self, VALUE change_trigger) {
|
61
|
+
ph_raise(PhidgetSoundSensor_setSPLChangeTrigger((PhidgetSoundSensorHandle)get_ph_handle(self), NUM2DBL(change_trigger)));
|
62
|
+
return Qnil;
|
63
|
+
}
|
64
|
+
|
65
|
+
VALUE ph_sound_get_min_spl_change_trigger(VALUE self) {
|
66
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getMinSPLChangeTrigger);
|
67
|
+
}
|
68
|
+
|
69
|
+
VALUE ph_sound_get_max_spl_change_trigger(VALUE self) {
|
70
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetSoundSensor_getMaxSPLChangeTrigger);
|
71
|
+
}
|
72
|
+
|
73
|
+
VALUE ph_sound_get_spl_range(VALUE self) {
|
74
|
+
return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetSoundSensor_getSPLRange);
|
75
|
+
}
|
76
|
+
|
77
|
+
VALUE ph_sound_set_spl_range(VALUE self, VALUE spl_range) {
|
78
|
+
ph_raise(PhidgetSoundSensor_setSPLRange((PhidgetSoundSensorHandle)get_ph_handle(self), NUM2INT(spl_range)));
|
79
|
+
return Qnil;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
void CCONV ph_sound_on_spl_change(PhidgetSoundSensorHandle phid, void *userPtr, double db, double dba, double dbc, const double octaves[10]) {
|
84
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
85
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
86
|
+
callback_data->arg1 = DBL2NUM(db);
|
87
|
+
callback_data->arg2 = DBL2NUM(dba);
|
88
|
+
callback_data->arg3 = DBL2NUM(dbc);
|
89
|
+
callback_data->arg4 = rb_ary_new3(10, DBL2NUM(octaves[0]), DBL2NUM(octaves[1]), DBL2NUM(octaves[2]), DBL2NUM(octaves[3]), DBL2NUM(octaves[4]), DBL2NUM(octaves[5]), DBL2NUM(octaves[6]), DBL2NUM(octaves[7]), DBL2NUM(octaves[8]), DBL2NUM(octaves[9]));
|
90
|
+
sem_post(&callback_data->callback_called);
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
VALUE ph_sound_set_on_spl_change_handler(VALUE self, VALUE handler) {
|
95
|
+
ph_data_t *ph = get_ph_data(self);
|
96
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[SOUND_SENSOR_SPL_CHANGE_CALLBACK];
|
97
|
+
if( TYPE(handler) == T_NIL ) {
|
98
|
+
callback_data->callback = T_NIL;
|
99
|
+
callback_data->exit = true;
|
100
|
+
ph_raise(PhidgetSoundSensor_setOnSPLChangeHandler((PhidgetSoundSensorHandle)ph->handle, NULL, (void *)NULL));
|
101
|
+
sem_post(&callback_data->callback_called);
|
102
|
+
} else {
|
103
|
+
callback_data->exit = false;
|
104
|
+
callback_data->phidget = self;
|
105
|
+
callback_data->callback = handler;
|
106
|
+
ph_raise(PhidgetSoundSensor_setOnSPLChangeHandler((PhidgetSoundSensorHandle)ph->handle, ph_sound_on_spl_change, (void *)callback_data));
|
107
|
+
ph_callback_thread(callback_data);
|
108
|
+
}
|
109
|
+
return Qnil;
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
void Init_sound() {
|
114
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
115
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
116
|
+
VALUE ph_sound = rb_define_class_under(ph_module, "SoundSensor", ph_common);
|
117
|
+
|
118
|
+
|
119
|
+
rb_define_const(ph_sound, "SPL_RANGE_102dB", INT2NUM(SPL_RANGE_102dB));
|
120
|
+
rb_define_const(ph_sound, "SPL_RANGE_82dB", INT2NUM(SPL_RANGE_82dB));
|
121
|
+
|
122
|
+
|
123
|
+
/* Document-method: new
|
124
|
+
* call-seq: new
|
125
|
+
*
|
126
|
+
* Creates a Phidget SoundSensor object.
|
127
|
+
*/
|
128
|
+
rb_define_method(ph_sound, "initialize", ph_sound_init, 0);
|
129
|
+
|
130
|
+
/* Document-method: getDataInterval
|
131
|
+
* call-seq: getDataInterval -> interval
|
132
|
+
*
|
133
|
+
* The DataInterval is the time that must elapse before the channel will fire another SPLChange event.
|
134
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
135
|
+
* The timing between SPLChange events can also affected by the SPLChangeTrigger.
|
136
|
+
*/
|
137
|
+
rb_define_method(ph_sound, "getDataInterval", ph_sound_get_data_interval, 0);
|
138
|
+
rb_define_alias(ph_sound, "data_interval", "getDataInterval");
|
139
|
+
|
140
|
+
/* Document-method: setDataInterval
|
141
|
+
* call-seq: setDataInterval(interval)
|
142
|
+
*
|
143
|
+
* The DataInterval is the time that must elapse before the channel will fire another SPLChange event.
|
144
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
145
|
+
* The timing between SPLChange events can also affected by the SPLChangeTrigger.
|
146
|
+
*/
|
147
|
+
rb_define_method(ph_sound, "setDataInterval", ph_sound_set_data_interval, 1);
|
148
|
+
rb_define_alias(ph_sound, "data_interval=", "setDataInterval");
|
149
|
+
|
150
|
+
/* Document-method: getMinDataInterval
|
151
|
+
* call-seq: getMinDataInterval -> interval
|
152
|
+
*
|
153
|
+
* The minimum value that DataInterval can be set to.
|
154
|
+
*/
|
155
|
+
rb_define_method(ph_sound, "getMinDataInterval", ph_sound_get_min_data_interval, 0);
|
156
|
+
rb_define_alias(ph_sound, "min_data_interval", "getMinDataInterval");
|
157
|
+
|
158
|
+
/* Document-method: getMaxDataInterval
|
159
|
+
* call-seq: getMaxDataInterval -> interval
|
160
|
+
*
|
161
|
+
* The maximum value that DataInterval can be set to.
|
162
|
+
*/
|
163
|
+
rb_define_method(ph_sound, "getMaxDataInterval", ph_sound_get_max_data_interval, 0);
|
164
|
+
rb_define_alias(ph_sound, "max_data_interval", "getMaxDataInterval");
|
165
|
+
|
166
|
+
/* Document-method: getdB
|
167
|
+
* call-seq: getdB -> db
|
168
|
+
*
|
169
|
+
* The most recent dB SPL value that has been calculated.
|
170
|
+
* This value is bounded by MaxdB.
|
171
|
+
*/
|
172
|
+
rb_define_method(ph_sound, "getdB", ph_sound_get_db, 0);
|
173
|
+
rb_define_alias(ph_sound, "db", "getdB");
|
174
|
+
|
175
|
+
/* Document-method: getMaxdB
|
176
|
+
* call-seq: getMaxdB -> db
|
177
|
+
*
|
178
|
+
* The maximum value the SPLChange event will report.
|
179
|
+
*/
|
180
|
+
rb_define_method(ph_sound, "getMaxdB", ph_sound_get_max_db, 0);
|
181
|
+
rb_define_alias(ph_sound, "max_db", "getMaxdB");
|
182
|
+
|
183
|
+
/* Document-method: getdBA
|
184
|
+
* call-seq: getdBA -> dba
|
185
|
+
*
|
186
|
+
* The most recent dBA SPL value that has been calculated.
|
187
|
+
* The dBA SPL value is calculated by applying a A-weighted filter to the Octaves data.
|
188
|
+
*/
|
189
|
+
rb_define_method(ph_sound, "getdBA", ph_sound_get_dba, 0);
|
190
|
+
rb_define_alias(ph_sound, "dba", "getdBA");
|
191
|
+
|
192
|
+
/* Document-method: getdBC
|
193
|
+
* call-seq: getdBC -> dbc
|
194
|
+
*
|
195
|
+
* The most recent dBC SPL value that has been calculated.
|
196
|
+
* The dBC SPL value is calculated by applying a C-weighted filter to the Octaves data.
|
197
|
+
*/
|
198
|
+
rb_define_method(ph_sound, "getdBC", ph_sound_get_dbc, 0);
|
199
|
+
rb_define_alias(ph_sound, "dbc", "getdBC");
|
200
|
+
|
201
|
+
/* Document-method: getNoiseFloor
|
202
|
+
* call-seq: getNoiseFloor -> noise_floor
|
203
|
+
*
|
204
|
+
* The minimum SPL value that the channel can accurately measure.
|
205
|
+
* Input SPLs below this level will not produce an output from the microphone.
|
206
|
+
*/
|
207
|
+
rb_define_method(ph_sound, "getNoiseFloor", ph_sound_get_noise_floor, 0);
|
208
|
+
rb_define_alias(ph_sound, "noise_floor", "getNoiseFloor");
|
209
|
+
|
210
|
+
/* Document-method: getOctaves
|
211
|
+
* call-seq: getOctaves -> octaves
|
212
|
+
*
|
213
|
+
* The unweighted value of each frequency band.
|
214
|
+
* The following frequency bands are represented:
|
215
|
+
* octaves[0] = 31.5 Hz
|
216
|
+
* octaves[1] = 63 Hz
|
217
|
+
* octaves[2] = 125 Hz
|
218
|
+
* octaves[3] = 250 Hz
|
219
|
+
* octaves[4] = 500 Hz
|
220
|
+
* octaves[5] = 1 kHz
|
221
|
+
* octaves[6] = 2 kHz
|
222
|
+
* octaves[7] = 4 kHz
|
223
|
+
* octaves[8] = 8 kHz
|
224
|
+
* octaves[9] = 16 kHz
|
225
|
+
*/
|
226
|
+
rb_define_method(ph_sound, "getOctaves", ph_sound_get_octaves, 0);
|
227
|
+
rb_define_alias(ph_sound, "octaves", "getOctaves");
|
228
|
+
|
229
|
+
/* Document-method: getSPLChangeTrigger
|
230
|
+
* call-seq: getSPLChangeTrigger -> change_trigger
|
231
|
+
*
|
232
|
+
* The channel will not issue a SPLChange event until the dB value has changed by the amount specified by the SPLChangeTrigger.
|
233
|
+
* Setting the SPLChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
234
|
+
*/
|
235
|
+
rb_define_method(ph_sound, "getSPLChangeTrigger", ph_sound_get_spl_change_trigger, 0);
|
236
|
+
rb_define_alias(ph_sound, "spl_change_trigger", "getSPLChangeTrigger");
|
237
|
+
|
238
|
+
/* Document-method: setSPLChangeTrigger
|
239
|
+
* call-seq: setSPLChangeTrigger(change_trigger)
|
240
|
+
*
|
241
|
+
* The channel will not issue a SPLChange event until the dB value has changed by the amount specified by the SPLChangeTrigger.
|
242
|
+
* Setting the SPLChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
243
|
+
*/
|
244
|
+
rb_define_method(ph_sound, "setSPLChangeTrigger", ph_sound_set_spl_change_trigger, 1);
|
245
|
+
rb_define_alias(ph_sound, "spl_change_trigger=", "setSPLChangeTrigger");
|
246
|
+
|
247
|
+
/* Document-method: getMinSPLChangeTrigger
|
248
|
+
* call-seq: getMinSPLChangeTrigger -> change_trigger
|
249
|
+
*
|
250
|
+
* The minimum value that SPLChangeTrigger can be set to.
|
251
|
+
*/
|
252
|
+
rb_define_method(ph_sound, "getMinSPLChangeTrigger", ph_sound_get_min_spl_change_trigger, 0);
|
253
|
+
rb_define_alias(ph_sound, "min_spl_change_trigger", "getMinSPLChangeTrigger");
|
254
|
+
|
255
|
+
/* Document-method: getMaxSPLChangeTrigger
|
256
|
+
* call-seq: getMaxSPLChangeTrigger -> change_trigger
|
257
|
+
*
|
258
|
+
* The maximum value that SPLChangeTrigger can be set to.
|
259
|
+
*/
|
260
|
+
rb_define_method(ph_sound, "getMaxSPLChangeTrigger", ph_sound_get_max_spl_change_trigger, 0);
|
261
|
+
rb_define_alias(ph_sound, "max_spl_change_trigger", "getMaxSPLChangeTrigger");
|
262
|
+
|
263
|
+
/* Document-method: getSPLRange
|
264
|
+
* call-seq: getSPLRange -> spl_range
|
265
|
+
*
|
266
|
+
* When selecting a range, first decide how sensitive you want the microphone to be. Select a smaller range when you want more sensitivity from the microphone.
|
267
|
+
* If a Saturation event occurrs, increase the range.
|
268
|
+
*/
|
269
|
+
rb_define_method(ph_sound, "getSPLRange", ph_sound_get_spl_range, 0);
|
270
|
+
rb_define_alias(ph_sound, "spl_range", "getSPLRange");
|
271
|
+
|
272
|
+
/* Document-method: setSPLRange
|
273
|
+
* call-seq: setSPLRange(spl_range)
|
274
|
+
*
|
275
|
+
* When selecting a range, first decide how sensitive you want the microphone to be. Select a smaller range when you want more sensitivity from the microphone.
|
276
|
+
* If a Saturation event occurrs, increase the range.
|
277
|
+
*/
|
278
|
+
rb_define_method(ph_sound, "setSPLRange", ph_sound_set_spl_range, 1);
|
279
|
+
rb_define_alias(ph_sound, "spl_range=", "setSPLRange");
|
280
|
+
|
281
|
+
|
282
|
+
rb_define_private_method(ph_sound, "ext_setOnSPLChangeHandler", ph_sound_set_on_spl_change_handler, 1);
|
283
|
+
}
|
284
|
+
|
@@ -1,369 +1,175 @@
|
|
1
1
|
|
2
2
|
#include "phidgets.h"
|
3
3
|
|
4
|
+
#define SPATIAL_SPATIAL_DATA_CALLBACK 0
|
4
5
|
|
5
|
-
VALUE ph_spatial_init(VALUE self);
|
6
|
-
VALUE ph_spatial_get_acceleration_axis_count(VALUE self);
|
7
|
-
VALUE ph_spatial_get_gyro_axis_count(VALUE self);
|
8
|
-
VALUE ph_spatial_get_compass_axis_count(VALUE self);
|
9
|
-
VALUE ph_spatial_get_acceleration(VALUE self, VALUE index);
|
10
|
-
VALUE ph_spatial_get_acceleration_min(VALUE self, VALUE index);
|
11
|
-
VALUE ph_spatial_get_acceleration_max(VALUE self, VALUE index);
|
12
|
-
VALUE ph_spatial_get_angular_rate(VALUE self, VALUE index);
|
13
|
-
VALUE ph_spatial_get_angular_rate_min(VALUE self, VALUE index);
|
14
|
-
VALUE ph_spatial_get_angular_rate_max(VALUE self, VALUE index);
|
15
|
-
VALUE ph_spatial_get_magnetic_field(VALUE self, VALUE index);
|
16
|
-
VALUE ph_spatial_get_magnetic_field_min(VALUE self, VALUE index);
|
17
|
-
VALUE ph_spatial_get_magnetic_field_max(VALUE self, VALUE index);
|
18
|
-
VALUE ph_spatial_get_data_rate(VALUE self);
|
19
|
-
VALUE ph_spatial_get_data_rate_min(VALUE self);
|
20
|
-
VALUE ph_spatial_get_data_rate_max(VALUE self);
|
21
|
-
VALUE ph_spatial_set_data_rate(VALUE self, VALUE rate);
|
22
|
-
VALUE ph_spatial_zero_gyro(VALUE self);
|
23
|
-
VALUE ph_spatial_set_compass_correction_parameters(VALUE self, VALUE mag_field, VALUE offset0, VALUE offset1, VALUE offset2, VALUE gain0, VALUE gain1, VALUE gain2, VALUE T0, VALUE T1, VALUE T2, VALUE T3, VALUE T4, VALUE T5);
|
24
|
-
VALUE ph_spatial_reset_compass_correction_parameters(VALUE self);
|
25
6
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
7
|
+
VALUE ph_spatial_init(VALUE self) {
|
8
|
+
ph_data_t *ph = get_ph_data(self);
|
9
|
+
ph_raise(PhidgetSpatial_create((PhidgetSpatialHandle *)(&(ph->handle))));
|
10
|
+
return self;
|
11
|
+
}
|
30
12
|
|
13
|
+
VALUE ph_spatial_get_data_interval(VALUE self) {
|
14
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSpatial_getDataInterval);
|
15
|
+
}
|
31
16
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
17
|
+
VALUE ph_spatial_set_data_interval(VALUE self, VALUE interval) {
|
18
|
+
ph_raise(PhidgetSpatial_setDataInterval((PhidgetSpatialHandle)get_ph_handle(self), NUM2UINT(interval)));
|
19
|
+
return Qnil;
|
20
|
+
}
|
36
21
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
* Creates a Phidget Spatial object.
|
41
|
-
*/
|
42
|
-
rb_define_method(ph_spatial, "initialize", ph_spatial_init, 0);
|
22
|
+
VALUE ph_spatial_get_min_data_interval(VALUE self) {
|
23
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSpatial_getMinDataInterval);
|
24
|
+
}
|
43
25
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
* Gets the number of acceleration axes supplied by this board.
|
48
|
-
*/
|
49
|
-
rb_define_method(ph_spatial, "getAccelerationAxisCount", ph_spatial_get_acceleration_axis_count, 0);
|
26
|
+
VALUE ph_spatial_get_max_data_interval(VALUE self) {
|
27
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetSpatial_getMaxDataInterval);
|
28
|
+
}
|
50
29
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
rb_define_method(ph_spatial, "getGyroAxisCount", ph_spatial_get_gyro_axis_count, 0);
|
30
|
+
VALUE ph_spatial_set_magnetometer_correction_parameters(VALUE self, VALUE mag_field, VALUE offset0, VALUE offset1, VALUE offset2, VALUE gain0, VALUE gain1, VALUE gain2, VALUE T0, VALUE T1, VALUE T2, VALUE T3, VALUE T4, VALUE T5) {
|
31
|
+
ph_raise(PhidgetSpatial_setMagnetometerCorrectionParameters((PhidgetSpatialHandle)get_ph_handle(self), NUM2DBL(mag_field), NUM2DBL(offset0), NUM2DBL(offset1), NUM2DBL(offset2),
|
32
|
+
NUM2DBL(gain0), NUM2DBL(gain1), NUM2DBL(gain2), NUM2DBL(T0), NUM2DBL(T1), NUM2DBL(T2), NUM2DBL(T3), NUM2DBL(T4), NUM2DBL(T5)));
|
33
|
+
return Qnil;
|
34
|
+
}
|
57
35
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
*/
|
63
|
-
rb_define_method(ph_spatial, "getCompassAxisCount", ph_spatial_get_compass_axis_count, 0);
|
36
|
+
VALUE ph_spatial_reset_magnetometer_correction_parameters(VALUE self) {
|
37
|
+
ph_raise(PhidgetSpatial_resetMagnetometerCorrectionParameters((PhidgetSpatialHandle)get_ph_handle(self)));
|
38
|
+
return Qnil;
|
39
|
+
}
|
64
40
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
*/
|
70
|
-
rb_define_method(ph_spatial, "getAcceleration", ph_spatial_get_acceleration, 1);
|
41
|
+
VALUE ph_spatial_save_magnetometer_correction_parameters(VALUE self) {
|
42
|
+
ph_raise(PhidgetSpatial_saveMagnetometerCorrectionParameters((PhidgetSpatialHandle)get_ph_handle(self)));
|
43
|
+
return Qnil;
|
44
|
+
}
|
71
45
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
*/
|
77
|
-
rb_define_method(ph_spatial, "getAccelerationMin", ph_spatial_get_acceleration_min, 1);
|
46
|
+
VALUE ph_spatial_zero_gyro(VALUE self) {
|
47
|
+
ph_raise(PhidgetSpatial_zeroGyro((PhidgetSpatialHandle)get_ph_handle(self)));
|
48
|
+
return Qnil;
|
49
|
+
}
|
78
50
|
|
79
|
-
/* Document-method: getAccelerationMax
|
80
|
-
* call-seq: getAccelerationMax(index) -> acceleration
|
81
|
-
*
|
82
|
-
* Gets the maximum accleration supported by an axis.
|
83
|
-
*/
|
84
|
-
rb_define_method(ph_spatial, "getAccelerationMax", ph_spatial_get_acceleration_max, 1);
|
85
51
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
52
|
+
void CCONV ph_spatial_on_spatial_data(PhidgetSpatialHandle phid, void *userPtr, const double accel[3], const double angularRate[3], const double magneticField[3], double timestamp) {
|
53
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
54
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
55
|
+
callback_data->arg1 = rb_ary_new3(3, DBL2NUM(accel[0]), DBL2NUM(accel[1]), DBL2NUM(accel[2]));
|
56
|
+
callback_data->arg2 = rb_ary_new3(3, DBL2NUM(angularRate[0]), DBL2NUM(angularRate[1]), DBL2NUM(angularRate[2]));
|
57
|
+
callback_data->arg3 = rb_ary_new3(3, DBL2NUM(magneticField[0]), DBL2NUM(magneticField[1]), DBL2NUM(magneticField[2]));
|
58
|
+
callback_data->arg4 = DBL2NUM(timestamp);
|
59
|
+
sem_post(&callback_data->callback_called);
|
60
|
+
}
|
92
61
|
|
93
|
-
/* Document-method: getAngularRateMin
|
94
|
-
* call-seq: getAngularRateMin(index) -> rate
|
95
|
-
*
|
96
|
-
* Gets the minimum angular rate supported by an axis.
|
97
|
-
*/
|
98
|
-
rb_define_method(ph_spatial, "getAngularRateMin", ph_spatial_get_angular_rate_min, 1);
|
99
62
|
|
100
|
-
|
101
|
-
|
63
|
+
VALUE ph_spatial_set_on_spatial_data_handler(VALUE self, VALUE handler) {
|
64
|
+
ph_data_t *ph = get_ph_data(self);
|
65
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[SPATIAL_SPATIAL_DATA_CALLBACK];
|
66
|
+
if( TYPE(handler) == T_NIL ) {
|
67
|
+
callback_data->callback = T_NIL;
|
68
|
+
callback_data->exit = true;
|
69
|
+
ph_raise(PhidgetSpatial_setOnSpatialDataHandler((PhidgetSpatialHandle)ph->handle, NULL, (void *)NULL));
|
70
|
+
sem_post(&callback_data->callback_called);
|
71
|
+
} else {
|
72
|
+
callback_data->exit = false;
|
73
|
+
callback_data->phidget = self;
|
74
|
+
callback_data->callback = handler;
|
75
|
+
ph_raise(PhidgetSpatial_setOnSpatialDataHandler((PhidgetSpatialHandle)ph->handle, ph_spatial_on_spatial_data, (void *)callback_data));
|
76
|
+
ph_callback_thread(callback_data);
|
77
|
+
}
|
78
|
+
return Qnil;
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
void Init_spatial() {
|
83
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
84
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
85
|
+
VALUE ph_spatial = rb_define_class_under(ph_module, "Spatial", ph_common);
|
86
|
+
|
87
|
+
/* Document-method: new
|
88
|
+
* call-seq: new
|
102
89
|
*
|
103
|
-
*
|
90
|
+
* Creates a Phidget Spatial object.
|
104
91
|
*/
|
105
|
-
rb_define_method(ph_spatial, "
|
92
|
+
rb_define_method(ph_spatial, "initialize", ph_spatial_init, 0);
|
106
93
|
|
107
|
-
/* Document-method:
|
108
|
-
* call-seq:
|
94
|
+
/* Document-method: getDataInterval
|
95
|
+
* call-seq: getDataInterval -> interval
|
109
96
|
*
|
110
|
-
*
|
97
|
+
* The DataInterval is the time that must elapse before the channel will fire another SpatialData event.
|
98
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
111
99
|
*/
|
112
|
-
rb_define_method(ph_spatial, "
|
100
|
+
rb_define_method(ph_spatial, "getDataInterval", ph_spatial_get_data_interval, 0);
|
101
|
+
rb_define_alias(ph_spatial, "data_interval", "getDataInterval");
|
113
102
|
|
114
|
-
/* Document-method:
|
115
|
-
* call-seq:
|
103
|
+
/* Document-method: setDataInterval
|
104
|
+
* call-seq: setDataInterval(interval)
|
116
105
|
*
|
117
|
-
*
|
106
|
+
* The DataInterval is the time that must elapse before the channel will fire another SpatialData event.
|
107
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
118
108
|
*/
|
119
|
-
rb_define_method(ph_spatial, "
|
109
|
+
rb_define_method(ph_spatial, "setDataInterval", ph_spatial_set_data_interval, 1);
|
110
|
+
rb_define_alias(ph_spatial, "data_interval=", "setDataInterval");
|
120
111
|
|
121
|
-
/* Document-method:
|
122
|
-
* call-seq:
|
112
|
+
/* Document-method: getMinDataInterval
|
113
|
+
* call-seq: getMinDataInterval -> interval
|
123
114
|
*
|
124
|
-
*
|
115
|
+
* The minimum value that DataInterval can be set to.
|
125
116
|
*/
|
126
|
-
rb_define_method(ph_spatial, "
|
117
|
+
rb_define_method(ph_spatial, "getMinDataInterval", ph_spatial_get_min_data_interval, 0);
|
118
|
+
rb_define_alias(ph_spatial, "min_data_interval", "getMinDataInterval");
|
127
119
|
|
128
|
-
/* Document-method:
|
129
|
-
* call-seq:
|
120
|
+
/* Document-method: getMaxDataInterval
|
121
|
+
* call-seq: getMaxDataInterval -> interval
|
130
122
|
*
|
131
|
-
*
|
123
|
+
* The maximum value that DataInterval can be set to.
|
132
124
|
*/
|
133
|
-
rb_define_method(ph_spatial, "
|
125
|
+
rb_define_method(ph_spatial, "getMaxDataInterval", ph_spatial_get_max_data_interval, 0);
|
126
|
+
rb_define_alias(ph_spatial, "max_data_interval", "getMaxDataInterval");
|
134
127
|
|
135
|
-
/* Document-method:
|
136
|
-
* call-seq:
|
128
|
+
/* Document-method: setMagnetometerCorrectionParameters
|
129
|
+
* call-seq: setMagnetometerCorrectionParameters(mag_field, offset0, offset1, offset2, gain0, gain1, gain2, T0, T1, T2, T3, T4, T5)
|
137
130
|
*
|
138
|
-
*
|
131
|
+
* Calibrate your device for the environment it will be used in.
|
132
|
+
* Due to physical location, hard and soft iron offsets, and even bias errors, your device should be calibrated.
|
133
|
+
* We have created a calibration program that will provide you with the MagnetometerCorrectionParameters for your specific situation.
|
134
|
+
* See your device's User Guide for more information.
|
139
135
|
*/
|
140
|
-
rb_define_method(ph_spatial, "
|
136
|
+
rb_define_method(ph_spatial, "setMagnetometerCorrectionParameters", ph_spatial_set_magnetometer_correction_parameters, 13);
|
137
|
+
rb_define_alias(ph_spatial, "set_magnetometer_correction_parameters", "setMagnetometerCorrectionParameters");
|
141
138
|
|
142
|
-
/* Document-method:
|
143
|
-
* call-seq:
|
139
|
+
/* Document-method: resetMagnetometerCorrectionParameters
|
140
|
+
* call-seq: resetMagnetometerCorrectionParameters
|
144
141
|
*
|
145
|
-
*
|
142
|
+
* Resets the MagnetometerCorrectionParameters to their default values.
|
143
|
+
* Due to physical location, hard and soft iron offsets, and even bias errors, your device should be calibrated.
|
144
|
+
* We have created a calibration program that will provide you with the MagnetometerCorrectionParameters for your specific situation.
|
145
|
+
* See your device's User Guide for more information
|
146
146
|
*/
|
147
|
-
rb_define_method(ph_spatial, "
|
147
|
+
rb_define_method(ph_spatial, "resetMagnetometerCorrectionParameters", ph_spatial_reset_magnetometer_correction_parameters, 0);
|
148
|
+
rb_define_alias(ph_spatial, "reset_magnetometer_correction_parameters", "resetMagnetometerCorrectionParameters");
|
148
149
|
|
149
|
-
/* Document-method:
|
150
|
-
* call-seq:
|
150
|
+
/* Document-method: saveMagnetometerCorrectionParameters
|
151
|
+
* call-seq: saveMagnetometerCorrectionParameters
|
151
152
|
*
|
152
|
-
*
|
153
|
+
* Saves the MagnetometerCorrectionParameters.
|
154
|
+
* Due to physical location, hard and soft iron offsets, and even bias errors, your device should be calibrated.
|
155
|
+
* We have created a calibration program that will provide you with the MagnetometerCorrectionParameters for your specific situation.
|
156
|
+
* See your device's User Guide for more information
|
153
157
|
*/
|
154
|
-
rb_define_method(ph_spatial, "
|
158
|
+
rb_define_method(ph_spatial, "saveMagnetometerCorrectionParameters", ph_spatial_save_magnetometer_correction_parameters, 0);
|
159
|
+
rb_define_alias(ph_spatial, "save_magnetometer_correction_parameters", "saveMagnetometerCorrectionParameters");
|
155
160
|
|
156
161
|
/* Document-method: zeroGyro
|
157
162
|
* call-seq: zeroGyro
|
158
163
|
*
|
159
|
-
*
|
160
|
-
*
|
164
|
+
* Re-zeros the gyroscope in 1-2 seconds.
|
165
|
+
* The device must be stationary when zeroing.
|
166
|
+
* The angular rate will be reported as 0.0°/s while zeroing.
|
167
|
+
* Zeroing the gyroscope is a method of compensating for the drift that is inherent to all gyroscopes. See your device's User Guide for more information on dealing with drift.
|
161
168
|
*/
|
162
169
|
rb_define_method(ph_spatial, "zeroGyro", ph_spatial_zero_gyro, 0);
|
163
|
-
|
164
|
-
/* Document-method: setCompassCorrectionParameters
|
165
|
-
* call-seq: setCompassCorrectionParameters(mag_field, offset0, offset1, offset2, gain0, gain1, gain2, T0, T1, T2, T3, T4, T5)
|
166
|
-
*
|
167
|
-
* Sets the compass correction factors. This can be used to correcting any sensor errors,
|
168
|
-
* including hard and soft iron offsets and sensor error factors.
|
169
|
-
*/
|
170
|
-
rb_define_method(ph_spatial, "setCompassCorrectionParameters", ph_spatial_set_compass_correction_parameters, 13);
|
171
|
-
|
172
|
-
/* Document-method: resetCompassCorrectionParameters
|
173
|
-
* call-seq: resetCompassCorrectionParameters
|
174
|
-
*
|
175
|
-
* Resets the compass correction factors. Magnetic field data will be presented directly as reported by the sensor.
|
176
|
-
*/
|
177
|
-
rb_define_method(ph_spatial, "resetCompassCorrectionParameters", ph_spatial_reset_compass_correction_parameters, 0);
|
178
|
-
|
179
|
-
#ifdef PH_CALLBACK
|
180
|
-
rb_define_private_method(ph_spatial, "ext_setOnSpatialDataHandler", ph_spatial_set_on_spatial_data_handler, 1);
|
181
|
-
#endif
|
182
|
-
|
183
|
-
rb_define_alias(ph_spatial, "acceleration_axis_count", "getAccelerationAxisCount");
|
184
|
-
rb_define_alias(ph_spatial, "gyro_axis_count", "getGyroAxisCount");
|
185
|
-
rb_define_alias(ph_spatial, "compass_axis_count", "getCompassAxisCount");
|
186
|
-
rb_define_alias(ph_spatial, "acceleration", "getAcceleration");
|
187
|
-
rb_define_alias(ph_spatial, "acceleration_min", "getAccelerationMin");
|
188
|
-
rb_define_alias(ph_spatial, "acceleration_max", "getAccelerationMax");
|
189
|
-
rb_define_alias(ph_spatial, "angular_rate", "getAngularRate");
|
190
|
-
rb_define_alias(ph_spatial, "angular_rate_min", "getAngularRateMin");
|
191
|
-
rb_define_alias(ph_spatial, "angular_rate_max", "getAngularRateMax");
|
192
|
-
rb_define_alias(ph_spatial, "magnetic_field", "getMagneticField");
|
193
|
-
rb_define_alias(ph_spatial, "magnetic_field_min", "getMagneticFieldMin");
|
194
|
-
rb_define_alias(ph_spatial, "magnetic_field_max", "getMagneticFieldMax");
|
195
|
-
rb_define_alias(ph_spatial, "data_rate", "getDataRate");
|
196
|
-
rb_define_alias(ph_spatial, "data_rate_min", "getDataRateMin");
|
197
|
-
rb_define_alias(ph_spatial, "data_rate_max", "getDataRateMax");
|
198
|
-
rb_define_alias(ph_spatial, "data_rate=", "setDataRate");
|
199
170
|
rb_define_alias(ph_spatial, "zero_gyro", "zeroGyro");
|
200
|
-
rb_define_alias(ph_spatial, "set_compass_correction_parameters", "setCompassCorrectionParameters");
|
201
|
-
rb_define_alias(ph_spatial, "reset_compass_correction_parameters", "resetCompassCorrectionParameters");
|
202
|
-
}
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
VALUE ph_spatial_init(VALUE self) {
|
207
|
-
ph_data_t *ph = get_ph_data(self);
|
208
|
-
ph_raise(CPhidgetSpatial_create((CPhidgetSpatialHandle *)(&(ph->handle))));
|
209
|
-
return self;
|
210
|
-
}
|
211
|
-
|
212
|
-
VALUE ph_spatial_get_acceleration_axis_count(VALUE self) {
|
213
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
214
|
-
int count;
|
215
|
-
ph_raise(CPhidgetSpatial_getAccelerationAxisCount(handle, &count));
|
216
|
-
return INT2FIX(count);
|
217
|
-
}
|
218
|
-
|
219
|
-
VALUE ph_spatial_get_gyro_axis_count(VALUE self) {
|
220
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
221
|
-
int count;
|
222
|
-
ph_raise(CPhidgetSpatial_getGyroAxisCount(handle, &count));
|
223
|
-
return INT2FIX(count);
|
224
|
-
}
|
225
|
-
|
226
|
-
VALUE ph_spatial_get_compass_axis_count(VALUE self) {
|
227
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
228
|
-
int count;
|
229
|
-
ph_raise(CPhidgetSpatial_getCompassAxisCount(handle, &count));
|
230
|
-
return INT2FIX(count);
|
231
|
-
}
|
232
|
-
|
233
|
-
VALUE ph_spatial_get_acceleration(VALUE self, VALUE index) {
|
234
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
235
|
-
double value;
|
236
|
-
ph_raise(CPhidgetSpatial_getAcceleration(handle, FIX2INT(index), &value));
|
237
|
-
return rb_float_new(value);
|
238
|
-
}
|
239
|
-
|
240
|
-
VALUE ph_spatial_get_acceleration_min(VALUE self, VALUE index) {
|
241
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
242
|
-
double value;
|
243
|
-
ph_raise(CPhidgetSpatial_getAccelerationMin(handle, FIX2INT(index), &value));
|
244
|
-
return rb_float_new(value);
|
245
|
-
}
|
246
|
-
|
247
|
-
VALUE ph_spatial_get_acceleration_max(VALUE self, VALUE index) {
|
248
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
249
|
-
double value;
|
250
|
-
ph_raise(CPhidgetSpatial_getAccelerationMax(handle, FIX2INT(index), &value));
|
251
|
-
return rb_float_new(value);
|
252
|
-
}
|
253
|
-
|
254
|
-
VALUE ph_spatial_get_angular_rate(VALUE self, VALUE index) {
|
255
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
256
|
-
double value;
|
257
|
-
ph_raise(CPhidgetSpatial_getAngularRate(handle, FIX2INT(index), &value));
|
258
|
-
return rb_float_new(value);
|
259
|
-
}
|
260
|
-
|
261
|
-
VALUE ph_spatial_get_angular_rate_min(VALUE self, VALUE index) {
|
262
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
263
|
-
double value;
|
264
|
-
ph_raise(CPhidgetSpatial_getAngularRateMin(handle, FIX2INT(index), &value));
|
265
|
-
return rb_float_new(value);
|
266
|
-
}
|
267
|
-
|
268
|
-
VALUE ph_spatial_get_angular_rate_max(VALUE self, VALUE index) {
|
269
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
270
|
-
double value;
|
271
|
-
ph_raise(CPhidgetSpatial_getAngularRateMax(handle, FIX2INT(index), &value));
|
272
|
-
return rb_float_new(value);
|
273
|
-
}
|
274
|
-
|
275
|
-
VALUE ph_spatial_get_magnetic_field(VALUE self, VALUE index) {
|
276
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
277
|
-
double value;
|
278
|
-
ph_raise(CPhidgetSpatial_getMagneticField(handle, FIX2INT(index), &value));
|
279
|
-
return rb_float_new(value);
|
280
|
-
}
|
281
|
-
|
282
|
-
VALUE ph_spatial_get_magnetic_field_min(VALUE self, VALUE index) {
|
283
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
284
|
-
double value;
|
285
|
-
ph_raise(CPhidgetSpatial_getMagneticFieldMin(handle, FIX2INT(index), &value));
|
286
|
-
return rb_float_new(value);
|
287
|
-
}
|
288
|
-
|
289
|
-
VALUE ph_spatial_get_magnetic_field_max(VALUE self, VALUE index) {
|
290
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
291
|
-
double value;
|
292
|
-
ph_raise(CPhidgetSpatial_getMagneticFieldMax(handle, FIX2INT(index), &value));
|
293
|
-
return rb_float_new(value);
|
294
|
-
}
|
295
171
|
|
296
|
-
VALUE ph_spatial_get_data_rate(VALUE self) {
|
297
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
298
|
-
int value;
|
299
|
-
ph_raise(CPhidgetSpatial_getDataRate(handle, &value));
|
300
|
-
return INT2FIX(value);
|
301
|
-
}
|
302
|
-
|
303
|
-
VALUE ph_spatial_get_data_rate_min(VALUE self) {
|
304
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
305
|
-
int value;
|
306
|
-
ph_raise(CPhidgetSpatial_getDataRateMin(handle, &value));
|
307
|
-
return INT2FIX(value);
|
308
|
-
}
|
309
|
-
|
310
|
-
VALUE ph_spatial_get_data_rate_max(VALUE self) {
|
311
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
312
|
-
int value;
|
313
|
-
ph_raise(CPhidgetSpatial_getDataRateMax(handle, &value));
|
314
|
-
return INT2FIX(value);
|
315
|
-
}
|
316
|
-
|
317
|
-
VALUE ph_spatial_set_data_rate(VALUE self, VALUE milliseconds) {
|
318
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
319
|
-
ph_raise(CPhidgetSpatial_setDataRate(handle, FIX2INT(milliseconds)));
|
320
|
-
return Qnil;
|
321
|
-
}
|
322
|
-
|
323
|
-
VALUE ph_spatial_zero_gyro(VALUE self) {
|
324
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
325
|
-
ph_raise(CPhidgetSpatial_zeroGyro(handle));
|
326
|
-
return Qnil;
|
327
|
-
}
|
328
|
-
|
329
|
-
VALUE ph_spatial_set_compass_correction_parameters(VALUE self, VALUE mag_field, VALUE offset0, VALUE offset1, VALUE offset2, VALUE gain0, VALUE gain1, VALUE gain2, VALUE T0, VALUE T1, VALUE T2, VALUE T3, VALUE T4, VALUE T5) {
|
330
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
331
|
-
ph_raise(CPhidgetSpatial_setCompassCorrectionParameters(handle, NUM2DBL(mag_field), NUM2DBL(offset0), NUM2DBL(offset1), NUM2DBL(offset2),
|
332
|
-
NUM2DBL(gain0), NUM2DBL(gain1), NUM2DBL(gain2), NUM2DBL(T0), NUM2DBL(T1), NUM2DBL(T2), NUM2DBL(T3), NUM2DBL(T4), NUM2DBL(T5)));
|
333
|
-
return Qnil;
|
334
|
-
}
|
335
|
-
|
336
|
-
VALUE ph_spatial_reset_compass_correction_parameters(VALUE self) {
|
337
|
-
CPhidgetSpatialHandle handle = (CPhidgetSpatialHandle)get_ph_handle(self);
|
338
|
-
ph_raise(CPhidgetSpatial_resetCompassCorrectionParameters(handle));
|
339
|
-
return Qnil;
|
340
|
-
}
|
341
172
|
|
342
|
-
|
343
|
-
#ifdef PH_CALLBACK
|
344
|
-
VALUE ph_spatial_set_on_spatial_data_handler(VALUE self, VALUE handler) {
|
345
|
-
ph_data_t *ph = get_ph_data(self);
|
346
|
-
ph_callback_data_t *callback_data = &ph->dev_callback_1;
|
347
|
-
if( TYPE(handler) == T_NIL ) {
|
348
|
-
callback_data->exit = true;
|
349
|
-
ph_raise(CPhidgetSpatial_set_OnSpatialData_Handler((CPhidgetSpatialHandle)ph->handle, NULL, (void *)NULL));
|
350
|
-
} else {
|
351
|
-
callback_data->called = false;
|
352
|
-
callback_data->exit = false;
|
353
|
-
callback_data->phidget = self;
|
354
|
-
callback_data->callback = handler;
|
355
|
-
ph_raise(CPhidgetSpatial_set_OnSpatialData_Handler((CPhidgetSpatialHandle)ph->handle, ph_spatial_on_spatial_data, (void *)callback_data));
|
356
|
-
ph_callback_thread(callback_data);
|
357
|
-
}
|
358
|
-
return Qnil;
|
359
|
-
}
|
360
|
-
|
361
|
-
|
362
|
-
int ph_spatial_on_spatial_data(CPhidgetSpatialHandle phid, void *userPtr, CPhidgetSpatial_SpatialEventDataHandle *data, int data_count) {
|
363
|
-
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
364
|
-
callback_data->called = true;
|
365
|
-
return EPHIDGET_OK;
|
173
|
+
rb_define_private_method(ph_spatial, "ext_setOnSpatialDataHandler", ph_spatial_set_on_spatial_data_handler, 1);
|
366
174
|
}
|
367
175
|
|
368
|
-
#endif
|
369
|
-
|