phidgets 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/History.txt +10 -2
  2. data/README.rdoc +41 -18
  3. data/Rakefile +31 -20
  4. data/bin/phidget +29 -44
  5. data/ext/phidgets/extconf.rb +14 -0
  6. data/ext/phidgets/phidgets.c +272 -0
  7. data/ext/phidgets/phidgets.h +82 -0
  8. data/ext/phidgets/phidgets_accelerometer.c +165 -0
  9. data/ext/phidgets/phidgets_advanced_servo.c +567 -0
  10. data/ext/phidgets/phidgets_analog.c +139 -0
  11. data/ext/phidgets/phidgets_bridge.c +263 -0
  12. data/ext/phidgets/phidgets_common.c +454 -0
  13. data/ext/phidgets/phidgets_dictionary.c +279 -0
  14. data/ext/phidgets/phidgets_encoder.c +249 -0
  15. data/ext/phidgets/phidgets_frequency_counter.c +241 -0
  16. data/ext/phidgets/phidgets_gps.c +235 -0
  17. data/ext/phidgets/phidgets_interface_kit.c +340 -0
  18. data/ext/phidgets/phidgets_ir.c +251 -0
  19. data/ext/phidgets/phidgets_led.c +178 -0
  20. data/ext/phidgets/phidgets_manager.c +366 -0
  21. data/ext/phidgets/phidgets_motor_control.c +642 -0
  22. data/ext/phidgets/phidgets_phsensor.c +208 -0
  23. data/ext/phidgets/phidgets_rfid.c +281 -0
  24. data/ext/phidgets/phidgets_servo.c +276 -0
  25. data/ext/phidgets/phidgets_spatial.c +369 -0
  26. data/ext/phidgets/phidgets_stepper.c +560 -0
  27. data/ext/phidgets/phidgets_temp_sensor.c +295 -0
  28. data/ext/phidgets/phidgets_text_lcd.c +381 -0
  29. data/ext/phidgets/phidgets_text_led.c +107 -0
  30. data/ext/phidgets/phidgets_weight_sensor.c +113 -0
  31. data/lib/phidgets/accelerometer.rb +25 -0
  32. data/lib/phidgets/advanced_servo.rb +49 -0
  33. data/lib/phidgets/analog.rb +8 -0
  34. data/lib/phidgets/bridge.rb +25 -0
  35. data/lib/phidgets/common.rb +75 -190
  36. data/lib/phidgets/dictionary.rb +53 -0
  37. data/lib/phidgets/encoder.rb +49 -0
  38. data/lib/phidgets/frequency_counter.rb +25 -0
  39. data/lib/phidgets/gps.rb +37 -0
  40. data/lib/phidgets/interfacekit.rb +38 -128
  41. data/lib/phidgets/ir.rb +50 -0
  42. data/lib/phidgets/led.rb +8 -0
  43. data/lib/phidgets/manager.rb +67 -119
  44. data/lib/phidgets/motor_control.rb +110 -0
  45. data/lib/phidgets/ph_sensor.rb +25 -0
  46. data/lib/phidgets/rfid.rb +38 -111
  47. data/lib/phidgets/servo.rb +12 -95
  48. data/lib/phidgets/spatial.rb +25 -0
  49. data/lib/phidgets/stepper.rb +61 -0
  50. data/lib/phidgets/temperature_sensor.rb +25 -0
  51. data/lib/phidgets/text_lcd.rb +8 -0
  52. data/lib/phidgets/text_led.rb +8 -0
  53. data/lib/phidgets/weight_sensor.rb +25 -0
  54. data/lib/phidgets.rb +22 -3
  55. data/phidgets.gemspec +42 -0
  56. data/test/test_accelerometer.rb +47 -0
  57. data/test/test_advanced_servo.rb +152 -0
  58. data/test/test_analog.rb +45 -0
  59. data/test/test_bridge.rb +77 -0
  60. data/test/test_common.rb +167 -0
  61. data/test/test_dictionary.rb +82 -0
  62. data/test/test_encoder.rb +67 -0
  63. data/test/test_frequency_counter.rb +67 -0
  64. data/test/test_gps.rb +67 -0
  65. data/test/test_helper.rb +1 -0
  66. data/test/test_interfacekit.rb +86 -182
  67. data/test/test_ir.rb +57 -0
  68. data/test/test_led.rb +55 -0
  69. data/test/test_manager.rb +94 -0
  70. data/test/test_motor_control.rb +172 -0
  71. data/test/test_phidgets.rb +14 -6
  72. data/test/test_phsensor.rb +62 -0
  73. data/test/test_rfid.rb +77 -0
  74. data/test/test_servo.rb +67 -0
  75. data/test/test_spatial.rb +112 -0
  76. data/test/test_stepper.rb +163 -0
  77. data/test/test_temp_sensor.rb +87 -0
  78. data/test/test_text_lcd.rb +115 -0
  79. data/test/test_text_led.rb +35 -0
  80. data/test/test_weight_sensor.rb +32 -0
  81. metadata +165 -75
  82. data/Manifest.txt +0 -21
  83. data/PostInstall.txt +0 -3
  84. data/README.txt +0 -87
  85. data/lib/phidgets/phidgets.rb +0 -225
  86. data/script/console +0 -10
  87. data/script/destroy +0 -14
  88. data/script/generate +0 -14
@@ -0,0 +1,276 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+
5
+ VALUE ph_servo_init(VALUE self);
6
+ VALUE ph_servo_get_motor_count(VALUE self);
7
+ VALUE ph_servo_get_position(VALUE self, VALUE index);
8
+ VALUE ph_servo_get_position_min(VALUE self, VALUE index);
9
+ VALUE ph_servo_get_position_max(VALUE self, VALUE index);
10
+ VALUE ph_servo_set_position(VALUE self, VALUE index, VALUE position);
11
+ VALUE ph_servo_get_engaged(VALUE self, VALUE index);
12
+ VALUE ph_servo_set_engaged(VALUE self, VALUE index, VALUE engaged);
13
+ VALUE ph_servo_get_servo_type(VALUE self, VALUE index);
14
+ VALUE ph_servo_set_servo_type(VALUE self, VALUE index, VALUE type);
15
+ VALUE ph_servo_set_servo_parameters(VALUE self, VALUE index, VALUE min_us, VALUE max_us, VALUE degrees);
16
+
17
+ #ifdef PH_CALLBACK
18
+ VALUE ph_servo_set_on_position_change_handler(VALUE self, VALUE handler);
19
+ int ph_servo_on_position_change(CPhidgetServoHandle phid, void *userPtr, int index, double position);
20
+ #endif
21
+
22
+
23
+ VALUE Init_phidgets_servo(VALUE ph_module, VALUE ph_common) {
24
+ VALUE ph_servo = rb_define_class_under(ph_module, "Servo", ph_common);
25
+
26
+ /* Default - This is what the servo API been historically used, originally based on the Futaba FP-S148 */
27
+ rb_define_const(ph_servo, "DEFAULT", INT2FIX(PHIDGET_SERVO_DEFAULT));
28
+ /* Raw us mode - all position, velocity, acceleration functions are specified in microseconds rather then degrees */
29
+ rb_define_const(ph_servo, "RAW_US_MODE", INT2FIX(PHIDGET_SERVO_RAW_us_MODE));
30
+ /* HiTec HS-322HD Standard \Servo */
31
+ rb_define_const(ph_servo, "HITEC_HS322HD", INT2FIX(PHIDGET_SERVO_HITEC_HS322HD));
32
+ /* HiTec HS-5245MG Digital Mini \Servo */
33
+ rb_define_const(ph_servo, "HITEC_HS5245MG", INT2FIX(PHIDGET_SERVO_HITEC_HS5245MG));
34
+ /* HiTec HS-805BB Mega Quarter Scale \Servo */
35
+ rb_define_const(ph_servo, "HITEC_805BB", INT2FIX(PHIDGET_SERVO_HITEC_805BB));
36
+ /* HiTec HS-422 Standard \Servo */
37
+ rb_define_const(ph_servo, "HITEC_HS422", INT2FIX(PHIDGET_SERVO_HITEC_HS422));
38
+ /* Tower Pro MG90 Micro \Servo */
39
+ rb_define_const(ph_servo, "TOWERPRO_MG90", INT2FIX(PHIDGET_SERVO_TOWERPRO_MG90));
40
+ /* HiTec HSR-1425CR Continuous Rotation \Servo */
41
+ rb_define_const(ph_servo, "HITEC_HSR1425CR", INT2FIX(PHIDGET_SERVO_HITEC_HSR1425CR));
42
+ /* HiTec HS-785HB Sail Winch \Servo */
43
+ rb_define_const(ph_servo, "HITEC_HS785HB", INT2FIX(PHIDGET_SERVO_HITEC_HS785HB));
44
+ /* HiTec HS-485HB Deluxe \Servo */
45
+ rb_define_const(ph_servo, "HITEC_HS485HB", INT2FIX(PHIDGET_SERVO_HITEC_HS485HB));
46
+ /* HiTec HS-645MG Ultra Torque \Servo */
47
+ rb_define_const(ph_servo, "HITEC_HS645MG", INT2FIX(PHIDGET_SERVO_HITEC_HS645MG));
48
+ /* HiTec HS-815BB Mega Sail \Servo */
49
+ rb_define_const(ph_servo, "HITEC_815BB", INT2FIX(PHIDGET_SERVO_HITEC_815BB));
50
+ /* Document-const:
51
+ * Firgelli L12 Linear Actuator 30mm 50\:1 */
52
+ rb_define_const(ph_servo, "FIRGELLI_L12_30_50_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R));
53
+ /* Document-const:
54
+ * Firgelli L12 Linear Actuator 50mm 100\:1 */
55
+ rb_define_const(ph_servo, "FIRGELLI_L12_50_100_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R));
56
+ /* Document-const:
57
+ * Firgelli L12 Linear Actuator 50mm 210\:1 */
58
+ rb_define_const(ph_servo, "FIRGELLI_L12_50_210_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R));
59
+ /* Document-const:
60
+ * Firgelli L12 Linear Actuator 100mm 50\:1 */
61
+ rb_define_const(ph_servo, "FIRGELLI_L12_100_50_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R));
62
+ /* Document-const:
63
+ * Firgelli L12 Linear Actuator 100mm 100\:1 */
64
+ rb_define_const(ph_servo, "FIRGELLI_L12_100_100_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R));
65
+ /* SpringRC SM-S2313M Micro \Servo */
66
+ rb_define_const(ph_servo, "SPRINGRC_SM_S2313M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S2313M));
67
+ /* SpringRC SM-S3317M Small \Servo */
68
+ rb_define_const(ph_servo, "SPRINGRC_SM_S3317M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S3317M));
69
+ /* SpringRC SM-S3317SR Small Continuous Rotation \Servo */
70
+ rb_define_const(ph_servo, "SPRINGRC_SM_S3317SR", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S3317SR));
71
+ /* SpringRC SM-S4303R Standard Continuous Rotation \Servo */
72
+ rb_define_const(ph_servo, "SPRINGRC_SM_S4303R", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4303R));
73
+ /* SpringRC SM-S4315M High Torque \Servo */
74
+ rb_define_const(ph_servo, "SPRINGRC_SM_S4315M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4315M));
75
+ /* SpringRC SM-S4315R High Torque Continuous Rotation \Servo */
76
+ rb_define_const(ph_servo, "SPRINGRC_SM_S4315R", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4315R));
77
+ /* SpringRC SM-S4505B Standard \Servo */
78
+ rb_define_const(ph_servo, "SPRINGRC_SM_S4505B", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4505B));
79
+
80
+ /* Document-method: new
81
+ * call-seq: new
82
+ *
83
+ * Creates a Phidget Servo object.
84
+ */
85
+ rb_define_method(ph_servo, "initialize", ph_servo_init, 0);
86
+
87
+ /* Document-method: getMotorCount
88
+ * call-seq: getMotorCount -> count
89
+ *
90
+ * Gets the number of motors supported by this controller
91
+ */
92
+ rb_define_method(ph_servo, "getMotorCount", ph_servo_get_motor_count, 0);
93
+
94
+ /* Document-method: getPosition
95
+ * call-seq: getPosition(index) -> position
96
+ *
97
+ * Gets the current position of a motor.
98
+ */
99
+ rb_define_method(ph_servo, "getPosition", ph_servo_get_position, 1);
100
+
101
+ /* Document-method: getPositionMin
102
+ * call-seq: getPositionMin(index) -> min
103
+ *
104
+ * Gets the minimum position that a motor can go to.
105
+ */
106
+ rb_define_method(ph_servo, "getPositionMin", ph_servo_get_position_min, 1);
107
+
108
+ /* Document-method: getPositionMax
109
+ * call-seq: getPositionMax(index) -> max
110
+ *
111
+ * Gets the maximum position that a motor can go to.
112
+ */
113
+ rb_define_method(ph_servo, "getPositionMax", ph_servo_get_position_max, 1);
114
+
115
+ /* Document-method: setPosition
116
+ * call-seq: setPosition(index, position)
117
+ *
118
+ * Sets the position of a motor.
119
+ */
120
+ rb_define_method(ph_servo, "setPosition", ph_servo_set_position, 2);
121
+
122
+ /* Document-method: getEngaged
123
+ * call-seq: getEngaged(index) -> true or false
124
+ *
125
+ * Gets the engaged state of a motor. This is whether the motor is powered or not.
126
+ */
127
+ rb_define_method(ph_servo, "getEngaged", ph_servo_get_engaged, 1);
128
+
129
+ /* Document-method: setEngaged
130
+ * call-seq: setEngaged(index, state)
131
+ *
132
+ * Sets the engaged state of a motor. This is whether the motor is powered or not.
133
+ */
134
+ rb_define_method(ph_servo, "setEngaged", ph_servo_set_engaged, 2);
135
+
136
+ /* Document-method: getServoType
137
+ * call-seq: getServoType(index) -> servo_type
138
+ *
139
+ * Gets the servo type of a motor.
140
+ */
141
+ rb_define_method(ph_servo, "getServoType", ph_servo_get_servo_type, 1);
142
+
143
+ /* Document-method: setServoType
144
+ * call-seq: setServoType(index, servo_type)
145
+ *
146
+ * Sets the servo type of a motor.
147
+ */
148
+ rb_define_method(ph_servo, "setServoType", ph_servo_set_servo_type, 2);
149
+
150
+ /* Document-method: setServoParameters
151
+ * call-seq: setServoParameters(index, min_us, max_us, degrees)
152
+ *
153
+ * Sets the servo parameters of a motor.
154
+ */
155
+ rb_define_method(ph_servo, "setServoParameters", ph_servo_set_servo_parameters, 4);
156
+
157
+ #ifdef PH_CALLBACK
158
+ rb_define_private_method(ph_servo, "ext_setOnPositionChangeHandler", ph_servo_set_on_position_change_handler, 1);
159
+ #endif
160
+
161
+ rb_define_alias(ph_servo, "motor_count", "getMotorCount");
162
+ rb_define_alias(ph_servo, "position", "getPosition");
163
+ rb_define_alias(ph_servo, "position_min", "getPositionMin");
164
+ rb_define_alias(ph_servo, "position_max", "getPositionMax");
165
+ rb_define_alias(ph_servo, "set_position", "setPosition");
166
+ rb_define_alias(ph_servo, "engaged?", "getEngaged");
167
+ rb_define_alias(ph_servo, "set_engaged", "setEngaged");
168
+ rb_define_alias(ph_servo, "servo_type", "getServoType");
169
+ rb_define_alias(ph_servo, "set_servo_type", "setServoType");
170
+ rb_define_alias(ph_servo, "set_servo_parameters", "setServoParameters");
171
+
172
+ return ph_servo;
173
+ }
174
+
175
+
176
+
177
+ VALUE ph_servo_init(VALUE self) {
178
+ ph_data_t *ph = get_ph_data(self);
179
+ ph_raise(CPhidgetServo_create((CPhidgetServoHandle *)(&(ph->handle))));
180
+ return self;
181
+ }
182
+
183
+ VALUE ph_servo_get_motor_count(VALUE self) {
184
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
185
+ int count;
186
+ ph_raise(CPhidgetServo_getMotorCount(handle, &count));
187
+ return INT2FIX(count);
188
+ }
189
+
190
+ VALUE ph_servo_get_position(VALUE self, VALUE index) {
191
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
192
+ double position;
193
+ ph_raise(CPhidgetServo_getPosition(handle, FIX2INT(index), &position));
194
+ return rb_float_new(position);
195
+ }
196
+
197
+ VALUE ph_servo_get_position_min(VALUE self, VALUE index) {
198
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
199
+ double position;
200
+ ph_raise(CPhidgetServo_getPositionMin(handle, FIX2INT(index), &position));
201
+ return rb_float_new(position);
202
+ }
203
+
204
+ VALUE ph_servo_get_position_max(VALUE self, VALUE index) {
205
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
206
+ double position;
207
+ ph_raise(CPhidgetServo_getPositionMax(handle, FIX2INT(index), &position));
208
+ return rb_float_new(position);
209
+ }
210
+
211
+ VALUE ph_servo_set_position(VALUE self, VALUE index, VALUE position) {
212
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
213
+ ph_raise(CPhidgetServo_setPosition(handle, FIX2INT(index), NUM2DBL(position)));
214
+ return Qnil;
215
+ }
216
+
217
+ VALUE ph_servo_get_engaged(VALUE self, VALUE index) {
218
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
219
+ int engaged;
220
+ ph_raise(CPhidgetServo_getEngaged(handle, FIX2INT(index), &engaged));
221
+ return engaged == PTRUE ? Qtrue : Qfalse;
222
+ }
223
+
224
+ VALUE ph_servo_set_engaged(VALUE self, VALUE index, VALUE engaged) {
225
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
226
+ ph_raise(CPhidgetServo_setEngaged(handle, FIX2INT(index), TYPE(engaged) == T_TRUE ? PTRUE : PFALSE));
227
+ return Qnil;
228
+ }
229
+
230
+ VALUE ph_servo_get_servo_type(VALUE self, VALUE index) {
231
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
232
+ CPhidget_ServoType type;
233
+ ph_raise(CPhidgetServo_getServoType(handle, FIX2INT(index), &type));
234
+ return INT2FIX(type);
235
+ }
236
+
237
+ VALUE ph_servo_set_servo_type(VALUE self, VALUE index, VALUE type) {
238
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
239
+ ph_raise(CPhidgetServo_setServoType(handle, FIX2INT(index), (CPhidget_ServoType)FIX2INT(type)));
240
+ return Qnil;
241
+ }
242
+
243
+ VALUE ph_servo_set_servo_parameters(VALUE self, VALUE index, VALUE min_us, VALUE max_us, VALUE degrees) {
244
+ CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
245
+ ph_raise(CPhidgetServo_setServoParameters(handle, FIX2INT(index), NUM2DBL(min_us), NUM2DBL(max_us), NUM2DBL(degrees)));
246
+ return Qnil;
247
+ }
248
+
249
+
250
+ #ifdef PH_CALLBACK
251
+ VALUE ph_servo_set_on_position_change_handler(VALUE self, VALUE handler) {
252
+ ph_data_t *ph = get_ph_data(self);
253
+ ph_callback_data_t *callback_data = &ph->dev_callback_1;
254
+ if( TYPE(handler) == T_NIL ) {
255
+ callback_data->exit = true;
256
+ ph_raise(CPhidgetServo_set_OnPositionChange_Handler((CPhidgetServoHandle)ph->handle, NULL, (void *)NULL));
257
+ } else {
258
+ callback_data->called = false;
259
+ callback_data->exit = false;
260
+ callback_data->phidget = self;
261
+ callback_data->callback = handler;
262
+ ph_raise(CPhidgetServo_set_OnPositionChange_Handler((CPhidgetServoHandle)ph->handle, ph_servo_on_position_change, (void *)callback_data));
263
+ ph_callback_thread(callback_data);
264
+ }
265
+ return Qnil;
266
+ }
267
+
268
+
269
+ int ph_servo_on_position_change(CPhidgetServoHandle phid, void *userPtr, int index, double position) {
270
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
271
+ callback_data->called = true;
272
+ return EPHIDGET_OK;
273
+ }
274
+
275
+ #endif
276
+
@@ -0,0 +1,369 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+
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
+
26
+ #ifdef PH_CALLBACK
27
+ VALUE ph_spatial_set_on_spatial_data_handler(VALUE self, VALUE handler);
28
+ int ph_spatial_on_spatial_data(CPhidgetSpatialHandle phid, void *userPtr, CPhidgetSpatial_SpatialEventDataHandle *data, int data_count);
29
+ #endif
30
+
31
+
32
+ VALUE Init_phidgets_spatial(VALUE ph_module, VALUE ph_common) {
33
+ VALUE ph_spatial = rb_define_class_under(ph_module, "Spatial", ph_common);
34
+
35
+ /* Document-method: new
36
+ * call-seq: new
37
+ *
38
+ * Creates a Phidget Spatial object.
39
+ */
40
+ rb_define_method(ph_spatial, "initialize", ph_spatial_init, 0);
41
+
42
+ /* Document-method: getAccelerationAxisCount
43
+ * call-seq: getAccelerationAxisCount -> count
44
+ *
45
+ * Gets the number of acceleration axes supplied by this board.
46
+ */
47
+ rb_define_method(ph_spatial, "getAccelerationAxisCount", ph_spatial_get_acceleration_axis_count, 0);
48
+
49
+ /* Document-method: getGyroAxisCount
50
+ * call-seq: getGyroAxisCount -> count
51
+ *
52
+ * Gets the number of gyroscope axes supplied by this board.
53
+ */
54
+ rb_define_method(ph_spatial, "getGyroAxisCount", ph_spatial_get_gyro_axis_count, 0);
55
+
56
+ /* Document-method: getCompassAxisCount
57
+ * call-seq: getCompassAxisCount -> count
58
+ *
59
+ * Gets the number of compass axes supplied by this board.
60
+ */
61
+ rb_define_method(ph_spatial, "getCompassAxisCount", ph_spatial_get_compass_axis_count, 0);
62
+
63
+ /* Document-method: getAcceleration
64
+ * call-seq: getAcceleration(index) -> acceleration
65
+ *
66
+ * Gets the current acceleration of an axis.
67
+ */
68
+ rb_define_method(ph_spatial, "getAcceleration", ph_spatial_get_acceleration, 1);
69
+
70
+ /* Document-method: getAccelerationMin
71
+ * call-seq: getAccelerationMin(index) -> acceleration
72
+ *
73
+ * Gets the minimum acceleration supported by an axis.
74
+ */
75
+ rb_define_method(ph_spatial, "getAccelerationMin", ph_spatial_get_acceleration_min, 1);
76
+
77
+ /* Document-method: getAccelerationMax
78
+ * call-seq: getAccelerationMax(index) -> acceleration
79
+ *
80
+ * Gets the maximum accleration supported by an axis.
81
+ */
82
+ rb_define_method(ph_spatial, "getAccelerationMax", ph_spatial_get_acceleration_max, 1);
83
+
84
+ /* Document-method: getAngularRate
85
+ * call-seq: getAngularRate(index) -> rate
86
+ *
87
+ * Gets the current angular rate of an axis.
88
+ */
89
+ rb_define_method(ph_spatial, "getAngularRate", ph_spatial_get_angular_rate, 1);
90
+
91
+ /* Document-method: getAngularRateMin
92
+ * call-seq: getAngularRateMin(index) -> rate
93
+ *
94
+ * Gets the minimum angular rate supported by an axis.
95
+ */
96
+ rb_define_method(ph_spatial, "getAngularRateMin", ph_spatial_get_angular_rate_min, 1);
97
+
98
+ /* Document-method: getAngularRateMax
99
+ * call-seq: getAngularRateMax(index) -> rate
100
+ *
101
+ * Gets the maximum angular rate supported by an axis.
102
+ */
103
+ rb_define_method(ph_spatial, "getAngularRateMax", ph_spatial_get_angular_rate_max, 1);
104
+
105
+ /* Document-method: getMagneticField
106
+ * call-seq: getMagneticField(index) -> field
107
+ *
108
+ * Gets the current magnetic field stregth of an axis.
109
+ */
110
+ rb_define_method(ph_spatial, "getMagneticField", ph_spatial_get_magnetic_field, 1);
111
+
112
+ /* Document-method: getMagneticFieldMin
113
+ * call-seq: getMagneticFieldMin(index) -> field
114
+ *
115
+ * Gets the minimum magnetic field stregth supported by an axis.
116
+ */
117
+ rb_define_method(ph_spatial, "getMagneticFieldMin", ph_spatial_get_magnetic_field_min, 1);
118
+
119
+ /* Document-method: getMagneticFieldMax
120
+ * call-seq: getMagneticFieldMax(index) -> field
121
+ *
122
+ * Gets the maximum magnetic field stregth supported by an axis.
123
+ */
124
+ rb_define_method(ph_spatial, "getMagneticFieldMax", ph_spatial_get_magnetic_field_max, 1);
125
+
126
+ /* Document-method: getDataRate
127
+ * call-seq: getDataRate -> rate
128
+ *
129
+ * Get the data rate in milliseconds.
130
+ */
131
+ rb_define_method(ph_spatial, "getDataRate", ph_spatial_get_data_rate, 0);
132
+
133
+ /* Document-method: getDataRateMin
134
+ * call-seq: getDataRateMin -> rate
135
+ *
136
+ * Gets the minimum supported data rate in milliseconds.
137
+ */
138
+ rb_define_method(ph_spatial, "getDataRateMin", ph_spatial_get_data_rate_min, 0);
139
+
140
+ /* Document-method: getDataRateMax
141
+ * call-seq: getDataRateMax -> rate
142
+ *
143
+ * Gets the maximum supported data rate in milliseconds.
144
+ */
145
+ rb_define_method(ph_spatial, "getDataRateMax", ph_spatial_get_data_rate_max, 0);
146
+
147
+ /* Document-method: setDataRate
148
+ * call-seq: setDataRate(rate)
149
+ *
150
+ * Sets the data rate in milliseconds.
151
+ */
152
+ rb_define_method(ph_spatial, "setDataRate", ph_spatial_set_data_rate, 1);
153
+
154
+ /* Document-method: zeroGyro
155
+ * call-seq: zeroGyro
156
+ *
157
+ * Zeroes the gyroscope. This takes about two seconds and the gyro zxes will report 0 during the process.
158
+ * This should only be called when the board is not moving.
159
+ */
160
+ rb_define_method(ph_spatial, "zeroGyro", ph_spatial_zero_gyro, 0);
161
+
162
+ /* Document-method: setCompassCorrectionParameters
163
+ * call-seq: setCompassCorrectionParameters(mag_field, offset0, offset1, offset2, gain0, gain1, gain2, T0, T1, T2, T3, T4, T5)
164
+ *
165
+ * Sets the compass correction factors. This can be used to correcting any sensor errors,
166
+ * including hard and soft iron offsets and sensor error factors.
167
+ */
168
+ rb_define_method(ph_spatial, "setCompassCorrectionParameters", ph_spatial_set_compass_correction_parameters, 13);
169
+
170
+ /* Document-method: resetCompassCorrectionParameters
171
+ * call-seq: resetCompassCorrectionParameters
172
+ *
173
+ * Resets the compass correction factors. Magnetic field data will be presented directly as reported by the sensor.
174
+ */
175
+ rb_define_method(ph_spatial, "resetCompassCorrectionParameters", ph_spatial_reset_compass_correction_parameters, 0);
176
+
177
+ #ifdef PH_CALLBACK
178
+ rb_define_private_method(ph_spatial, "ext_setOnSpatialDataHandler", ph_spatial_set_on_spatial_data_handler, 1);
179
+ #endif
180
+
181
+ rb_define_alias(ph_spatial, "acceleration_axis_count", "getAccelerationAxisCount");
182
+ rb_define_alias(ph_spatial, "gyro_axis_count", "getGyroAxisCount");
183
+ rb_define_alias(ph_spatial, "compass_axis_count", "getCompassAxisCount");
184
+ rb_define_alias(ph_spatial, "acceleration", "getAcceleration");
185
+ rb_define_alias(ph_spatial, "acceleration_min", "getAccelerationMin");
186
+ rb_define_alias(ph_spatial, "acceleration_max", "getAccelerationMax");
187
+ rb_define_alias(ph_spatial, "angular_rate", "getAngularRate");
188
+ rb_define_alias(ph_spatial, "angular_rate_min", "getAngularRateMin");
189
+ rb_define_alias(ph_spatial, "angular_rate_max", "getAngularRateMax");
190
+ rb_define_alias(ph_spatial, "magnetic_field", "getMagneticField");
191
+ rb_define_alias(ph_spatial, "magnetic_field_min", "getMagneticFieldMin");
192
+ rb_define_alias(ph_spatial, "magnetic_field_max", "getMagneticFieldMax");
193
+ rb_define_alias(ph_spatial, "data_rate", "getDataRate");
194
+ rb_define_alias(ph_spatial, "data_rate_min", "getDataRateMin");
195
+ rb_define_alias(ph_spatial, "data_rate_max", "getDataRateMax");
196
+ rb_define_alias(ph_spatial, "data_rate=", "setDataRate");
197
+ rb_define_alias(ph_spatial, "zero_gyro", "zeroGyro");
198
+ rb_define_alias(ph_spatial, "set_compass_correction_parameters", "setCompassCorrectionParameters");
199
+ rb_define_alias(ph_spatial, "reset_compass_correction_parameters", "resetCompassCorrectionParameters");
200
+
201
+ return ph_spatial;
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
+
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
+
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;
366
+ }
367
+
368
+ #endif
369
+