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,642 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+
5
+ VALUE ph_motor_init(VALUE self);
6
+ VALUE ph_motor_get_motor_count(VALUE self);
7
+ VALUE ph_motor_get_velocity(VALUE self, VALUE index);
8
+ VALUE ph_motor_set_velocity(VALUE self, VALUE index, VALUE velocity);
9
+ VALUE ph_motor_get_acceleration(VALUE self, VALUE index);
10
+ VALUE ph_motor_get_acceleration_min(VALUE self, VALUE index);
11
+ VALUE ph_motor_get_acceleration_max(VALUE self, VALUE index);
12
+ VALUE ph_motor_set_acceleration(VALUE self, VALUE index, VALUE accel);
13
+ VALUE ph_motor_get_current(VALUE self, VALUE index);
14
+ VALUE ph_motor_get_input_count(VALUE self);
15
+ VALUE ph_motor_get_input_state(VALUE self, VALUE index);
16
+ VALUE ph_motor_get_encoder_count(VALUE self);
17
+ VALUE ph_motor_get_encoder_position(VALUE self, VALUE index);
18
+ VALUE ph_motor_set_encoder_position(VALUE self, VALUE index, VALUE position);
19
+ VALUE ph_motor_get_back_emf(VALUE self, VALUE index);
20
+ VALUE ph_motor_get_back_emf_sensing_state(VALUE self, VALUE index);
21
+ VALUE ph_motor_set_back_emf_sensing_state(VALUE self, VALUE index, VALUE state);
22
+ VALUE ph_motor_get_supply_voltage(VALUE self);
23
+ VALUE ph_motor_get_braking(VALUE self, VALUE index);
24
+ VALUE ph_motor_set_braking(VALUE self, VALUE index, VALUE braking);
25
+ VALUE ph_motor_get_sensor_count(VALUE self);
26
+ VALUE ph_motor_get_sensor_value(VALUE self, VALUE index);
27
+ VALUE ph_motor_get_sensor_raw_value(VALUE self, VALUE index);
28
+ VALUE ph_motor_get_ratiometric(VALUE self);
29
+ VALUE ph_motor_set_ratiometric(VALUE self, VALUE ratiometric);
30
+
31
+ #ifdef PH_CALLBACK
32
+ VALUE ph_motor_set_on_velocity_change_handler(VALUE self, VALUE handler);
33
+ VALUE ph_motor_set_on_current_change_handler(VALUE self, VALUE handler);
34
+ VALUE ph_motor_set_on_current_update_handler(VALUE self, VALUE handler);
35
+ VALUE ph_motor_set_on_input_change_handler(VALUE self, VALUE handler);
36
+ VALUE ph_motor_set_on_encoder_position_change_handler(VALUE self, VALUE handler);
37
+ VALUE ph_motor_set_on_encoder_position_update_handler(VALUE self, VALUE handler);
38
+ VALUE ph_motor_set_on_back_emf_update_handler(VALUE self, VALUE handler);
39
+ VALUE ph_motor_set_on_sensor_update_handler(VALUE self, VALUE handler);
40
+ int ph_motor_on_velocity_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, double velocity);
41
+ int ph_motor_on_current_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, double current);
42
+ int ph_motor_on_current_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, double current);
43
+ int ph_motor_on_input_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, int state);
44
+ int ph_motor_on_encoder_position_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, int time, int change);
45
+ int ph_motor_on_encoder_position_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, int change);
46
+ int ph_motor_on_back_emf_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, double voltage);
47
+ int ph_motor_on_sensor_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, int value);
48
+ #endif
49
+
50
+
51
+ VALUE Init_phidgets_motor_control(VALUE ph_module, VALUE ph_common) {
52
+ VALUE ph_motor = rb_define_class_under(ph_module, "MotorControl", ph_common);
53
+
54
+ /* Document-method: new
55
+ * call-seq: new
56
+ *
57
+ * Creates a Phidget MotorControl object.
58
+ */
59
+ rb_define_method(ph_motor, "initialize", ph_motor_init, 0);
60
+
61
+ /* Document-method: getMotorCount
62
+ * call-seq: getMotorCount -> count
63
+ *
64
+ * Gets the number of motors supported by this controller.
65
+ */
66
+ rb_define_method(ph_motor, "getMotorCount", ph_motor_get_motor_count, 0);
67
+
68
+ /* Document-method: getVelocity
69
+ * call-seq: getVelocity(index) -> velocity
70
+ *
71
+ * Gets the current velocity of a motor.
72
+ */
73
+ rb_define_method(ph_motor, "getVelocity", ph_motor_get_velocity, 1);
74
+
75
+ /* Document-method: setVelocity
76
+ * call-seq: setVelocity(index, velocity)
77
+ *
78
+ * Sets the velocity of a motor.
79
+ */
80
+ rb_define_method(ph_motor, "setVelocity", ph_motor_set_velocity, 2);
81
+
82
+ /* Document-method: getAcceleration
83
+ * call-seq: getAcceleration(index) -> acceleration
84
+ *
85
+ * Gets the last set acceleration of a motor.
86
+ */
87
+ rb_define_method(ph_motor, "getAcceleration", ph_motor_get_acceleration, 1);
88
+
89
+ /* Document-method: getAccelerationMin
90
+ * call-seq: getAccelerationMin(index) -> acceleration
91
+ *
92
+ * Gets the minimum acceleration supported by a motor.
93
+ */
94
+ rb_define_method(ph_motor, "getAccelerationMin", ph_motor_get_acceleration_min, 1);
95
+
96
+ /* Document-method: getAccelerationMax
97
+ * call-seq: getAccelerationMax(index) -> acceleration
98
+ *
99
+ * Gets the maximum acceleration supported by a motor
100
+ */
101
+ rb_define_method(ph_motor, "getAccelerationMax", ph_motor_get_acceleration_max, 1);
102
+
103
+ /* Document-method: setAcceleration
104
+ * call-seq: setAcceleration(index, acceleration)
105
+ *
106
+ * Sets the acceleration of a motor.
107
+ */
108
+ rb_define_method(ph_motor, "setAcceleration", ph_motor_set_acceleration, 2);
109
+
110
+ /* Document-method: getCurrent
111
+ * call-seq: getCurrent(index) -> current
112
+ *
113
+ * Gets the current current draw for a motor.
114
+ */
115
+ rb_define_method(ph_motor, "getCurrent", ph_motor_get_current, 1);
116
+
117
+ /* Document-method: getInputCount
118
+ * call-seq: getInputCount -> count
119
+ *
120
+ * Gets the number of digital inputs supported by this board.
121
+ */
122
+ rb_define_method(ph_motor, "getInputCount", ph_motor_get_input_count, 0);
123
+
124
+ /* Document-method: getInputState
125
+ * call-seq: getInputState(index) -> true or false
126
+ *
127
+ * Gets the state of a digital input.
128
+ */
129
+ rb_define_method(ph_motor, "getInputState", ph_motor_get_input_state, 1);
130
+
131
+ /* Document-method: getEncoderCount
132
+ * call-seq: getEncoderCount -> count
133
+ *
134
+ * Gets the number of encoder inputs supported by this board.
135
+ */
136
+ rb_define_method(ph_motor, "getEncoderCount", ph_motor_get_encoder_count, 0);
137
+
138
+ /* Document-method: getEncoderPosition
139
+ * call-seq: getEncoderPosition(index) -> position
140
+ *
141
+ * Gets the position of an encoder. This position starts at 0 every time the phidget is opened.
142
+ */
143
+ rb_define_method(ph_motor, "getEncoderPosition", ph_motor_get_encoder_position, 1);
144
+
145
+ /* Document-method: setEncoderPosition
146
+ * call-seq: setEncoderPosition(index, position)
147
+ *
148
+ * Sets the encoder position. This can be used to set the position to a known value,
149
+ * and should only be called when the encoder is not moving.
150
+ */
151
+ rb_define_method(ph_motor, "setEncoderPosition", ph_motor_set_encoder_position, 2);
152
+
153
+ /* Document-method: getBackEMF
154
+ * call-seq: getBackEMF(index) -> voltage
155
+ *
156
+ * Gets the Back EMF voltage for a motor.
157
+ */
158
+ rb_define_method(ph_motor, "getBackEMF", ph_motor_get_back_emf, 1);
159
+
160
+ /* Document-method: getBackEMFSensingState
161
+ * call-seq: getBackEMFSensingState(index) -> true or false
162
+ *
163
+ * Gets the Back EMF sensing state for a motor.
164
+ */
165
+ rb_define_method(ph_motor, "getBackEMFSensingState", ph_motor_get_back_emf_sensing_state, 1);
166
+
167
+ /* Document-method: setBackEMFSensingState
168
+ * call-seq: setBackEMFSensingState(index, state)
169
+ *
170
+ * Sets the Back EMF sensing state for a motor.
171
+ */
172
+ rb_define_method(ph_motor, "setBackEMFSensingState", ph_motor_set_back_emf_sensing_state, 2);
173
+
174
+ /* Document-method: getSupplyVoltage
175
+ * call-seq: getSupplyVoltage -> voltage
176
+ *
177
+ * Gets the Supply voltage for the motors. This could be higher then the actual supply voltage.
178
+ */
179
+ rb_define_method(ph_motor, "getSupplyVoltage", ph_motor_get_supply_voltage, 0);
180
+
181
+ /* Document-method: getBraking
182
+ * call-seq: getBraking(index) -> braking
183
+ *
184
+ * Gets the Braking value for a motor.
185
+ */
186
+ rb_define_method(ph_motor, "getBraking", ph_motor_get_braking, 1);
187
+
188
+ /* Document-method: setBraking
189
+ * call-seq: setBraking(index, braking)
190
+ *
191
+ * Sets the Braking value for a motor. This is applied when velocity is 0. Default is 0%.
192
+ */
193
+ rb_define_method(ph_motor, "setBraking", ph_motor_set_braking, 2);
194
+
195
+ /* Document-method: getSensorCount
196
+ * call-seq: getSensorCount -> count
197
+ *
198
+ * Gets the number of sensor inputs supported by this board.
199
+ */
200
+ rb_define_method(ph_motor, "getSensorCount", ph_motor_get_sensor_count, 0);
201
+
202
+ /* Document-method: getSensorValue
203
+ * call-seq: getSensorValue(index) -> value
204
+ *
205
+ * Gets the value of a sensor.
206
+ */
207
+ rb_define_method(ph_motor, "getSensorValue", ph_motor_get_sensor_value, 1);
208
+
209
+ /* Document-method: getSensorRawValue
210
+ * call-seq: getSensorRawValue(index) -> value
211
+ *
212
+ * Gets the raw value of a sensor (12-bit).
213
+ */
214
+ rb_define_method(ph_motor, "getSensorRawValue", ph_motor_get_sensor_raw_value, 1);
215
+
216
+ /* Document-method: getRatiometric
217
+ * call-seq: getRatiometric -> true or false
218
+ *
219
+ * Gets the ratiometric state.
220
+ */
221
+ rb_define_method(ph_motor, "getRatiometric", ph_motor_get_ratiometric, 0);
222
+
223
+ /* Document-method: setRatiometric
224
+ * call-seq: setRatiometric(state)
225
+ *
226
+ * Sets the ratiometric state. This controls the voltage reference used for sampling the analog sensors.
227
+ */
228
+ rb_define_method(ph_motor, "setRatiometric", ph_motor_set_ratiometric, 1);
229
+
230
+ #ifdef PH_CALLBACK
231
+ rb_define_private_method(ph_motor, "ext_setOnVelocityChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
232
+ rb_define_private_method(ph_motor, "ext_setOnCurrentChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
233
+ rb_define_private_method(ph_motor, "ext_setOnCurrentUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
234
+ rb_define_private_method(ph_motor, "ext_setOnInputChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
235
+ rb_define_private_method(ph_motor, "ext_setOnEncoderPositionChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
236
+ rb_define_private_method(ph_motor, "ext_setOnEncoderPositionUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
237
+ rb_define_private_method(ph_motor, "ext_setOnBackEMFUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
238
+ rb_define_private_method(ph_motor, "ext_setOnSensorUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
239
+ #endif
240
+
241
+ rb_define_alias(ph_motor, "motor_count", "getMotorCount");
242
+ rb_define_alias(ph_motor, "velocity", "getVelocity");
243
+ rb_define_alias(ph_motor, "set_velocity", "setVelocity");
244
+ rb_define_alias(ph_motor, "acceleration", "getAcceleration");
245
+ rb_define_alias(ph_motor, "acceleration_min", "getAccelerationMin");
246
+ rb_define_alias(ph_motor, "acceleration_max", "getAccelerationMax");
247
+ rb_define_alias(ph_motor, "set_acceleration", "setAcceleration");
248
+ rb_define_alias(ph_motor, "current", "getCurrent");
249
+ rb_define_alias(ph_motor, "input_count", "getInputCount");
250
+ rb_define_alias(ph_motor, "input_state", "getInputState");
251
+ rb_define_alias(ph_motor, "encoder_count", "getEncoderCount");
252
+ rb_define_alias(ph_motor, "encoder_position", "getEncoderPosition");
253
+ rb_define_alias(ph_motor, "set_encoder_position", "setEncoderPosition");
254
+ rb_define_alias(ph_motor, "back_emf", "getBackEMF");
255
+ rb_define_alias(ph_motor, "back_emf_sensing_state", "getBackEMFSensingState");
256
+ rb_define_alias(ph_motor, "set_back_emf_sensing_state", "setBackEMFSensingState");
257
+ rb_define_alias(ph_motor, "supply_voltage", "getSupplyVoltage");
258
+ rb_define_alias(ph_motor, "braking", "getBraking");
259
+ rb_define_alias(ph_motor, "set_braking", "setBraking");
260
+ rb_define_alias(ph_motor, "sensor_count", "getSensorCount");
261
+ rb_define_alias(ph_motor, "sensor_value", "getSensorValue");
262
+ rb_define_alias(ph_motor, "sensor_raw_value", "getSensorRawValue");
263
+ rb_define_alias(ph_motor, "ratiometric?", "getRatiometric");
264
+ rb_define_alias(ph_motor, "ratiometric=", "setRatiometric");
265
+
266
+ return ph_motor;
267
+ }
268
+
269
+
270
+
271
+ VALUE ph_motor_init(VALUE self) {
272
+ ph_data_t *ph = get_ph_data(self);
273
+ ph_raise(CPhidgetMotorControl_create((CPhidgetMotorControlHandle *)(&(ph->handle))));
274
+ return self;
275
+ }
276
+
277
+ VALUE ph_motor_get_motor_count(VALUE self) {
278
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
279
+ int count;
280
+ ph_raise(CPhidgetMotorControl_getMotorCount(handle, &count));
281
+ return INT2FIX(count);
282
+ }
283
+
284
+ VALUE ph_motor_get_velocity(VALUE self, VALUE index) {
285
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
286
+ double velocity;
287
+ ph_raise(CPhidgetMotorControl_getVelocity(handle, FIX2INT(index), &velocity));
288
+ return rb_float_new(velocity);
289
+ }
290
+
291
+ VALUE ph_motor_set_velocity(VALUE self, VALUE index, VALUE velocity) {
292
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
293
+ ph_raise(CPhidgetMotorControl_setVelocity(handle, FIX2INT(index), NUM2DBL(velocity)));
294
+ return Qnil;
295
+ }
296
+
297
+ VALUE ph_motor_get_acceleration(VALUE self, VALUE index) {
298
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
299
+ double accel;
300
+ ph_raise(CPhidgetMotorControl_getAcceleration(handle, FIX2INT(index), &accel));
301
+ return rb_float_new(accel);
302
+ }
303
+
304
+ VALUE ph_motor_get_acceleration_min(VALUE self, VALUE index) {
305
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
306
+ double accel;
307
+ ph_raise(CPhidgetMotorControl_getAccelerationMin(handle, FIX2INT(index), &accel));
308
+ return rb_float_new(accel);
309
+ }
310
+
311
+ VALUE ph_motor_get_acceleration_max(VALUE self, VALUE index) {
312
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
313
+ double accel;
314
+ ph_raise(CPhidgetMotorControl_getAccelerationMax(handle, FIX2INT(index), &accel));
315
+ return rb_float_new(accel);
316
+ }
317
+
318
+ VALUE ph_motor_set_acceleration(VALUE self, VALUE index, VALUE accel) {
319
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
320
+ ph_raise(CPhidgetMotorControl_setAcceleration(handle, FIX2INT(index), NUM2DBL(accel)));
321
+ return Qnil;
322
+ }
323
+
324
+ VALUE ph_motor_get_current(VALUE self, VALUE index) {
325
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
326
+ double current;
327
+ ph_raise(CPhidgetMotorControl_getCurrent(handle, FIX2INT(index), &current));
328
+ return rb_float_new(current);
329
+ }
330
+
331
+ VALUE ph_motor_get_input_count(VALUE self) {
332
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
333
+ int count;
334
+ ph_raise(CPhidgetMotorControl_getInputCount(handle, &count));
335
+ return INT2FIX(count);
336
+ }
337
+
338
+ VALUE ph_motor_get_input_state(VALUE self, VALUE index) {
339
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
340
+ int state;
341
+ ph_raise(CPhidgetMotorControl_getInputState(handle, FIX2INT(index), &state));
342
+ return state == PTRUE ? Qtrue : Qfalse;
343
+ }
344
+
345
+ VALUE ph_motor_get_encoder_count(VALUE self) {
346
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
347
+ int count;
348
+ ph_raise(CPhidgetMotorControl_getEncoderCount(handle, &count));
349
+ return INT2FIX(count);
350
+ }
351
+
352
+ VALUE ph_motor_get_encoder_position(VALUE self, VALUE index) {
353
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
354
+ int position;
355
+ ph_raise(CPhidgetMotorControl_getEncoderPosition(handle, FIX2INT(index), &position));
356
+ return INT2FIX(position);
357
+ }
358
+
359
+ VALUE ph_motor_set_encoder_position(VALUE self, VALUE index, VALUE position) {
360
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
361
+ ph_raise(CPhidgetMotorControl_setEncoderPosition(handle, FIX2INT(index), FIX2INT(position)));
362
+ return Qnil;
363
+ }
364
+
365
+ VALUE ph_motor_get_back_emf(VALUE self, VALUE index) {
366
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
367
+ double voltage;
368
+ ph_raise(CPhidgetMotorControl_getBackEMF(handle, FIX2INT(index), &voltage));
369
+ return rb_float_new(voltage);
370
+ }
371
+
372
+ VALUE ph_motor_get_back_emf_sensing_state(VALUE self, VALUE index) {
373
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
374
+ int state;
375
+ ph_raise(CPhidgetMotorControl_getBackEMFSensingState(handle, FIX2INT(index), &state));
376
+ return state == PTRUE ? Qtrue : Qfalse;
377
+ }
378
+
379
+ VALUE ph_motor_set_back_emf_sensing_state(VALUE self, VALUE index, VALUE state) {
380
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
381
+ ph_raise(CPhidgetMotorControl_setBackEMFSensingState(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
382
+ return Qnil;
383
+ }
384
+
385
+ VALUE ph_motor_get_supply_voltage(VALUE self) {
386
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
387
+ double voltage;
388
+ ph_raise(CPhidgetMotorControl_getSupplyVoltage(handle, &voltage));
389
+ return rb_float_new(voltage);
390
+ }
391
+
392
+ VALUE ph_motor_get_braking(VALUE self, VALUE index) {
393
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
394
+ double braking;
395
+ ph_raise(CPhidgetMotorControl_getBraking(handle, FIX2INT(index), &braking));
396
+ return rb_float_new(braking);
397
+ }
398
+
399
+ VALUE ph_motor_set_braking(VALUE self, VALUE index, VALUE braking) {
400
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
401
+ ph_raise(CPhidgetMotorControl_setBraking(handle, FIX2INT(index), NUM2DBL(braking)));
402
+ return Qnil;
403
+ }
404
+
405
+ VALUE ph_motor_get_sensor_count(VALUE self) {
406
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
407
+ int count;
408
+ ph_raise(CPhidgetMotorControl_getSensorCount(handle, &count));
409
+ return INT2FIX(count);
410
+ }
411
+
412
+ VALUE ph_motor_get_sensor_value(VALUE self, VALUE index) {
413
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
414
+ int value;
415
+ ph_raise(CPhidgetMotorControl_getSensorValue(handle, FIX2INT(index), &value));
416
+ return INT2FIX(value);
417
+ }
418
+
419
+ VALUE ph_motor_get_sensor_raw_value(VALUE self, VALUE index) {
420
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
421
+ int value;
422
+ ph_raise(CPhidgetMotorControl_getSensorRawValue(handle, FIX2INT(index), &value));
423
+ return INT2FIX(value);
424
+ }
425
+
426
+ VALUE ph_motor_get_ratiometric(VALUE self) {
427
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
428
+ int ratiometric;
429
+ ph_raise(CPhidgetMotorControl_getRatiometric(handle, &ratiometric));
430
+ return ratiometric == PTRUE ? Qtrue : Qfalse;
431
+ }
432
+
433
+ VALUE ph_motor_set_ratiometric(VALUE self, VALUE ratiometric) {
434
+ CPhidgetMotorControlHandle handle = (CPhidgetMotorControlHandle)get_ph_handle(self);
435
+ ph_raise(CPhidgetMotorControl_setRatiometric(handle, TYPE(ratiometric) == T_TRUE ? PTRUE : PFALSE));
436
+ return Qnil;
437
+ }
438
+
439
+
440
+
441
+ #ifdef PH_CALLBACK
442
+ VALUE ph_motor_set_on_velocity_change_handler(VALUE self, VALUE handler) {
443
+ ph_data_t *ph = get_ph_data(self);
444
+ ph_callback_data_t *callback_data = &ph->dev_callback_1;
445
+ if( TYPE(handler) == T_NIL ) {
446
+ callback_data->exit = true;
447
+ ph_raise(CPhidgetMotorControl_set_OnVelocityChange_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
448
+ } else {
449
+ callback_data->called = false;
450
+ callback_data->exit = false;
451
+ callback_data->phidget = self;
452
+ callback_data->callback = handler;
453
+ ph_raise(CPhidgetMotorControl_set_OnVelocityChange_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_velocity_change, (void *)callback_data));
454
+ ph_callback_thread(callback_data);
455
+ }
456
+ return Qnil;
457
+ }
458
+
459
+
460
+ VALUE ph_motor_set_on_current_change_handler(VALUE self, VALUE handler) {
461
+ ph_data_t *ph = get_ph_data(self);
462
+ ph_callback_data_t *callback_data = &ph->dev_callback_2;
463
+ if( TYPE(handler) == T_NIL ) {
464
+ callback_data->exit = true;
465
+ ph_raise(CPhidgetMotorControl_set_OnCurrentChange_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
466
+ } else {
467
+ callback_data->called = false;
468
+ callback_data->exit = false;
469
+ callback_data->phidget = self;
470
+ callback_data->callback = handler;
471
+ ph_raise(CPhidgetMotorControl_set_OnCurrentChange_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_current_change, (void *)callback_data));
472
+ ph_callback_thread(callback_data);
473
+ }
474
+ return Qnil;
475
+ }
476
+
477
+
478
+ VALUE ph_motor_set_on_current_update_handler(VALUE self, VALUE handler) {
479
+ ph_data_t *ph = get_ph_data(self);
480
+ ph_callback_data_t *callback_data = &ph->dev_callback_3;
481
+ if( TYPE(handler) == T_NIL ) {
482
+ callback_data->exit = true;
483
+ ph_raise(CPhidgetMotorControl_set_OnCurrentUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
484
+ } else {
485
+ callback_data->called = false;
486
+ callback_data->exit = false;
487
+ callback_data->phidget = self;
488
+ callback_data->callback = handler;
489
+ ph_raise(CPhidgetMotorControl_set_OnCurrentUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_current_update, (void *)callback_data));
490
+ ph_callback_thread(callback_data);
491
+ }
492
+ return Qnil;
493
+ }
494
+
495
+
496
+ VALUE ph_motor_set_on_input_change_handler(VALUE self, VALUE handler) {
497
+ ph_data_t *ph = get_ph_data(self);
498
+ ph_callback_data_t *callback_data = &ph->dev_callback_4;
499
+ if( TYPE(handler) == T_NIL ) {
500
+ callback_data->exit = true;
501
+ ph_raise(CPhidgetMotorControl_set_OnInputChange_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
502
+ } else {
503
+ callback_data->called = false;
504
+ callback_data->exit = false;
505
+ callback_data->phidget = self;
506
+ callback_data->callback = handler;
507
+ ph_raise(CPhidgetMotorControl_set_OnInputChange_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_input_change, (void *)callback_data));
508
+ ph_callback_thread(callback_data);
509
+ }
510
+ return Qnil;
511
+ }
512
+
513
+
514
+ VALUE ph_motor_set_on_encoder_position_change_handler(VALUE self, VALUE handler) {
515
+ ph_data_t *ph = get_ph_data(self);
516
+ ph_callback_data_t *callback_data = &ph->dev_callback_5;
517
+ if( TYPE(handler) == T_NIL ) {
518
+ callback_data->exit = true;
519
+ ph_raise(CPhidgetMotorControl_set_OnEncoderPositionChange_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
520
+ } else {
521
+ callback_data->called = false;
522
+ callback_data->exit = false;
523
+ callback_data->phidget = self;
524
+ callback_data->callback = handler;
525
+ ph_raise(CPhidgetMotorControl_set_OnEncoderPositionChange_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_encoder_position_change, (void *)callback_data));
526
+ ph_callback_thread(callback_data);
527
+ }
528
+ return Qnil;
529
+ }
530
+
531
+
532
+ VALUE ph_motor_set_on_encoder_position_update_handler(VALUE self, VALUE handler) {
533
+ ph_data_t *ph = get_ph_data(self);
534
+ ph_callback_data_t *callback_data = &ph->dev_callback_6;
535
+ if( TYPE(handler) == T_NIL ) {
536
+ callback_data->exit = true;
537
+ ph_raise(CPhidgetMotorControl_set_OnEncoderPositionUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
538
+ } else {
539
+ callback_data->called = false;
540
+ callback_data->exit = false;
541
+ callback_data->phidget = self;
542
+ callback_data->callback = handler;
543
+ ph_raise(CPhidgetMotorControl_set_OnEncoderPositionUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_encoder_position_update, (void *)callback_data));
544
+ ph_callback_thread(callback_data);
545
+ }
546
+ return Qnil;
547
+ }
548
+
549
+
550
+ VALUE ph_motor_set_on_back_emf_update_handler(VALUE self, VALUE handler) {
551
+ ph_data_t *ph = get_ph_data(self);
552
+ ph_callback_data_t *callback_data = &ph->dev_callback_7;
553
+ if( TYPE(handler) == T_NIL ) {
554
+ callback_data->exit = true;
555
+ ph_raise(CPhidgetMotorControl_set_OnBackEMFUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
556
+ } else {
557
+ callback_data->called = false;
558
+ callback_data->exit = false;
559
+ callback_data->phidget = self;
560
+ callback_data->callback = handler;
561
+ ph_raise(CPhidgetMotorControl_set_OnBackEMFUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_back_emf_update, (void *)callback_data));
562
+ ph_callback_thread(callback_data);
563
+ }
564
+ return Qnil;
565
+ }
566
+
567
+
568
+ VALUE ph_motor_set_on_sensor_update_handler(VALUE self, VALUE handler) {
569
+ ph_data_t *ph = get_ph_data(self);
570
+ ph_callback_data_t *callback_data = &ph->dev_callback_8;
571
+ if( TYPE(handler) == T_NIL ) {
572
+ callback_data->exit = true;
573
+ ph_raise(CPhidgetMotorControl_set_OnSensorUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, NULL, (void *)NULL));
574
+ } else {
575
+ callback_data->called = false;
576
+ callback_data->exit = false;
577
+ callback_data->phidget = self;
578
+ callback_data->callback = handler;
579
+ ph_raise(CPhidgetMotorControl_set_OnSensorUpdate_Handler((CPhidgetMotorControlHandle)ph->handle, ph_motor_on_sensor_update, (void *)callback_data));
580
+ ph_callback_thread(callback_data);
581
+ }
582
+ return Qnil;
583
+ }
584
+
585
+
586
+ int ph_motor_on_velocity_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, double velocity) {
587
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
588
+ callback_data->called = true;
589
+ return EPHIDGET_OK;
590
+ }
591
+
592
+
593
+ int ph_motor_on_current_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, double current) {
594
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
595
+ callback_data->called = true;
596
+ return EPHIDGET_OK;
597
+ }
598
+
599
+
600
+ int ph_motor_on_current_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, double current) {
601
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
602
+ callback_data->called = true;
603
+ return EPHIDGET_OK;
604
+ }
605
+
606
+
607
+ int ph_motor_on_input_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, int state) {
608
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
609
+ callback_data->called = true;
610
+ return EPHIDGET_OK;
611
+ }
612
+
613
+
614
+ int ph_motor_on_encoder_position_change(CPhidgetMotorControlHandle phid, void *userPtr, int index, int time, int change) {
615
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
616
+ callback_data->called = true;
617
+ return EPHIDGET_OK;
618
+ }
619
+
620
+
621
+ int ph_motor_on_encoder_position_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, int change) {
622
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
623
+ callback_data->called = true;
624
+ return EPHIDGET_OK;
625
+ }
626
+
627
+
628
+ int ph_motor_on_back_emf_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, double voltage) {
629
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
630
+ callback_data->called = true;
631
+ return EPHIDGET_OK;
632
+ }
633
+
634
+
635
+ int ph_motor_on_sensor_update(CPhidgetMotorControlHandle phid, void *userPtr, int index, int value) {
636
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
637
+ callback_data->called = true;
638
+ return EPHIDGET_OK;
639
+ }
640
+
641
+ #endif
642
+