phidgets 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +3 -0
  3. data/README.rdoc +32 -43
  4. data/Rakefile +4 -2
  5. data/bin/phidget +18 -72
  6. data/ext/phidgets/extconf.rb +5 -8
  7. data/ext/phidgets/phidgets.c +708 -173
  8. data/ext/phidgets/phidgets.h +54 -35
  9. data/ext/phidgets/phidgets_accelerometer.c +193 -109
  10. data/ext/phidgets/phidgets_bldc_motor.c +529 -0
  11. data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
  12. data/ext/phidgets/phidgets_common.c +570 -315
  13. data/ext/phidgets/phidgets_current_input.c +229 -0
  14. data/ext/phidgets/phidgets_dc_motor.c +562 -0
  15. data/ext/phidgets/phidgets_dictionary.c +154 -213
  16. data/ext/phidgets/phidgets_digital_input.c +127 -0
  17. data/ext/phidgets/phidgets_digital_output.c +288 -0
  18. data/ext/phidgets/phidgets_distance_sensor.c +295 -0
  19. data/ext/phidgets/phidgets_encoder.c +211 -192
  20. data/ext/phidgets/phidgets_frequency_counter.c +310 -177
  21. data/ext/phidgets/phidgets_gps.c +226 -164
  22. data/ext/phidgets/phidgets_gyroscope.c +195 -0
  23. data/ext/phidgets/phidgets_hub.c +39 -0
  24. data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
  25. data/ext/phidgets/phidgets_ir.c +211 -171
  26. data/ext/phidgets/phidgets_lcd.c +512 -0
  27. data/ext/phidgets/phidgets_light_sensor.c +200 -0
  28. data/ext/phidgets/phidgets_log.c +263 -0
  29. data/ext/phidgets/phidgets_magnetometer.c +279 -0
  30. data/ext/phidgets/phidgets_manager.c +86 -297
  31. data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
  32. data/ext/phidgets/phidgets_phsensor.c +200 -152
  33. data/ext/phidgets/phidgets_power_guard.c +144 -0
  34. data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
  35. data/ext/phidgets/phidgets_rc_servo.c +672 -0
  36. data/ext/phidgets/phidgets_resistance_input.c +227 -0
  37. data/ext/phidgets/phidgets_rfid.c +107 -221
  38. data/ext/phidgets/phidgets_sound_sensor.c +284 -0
  39. data/ext/phidgets/phidgets_spatial.c +124 -318
  40. data/ext/phidgets/phidgets_stepper.c +457 -430
  41. data/ext/phidgets/phidgets_temp_sensor.c +223 -228
  42. data/ext/phidgets/phidgets_voltage_input.c +428 -0
  43. data/ext/phidgets/phidgets_voltage_output.c +167 -0
  44. data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
  45. data/lib/phidgets.rb +21 -14
  46. data/lib/phidgets/accelerometer.rb +11 -15
  47. data/lib/phidgets/bldc_motor.rb +45 -0
  48. data/lib/phidgets/capacitive_touch.rb +33 -0
  49. data/lib/phidgets/common.rb +40 -69
  50. data/lib/phidgets/current_input.rb +21 -0
  51. data/lib/phidgets/dc_motor.rb +45 -0
  52. data/lib/phidgets/dictionary.rb +30 -39
  53. data/lib/phidgets/digital_input.rb +21 -0
  54. data/lib/phidgets/digital_output.rb +56 -0
  55. data/lib/phidgets/distance_sensor.rb +33 -0
  56. data/lib/phidgets/encoder.rb +1 -29
  57. data/lib/phidgets/frequency_counter.rb +23 -14
  58. data/lib/phidgets/gps.rb +34 -26
  59. data/lib/phidgets/gyroscope.rb +21 -0
  60. data/lib/phidgets/humidity_sensor.rb +21 -0
  61. data/lib/phidgets/ir.rb +34 -39
  62. data/lib/phidgets/light_sensor.rb +21 -0
  63. data/lib/phidgets/magnetometer.rb +21 -0
  64. data/lib/phidgets/manager.rb +18 -66
  65. data/lib/phidgets/motor_position_controller.rb +45 -0
  66. data/lib/phidgets/ph_sensor.rb +2 -6
  67. data/lib/phidgets/pressure_sensor.rb +21 -0
  68. data/lib/phidgets/rc_servo.rb +58 -0
  69. data/lib/phidgets/resistance_input.rb +21 -0
  70. data/lib/phidgets/rfid.rb +22 -38
  71. data/lib/phidgets/sound_sensor.rb +21 -0
  72. data/lib/phidgets/spatial.rb +11 -15
  73. data/lib/phidgets/stepper.rb +48 -50
  74. data/lib/phidgets/temperature_sensor.rb +11 -15
  75. data/lib/phidgets/version.rb +5 -0
  76. data/lib/phidgets/voltage_input.rb +34 -0
  77. data/lib/phidgets/voltage_output.rb +23 -0
  78. data/lib/phidgets/voltage_ratio_input.rb +34 -0
  79. data/phidgets.gemspec +3 -22
  80. data/test/test_accelerometer.rb +42 -23
  81. data/test/test_bldc_motor.rb +134 -0
  82. data/test/test_capacitive_touch.rb +82 -0
  83. data/test/test_common.rb +125 -108
  84. data/test/test_current_input.rb +62 -0
  85. data/test/test_dc_motor.rb +146 -0
  86. data/test/test_dictionary.rb +22 -54
  87. data/test/test_digital_input.rb +30 -0
  88. data/test/test_digital_output.rb +70 -0
  89. data/test/test_distance_sensor.rb +76 -0
  90. data/test/test_encoder.rb +45 -38
  91. data/test/test_frequency_counter.rb +71 -36
  92. data/test/test_gps.rb +29 -38
  93. data/test/test_gyroscope.rb +54 -0
  94. data/test/test_helper.rb +0 -1
  95. data/test/test_hub.rb +14 -0
  96. data/test/test_humidity_sensor.rb +58 -0
  97. data/test/test_ir.rb +34 -34
  98. data/test/test_lcd.rb +146 -0
  99. data/test/test_light_sensor.rb +58 -0
  100. data/test/test_magnetometer.rb +78 -0
  101. data/test/test_manager.rb +10 -79
  102. data/test/test_motor_control.rb +146 -108
  103. data/test/test_phidgets.rb +2 -14
  104. data/test/test_phsensor.rb +46 -34
  105. data/test/test_power_guard.rb +42 -0
  106. data/test/test_pressure_sensor.rb +58 -0
  107. data/test/test_rc_servo.rb +174 -0
  108. data/test/test_resistance_input.rb +66 -0
  109. data/test/test_rfid.rb +15 -54
  110. data/test/test_sound_sensor.rb +78 -0
  111. data/test/test_spatial.rb +19 -85
  112. data/test/test_stepper.rb +89 -98
  113. data/test/test_temp_sensor.rb +42 -47
  114. data/test/test_voltage_input.rb +102 -0
  115. data/test/test_voltage_output.rb +46 -0
  116. data/test/test_voltage_ratio_input.rb +102 -0
  117. metadata +72 -89
  118. data/ext/phidgets/phidgets_advanced_servo.c +0 -567
  119. data/ext/phidgets/phidgets_analog.c +0 -139
  120. data/ext/phidgets/phidgets_bridge.c +0 -263
  121. data/ext/phidgets/phidgets_interface_kit.c +0 -340
  122. data/ext/phidgets/phidgets_led.c +0 -178
  123. data/ext/phidgets/phidgets_motor_control.c +0 -642
  124. data/ext/phidgets/phidgets_servo.c +0 -276
  125. data/ext/phidgets/phidgets_text_lcd.c +0 -381
  126. data/ext/phidgets/phidgets_text_led.c +0 -107
  127. data/ext/phidgets/phidgets_weight_sensor.c +0 -113
  128. data/lib/phidgets/advanced_servo.rb +0 -49
  129. data/lib/phidgets/analog.rb +0 -8
  130. data/lib/phidgets/bridge.rb +0 -25
  131. data/lib/phidgets/interfacekit.rb +0 -49
  132. data/lib/phidgets/led.rb +0 -8
  133. data/lib/phidgets/motor_control.rb +0 -110
  134. data/lib/phidgets/servo.rb +0 -23
  135. data/lib/phidgets/text_lcd.rb +0 -8
  136. data/lib/phidgets/text_led.rb +0 -8
  137. data/lib/phidgets/weight_sensor.rb +0 -25
  138. data/test/test_advanced_servo.rb +0 -152
  139. data/test/test_analog.rb +0 -45
  140. data/test/test_bridge.rb +0 -77
  141. data/test/test_interfacekit.rb +0 -97
  142. data/test/test_led.rb +0 -55
  143. data/test/test_servo.rb +0 -67
  144. data/test/test_text_lcd.rb +0 -115
  145. data/test/test_text_led.rb +0 -35
  146. data/test/test_weight_sensor.rb +0 -32
@@ -1,560 +1,587 @@
1
1
 
2
2
  #include "phidgets.h"
3
3
 
4
+ #define STEPPER_POSITION_CHANGE_CALLBACK 0
5
+ #define STEPPER_STOPPED_CALLBACK 1
6
+ #define STEPPER_VELOCITY_CHANGE_CALLBACK 2
7
+ #define STEPPER_TARGET_POSITION_ASYNC_CALLBACK 3
4
8
 
5
- VALUE ph_stepper_init(VALUE self);
6
- VALUE ph_stepper_get_input_count(VALUE self);
7
- VALUE ph_stepper_get_input_state(VALUE self, VALUE index);
8
- VALUE ph_stepper_get_motor_count(VALUE self);
9
- VALUE ph_stepper_get_acceleration(VALUE self, VALUE index);
10
- VALUE ph_stepper_get_acceleration_min(VALUE self, VALUE index);
11
- VALUE ph_stepper_get_acceleration_max(VALUE self, VALUE index);
12
- VALUE ph_stepper_set_acceleration(VALUE self, VALUE index, VALUE accel);
13
- VALUE ph_stepper_get_velocity_limit(VALUE self, VALUE index);
14
- VALUE ph_stepper_set_velocity_limit(VALUE self, VALUE index, VALUE limit);
15
- VALUE ph_stepper_get_velocity(VALUE self, VALUE index);
16
- VALUE ph_stepper_get_velocity_min(VALUE self, VALUE index);
17
- VALUE ph_stepper_get_velocity_max(VALUE self, VALUE index);
18
- VALUE ph_stepper_get_target_position(VALUE self, VALUE index);
19
- VALUE ph_stepper_set_target_position(VALUE self, VALUE index, VALUE position);
20
- VALUE ph_stepper_get_current_position(VALUE self, VALUE index);
21
- VALUE ph_stepper_set_current_position(VALUE self, VALUE index, VALUE position);
22
- VALUE ph_stepper_get_position_min(VALUE self, VALUE index);
23
- VALUE ph_stepper_get_position_max(VALUE self, VALUE index);
24
- VALUE ph_stepper_get_current_limit(VALUE self, VALUE index);
25
- VALUE ph_stepper_set_current_limit(VALUE self, VALUE index, VALUE limit);
26
- VALUE ph_stepper_get_current(VALUE self, VALUE index);
27
- VALUE ph_stepper_get_current_min(VALUE self, VALUE index);
28
- VALUE ph_stepper_get_current_max(VALUE self, VALUE index);
29
- VALUE ph_stepper_get_engaged(VALUE self, VALUE index);
30
- VALUE ph_stepper_set_engaged(VALUE self, VALUE index, VALUE state);
31
- VALUE ph_stepper_get_stopped(VALUE self, VALUE index);
32
-
33
- #ifdef PH_CALLBACK
34
- VALUE ph_stepper_set_on_input_change_handler(VALUE self, VALUE handler);
35
- VALUE ph_stepper_set_on_velocity_change_handler(VALUE self, VALUE handler);
36
- VALUE ph_stepper_set_on_position_change_handler(VALUE self, VALUE handler);
37
- VALUE ph_stepper_set_on_current_change_handler(VALUE self, VALUE handler);
38
- int ph_stepper_on_input_change(CPhidgetStepperHandle phid, void *userPtr, int index, int state);
39
- int ph_stepper_on_velocity_change(CPhidgetStepperHandle phid, void *userPtr, int index, double velocity);
40
- int ph_stepper_on_position_change(CPhidgetStepperHandle phid, void *userPtr, int index, __int64 position);
41
- int ph_stepper_on_current_change(CPhidgetStepperHandle phid, void *userPtr, int index, double current);
42
- #endif
43
9
 
10
+ VALUE ph_stepper_init(VALUE self) {
11
+ ph_data_t *ph = get_ph_data(self);
12
+ ph_raise(PhidgetStepper_create((PhidgetStepperHandle *)(&(ph->handle))));
13
+ return self;
14
+ }
44
15
 
45
- void Init_stepper() {
46
- VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
47
- VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
48
- VALUE ph_stepper = rb_define_class_under(ph_module, "Stepper", ph_common);
49
-
50
- /* Document-method: new
51
- * call-seq: new
52
- *
53
- * Creates a Phidget Stepper object.
54
- */
55
- rb_define_method(ph_stepper, "initialize", ph_stepper_init, 0);
56
-
57
- /* Document-method: getInputCount
58
- * call-seq: getInputCount -> count
59
- *
60
- * Gets the number of digital inputs supported by this board.
61
- */
62
- rb_define_method(ph_stepper, "getInputCount", ph_stepper_get_input_count, 0);
63
-
64
- /* Document-method: getInputState
65
- * call-seq: getInputState(index) -> true or false
66
- *
67
- * Gets the state of a digital input.
68
- */
69
- rb_define_method(ph_stepper, "getInputState", ph_stepper_get_input_state, 1);
70
-
71
- /* Document-method: getMotorCount
72
- * call-seq: getMotorCount -> count
73
- *
74
- * Gets the number of motors supported by this controller
75
- */
76
- rb_define_method(ph_stepper, "getMotorCount", ph_stepper_get_motor_count, 0);
77
-
78
- /* Document-method: getAcceleration
79
- * call-seq: getAcceleration(index) -> acceleration
80
- *
81
- * Gets the last set acceleration for a motor.
82
- */
83
- rb_define_method(ph_stepper, "getAcceleration", ph_stepper_get_acceleration, 1);
84
-
85
- /* Document-method: getAccelerationMin
86
- * call-seq: getAccelerationMin(index) -> acceleration
87
- *
88
- * Gets the minimum acceleration supported by a motor.
89
- */
90
- rb_define_method(ph_stepper, "getAccelerationMin", ph_stepper_get_acceleration_min, 1);
91
-
92
- /* Document-method: getAccelerationMax
93
- * call-seq: getAccelerationMax(index) -> acceleration
94
- *
95
- * Gets the maximum acceleration supported by a motor.
96
- */
97
- rb_define_method(ph_stepper, "getAccelerationMax", ph_stepper_get_acceleration_max, 1);
98
-
99
- /* Document-method: setAcceleration
100
- * call-seq: setAcceleration(index, acceleration)
101
- *
102
- * Sets the acceleration for a motor.
103
- */
104
- rb_define_method(ph_stepper, "setAcceleration", ph_stepper_set_acceleration, 2);
105
-
106
- /* Document-method: getVelocityLimit
107
- * call-seq: getVelocityLimit(index) -> velocity_limit
108
- *
109
- * Gets the last set velocity limit for a motor.
110
- */
111
- rb_define_method(ph_stepper, "getVelocityLimit", ph_stepper_get_velocity_limit, 1);
112
-
113
- /* Document-method: setVelocityLimit
114
- * call-seq: setVelocityLimit(index, velocity_limit)
115
- *
116
- * Sets the velocity limit for a motor.
117
- */
118
- rb_define_method(ph_stepper, "setVelocityLimit", ph_stepper_set_velocity_limit, 2);
119
-
120
- /* Document-method: getVelocity
121
- * call-seq: getVelocity(index) -> velocity
122
- *
123
- * Gets the current velocity of a motor.
124
- */
125
- rb_define_method(ph_stepper, "getVelocity", ph_stepper_get_velocity, 1);
126
-
127
- /* Document-method: getVelocityMin
128
- * call-seq: getVelocityMin(index) -> velocity
129
- *
130
- * Gets the minimum velocity that can be set for a motor.
131
- */
132
- rb_define_method(ph_stepper, "getVelocityMin", ph_stepper_get_velocity_min, 1);
133
-
134
- /* Document-method: getVelocityMax
135
- * call-seq: getVelocityMax(index) -> velocity
136
- *
137
- * Gets the maximum velocity that can be set for a motor.
138
- */
139
- rb_define_method(ph_stepper, "getVelocityMax", ph_stepper_get_velocity_max, 1);
140
-
141
- /* Document-method: getTargetPosition
142
- * call-seq: getTargetPosition(index) -> position
143
- *
144
- * Gets the last set target position of a motor.
145
- */
146
- rb_define_method(ph_stepper, "getTargetPosition", ph_stepper_get_target_position, 1);
147
-
148
- /* Document-method: setTargetPosition
149
- * call-seq: setTargetPosition(index, position)
150
- *
151
- * Sets the target position of a motor.
152
- */
153
- rb_define_method(ph_stepper, "setTargetPosition", ph_stepper_set_target_position, 2);
154
-
155
- /* Document-method: getCurrentPosition
156
- * call-seq: getCurrentPosition(index) -> position
157
- *
158
- * Gets the current position of a motor.
159
- */
160
- rb_define_method(ph_stepper, "getCurrentPosition", ph_stepper_get_current_position, 1);
161
-
162
- /* Document-method: setCurrentPosition
163
- * call-seq: setCurrentPosition(index, position)
164
- *
165
- * Sets the current position of a motor. This will not move the motor, just update the position value.
166
- */
167
- rb_define_method(ph_stepper, "setCurrentPosition", ph_stepper_set_current_position, 2);
168
-
169
- /* Document-method: getPositionMin
170
- * call-seq: getPositionMin(index) -> position
171
- *
172
- * Gets the minimum position that a motor can go to.
173
- */
174
- rb_define_method(ph_stepper, "getPositionMin", ph_stepper_get_position_min, 1);
175
-
176
- /* Document-method: getPositionMax
177
- * call-seq: getPositionMax(index) -> position
178
- *
179
- * Gets the maximum position that a motor can go to.
180
- */
181
- rb_define_method(ph_stepper, "getPositionMax", ph_stepper_get_position_max, 1);
182
-
183
- /* Document-method: getCurrentLimit
184
- * call-seq: getCurrentLimit(index) -> limit
185
- *
186
- * Gets the current limit for a motor.
187
- */
188
- rb_define_method(ph_stepper, "getCurrentLimit", ph_stepper_get_current_limit, 1);
189
-
190
- /* Document-method: setCurrentLimit
191
- * call-seq: setCurrentLimit(index, limit)
192
- *
193
- * Sets the current limit for a motor.
194
- */
195
- rb_define_method(ph_stepper, "setCurrentLimit", ph_stepper_set_current_limit, 2);
196
-
197
- /* Document-method: getCurrent
198
- * call-seq: getCurrent(index) -> current
199
- *
200
- * Gets the current current draw for a motor.
201
- */
202
- rb_define_method(ph_stepper, "getCurrent", ph_stepper_get_current, 1);
203
-
204
- /* Document-method: getCurrentMin
205
- * call-seq: getCurrentMin(index) -> current
206
- *
207
- * Gets the minimum current limit.
208
- */
209
- rb_define_method(ph_stepper, "getCurrentMin", ph_stepper_get_current_min, 1);
210
-
211
- /* Document-method: getCurrentMax
212
- * call-seq: getCurrentMax(index) -> current
213
- *
214
- * Gets the maximum current limit.
215
- */
216
- rb_define_method(ph_stepper, "getCurrentMax", ph_stepper_get_current_max, 1);
217
-
218
- /* Document-method: getEngaged
219
- * call-seq: getEngaged(index) -> true or false
220
- *
221
- * Gets the engaged state of a motor. This is whether the motor is powered or not.
222
- */
223
- rb_define_method(ph_stepper, "getEngaged", ph_stepper_get_engaged, 1);
224
-
225
- /* Document-method: setEngaged
226
- * call-seq: setEngaged(index, state)
227
- *
228
- * Sets the engaged state of a motor. This is whether the motor is powered or not.
229
- */
230
- rb_define_method(ph_stepper, "setEngaged", ph_stepper_set_engaged, 2);
16
+ VALUE ph_stepper_get_acceleration(VALUE self) {
17
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getAcceleration);
18
+ }
231
19
 
232
- /* Document-method: getStopped
233
- * call-seq: getStopped(index) -> true or false
234
- *
235
- * Gets the stopped state of a motor. This is true when the motor is not moving and there are no outstanding commands.
236
- */
237
- rb_define_method(ph_stepper, "getStopped", ph_stepper_get_stopped, 1);
20
+ VALUE ph_stepper_set_acceleration(VALUE self, VALUE accel) {
21
+ ph_raise(PhidgetStepper_setAcceleration((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(accel)));
22
+ return Qnil;
23
+ }
238
24
 
239
- #ifdef PH_CALLBACK
240
- rb_define_private_method(ph_stepper, "ext_setOnInputChangeHandler", ph_stepper_set_on_input_change_handler, 1);
241
- rb_define_private_method(ph_stepper, "ext_setOnVelocityChangeHandler", ph_stepper_set_on_velocity_change_handler, 1);
242
- rb_define_private_method(ph_stepper, "ext_setOnPositionChangeHandler", ph_stepper_set_on_position_change_handler, 1);
243
- rb_define_private_method(ph_stepper, "ext_setOnCurrentChangeHandler", ph_stepper_set_on_current_change_handler, 1);
244
- #endif
25
+ VALUE ph_stepper_get_min_acceleration(VALUE self) {
26
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMinAcceleration);
27
+ }
245
28
 
246
- rb_define_alias(ph_stepper, "input_count", "getInputCount");
247
- rb_define_alias(ph_stepper, "input_state", "getInputState");
248
- rb_define_alias(ph_stepper, "motor_count", "getMotorCount");
249
- rb_define_alias(ph_stepper, "acceleration", "getAcceleration");
250
- rb_define_alias(ph_stepper, "acceleration_min", "getAccelerationMin");
251
- rb_define_alias(ph_stepper, "acceleration_max", "getAccelerationMax");
252
- rb_define_alias(ph_stepper, "set_acceleration", "setAcceleration");
253
- rb_define_alias(ph_stepper, "velocity_limit", "getVelocityLimit");
254
- rb_define_alias(ph_stepper, "set_velocity_limit", "setVelocityLimit");
255
- rb_define_alias(ph_stepper, "velocity", "getVelocity");
256
- rb_define_alias(ph_stepper, "velocity_min", "getVelocityMin");
257
- rb_define_alias(ph_stepper, "velocity_max", "getVelocityMax");
258
- rb_define_alias(ph_stepper, "target_position", "getTargetPosition");
259
- rb_define_alias(ph_stepper, "set_target_position", "setTargetPosition");
260
- rb_define_alias(ph_stepper, "current_position", "getCurrentPosition");
261
- rb_define_alias(ph_stepper, "set_current_position", "setCurrentPosition");
262
- rb_define_alias(ph_stepper, "position_min", "getPositionMin");
263
- rb_define_alias(ph_stepper, "position_max", "getPositionMax");
264
- rb_define_alias(ph_stepper, "current_limit", "getCurrentLimit");
265
- rb_define_alias(ph_stepper, "set_current_limit", "setCurrentLimit");
266
- rb_define_alias(ph_stepper, "current", "getCurrent");
267
- rb_define_alias(ph_stepper, "current_min", "getCurrentMin");
268
- rb_define_alias(ph_stepper, "current_max", "getCurrentMax");
269
- rb_define_alias(ph_stepper, "engaged?", "getEngaged");
270
- rb_define_alias(ph_stepper, "set_engaged", "setEngaged");
271
- rb_define_alias(ph_stepper, "stopped?", "getStopped");
29
+ VALUE ph_stepper_get_max_acceleration(VALUE self) {
30
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxAcceleration);
272
31
  }
273
32
 
33
+ VALUE ph_stepper_get_control_mode(VALUE self) {
34
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetStepper_getControlMode);
35
+ }
274
36
 
37
+ VALUE ph_stepper_set_control_mode(VALUE self, VALUE mode) {
38
+ ph_raise(PhidgetStepper_setControlMode((PhidgetStepperHandle)get_ph_handle(self), NUM2INT(mode)));
39
+ return Qnil;
40
+ }
275
41
 
276
- VALUE ph_stepper_init(VALUE self) {
277
- ph_data_t *ph = get_ph_data(self);
278
- ph_raise(CPhidgetStepper_create((CPhidgetStepperHandle *)(&(ph->handle))));
279
- return self;
42
+ VALUE ph_stepper_get_current_limit(VALUE self) {
43
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getCurrentLimit);
280
44
  }
281
45
 
282
- VALUE ph_stepper_get_input_count(VALUE self) {
283
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
284
- int count;
285
- ph_raise(CPhidgetStepper_getInputCount(handle, &count));
286
- return INT2FIX(count);
46
+ VALUE ph_stepper_set_current_limit(VALUE self, VALUE limit) {
47
+ ph_raise(PhidgetStepper_setCurrentLimit((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(limit)));
48
+ return Qnil;
287
49
  }
288
50
 
289
- VALUE ph_stepper_get_input_state(VALUE self, VALUE index) {
290
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
291
- int state;
292
- ph_raise(CPhidgetStepper_getInputState(handle, FIX2INT(index), &state));
293
- return state == PTRUE ? Qtrue : Qfalse;
51
+ VALUE ph_stepper_get_min_current_limit(VALUE self) {
52
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMinCurrentLimit);
294
53
  }
295
54
 
296
- VALUE ph_stepper_get_motor_count(VALUE self) {
297
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
298
- int count;
299
- ph_raise(CPhidgetStepper_getMotorCount(handle, &count));
300
- return INT2FIX(count);
55
+ VALUE ph_stepper_get_max_current_limit(VALUE self) {
56
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxCurrentLimit);
301
57
  }
302
58
 
303
- VALUE ph_stepper_get_acceleration(VALUE self, VALUE index) {
304
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
305
- double accel;
306
- ph_raise(CPhidgetStepper_getAcceleration(handle, FIX2INT(index), &accel));
307
- return rb_float_new(accel);
59
+ VALUE ph_stepper_get_data_interval(VALUE self) {
60
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetStepper_getDataInterval);
308
61
  }
309
62
 
310
- VALUE ph_stepper_get_acceleration_min(VALUE self, VALUE index) {
311
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
312
- double accel;
313
- ph_raise(CPhidgetStepper_getAccelerationMin(handle, FIX2INT(index), &accel));
314
- return rb_float_new(accel);
63
+ VALUE ph_stepper_set_data_interval(VALUE self, VALUE interval) {
64
+ ph_raise(PhidgetStepper_setDataInterval((PhidgetStepperHandle)get_ph_handle(self), NUM2UINT(interval)));
65
+ return Qnil;
315
66
  }
316
67
 
317
- VALUE ph_stepper_get_acceleration_max(VALUE self, VALUE index) {
318
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
319
- double accel;
320
- ph_raise(CPhidgetStepper_getAccelerationMax(handle, FIX2INT(index), &accel));
321
- return rb_float_new(accel);
68
+ VALUE ph_stepper_get_min_data_interval(VALUE self) {
69
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetStepper_getMinDataInterval);
322
70
  }
323
71
 
324
- VALUE ph_stepper_set_acceleration(VALUE self, VALUE index, VALUE accel) {
325
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
326
- ph_raise(CPhidgetStepper_setAcceleration(handle, FIX2INT(index), NUM2DBL(accel)));
327
- return Qnil;
72
+ VALUE ph_stepper_get_max_data_interval(VALUE self) {
73
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetStepper_getMaxDataInterval);
328
74
  }
329
75
 
330
- VALUE ph_stepper_get_velocity_limit(VALUE self, VALUE index) {
331
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
332
- double limit;
333
- ph_raise(CPhidgetStepper_getVelocityLimit(handle, FIX2INT(index), &limit));
334
- return rb_float_new(limit);
76
+ VALUE ph_stepper_get_engaged(VALUE self) {
77
+ return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetStepper_getEngaged);
335
78
  }
336
79
 
337
- VALUE ph_stepper_set_velocity_limit(VALUE self, VALUE index, VALUE limit) {
338
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
339
- ph_raise(CPhidgetStepper_setVelocityLimit(handle, FIX2INT(index), NUM2DBL(limit)));
80
+ VALUE ph_stepper_set_engaged(VALUE self, VALUE state) {
81
+ ph_raise(PhidgetStepper_setEngaged((PhidgetStepperHandle)get_ph_handle(self), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
340
82
  return Qnil;
341
83
  }
342
84
 
343
- VALUE ph_stepper_get_velocity(VALUE self, VALUE index) {
344
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
345
- double velocity;
346
- ph_raise(CPhidgetStepper_getVelocity(handle, FIX2INT(index), &velocity));
347
- return rb_float_new(velocity);
85
+ VALUE ph_stepper_get_holding_current_limit(VALUE self) {
86
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getHoldingCurrentLimit);
348
87
  }
349
88
 
350
- VALUE ph_stepper_get_velocity_min(VALUE self, VALUE index) {
351
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
352
- double velocity;
353
- ph_raise(CPhidgetStepper_getVelocityMin(handle, FIX2INT(index), &velocity));
354
- return rb_float_new(velocity);
89
+ VALUE ph_stepper_set_holding_current_limit(VALUE self, VALUE limit) {
90
+ ph_raise(PhidgetStepper_setHoldingCurrentLimit((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(limit)));
91
+ return Qnil;
355
92
  }
356
93
 
357
- VALUE ph_stepper_get_velocity_max(VALUE self, VALUE index) {
358
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
359
- double velocity;
360
- ph_raise(CPhidgetStepper_getVelocityMax(handle, FIX2INT(index), &velocity));
361
- return rb_float_new(velocity);
94
+ VALUE ph_stepper_get_is_moving(VALUE self) {
95
+ return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetStepper_getIsMoving);
362
96
  }
363
97
 
364
- VALUE ph_stepper_get_target_position(VALUE self, VALUE index) {
365
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
366
- __int64 position;
367
- ph_raise(CPhidgetStepper_getTargetPosition(handle, FIX2INT(index), &position));
368
- return INT2NUM(position);
98
+ VALUE ph_stepper_get_position(VALUE self) {
99
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getPosition);
369
100
  }
370
101
 
371
- VALUE ph_stepper_set_target_position(VALUE self, VALUE index, VALUE position) {
372
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
373
- ph_raise(CPhidgetStepper_setTargetPosition(handle, FIX2INT(index), NUM2INT(position)));
374
- return Qnil;
102
+ VALUE ph_stepper_get_min_position(VALUE self) {
103
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMinPosition);
375
104
  }
376
105
 
377
- VALUE ph_stepper_get_current_position(VALUE self, VALUE index) {
378
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
379
- __int64 position;
380
- ph_raise(CPhidgetStepper_getCurrentPosition(handle, FIX2INT(index), &position));
381
- return INT2NUM(position);
106
+ VALUE ph_stepper_get_max_position(VALUE self) {
107
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxPosition);
382
108
  }
383
109
 
384
- VALUE ph_stepper_set_current_position(VALUE self, VALUE index, VALUE position) {
385
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
386
- ph_raise(CPhidgetStepper_setCurrentPosition(handle, FIX2INT(index), NUM2INT(position)));
110
+ VALUE ph_stepper_add_position_offset(VALUE self, VALUE offset) {
111
+ ph_raise(PhidgetStepper_addPositionOffset((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(offset)));
387
112
  return Qnil;
388
113
  }
389
114
 
390
- VALUE ph_stepper_get_position_min(VALUE self, VALUE index) {
391
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
392
- __int64 position;
393
- ph_raise(CPhidgetStepper_getPositionMin(handle, FIX2INT(index), &position));
394
- return INT2NUM(position);
115
+ VALUE ph_stepper_get_rescale_factor(VALUE self) {
116
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getRescaleFactor);
395
117
  }
396
118
 
397
- VALUE ph_stepper_get_position_max(VALUE self, VALUE index) {
398
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
399
- __int64 position;
400
- ph_raise(CPhidgetStepper_getPositionMax(handle, FIX2INT(index), &position));
401
- return INT2NUM(position);
119
+ VALUE ph_stepper_set_rescale_factor(VALUE self, VALUE rescale_factor) {
120
+ ph_raise(PhidgetStepper_setRescaleFactor((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(rescale_factor)));
121
+ return Qnil;
402
122
  }
403
123
 
404
- VALUE ph_stepper_get_current_limit(VALUE self, VALUE index) {
405
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
406
- double current;
407
- ph_raise(CPhidgetStepper_getCurrentLimit(handle, FIX2INT(index), &current));
408
- return rb_float_new(current);
124
+ VALUE ph_stepper_get_target_position(VALUE self) {
125
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getTargetPosition);
409
126
  }
410
127
 
411
- VALUE ph_stepper_set_current_limit(VALUE self, VALUE index, VALUE limit) {
412
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
413
- ph_raise(CPhidgetStepper_setCurrentLimit(handle, FIX2INT(index), NUM2DBL(limit)));
128
+ VALUE ph_stepper_set_target_position(VALUE self, VALUE position) {
129
+ ph_raise(PhidgetStepper_setTargetPosition((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(position)));
414
130
  return Qnil;
415
131
  }
416
132
 
417
- VALUE ph_stepper_get_current(VALUE self, VALUE index) {
418
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
419
- double current;
420
- ph_raise(CPhidgetStepper_getCurrent(handle, FIX2INT(index), &current));
421
- return rb_float_new(current);
133
+ VALUE ph_stepper_get_velocity(VALUE self) {
134
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getVelocity);
422
135
  }
423
136
 
424
- VALUE ph_stepper_get_current_min(VALUE self, VALUE index) {
425
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
426
- double current;
427
- ph_raise(CPhidgetStepper_getCurrentMin(handle, FIX2INT(index), &current));
428
- return rb_float_new(current);
137
+ VALUE ph_stepper_get_velocity_limit(VALUE self) {
138
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getVelocityLimit);
429
139
  }
430
140
 
431
- VALUE ph_stepper_get_current_max(VALUE self, VALUE index) {
432
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
433
- double current;
434
- ph_raise(CPhidgetStepper_getCurrentMax(handle, FIX2INT(index), &current));
435
- return rb_float_new(current);
141
+ VALUE ph_stepper_set_velocity_limit(VALUE self, VALUE limit) {
142
+ ph_raise(PhidgetStepper_setVelocityLimit((PhidgetStepperHandle)get_ph_handle(self), NUM2DBL(limit)));
143
+ return Qnil;
436
144
  }
437
145
 
438
- VALUE ph_stepper_get_engaged(VALUE self, VALUE index) {
439
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
440
- int state;
441
- ph_raise(CPhidgetStepper_getEngaged(handle, FIX2INT(index), &state));
442
- return state == PTRUE ? Qtrue : Qfalse;
146
+ VALUE ph_stepper_get_min_velocity_limit(VALUE self) {
147
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMinVelocityLimit);
443
148
  }
444
149
 
445
- VALUE ph_stepper_set_engaged(VALUE self, VALUE index, VALUE state) {
446
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
447
- ph_raise(CPhidgetStepper_setEngaged(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
448
- return Qnil;
150
+ VALUE ph_stepper_get_max_velocity_limit(VALUE self) {
151
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetStepper_getMaxVelocityLimit);
449
152
  }
450
153
 
451
- VALUE ph_stepper_get_stopped(VALUE self, VALUE index) {
452
- CPhidgetStepperHandle handle = (CPhidgetStepperHandle)get_ph_handle(self);
453
- int state;
454
- ph_raise(CPhidgetStepper_getStopped(handle, FIX2INT(index), &state));
455
- return state == PTRUE ? Qtrue : Qfalse;
154
+
155
+ void CCONV ph_stepper_on_position_change(PhidgetStepperHandle phid, void *userPtr, double position) {
156
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
157
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
158
+ callback_data->arg1 = DBL2NUM(position);
159
+ callback_data->arg2 = Qnil;
160
+ callback_data->arg3 = Qnil;
161
+ callback_data->arg4 = Qnil;
162
+ sem_post(&callback_data->callback_called);
456
163
  }
457
164
 
458
165
 
459
- #ifdef PH_CALLBACK
460
- VALUE ph_stepper_set_on_input_change_handler(VALUE self, VALUE handler) {
166
+ VALUE ph_stepper_set_on_position_change_handler(VALUE self, VALUE handler) {
461
167
  ph_data_t *ph = get_ph_data(self);
462
- ph_callback_data_t *callback_data = &ph->dev_callback_1;
168
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[STEPPER_POSITION_CHANGE_CALLBACK];
463
169
  if( TYPE(handler) == T_NIL ) {
170
+ callback_data->callback = T_NIL;
464
171
  callback_data->exit = true;
465
- ph_raise(CPhidgetStepper_set_OnInputChange_Handler((CPhidgetStepperHandle)ph->handle, NULL, (void *)NULL));
172
+ ph_raise(PhidgetStepper_setOnPositionChangeHandler((PhidgetStepperHandle)ph->handle, NULL, (void *)NULL));
173
+ sem_post(&callback_data->callback_called);
466
174
  } else {
467
- callback_data->called = false;
468
175
  callback_data->exit = false;
469
176
  callback_data->phidget = self;
470
177
  callback_data->callback = handler;
471
- ph_raise(CPhidgetStepper_set_OnInputChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_input_change, (void *)callback_data));
178
+ ph_raise(PhidgetStepper_setOnPositionChangeHandler((PhidgetStepperHandle)ph->handle, ph_stepper_on_position_change, (void *)callback_data));
472
179
  ph_callback_thread(callback_data);
473
180
  }
474
181
  return Qnil;
475
182
  }
476
183
 
477
184
 
478
- VALUE ph_stepper_set_on_velocity_change_handler(VALUE self, VALUE handler) {
185
+ void CCONV ph_stepper_on_stopped(PhidgetStepperHandle phid, void *userPtr) {
186
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
187
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
188
+ callback_data->arg1 = Qnil;
189
+ callback_data->arg2 = Qnil;
190
+ callback_data->arg3 = Qnil;
191
+ callback_data->arg4 = Qnil;
192
+ sem_post(&callback_data->callback_called);
193
+ }
194
+
195
+
196
+ VALUE ph_stepper_set_on_stopped_handler(VALUE self, VALUE handler) {
479
197
  ph_data_t *ph = get_ph_data(self);
480
- ph_callback_data_t *callback_data = &ph->dev_callback_2;
198
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[STEPPER_STOPPED_CALLBACK];
481
199
  if( TYPE(handler) == T_NIL ) {
200
+ callback_data->callback = T_NIL;
482
201
  callback_data->exit = true;
483
- ph_raise(CPhidgetStepper_set_OnVelocityChange_Handler((CPhidgetStepperHandle)ph->handle, NULL, (void *)NULL));
202
+ ph_raise(PhidgetStepper_setOnStoppedHandler((PhidgetStepperHandle)ph->handle, NULL, (void *)NULL));
203
+ sem_post(&callback_data->callback_called);
484
204
  } else {
485
- callback_data->called = false;
486
205
  callback_data->exit = false;
487
206
  callback_data->phidget = self;
488
207
  callback_data->callback = handler;
489
- ph_raise(CPhidgetStepper_set_OnVelocityChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_velocity_change, (void *)callback_data));
208
+ ph_raise(PhidgetStepper_setOnStoppedHandler((PhidgetStepperHandle)ph->handle, ph_stepper_on_stopped, (void *)callback_data));
490
209
  ph_callback_thread(callback_data);
491
210
  }
492
211
  return Qnil;
493
212
  }
494
213
 
495
214
 
496
- VALUE ph_stepper_set_on_position_change_handler(VALUE self, VALUE handler) {
215
+ void CCONV ph_stepper_on_velocity_change(PhidgetStepperHandle phid, void *userPtr, double velocity) {
216
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
217
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
218
+ callback_data->arg1 = DBL2NUM(velocity);
219
+ callback_data->arg2 = Qnil;
220
+ callback_data->arg3 = Qnil;
221
+ callback_data->arg4 = Qnil;
222
+ sem_post(&callback_data->callback_called);
223
+ }
224
+
225
+
226
+ VALUE ph_stepper_set_on_velocity_change_handler(VALUE self, VALUE handler) {
497
227
  ph_data_t *ph = get_ph_data(self);
498
- ph_callback_data_t *callback_data = &ph->dev_callback_3;
228
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[STEPPER_VELOCITY_CHANGE_CALLBACK];
499
229
  if( TYPE(handler) == T_NIL ) {
230
+ callback_data->callback = T_NIL;
500
231
  callback_data->exit = true;
501
- ph_raise(CPhidgetStepper_set_OnPositionChange_Handler((CPhidgetStepperHandle)ph->handle, NULL, (void *)NULL));
232
+ ph_raise(PhidgetStepper_setOnVelocityChangeHandler((PhidgetStepperHandle)ph->handle, NULL, (void *)NULL));
233
+ sem_post(&callback_data->callback_called);
502
234
  } else {
503
- callback_data->called = false;
504
235
  callback_data->exit = false;
505
236
  callback_data->phidget = self;
506
237
  callback_data->callback = handler;
507
- ph_raise(CPhidgetStepper_set_OnPositionChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_position_change, (void *)callback_data));
238
+ ph_raise(PhidgetStepper_setOnVelocityChangeHandler((PhidgetStepperHandle)ph->handle, ph_stepper_on_velocity_change, (void *)callback_data));
508
239
  ph_callback_thread(callback_data);
509
240
  }
510
241
  return Qnil;
511
242
  }
512
243
 
513
244
 
514
- VALUE ph_stepper_set_on_current_change_handler(VALUE self, VALUE handler) {
245
+ void CCONV ph_stepper_target_position_async(PhidgetHandle phid, void *userPtr, PhidgetReturnCode res) {
246
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
247
+ callback_data->exit = true;
248
+ callback_data->arg1 = INT2NUM(res);
249
+ callback_data->arg2 = Qnil;
250
+ callback_data->arg3 = Qnil;
251
+ callback_data->arg4 = Qnil;
252
+ sem_post(&callback_data->callback_called);
253
+ }
254
+
255
+
256
+ VALUE ph_stepper_set_target_position_async(VALUE self, VALUE position, VALUE handler) {
515
257
  ph_data_t *ph = get_ph_data(self);
516
- ph_callback_data_t *callback_data = &ph->dev_callback_4;
258
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[STEPPER_TARGET_POSITION_ASYNC_CALLBACK];
517
259
  if( TYPE(handler) == T_NIL ) {
518
- callback_data->exit = true;
519
- ph_raise(CPhidgetStepper_set_OnCurrentChange_Handler((CPhidgetStepperHandle)ph->handle, NULL, (void *)NULL));
260
+ PhidgetStepper_setTargetPosition_async((PhidgetStepperHandle)ph->handle, NUM2DBL(position), NULL, (void *)NULL);
520
261
  } else {
521
- callback_data->called = false;
522
262
  callback_data->exit = false;
523
263
  callback_data->phidget = self;
524
264
  callback_data->callback = handler;
525
- ph_raise(CPhidgetStepper_set_OnCurrentChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_current_change, (void *)callback_data));
265
+ PhidgetStepper_setTargetPosition_async((PhidgetStepperHandle)ph->handle, NUM2DBL(position), ph_stepper_target_position_async, (void *)callback_data);
526
266
  ph_callback_thread(callback_data);
527
267
  }
528
268
  return Qnil;
529
269
  }
530
270
 
531
271
 
532
- int ph_stepper_on_input_change(CPhidgetStepperHandle phid, void *userPtr, int index, int state) {
533
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
534
- callback_data->called = true;
535
- return EPHIDGET_OK;
536
- }
537
272
 
273
+ void Init_stepper() {
274
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
275
+ VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
276
+ VALUE ph_stepper = rb_define_class_under(ph_module, "Stepper", ph_common);
538
277
 
539
- int ph_stepper_on_velocity_change(CPhidgetStepperHandle phid, void *userPtr, int index, double velocity) {
540
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
541
- callback_data->called = true;
542
- return EPHIDGET_OK;
543
- }
278
+ rb_define_const(ph_stepper, "CONTROL_MODE_STEP", INT2NUM(CONTROL_MODE_STEP));
279
+ rb_define_const(ph_stepper, "CONTROL_MODE_RUN", INT2NUM(CONTROL_MODE_RUN));
544
280
 
545
281
 
546
- int ph_stepper_on_position_change(CPhidgetStepperHandle phid, void *userPtr, int index, __int64 position) {
547
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
548
- callback_data->called = true;
549
- return EPHIDGET_OK;
550
- }
282
+ /* Document-method: new
283
+ * call-seq: new
284
+ *
285
+ * Creates a Phidget Stepper object.
286
+ */
287
+ rb_define_method(ph_stepper, "initialize", ph_stepper_init, 0);
551
288
 
289
+ /* Document-method: getAcceleration
290
+ * call-seq: getAcceleration -> acceleration
291
+ *
292
+ * The rate at which the controller can change the motor's Velocity.
293
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
294
+ */
295
+ rb_define_method(ph_stepper, "getAcceleration", ph_stepper_get_acceleration, 0);
296
+ rb_define_alias(ph_stepper, "acceleration", "getAcceleration");
552
297
 
553
- int ph_stepper_on_current_change(CPhidgetStepperHandle phid, void *userPtr, int index, double current) {
554
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
555
- callback_data->called = true;
556
- return EPHIDGET_OK;
557
- }
298
+ /* Document-method: setAcceleration
299
+ * call-seq: setAcceleration(acceleration)
300
+ *
301
+ * The rate at which the controller can change the motor's Velocity.
302
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
303
+ */
304
+ rb_define_method(ph_stepper, "setAcceleration", ph_stepper_set_acceleration, 1);
305
+ rb_define_alias(ph_stepper, "acceleration=", "setAcceleration");
306
+
307
+ /* Document-method: getMinAcceleration
308
+ * call-seq: getMinAcceleration -> acceleration
309
+ *
310
+ * The minimum value that Acceleration can be set to.
311
+ */
312
+ rb_define_method(ph_stepper, "getMinAcceleration", ph_stepper_get_min_acceleration, 0);
313
+ rb_define_alias(ph_stepper, "min_acceleration", "getMinAcceleration");
314
+
315
+ /* Document-method: getMaxAcceleration
316
+ * call-seq: getMaxAcceleration -> acceleration
317
+ *
318
+ * The maximum value that Acceleration can be set to.
319
+ */
320
+ rb_define_method(ph_stepper, "getMaxAcceleration", ph_stepper_get_max_acceleration, 0);
321
+ rb_define_alias(ph_stepper, "max_acceleration", "getMaxAcceleration");
322
+
323
+ /* Document-method: getControlMode
324
+ * call-seq: getControlMode -> control_mode
325
+ *
326
+ * Use step mode when you want to set a TargetPosition for the Stepper motor. Use run mode when you simply want the Stepper motor to rotate continuously in a specific direction.
327
+ */
328
+ rb_define_method(ph_stepper, "getControlMode", ph_stepper_get_control_mode, 0);
329
+ rb_define_alias(ph_stepper, "control_mode", "getControlMode");
330
+
331
+ /* Document-method: setControlMode
332
+ * call-seq: setControlMode(control_mode)
333
+ *
334
+ * Use step mode when you want to set a TargetPosition for the Stepper motor. Use run mode when you simply want the Stepper motor to rotate continuously in a specific direction.
335
+ */
336
+ rb_define_method(ph_stepper, "setControlMode", ph_stepper_set_control_mode, 1);
337
+ rb_define_alias(ph_stepper, "control_mode=", "setControlMode");
338
+
339
+ /* Document-method: getCurrentLimit
340
+ * call-seq: getCurrentLimit -> limit
341
+ *
342
+ * The current through the motor will be limited by the CurrentLimit.
343
+ * See your Stepper motor's data sheet for more information about what value the CurrentLimit should be.
344
+ */
345
+ rb_define_method(ph_stepper, "getCurrentLimit", ph_stepper_get_current_limit, 0);
346
+ rb_define_alias(ph_stepper, "current_limit", "getCurrentLimit");
347
+
348
+ /* Document-method: setCurrentLimit
349
+ * call-seq: setCurrentLimit(limit)
350
+ *
351
+ * The current through the motor will be limited by the CurrentLimit.
352
+ * See your Stepper motor's data sheet for more information about what value the CurrentLimit should be.
353
+ */
354
+ rb_define_method(ph_stepper, "setCurrentLimit", ph_stepper_set_current_limit, 1);
355
+ rb_define_alias(ph_stepper, "current_limit=", "setCurrentLimit");
356
+
357
+ /* Document-method: getMinCurrentLimit
358
+ * call-seq: getMinCurrentLimit -> current_limit
359
+ *
360
+ * The minimum value that CurrentLimit and HoldingCurrentLimit can be set to.
361
+ * Reference your controller's User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.
362
+ */
363
+ rb_define_method(ph_stepper, "getMinCurrentLimit", ph_stepper_get_min_current_limit, 0);
364
+ rb_define_alias(ph_stepper, "min_current_limit", "getMinCurrentLimit");
365
+
366
+ /* Document-method: getMaxCurrentLimit
367
+ * call-seq: getMaxCurrentLimit -> current_limit
368
+ *
369
+ * The maximum value that CurrentLimit and HoldingCurrentLimit can be set to.
370
+ * Reference your controller's User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.
371
+ */
372
+ rb_define_method(ph_stepper, "getMaxCurrentLimit", ph_stepper_get_max_current_limit, 0);
373
+ rb_define_alias(ph_stepper, "max_current_limit", "getMaxCurrentLimit");
374
+
375
+ /* Document-method: getDataInterval
376
+ * call-seq: getDataInterval -> interval
377
+ *
378
+ * The DataInterval is the time that must elapse before the controller will fire another PositionChange/VelocityChange event.
379
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
380
+ */
381
+ rb_define_method(ph_stepper, "getDataInterval", ph_stepper_get_data_interval, 0);
382
+ rb_define_alias(ph_stepper, "data_interval", "getDataInterval");
383
+
384
+ /* Document-method: setDataInterval
385
+ * call-seq: setDataInterval(interval)
386
+ *
387
+ * The DataInterval is the time that must elapse before the controller will fire another PositionChange/VelocityChange event.
388
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
389
+ */
390
+ rb_define_method(ph_stepper, "setDataInterval", ph_stepper_set_data_interval, 1);
391
+ rb_define_alias(ph_stepper, "data_interval=", "setDataInterval");
392
+
393
+ /* Document-method: getMinDataInterval
394
+ * call-seq: getMinDataInterval -> interval
395
+ *
396
+ * The minimum value that DataInterval can be set to.
397
+ */
398
+ rb_define_method(ph_stepper, "getMinDataInterval", ph_stepper_get_min_data_interval, 0);
399
+ rb_define_alias(ph_stepper, "min_data_interval", "getMinDataInterval");
400
+
401
+ /* Document-method: getMaxDataInterval
402
+ * call-seq: getMaxDataInterval -> interval
403
+ *
404
+ * The maximum value that DataInterval can be set to.
405
+ */
406
+ rb_define_method(ph_stepper, "getMaxDataInterval", ph_stepper_get_max_data_interval, 0);
407
+ rb_define_alias(ph_stepper, "max_data_interval", "getMaxDataInterval");
408
+
409
+ /* Document-method: getEngaged
410
+ * call-seq: getEngaged -> true or false
411
+ *
412
+ * When this property is true, the controller will supply power to the motor coils.
413
+ * The controller must be Engaged in order to move the Stepper motor, or have it hold position.
414
+ */
415
+ rb_define_method(ph_stepper, "getEngaged", ph_stepper_get_engaged, 0);
416
+ rb_define_alias(ph_stepper, "engaged?", "getEngaged");
417
+
418
+ /* Document-method: setEngaged
419
+ * call-seq: setEngaged(state)
420
+ *
421
+ * When this property is true, the controller will supply power to the motor coils.
422
+ * The controller must be Engaged in order to move the Stepper motor, or have it hold position.
423
+ */
424
+ rb_define_method(ph_stepper, "setEngaged", ph_stepper_set_engaged, 1);
425
+ rb_define_alias(ph_stepper, "engaged=", "setEngaged");
426
+
427
+ /* Document-method: getHoldingCurrentLimit
428
+ * call-seq: getHoldingCurrentLimit -> holding_current_limit
429
+ *
430
+ * The HoldingCurrentLimit will activate when the TargetPosition has been reached. It will limit current through the motor.
431
+ * When the motor is not stopped, the current through the motor is limited by the CurrentLimit.
432
+ * If no HoldingCurrentLimit is specified, the CurrentLimit value will persist when the motor is stopped.
433
+ * Reference your controller's User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.
434
+ */
435
+ rb_define_method(ph_stepper, "getHoldingCurrentLimit", ph_stepper_get_holding_current_limit, 0);
436
+ rb_define_alias(ph_stepper, "holding_current_limit", "getHoldingCurrentLimit");
437
+
438
+ /* Document-method: setHoldingCurrentLimit
439
+ * call-seq: setHoldingCurrentLimit(holding_current_limit)
440
+ *
441
+ * The HoldingCurrentLimit will activate when the TargetPosition has been reached. It will limit current through the motor.
442
+ * When the motor is not stopped, the current through the motor is limited by the CurrentLimit.
443
+ * If no HoldingCurrentLimit is specified, the CurrentLimit value will persist when the motor is stopped.
444
+ * Reference your controller's User Guide for more information about how the HoldingCurrentLimit and CurrentLimit can be used in your application.
445
+ */
446
+ rb_define_method(ph_stepper, "setHoldingCurrentLimit", ph_stepper_set_holding_current_limit, 1);
447
+ rb_define_alias(ph_stepper, "holding_current_limit=", "setHoldingCurrentLimit");
448
+
449
+ /* Document-method: getIsMoving
450
+ * call-seq: getIsMoving -> true or false
451
+ *
452
+ * IsMoving returns true while the controller is sending commands to the motor. Note: there is no feedback to the controller, so it does not know whether the motor shaft is actually moving or not.
453
+ */
454
+ rb_define_method(ph_stepper, "getIsMoving", ph_stepper_get_is_moving, 0);
455
+ rb_define_alias(ph_stepper, "is_moving?", "getIsMoving");
456
+
457
+ /* Document-method: getPosition
458
+ * call-seq: getPosition -> position
459
+ *
460
+ * The most recent position value that the controller has reported.
461
+ * This value will always be between MinPosition and MaxPosition.
462
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
463
+ */
464
+ rb_define_method(ph_stepper, "getPosition", ph_stepper_get_position, 0);
465
+ rb_define_alias(ph_stepper, "position", "getPosition");
466
+
467
+ /* Document-method: getMinPosition
468
+ * call-seq: getMinPosition -> position
469
+ *
470
+ * The minimum value that TargetPosition can be set to.
471
+ */
472
+ rb_define_method(ph_stepper, "getMinPosition", ph_stepper_get_min_position, 0);
473
+ rb_define_alias(ph_stepper, "min_position", "getMinPosition");
474
+
475
+ /* Document-method: getMaxPosition
476
+ * call-seq: getMaxPosition -> position
477
+ *
478
+ * The maximum value that TargetPosition can be set to.
479
+ */
480
+ rb_define_method(ph_stepper, "getMaxPosition", ph_stepper_get_max_position, 0);
481
+ rb_define_alias(ph_stepper, "max_position", "getMaxPosition");
482
+
483
+ /* Document-method: addPositionOffset
484
+ * call-seq: addPositionOffset(position_offset)
485
+ *
486
+ * Adds an offset (positive or negative) to the current position and target position.
487
+ * This is especially useful for zeroing position.
488
+ */
489
+ rb_define_method(ph_stepper, "addPositionOffset", ph_stepper_add_position_offset, 1);
490
+ rb_define_alias(ph_stepper, "add_position_offset", "addPositionOffset");
491
+
492
+ /* Document-method: getRescaleFactor
493
+ * call-seq: getRescaleFactor -> rescale_factor
494
+ *
495
+ * Applies a factor to the [user units] per step to all movement parameters to make the units in your application is more intuitive.
496
+ * For example, starting from position 0 and setting a new position with a rescale factor, the stepper will move Position / RescaleFactor steps.
497
+ * In this way, units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
498
+ */
499
+ rb_define_method(ph_stepper, "getRescaleFactor", ph_stepper_get_rescale_factor, 0);
500
+ rb_define_alias(ph_stepper, "rescale_factor", "getRescaleFactor");
558
501
 
559
- #endif
502
+ /* Document-method: setRescaleFactor
503
+ * call-seq: setRescaleFactor(rescale_factor)
504
+ *
505
+ * Applies a factor to the [user units] per step to all movement parameters to make the units in your application is more intuitive.
506
+ * For example, starting from position 0 and setting a new position with a rescale factor, the stepper will move Position / RescaleFactor steps.
507
+ * In this way, units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
508
+ */
509
+ rb_define_method(ph_stepper, "setRescaleFactor", ph_stepper_set_rescale_factor, 1);
510
+ rb_define_alias(ph_stepper, "rescale_factor=", "setRescaleFactor");
511
+
512
+ /* Document-method: getTargetPosition
513
+ * call-seq: getTargetPosition -> position
514
+ *
515
+ * If the controller is configured and the TargetPosition is set, the Stepper motor will move towards the TargetPosition at the specified Acceleration and Velocity.
516
+ * TargetPosition is only used when the ControlMode is set to step mode.
517
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
518
+ */
519
+ rb_define_method(ph_stepper, "getTargetPosition", ph_stepper_get_target_position, 0);
520
+ rb_define_alias(ph_stepper, "target_position", "getTargetPosition");
521
+
522
+ /* Document-method: setTargetPosition
523
+ * call-seq: setTargetPosition(position)
524
+ *
525
+ * If the controller is configured and the TargetPosition is set, the Stepper motor will move towards the TargetPosition at the specified Acceleration and Velocity.
526
+ * TargetPosition is only used when the ControlMode is set to step mode.
527
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
528
+ */
529
+ rb_define_method(ph_stepper, "setTargetPosition", ph_stepper_set_target_position, 1);
530
+ rb_define_alias(ph_stepper, "target_position=", "setTargetPosition");
531
+
532
+ /* Document-method: getVelocity
533
+ * call-seq: getVelocity -> velocity
534
+ *
535
+ * The most recent velocity value that the controller has reported.
536
+ * This value is bounded by MinVelocityLimit and MaxVelocityLimit.
537
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
538
+ */
539
+ rb_define_method(ph_stepper, "getVelocity", ph_stepper_get_velocity, 0);
540
+ rb_define_alias(ph_stepper, "velocity", "getVelocity");
541
+
542
+ /* Document-method: getVelocityLimit
543
+ * call-seq: getVelocityLimit -> velocity_limit
544
+ *
545
+ * When moving, the Stepper motor velocity will be limited by this value.
546
+ * The VelocityLimit is bounded by MinVelocityLimit and MaxVelocityLimit.
547
+ * When in step mode, the MinVelocityLimit has a value of 0. This is because the sign (±) of the TargetPosition will indicate the direction.
548
+ * When in run mode, the MinVelocityLimit has a value of -MaxVelocityLimit. This is because there is no target position, so the direction is defined by the sign (±) of the VelocityLimit.
549
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
550
+ */
551
+ rb_define_method(ph_stepper, "getVelocityLimit", ph_stepper_get_velocity_limit, 0);
552
+ rb_define_alias(ph_stepper, "velocity_limit", "getVelocityLimit");
553
+
554
+ /* Document-method: setVelocityLimit
555
+ * call-seq: setVelocityLimit(velocity_limit)
556
+ *
557
+ * When moving, the Stepper motor velocity will be limited by this value.
558
+ * The VelocityLimit is bounded by MinVelocityLimit and MaxVelocityLimit.
559
+ * When in step mode, the MinVelocityLimit has a value of 0. This is because the sign (±) of the TargetPosition will indicate the direction.
560
+ * When in run mode, the MinVelocityLimit has a value of -MaxVelocityLimit. This is because there is no target position, so the direction is defined by the sign (±) of the VelocityLimit.
561
+ * Units for Position, Velocity, and Acceleration can be set by the user through the RescaleFactor. The RescaleFactor allows you to use more intuitive units such as rotations, or degrees.
562
+ */
563
+ rb_define_method(ph_stepper, "setVelocityLimit", ph_stepper_set_velocity_limit, 1);
564
+ rb_define_alias(ph_stepper, "velocity_limit=", "setVelocityLimit");
565
+
566
+ /* Document-method: getMinVelocityLimit
567
+ * call-seq: getMinVelocityLimit -> velocity_limit
568
+ *
569
+ * The minimum value that VelocityLimit can be set to.
570
+ */
571
+ rb_define_method(ph_stepper, "getMinVelocityLimit", ph_stepper_get_min_velocity_limit, 0);
572
+ rb_define_alias(ph_stepper, "min_velocity_limit", "getMinVelocityLimit");
573
+
574
+ /* Document-method: getMaxVelocityLimit
575
+ * call-seq: getMaxVelocityLimit -> velocity_limit
576
+ *
577
+ * The maximum value that VelocityLimit can be set to.
578
+ */
579
+ rb_define_method(ph_stepper, "getMaxVelocityLimit", ph_stepper_get_max_velocity_limit, 0);
580
+ rb_define_alias(ph_stepper, "max_velocity_limit", "getMaxVelocityLimit");
581
+
582
+ rb_define_private_method(ph_stepper, "ext_setOnPositionChangeHandler", ph_stepper_set_on_position_change_handler, 1);
583
+ rb_define_private_method(ph_stepper, "ext_setOnStoppedHandler", ph_stepper_set_on_stopped_handler, 1);
584
+ rb_define_private_method(ph_stepper, "ext_setOnVelocityChangeHandler", ph_stepper_set_on_velocity_change_handler, 1);
585
+ rb_define_private_method(ph_stepper, "ext_setTargetPosition_async", ph_stepper_set_target_position_async, 2);
586
+ }
560
587