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,567 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+
5
+ VALUE ph_advservo_init(VALUE self);
6
+ VALUE ph_advservo_get_motor_count(VALUE self);
7
+ VALUE ph_advservo_get_acceleration(VALUE self, VALUE index);
8
+ VALUE ph_advservo_get_acceleration_min(VALUE self, VALUE index);
9
+ VALUE ph_advservo_get_acceleration_max(VALUE self, VALUE index);
10
+ VALUE ph_advservo_set_acceleration(VALUE self, VALUE index, VALUE accel);
11
+ VALUE ph_advservo_get_velocity(VALUE self, VALUE index);
12
+ VALUE ph_advservo_get_velocity_min(VALUE self, VALUE index);
13
+ VALUE ph_advservo_get_velocity_max(VALUE self, VALUE index);
14
+ VALUE ph_advservo_get_velocity_limit(VALUE self, VALUE index);
15
+ VALUE ph_advservo_set_velocity_limit(VALUE self, VALUE index, VALUE limit);
16
+ VALUE ph_advservo_get_position(VALUE self, VALUE index);
17
+ VALUE ph_advservo_get_position_min(VALUE self, VALUE index);
18
+ VALUE ph_advservo_get_position_max(VALUE self, VALUE index);
19
+ VALUE ph_advservo_set_position(VALUE self, VALUE index, VALUE position);
20
+ VALUE ph_advservo_set_position_min(VALUE self, VALUE index, VALUE min);
21
+ VALUE ph_advservo_set_position_max(VALUE self, VALUE index, VALUE max);
22
+ VALUE ph_advservo_get_current(VALUE self, VALUE index);
23
+ VALUE ph_advservo_get_speed_ramping_on(VALUE self, VALUE index);
24
+ VALUE ph_advservo_set_speed_ramping_on(VALUE self, VALUE index, VALUE state);
25
+ VALUE ph_advservo_get_engaged(VALUE self, VALUE index);
26
+ VALUE ph_advservo_set_engaged(VALUE self, VALUE index, VALUE state);
27
+ VALUE ph_advservo_get_stopped(VALUE self, VALUE index);
28
+ VALUE ph_advservo_get_servo_type(VALUE self, VALUE index);
29
+ VALUE ph_advservo_set_servo_type(VALUE self, VALUE index, VALUE type);
30
+ VALUE ph_advservo_set_servo_parameters(VALUE self, VALUE index, VALUE min_us, VALUE max_us, VALUE degrees, VALUE velocity_max);
31
+
32
+ #ifdef PH_CALLBACK
33
+ VALUE ph_advservo_set_on_velocity_change_handler(VALUE self, VALUE handler);
34
+ VALUE ph_advservo_set_on_position_change_handler(VALUE self, VALUE handler);
35
+ VALUE ph_advservo_set_on_current_change_handler(VALUE self, VALUE handler);
36
+ int ph_advservo_on_velocity_change(CPhidgetAdvancedServoHandle phid, void *userPtr, int index, double velocity);
37
+ int ph_advservo_on_position_change(CPhidgetAdvancedServoHandle phid, void *userPtr, int index, double position);
38
+ int ph_advservo_on_current_change(CPhidgetAdvancedServoHandle phid, void *userPtr, int index, double current);
39
+ #endif
40
+
41
+
42
+ VALUE Init_phidgets_advservo(VALUE ph_module, VALUE ph_common) {
43
+ VALUE ph_advservo = rb_define_class_under(ph_module, "AdvancedServo", ph_common);
44
+
45
+ /* Default - This is what the servo API been historically used, originally based on the Futaba FP-S148 */
46
+ rb_define_const(ph_advservo, "DEFAULT", INT2FIX(PHIDGET_SERVO_DEFAULT));
47
+ /* Raw us mode - all position, velocity, acceleration functions are specified in microseconds rather then degrees */
48
+ rb_define_const(ph_advservo, "RAW_US_MODE", INT2FIX(PHIDGET_SERVO_RAW_us_MODE));
49
+ /* HiTec HS-322HD Standard \Servo */
50
+ rb_define_const(ph_advservo, "HITEC_HS322HD", INT2FIX(PHIDGET_SERVO_HITEC_HS322HD));
51
+ /* HiTec HS-5245MG Digital Mini \Servo */
52
+ rb_define_const(ph_advservo, "HITEC_HS5245MG", INT2FIX(PHIDGET_SERVO_HITEC_HS5245MG));
53
+ /* HiTec HS-805BB Mega Quarter Scale \Servo */
54
+ rb_define_const(ph_advservo, "HITEC_805BB", INT2FIX(PHIDGET_SERVO_HITEC_805BB));
55
+ /* HiTec HS-422 Standard \Servo */
56
+ rb_define_const(ph_advservo, "HITEC_HS422", INT2FIX(PHIDGET_SERVO_HITEC_HS422));
57
+ /* Tower Pro MG90 Micro \Servo */
58
+ rb_define_const(ph_advservo, "TOWERPRO_MG90", INT2FIX(PHIDGET_SERVO_TOWERPRO_MG90));
59
+ /* HiTec HSR-1425CR Continuous Rotation \Servo */
60
+ rb_define_const(ph_advservo, "HITEC_HSR1425CR", INT2FIX(PHIDGET_SERVO_HITEC_HSR1425CR));
61
+ /* HiTec HS-785HB Sail Winch \Servo */
62
+ rb_define_const(ph_advservo, "HITEC_HS785HB", INT2FIX(PHIDGET_SERVO_HITEC_HS785HB));
63
+ /* HiTec HS-485HB Deluxe \Servo */
64
+ rb_define_const(ph_advservo, "HITEC_HS485HB", INT2FIX(PHIDGET_SERVO_HITEC_HS485HB));
65
+ /* HiTec HS-645MG Ultra Torque \Servo */
66
+ rb_define_const(ph_advservo, "HITEC_HS645MG", INT2FIX(PHIDGET_SERVO_HITEC_HS645MG));
67
+ /* HiTec HS-815BB Mega Sail \Servo */
68
+ rb_define_const(ph_advservo, "HITEC_815BB", INT2FIX(PHIDGET_SERVO_HITEC_815BB));
69
+ /* Document-const:
70
+ * Firgelli L12 Linear Actuator 30mm 50\:1 */
71
+ rb_define_const(ph_advservo, "FIRGELLI_L12_30_50_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R));
72
+ /* Document-const:
73
+ * Firgelli L12 Linear Actuator 50mm 100\:1 */
74
+ rb_define_const(ph_advservo, "FIRGELLI_L12_50_100_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R));
75
+ /* Document-const:
76
+ * Firgelli L12 Linear Actuator 50mm 210\:1 */
77
+ rb_define_const(ph_advservo, "FIRGELLI_L12_50_210_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R));
78
+ /* Document-const:
79
+ * Firgelli L12 Linear Actuator 100mm 50\:1 */
80
+ rb_define_const(ph_advservo, "FIRGELLI_L12_100_50_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R));
81
+ /* Document-const:
82
+ * Firgelli L12 Linear Actuator 100mm 100\:1 */
83
+ rb_define_const(ph_advservo, "FIRGELLI_L12_100_100_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R));
84
+ /* SpringRC SM-S2313M Micro \Servo */
85
+ rb_define_const(ph_advservo, "SPRINGRC_SM_S2313M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S2313M));
86
+ /* SpringRC SM-S3317M Small \Servo */
87
+ rb_define_const(ph_advservo, "SPRINGRC_SM_S3317M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S3317M));
88
+ /* SpringRC SM-S3317SR Small Continuous Rotation \Servo */
89
+ rb_define_const(ph_advservo, "SPRINGRC_SM_S3317SR", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S3317SR));
90
+ /* SpringRC SM-S4303R Standard Continuous Rotation \Servo */
91
+ rb_define_const(ph_advservo, "SPRINGRC_SM_S4303R", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4303R));
92
+ /* SpringRC SM-S4315M High Torque \Servo */
93
+ rb_define_const(ph_advservo, "SPRINGRC_SM_S4315M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4315M));
94
+ /* SpringRC SM-S4315R High Torque Continuous Rotation \Servo */
95
+ rb_define_const(ph_advservo, "SPRINGRC_SM_S4315R", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4315R));
96
+ /* SpringRC SM-S4505B Standard \Servo */
97
+ rb_define_const(ph_advservo, "SPRINGRC_SM_S4505B", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4505B));
98
+
99
+
100
+ /* Document-method: new
101
+ * call-seq: new
102
+ *
103
+ * Creates a Phidget AdvancedServo object.
104
+ */
105
+ rb_define_method(ph_advservo, "initialize", ph_advservo_init, 0);
106
+
107
+ /* Document-method: getMotorCount
108
+ * call-seq: getMotorCount -> count
109
+ *
110
+ * Gets the number of motors supported by this controller
111
+ */
112
+ rb_define_method(ph_advservo, "getMotorCount", ph_advservo_get_motor_count, 0);
113
+
114
+ /* Document-method: getAcceleration
115
+ * call-seq: getAcceleration(index) -> acceleration
116
+ *
117
+ * Gets the last set acceleration for a motor.
118
+ */
119
+ rb_define_method(ph_advservo, "getAcceleration", ph_advservo_get_acceleration, 1);
120
+
121
+ /* Document-method: getAccelerationMin
122
+ * call-seq: getAccelerationMin(index) -> min
123
+ *
124
+ * Gets the minimum acceleration supported by a motor.
125
+ */
126
+ rb_define_method(ph_advservo, "getAccelerationMin", ph_advservo_get_acceleration_min, 1);
127
+
128
+ /* Document-method: getAccelerationMax
129
+ * call-seq: getAccelerationMax(index) -> max
130
+ *
131
+ * Gets the maximum acceleration supported by a motor
132
+ */
133
+ rb_define_method(ph_advservo, "getAccelerationMax", ph_advservo_get_acceleration_max, 1);
134
+
135
+ /* Document-method: setAcceleration
136
+ * call-seq: setAcceleration(index, acceleration)
137
+ *
138
+ * Sets the acceleration for a motor.
139
+ */
140
+ rb_define_method(ph_advservo, "setAcceleration", ph_advservo_set_acceleration, 2);
141
+
142
+ /* Document-method: getVelocity
143
+ * call-seq: getVelocity(index) -> velocity
144
+ *
145
+ * Gets the current velocity of a motor.
146
+ */
147
+ rb_define_method(ph_advservo, "getVelocity", ph_advservo_get_velocity, 1);
148
+
149
+ /* Document-method: getVelocityMin
150
+ * call-seq: getVelocityMin(index) -> min
151
+ *
152
+ * Gets the minimum velocity that can be set for a motor.
153
+ */
154
+ rb_define_method(ph_advservo, "getVelocityMin", ph_advservo_get_velocity_min, 1);
155
+
156
+ /* Document-method: getVelocityMax
157
+ * call-seq: getVelocityMax(index) -> max
158
+ *
159
+ * Gets the maximum velocity that can be set for a motor.
160
+ */
161
+ rb_define_method(ph_advservo, "getVelocityMax", ph_advservo_get_velocity_max, 1);
162
+
163
+ /* Document-method: getVelocityLimit
164
+ * call-seq: getVelocityLimit(index) -> limit
165
+ *
166
+ * Gets the last set velocity limit for a motor.
167
+ */
168
+ rb_define_method(ph_advservo, "getVelocityLimit", ph_advservo_get_velocity_limit, 1);
169
+
170
+ /* Document-method: setVelocityLimit
171
+ * call-seq: setVelocityLimit(index, limit)
172
+ *
173
+ * Sets the velocity limit for a motor.
174
+ */
175
+ rb_define_method(ph_advservo, "setVelocityLimit", ph_advservo_set_velocity_limit, 2);
176
+
177
+ /* Document-method: getPosition
178
+ * call-seq: getPosition(index) -> position
179
+ *
180
+ * Gets the current position of a motor.
181
+ */
182
+ rb_define_method(ph_advservo, "getPosition", ph_advservo_get_position, 1);
183
+
184
+ /* Document-method: getPositionMin
185
+ * call-seq: getPositionMin(index) -> min
186
+ *
187
+ * Gets the minimum position that a motor can go to.
188
+ */
189
+ rb_define_method(ph_advservo, "getPositionMin", ph_advservo_get_position_min, 1);
190
+
191
+ /* Document-method: getPositionMax
192
+ * call-seq: getPositionMax(index) -> max
193
+ *
194
+ * Gets the maximum position that a motor can go to.
195
+ */
196
+ rb_define_method(ph_advservo, "getPositionMax", ph_advservo_get_position_max, 1);
197
+
198
+ /* Document-method: setPosition
199
+ * call-seq: setPosition(index, position)
200
+ *
201
+ * Sets the position of a motor.
202
+ */
203
+ rb_define_method(ph_advservo, "setPosition", ph_advservo_set_position, 2);
204
+
205
+ /* Document-method: setPositionMin
206
+ * call-seq: setPositionMin(index, position)
207
+ *
208
+ * Sets the minimum position that a motor can go to.
209
+ */
210
+ rb_define_method(ph_advservo, "setPositionMin", ph_advservo_set_position_min, 2);
211
+
212
+ /* Document-method: setPositionMax
213
+ * call-seq: setPositionMax(index, position)
214
+ *
215
+ * Sets the maximum position that a motor can go to.
216
+ */
217
+ rb_define_method(ph_advservo, "setPositionMax", ph_advservo_set_position_max, 2);
218
+
219
+ /* Document-method: getCurrent
220
+ * call-seq: getCurrent(index)
221
+ *
222
+ * Gets the current current draw for a motor.
223
+ */
224
+ rb_define_method(ph_advservo, "getCurrent", ph_advservo_get_current, 1);
225
+
226
+ /* Document-method: getSpeedRampingOn
227
+ * call-seq: getSpeedRampingOn(index) -> true or false
228
+ *
229
+ * Gets the speed ramping state for a motor. This is whether or not velocity and acceleration are used.
230
+ */
231
+ rb_define_method(ph_advservo, "getSpeedRampingOn", ph_advservo_get_speed_ramping_on, 1);
232
+
233
+ /* Document-method: setSpeedRampingOn
234
+ * call-seq: setSpeedRampingOn(index, ramping_state)
235
+ *
236
+ * Sets the speed ramping state for a motor. This is whether or not velocity and acceleration are used.
237
+ */
238
+ rb_define_method(ph_advservo, "setSpeedRampingOn", ph_advservo_set_speed_ramping_on, 2);
239
+
240
+ /* Document-method: getEngaged
241
+ * call-seq: getEngaged(index) -> true or false
242
+ *
243
+ * Gets the engaged state of a motor. This is whether the motor is powered or not.
244
+ */
245
+ rb_define_method(ph_advservo, "getEngaged", ph_advservo_get_engaged, 1);
246
+
247
+ /* Document-method: setEngaged
248
+ * call-seq: setEngaged(index, engaged_state)
249
+ *
250
+ * Sets the engaged state of a motor. This is whether the motor is powered or not.
251
+ */
252
+ rb_define_method(ph_advservo, "setEngaged", ph_advservo_set_engaged, 2);
253
+
254
+ /* Document-method: getStopped
255
+ * call-seq: getStopped(index) -> true or false
256
+ *
257
+ * Gets the stopped state of a motor. This is true when the motor is not moving and there are no outstanding commands.
258
+ */
259
+ rb_define_method(ph_advservo, "getStopped", ph_advservo_get_stopped, 1);
260
+
261
+ /* Document-method: getServoType
262
+ * call-seq: getServoType(index) -> servo_type
263
+ *
264
+ * Gets the servo type of a motor.
265
+ */
266
+ rb_define_method(ph_advservo, "getServoType", ph_advservo_get_servo_type, 1);
267
+
268
+ /* Document-method: setServoType
269
+ * call-seq: setServoType(index, servo_type)
270
+ *
271
+ * Sets the servo type of a motor.
272
+ */
273
+ rb_define_method(ph_advservo, "setServoType", ph_advservo_set_servo_type, 2);
274
+
275
+ /* Document-method: setServoParameters
276
+ * call-seq: setServoParameters(index, min_us, max_us, degrees, velocity_max)
277
+ *
278
+ * Sets the servo parameters of a motor.
279
+ */
280
+ rb_define_method(ph_advservo, "setServoParameters", ph_advservo_set_servo_parameters, 5);
281
+
282
+ #ifdef PH_CALLBACK
283
+ rb_define_private_method(ph_advservo, "ext_setOnVelocityChangeHandler", ph_advservo_set_on_velocity_change_handler, 1);
284
+ rb_define_private_method(ph_advservo, "ext_setOnPositionChangeHandler", ph_advservo_set_on_position_change_handler, 1);
285
+ rb_define_private_method(ph_advservo, "ext_setOnCurrentChangeHandler", ph_advservo_set_on_current_change_handler, 1);
286
+ #endif
287
+
288
+ rb_define_alias(ph_advservo, "motor_count", "getMotorCount");
289
+ rb_define_alias(ph_advservo, "acceleration", "getAcceleration");
290
+ rb_define_alias(ph_advservo, "acceleration_min", "getAccelerationMin");
291
+ rb_define_alias(ph_advservo, "acceleration_max", "getAccelerationMax");
292
+ rb_define_alias(ph_advservo, "set_acceleration", "setAcceleration");
293
+ rb_define_alias(ph_advservo, "velocity", "getVelocity");
294
+ rb_define_alias(ph_advservo, "velocity_min", "getVelocityMin");
295
+ rb_define_alias(ph_advservo, "velocity_max", "getVelocityMax");
296
+ rb_define_alias(ph_advservo, "velocity_limit", "getVelocityLimit");
297
+ rb_define_alias(ph_advservo, "set_velocity_limit", "setVelocityLimit");
298
+ rb_define_alias(ph_advservo, "position", "getPosition");
299
+ rb_define_alias(ph_advservo, "position_min", "getPositionMin");
300
+ rb_define_alias(ph_advservo, "position_max", "getPositionMax");
301
+ rb_define_alias(ph_advservo, "set_position", "setPosition");
302
+ rb_define_alias(ph_advservo, "set_position_min", "setPositionMin");
303
+ rb_define_alias(ph_advservo, "set_position_max", "setPositionMax");
304
+ rb_define_alias(ph_advservo, "current", "getCurrent");
305
+ rb_define_alias(ph_advservo, "speed_ramping_on?", "getSpeedRampingOn");
306
+ rb_define_alias(ph_advservo, "set_speed_ramping_on", "setSpeedRampingOn");
307
+ rb_define_alias(ph_advservo, "engaged?", "getEngaged");
308
+ rb_define_alias(ph_advservo, "set_engaged", "setEngaged");
309
+ rb_define_alias(ph_advservo, "stopped?", "getStopped");
310
+ rb_define_alias(ph_advservo, "servo_type", "getServoType");
311
+ rb_define_alias(ph_advservo, "set_servo_type", "setServoType");
312
+ rb_define_alias(ph_advservo, "set_servo_parameters", "setServoParameters");
313
+
314
+ return ph_advservo;
315
+ }
316
+
317
+
318
+ VALUE ph_advservo_init(VALUE self) {
319
+ ph_data_t *ph = get_ph_data(self);
320
+ ph_raise(CPhidgetAdvancedServo_create((CPhidgetAdvancedServoHandle *)(&(ph->handle))));
321
+ return self;
322
+ }
323
+
324
+ VALUE ph_advservo_get_motor_count(VALUE self) {
325
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
326
+ int count;
327
+ ph_raise(CPhidgetAdvancedServo_getMotorCount(handle, &count));
328
+ return INT2FIX(count);
329
+ }
330
+
331
+ VALUE ph_advservo_get_acceleration(VALUE self, VALUE index) {
332
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
333
+ double accel;
334
+ ph_raise(CPhidgetAdvancedServo_getAcceleration(handle, FIX2INT(index), &accel));
335
+ return rb_float_new(accel);
336
+ }
337
+
338
+ VALUE ph_advservo_get_acceleration_min(VALUE self, VALUE index) {
339
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
340
+ double accel;
341
+ ph_raise(CPhidgetAdvancedServo_getAccelerationMin(handle, FIX2INT(index), &accel));
342
+ return rb_float_new(accel);
343
+ }
344
+
345
+ VALUE ph_advservo_get_acceleration_max(VALUE self, VALUE index) {
346
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
347
+ double accel;
348
+ ph_raise(CPhidgetAdvancedServo_getAccelerationMax(handle, FIX2INT(index), &accel));
349
+ return rb_float_new(accel);
350
+ }
351
+
352
+ VALUE ph_advservo_set_acceleration(VALUE self, VALUE index, VALUE accel) {
353
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
354
+ ph_raise(CPhidgetAdvancedServo_setAcceleration(handle, FIX2INT(index), NUM2DBL(accel)));
355
+ return Qnil;
356
+ }
357
+
358
+ VALUE ph_advservo_get_velocity(VALUE self, VALUE index) {
359
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
360
+ double velocity;
361
+ ph_raise(CPhidgetAdvancedServo_getVelocity(handle, FIX2INT(index), &velocity));
362
+ return rb_float_new(velocity);
363
+ }
364
+
365
+ VALUE ph_advservo_get_velocity_min(VALUE self, VALUE index) {
366
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
367
+ double velocity;
368
+ ph_raise(CPhidgetAdvancedServo_getVelocityMin(handle, FIX2INT(index), &velocity));
369
+ return rb_float_new(velocity);
370
+ }
371
+
372
+ VALUE ph_advservo_get_velocity_max(VALUE self, VALUE index) {
373
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
374
+ double velocity;
375
+ ph_raise(CPhidgetAdvancedServo_getVelocityMax(handle, FIX2INT(index), &velocity));
376
+ return rb_float_new(velocity);
377
+ }
378
+
379
+ VALUE ph_advservo_get_velocity_limit(VALUE self, VALUE index) {
380
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
381
+ double velocity;
382
+ ph_raise(CPhidgetAdvancedServo_getVelocityLimit(handle, FIX2INT(index), &velocity));
383
+ return rb_float_new(velocity);
384
+ }
385
+
386
+ VALUE ph_advservo_set_velocity_limit(VALUE self, VALUE index, VALUE limit) {
387
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
388
+ ph_raise(CPhidgetAdvancedServo_setVelocityLimit(handle, FIX2INT(index), NUM2DBL(limit)));
389
+ return Qnil;
390
+ }
391
+
392
+ VALUE ph_advservo_get_position(VALUE self, VALUE index) {
393
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
394
+ double position;
395
+ ph_raise(CPhidgetAdvancedServo_getPosition(handle, FIX2INT(index), &position));
396
+ return rb_float_new(position);
397
+ }
398
+
399
+ VALUE ph_advservo_get_position_min(VALUE self, VALUE index) {
400
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
401
+ double position;
402
+ ph_raise(CPhidgetAdvancedServo_getPositionMin(handle, FIX2INT(index), &position));
403
+ return rb_float_new(position);
404
+ }
405
+
406
+ VALUE ph_advservo_get_position_max(VALUE self, VALUE index) {
407
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
408
+ double position;
409
+ ph_raise(CPhidgetAdvancedServo_getPositionMax(handle, FIX2INT(index), &position));
410
+ return rb_float_new(position);
411
+ }
412
+
413
+ VALUE ph_advservo_set_position(VALUE self, VALUE index, VALUE position) {
414
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
415
+ ph_raise(CPhidgetAdvancedServo_setPosition(handle, FIX2INT(index), NUM2DBL(position)));
416
+ return Qnil;
417
+ }
418
+
419
+ VALUE ph_advservo_set_position_min(VALUE self, VALUE index, VALUE min) {
420
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
421
+ ph_raise(CPhidgetAdvancedServo_setPositionMin(handle, FIX2INT(index), NUM2DBL(min)));
422
+ return Qnil;
423
+ }
424
+
425
+ VALUE ph_advservo_set_position_max(VALUE self, VALUE index, VALUE max) {
426
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
427
+ ph_raise(CPhidgetAdvancedServo_setPositionMax(handle, FIX2INT(index), NUM2DBL(max)));
428
+ return Qnil;
429
+ }
430
+
431
+ VALUE ph_advservo_get_current(VALUE self, VALUE index) {
432
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
433
+ double current;
434
+ ph_raise(CPhidgetAdvancedServo_getCurrent(handle, FIX2INT(index), &current));
435
+ return rb_float_new(current);
436
+ }
437
+
438
+ VALUE ph_advservo_get_speed_ramping_on(VALUE self, VALUE index) {
439
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
440
+ int on;
441
+ ph_raise(CPhidgetAdvancedServo_getSpeedRampingOn(handle, FIX2INT(index), &on));
442
+ return on == PTRUE ? Qtrue : Qfalse;
443
+ }
444
+
445
+ VALUE ph_advservo_set_speed_ramping_on(VALUE self, VALUE index, VALUE state) {
446
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
447
+ ph_raise(CPhidgetAdvancedServo_setSpeedRampingOn(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
448
+ return Qnil;
449
+ }
450
+
451
+ VALUE ph_advservo_get_engaged(VALUE self, VALUE index) {
452
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
453
+ int engaged;
454
+ ph_raise(CPhidgetAdvancedServo_getEngaged(handle, FIX2INT(index), &engaged));
455
+ return engaged == PTRUE ? Qtrue : Qfalse;
456
+ }
457
+
458
+ VALUE ph_advservo_set_engaged(VALUE self, VALUE index, VALUE state) {
459
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
460
+ ph_raise(CPhidgetAdvancedServo_setEngaged(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
461
+ return Qnil;
462
+ }
463
+
464
+ VALUE ph_advservo_get_stopped(VALUE self, VALUE index) {
465
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
466
+ int stopped;
467
+ ph_raise(CPhidgetAdvancedServo_getStopped(handle, FIX2INT(index), &stopped));
468
+ return stopped == PTRUE ? Qtrue : Qfalse;
469
+ }
470
+
471
+ VALUE ph_advservo_get_servo_type(VALUE self, VALUE index) {
472
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
473
+ CPhidget_ServoType type;
474
+ ph_raise(CPhidgetAdvancedServo_getServoType(handle, FIX2INT(index), &type));
475
+ return INT2FIX(type);
476
+ }
477
+
478
+ VALUE ph_advservo_set_servo_type(VALUE self, VALUE index, VALUE type) {
479
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
480
+ ph_raise(CPhidgetAdvancedServo_setServoType(handle, FIX2INT(index), (CPhidget_ServoType)FIX2INT(type)));
481
+ return Qnil;
482
+ }
483
+
484
+ VALUE ph_advservo_set_servo_parameters(VALUE self, VALUE index, VALUE min_us, VALUE max_us, VALUE degrees, VALUE velocity_max) {
485
+ CPhidgetAdvancedServoHandle handle = (CPhidgetAdvancedServoHandle)get_ph_handle(self);
486
+ ph_raise(CPhidgetAdvancedServo_setServoParameters(handle, FIX2INT(index), NUM2DBL(min_us), NUM2DBL(max_us), NUM2DBL(degrees), NUM2DBL(velocity_max)));
487
+ return Qnil;
488
+ }
489
+
490
+
491
+ #ifdef PH_CALLBACK
492
+ VALUE ph_advservo_set_on_velocity_change_handler(VALUE self, VALUE handler) {
493
+ ph_data_t *ph = get_ph_data(self);
494
+ ph_callback_data_t *callback_data = &ph->dev_callback_1;
495
+ if( TYPE(handler) == T_NIL ) {
496
+ callback_data->exit = true;
497
+ ph_raise(CPhidgetAdvancedServo_set_OnVelocityChange_Handler((CPhidgetAdvancedServoHandle)ph->handle, NULL, (void *)NULL));
498
+ } else {
499
+ callback_data->called = false;
500
+ callback_data->exit = false;
501
+ callback_data->phidget = self;
502
+ callback_data->callback = handler;
503
+ ph_raise(CPhidgetAdvancedServo_set_OnVelocityChange_Handler((CPhidgetAdvancedServoHandle)ph->handle, ph_advservo_on_velocity_change, (void *)callback_data));
504
+ ph_callback_thread(callback_data);
505
+ }
506
+ return Qnil;
507
+ }
508
+
509
+
510
+ VALUE ph_advservo_set_on_position_change_handler(VALUE self, VALUE handler) {
511
+ ph_data_t *ph = get_ph_data(self);
512
+ ph_callback_data_t *callback_data = &ph->dev_callback_2;
513
+ if( TYPE(handler) == T_NIL ) {
514
+ callback_data->exit = true;
515
+ ph_raise(CPhidgetAdvancedServo_set_OnPositionChange_Handler((CPhidgetAdvancedServoHandle)ph->handle, NULL, (void *)NULL));
516
+ } else {
517
+ callback_data->called = false;
518
+ callback_data->exit = false;
519
+ callback_data->phidget = self;
520
+ callback_data->callback = handler;
521
+ ph_raise(CPhidgetAdvancedServo_set_OnPositionChange_Handler((CPhidgetAdvancedServoHandle)ph->handle, ph_advservo_on_position_change, (void *)callback_data));
522
+ ph_callback_thread(callback_data);
523
+ }
524
+ return Qnil;
525
+ }
526
+
527
+
528
+ VALUE ph_advservo_set_on_current_change_handler(VALUE self, VALUE handler) {
529
+ ph_data_t *ph = get_ph_data(self);
530
+ ph_callback_data_t *callback_data = &ph->dev_callback_3;
531
+ if( TYPE(handler) == T_NIL ) {
532
+ callback_data->exit = true;
533
+ ph_raise(CPhidgetAdvancedServo_set_OnCurrentChange_Handler((CPhidgetAdvancedServoHandle)ph->handle, NULL, (void *)NULL));
534
+ } else {
535
+ callback_data->called = false;
536
+ callback_data->exit = false;
537
+ callback_data->phidget = self;
538
+ callback_data->callback = handler;
539
+ ph_raise(CPhidgetAdvancedServo_set_OnCurrentChange_Handler((CPhidgetAdvancedServoHandle)ph->handle, ph_advservo_on_current_change, (void *)callback_data));
540
+ ph_callback_thread(callback_data);
541
+ }
542
+ return Qnil;
543
+ }
544
+
545
+
546
+ int ph_advservo_on_velocity_change(CPhidgetAdvancedServoHandle phid, void *userPtr, int index, double velocity) {
547
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
548
+ callback_data->called = true;
549
+ return EPHIDGET_OK;
550
+ }
551
+
552
+
553
+ int ph_advservo_on_position_change(CPhidgetAdvancedServoHandle phid, void *userPtr, int index, double position) {
554
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
555
+ callback_data->called = true;
556
+ return EPHIDGET_OK;
557
+ }
558
+
559
+
560
+ int ph_advservo_on_current_change(CPhidgetAdvancedServoHandle phid, void *userPtr, int index, double current) {
561
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
562
+ callback_data->called = true;
563
+ return EPHIDGET_OK;
564
+ }
565
+
566
+ #endif
567
+