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.
- data/History.txt +10 -2
- data/README.rdoc +41 -18
- data/Rakefile +31 -20
- data/bin/phidget +29 -44
- data/ext/phidgets/extconf.rb +14 -0
- data/ext/phidgets/phidgets.c +272 -0
- data/ext/phidgets/phidgets.h +82 -0
- data/ext/phidgets/phidgets_accelerometer.c +165 -0
- data/ext/phidgets/phidgets_advanced_servo.c +567 -0
- data/ext/phidgets/phidgets_analog.c +139 -0
- data/ext/phidgets/phidgets_bridge.c +263 -0
- data/ext/phidgets/phidgets_common.c +454 -0
- data/ext/phidgets/phidgets_dictionary.c +279 -0
- data/ext/phidgets/phidgets_encoder.c +249 -0
- data/ext/phidgets/phidgets_frequency_counter.c +241 -0
- data/ext/phidgets/phidgets_gps.c +235 -0
- data/ext/phidgets/phidgets_interface_kit.c +340 -0
- data/ext/phidgets/phidgets_ir.c +251 -0
- data/ext/phidgets/phidgets_led.c +178 -0
- data/ext/phidgets/phidgets_manager.c +366 -0
- data/ext/phidgets/phidgets_motor_control.c +642 -0
- data/ext/phidgets/phidgets_phsensor.c +208 -0
- data/ext/phidgets/phidgets_rfid.c +281 -0
- data/ext/phidgets/phidgets_servo.c +276 -0
- data/ext/phidgets/phidgets_spatial.c +369 -0
- data/ext/phidgets/phidgets_stepper.c +560 -0
- data/ext/phidgets/phidgets_temp_sensor.c +295 -0
- data/ext/phidgets/phidgets_text_lcd.c +381 -0
- data/ext/phidgets/phidgets_text_led.c +107 -0
- data/ext/phidgets/phidgets_weight_sensor.c +113 -0
- data/lib/phidgets/accelerometer.rb +25 -0
- data/lib/phidgets/advanced_servo.rb +49 -0
- data/lib/phidgets/analog.rb +8 -0
- data/lib/phidgets/bridge.rb +25 -0
- data/lib/phidgets/common.rb +75 -190
- data/lib/phidgets/dictionary.rb +53 -0
- data/lib/phidgets/encoder.rb +49 -0
- data/lib/phidgets/frequency_counter.rb +25 -0
- data/lib/phidgets/gps.rb +37 -0
- data/lib/phidgets/interfacekit.rb +38 -128
- data/lib/phidgets/ir.rb +50 -0
- data/lib/phidgets/led.rb +8 -0
- data/lib/phidgets/manager.rb +67 -119
- data/lib/phidgets/motor_control.rb +110 -0
- data/lib/phidgets/ph_sensor.rb +25 -0
- data/lib/phidgets/rfid.rb +38 -111
- data/lib/phidgets/servo.rb +12 -95
- data/lib/phidgets/spatial.rb +25 -0
- data/lib/phidgets/stepper.rb +61 -0
- data/lib/phidgets/temperature_sensor.rb +25 -0
- data/lib/phidgets/text_lcd.rb +8 -0
- data/lib/phidgets/text_led.rb +8 -0
- data/lib/phidgets/weight_sensor.rb +25 -0
- data/lib/phidgets.rb +22 -3
- data/phidgets.gemspec +42 -0
- data/test/test_accelerometer.rb +47 -0
- data/test/test_advanced_servo.rb +152 -0
- data/test/test_analog.rb +45 -0
- data/test/test_bridge.rb +77 -0
- data/test/test_common.rb +167 -0
- data/test/test_dictionary.rb +82 -0
- data/test/test_encoder.rb +67 -0
- data/test/test_frequency_counter.rb +67 -0
- data/test/test_gps.rb +67 -0
- data/test/test_helper.rb +1 -0
- data/test/test_interfacekit.rb +86 -182
- data/test/test_ir.rb +57 -0
- data/test/test_led.rb +55 -0
- data/test/test_manager.rb +94 -0
- data/test/test_motor_control.rb +172 -0
- data/test/test_phidgets.rb +14 -6
- data/test/test_phsensor.rb +62 -0
- data/test/test_rfid.rb +77 -0
- data/test/test_servo.rb +67 -0
- data/test/test_spatial.rb +112 -0
- data/test/test_stepper.rb +163 -0
- data/test/test_temp_sensor.rb +87 -0
- data/test/test_text_lcd.rb +115 -0
- data/test/test_text_led.rb +35 -0
- data/test/test_weight_sensor.rb +32 -0
- metadata +165 -75
- data/Manifest.txt +0 -21
- data/PostInstall.txt +0 -3
- data/README.txt +0 -87
- data/lib/phidgets/phidgets.rb +0 -225
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
@@ -0,0 +1,560 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
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
|
+
|
44
|
+
|
45
|
+
VALUE Init_phidgets_stepper(VALUE ph_module, VALUE ph_common) {
|
46
|
+
VALUE ph_stepper = rb_define_class_under(ph_module, "Stepper", ph_common);
|
47
|
+
|
48
|
+
/* Document-method: new
|
49
|
+
* call-seq: new
|
50
|
+
*
|
51
|
+
* Creates a Phidget Stepper object.
|
52
|
+
*/
|
53
|
+
rb_define_method(ph_stepper, "initialize", ph_stepper_init, 0);
|
54
|
+
|
55
|
+
/* Document-method: getInputCount
|
56
|
+
* call-seq: getInputCount -> count
|
57
|
+
*
|
58
|
+
* Gets the number of digital inputs supported by this board.
|
59
|
+
*/
|
60
|
+
rb_define_method(ph_stepper, "getInputCount", ph_stepper_get_input_count, 0);
|
61
|
+
|
62
|
+
/* Document-method: getInputState
|
63
|
+
* call-seq: getInputState(index) -> true or false
|
64
|
+
*
|
65
|
+
* Gets the state of a digital input.
|
66
|
+
*/
|
67
|
+
rb_define_method(ph_stepper, "getInputState", ph_stepper_get_input_state, 1);
|
68
|
+
|
69
|
+
/* Document-method: getMotorCount
|
70
|
+
* call-seq: getMotorCount -> count
|
71
|
+
*
|
72
|
+
* Gets the number of motors supported by this controller
|
73
|
+
*/
|
74
|
+
rb_define_method(ph_stepper, "getMotorCount", ph_stepper_get_motor_count, 0);
|
75
|
+
|
76
|
+
/* Document-method: getAcceleration
|
77
|
+
* call-seq: getAcceleration(index) -> acceleration
|
78
|
+
*
|
79
|
+
* Gets the last set acceleration for a motor.
|
80
|
+
*/
|
81
|
+
rb_define_method(ph_stepper, "getAcceleration", ph_stepper_get_acceleration, 1);
|
82
|
+
|
83
|
+
/* Document-method: getAccelerationMin
|
84
|
+
* call-seq: getAccelerationMin(index) -> acceleration
|
85
|
+
*
|
86
|
+
* Gets the minimum acceleration supported by a motor.
|
87
|
+
*/
|
88
|
+
rb_define_method(ph_stepper, "getAccelerationMin", ph_stepper_get_acceleration_min, 1);
|
89
|
+
|
90
|
+
/* Document-method: getAccelerationMax
|
91
|
+
* call-seq: getAccelerationMax(index) -> acceleration
|
92
|
+
*
|
93
|
+
* Gets the maximum acceleration supported by a motor.
|
94
|
+
*/
|
95
|
+
rb_define_method(ph_stepper, "getAccelerationMax", ph_stepper_get_acceleration_max, 1);
|
96
|
+
|
97
|
+
/* Document-method: setAcceleration
|
98
|
+
* call-seq: setAcceleration(index, acceleration)
|
99
|
+
*
|
100
|
+
* Sets the acceleration for a motor.
|
101
|
+
*/
|
102
|
+
rb_define_method(ph_stepper, "setAcceleration", ph_stepper_set_acceleration, 2);
|
103
|
+
|
104
|
+
/* Document-method: getVelocityLimit
|
105
|
+
* call-seq: getVelocityLimit(index) -> velocity_limit
|
106
|
+
*
|
107
|
+
* Gets the last set velocity limit for a motor.
|
108
|
+
*/
|
109
|
+
rb_define_method(ph_stepper, "getVelocityLimit", ph_stepper_get_velocity_limit, 1);
|
110
|
+
|
111
|
+
/* Document-method: setVelocityLimit
|
112
|
+
* call-seq: setVelocityLimit(index, velocity_limit)
|
113
|
+
*
|
114
|
+
* Sets the velocity limit for a motor.
|
115
|
+
*/
|
116
|
+
rb_define_method(ph_stepper, "setVelocityLimit", ph_stepper_set_velocity_limit, 2);
|
117
|
+
|
118
|
+
/* Document-method: getVelocity
|
119
|
+
* call-seq: getVelocity(index) -> velocity
|
120
|
+
*
|
121
|
+
* Gets the current velocity of a motor.
|
122
|
+
*/
|
123
|
+
rb_define_method(ph_stepper, "getVelocity", ph_stepper_get_velocity, 1);
|
124
|
+
|
125
|
+
/* Document-method: getVelocityMin
|
126
|
+
* call-seq: getVelocityMin(index) -> velocity
|
127
|
+
*
|
128
|
+
* Gets the minimum velocity that can be set for a motor.
|
129
|
+
*/
|
130
|
+
rb_define_method(ph_stepper, "getVelocityMin", ph_stepper_get_velocity_min, 1);
|
131
|
+
|
132
|
+
/* Document-method: getVelocityMax
|
133
|
+
* call-seq: getVelocityMax(index) -> velocity
|
134
|
+
*
|
135
|
+
* Gets the maximum velocity that can be set for a motor.
|
136
|
+
*/
|
137
|
+
rb_define_method(ph_stepper, "getVelocityMax", ph_stepper_get_velocity_max, 1);
|
138
|
+
|
139
|
+
/* Document-method: getTargetPosition
|
140
|
+
* call-seq: getTargetPosition(index) -> position
|
141
|
+
*
|
142
|
+
* Gets the last set target position of a motor.
|
143
|
+
*/
|
144
|
+
rb_define_method(ph_stepper, "getTargetPosition", ph_stepper_get_target_position, 1);
|
145
|
+
|
146
|
+
/* Document-method: setTargetPosition
|
147
|
+
* call-seq: setTargetPosition(index, position)
|
148
|
+
*
|
149
|
+
* Sets the target position of a motor.
|
150
|
+
*/
|
151
|
+
rb_define_method(ph_stepper, "setTargetPosition", ph_stepper_set_target_position, 2);
|
152
|
+
|
153
|
+
/* Document-method: getCurrentPosition
|
154
|
+
* call-seq: getCurrentPosition(index) -> position
|
155
|
+
*
|
156
|
+
* Gets the current position of a motor.
|
157
|
+
*/
|
158
|
+
rb_define_method(ph_stepper, "getCurrentPosition", ph_stepper_get_current_position, 1);
|
159
|
+
|
160
|
+
/* Document-method: setCurrentPosition
|
161
|
+
* call-seq: setCurrentPosition(index, position)
|
162
|
+
*
|
163
|
+
* Sets the current position of a motor. This will not move the motor, just update the position value.
|
164
|
+
*/
|
165
|
+
rb_define_method(ph_stepper, "setCurrentPosition", ph_stepper_set_current_position, 2);
|
166
|
+
|
167
|
+
/* Document-method: getPositionMin
|
168
|
+
* call-seq: getPositionMin(index) -> position
|
169
|
+
*
|
170
|
+
* Gets the minimum position that a motor can go to.
|
171
|
+
*/
|
172
|
+
rb_define_method(ph_stepper, "getPositionMin", ph_stepper_get_position_min, 1);
|
173
|
+
|
174
|
+
/* Document-method: getPositionMax
|
175
|
+
* call-seq: getPositionMax(index) -> position
|
176
|
+
*
|
177
|
+
* Gets the maximum position that a motor can go to.
|
178
|
+
*/
|
179
|
+
rb_define_method(ph_stepper, "getPositionMax", ph_stepper_get_position_max, 1);
|
180
|
+
|
181
|
+
/* Document-method: getCurrentLimit
|
182
|
+
* call-seq: getCurrentLimit(index) -> limit
|
183
|
+
*
|
184
|
+
* Gets the current limit for a motor.
|
185
|
+
*/
|
186
|
+
rb_define_method(ph_stepper, "getCurrentLimit", ph_stepper_get_current_limit, 1);
|
187
|
+
|
188
|
+
/* Document-method: setCurrentLimit
|
189
|
+
* call-seq: setCurrentLimit(index, limit)
|
190
|
+
*
|
191
|
+
* Sets the current limit for a motor.
|
192
|
+
*/
|
193
|
+
rb_define_method(ph_stepper, "setCurrentLimit", ph_stepper_set_current_limit, 2);
|
194
|
+
|
195
|
+
/* Document-method: getCurrent
|
196
|
+
* call-seq: getCurrent(index) -> current
|
197
|
+
*
|
198
|
+
* Gets the current current draw for a motor.
|
199
|
+
*/
|
200
|
+
rb_define_method(ph_stepper, "getCurrent", ph_stepper_get_current, 1);
|
201
|
+
|
202
|
+
/* Document-method: getCurrentMin
|
203
|
+
* call-seq: getCurrentMin(index) -> current
|
204
|
+
*
|
205
|
+
* Gets the minimum current limit.
|
206
|
+
*/
|
207
|
+
rb_define_method(ph_stepper, "getCurrentMin", ph_stepper_get_current_min, 1);
|
208
|
+
|
209
|
+
/* Document-method: getCurrentMax
|
210
|
+
* call-seq: getCurrentMax(index) -> current
|
211
|
+
*
|
212
|
+
* Gets the maximum current limit.
|
213
|
+
*/
|
214
|
+
rb_define_method(ph_stepper, "getCurrentMax", ph_stepper_get_current_max, 1);
|
215
|
+
|
216
|
+
/* Document-method: getEngaged
|
217
|
+
* call-seq: getEngaged(index) -> true or false
|
218
|
+
*
|
219
|
+
* Gets the engaged state of a motor. This is whether the motor is powered or not.
|
220
|
+
*/
|
221
|
+
rb_define_method(ph_stepper, "getEngaged", ph_stepper_get_engaged, 1);
|
222
|
+
|
223
|
+
/* Document-method: setEngaged
|
224
|
+
* call-seq: setEngaged(index, state)
|
225
|
+
*
|
226
|
+
* Sets the engaged state of a motor. This is whether the motor is powered or not.
|
227
|
+
*/
|
228
|
+
rb_define_method(ph_stepper, "setEngaged", ph_stepper_set_engaged, 2);
|
229
|
+
|
230
|
+
/* Document-method: getStopped
|
231
|
+
* call-seq: getStopped(index) -> true or false
|
232
|
+
*
|
233
|
+
* Gets the stopped state of a motor. This is true when the motor is not moving and there are no outstanding commands.
|
234
|
+
*/
|
235
|
+
rb_define_method(ph_stepper, "getStopped", ph_stepper_get_stopped, 1);
|
236
|
+
|
237
|
+
#ifdef PH_CALLBACK
|
238
|
+
rb_define_private_method(ph_stepper, "ext_setOnInputChangeHandler", ph_stepper_set_on_input_change_handler, 1);
|
239
|
+
rb_define_private_method(ph_stepper, "ext_setOnVelocityChangeHandler", ph_stepper_set_on_velocity_change_handler, 1);
|
240
|
+
rb_define_private_method(ph_stepper, "ext_setOnPositionChangeHandler", ph_stepper_set_on_position_change_handler, 1);
|
241
|
+
rb_define_private_method(ph_stepper, "ext_setOnCurrentChangeHandler", ph_stepper_set_on_current_change_handler, 1);
|
242
|
+
#endif
|
243
|
+
|
244
|
+
rb_define_alias(ph_stepper, "input_count", "getInputCount");
|
245
|
+
rb_define_alias(ph_stepper, "input_state", "getInputState");
|
246
|
+
rb_define_alias(ph_stepper, "motor_count", "getMotorCount");
|
247
|
+
rb_define_alias(ph_stepper, "acceleration", "getAcceleration");
|
248
|
+
rb_define_alias(ph_stepper, "acceleration_min", "getAccelerationMin");
|
249
|
+
rb_define_alias(ph_stepper, "acceleration_max", "getAccelerationMax");
|
250
|
+
rb_define_alias(ph_stepper, "set_acceleration", "setAcceleration");
|
251
|
+
rb_define_alias(ph_stepper, "velocity_limit", "getVelocityLimit");
|
252
|
+
rb_define_alias(ph_stepper, "set_velocity_limit", "setVelocityLimit");
|
253
|
+
rb_define_alias(ph_stepper, "velocity", "getVelocity");
|
254
|
+
rb_define_alias(ph_stepper, "velocity_min", "getVelocityMin");
|
255
|
+
rb_define_alias(ph_stepper, "velocity_max", "getVelocityMax");
|
256
|
+
rb_define_alias(ph_stepper, "target_position", "getTargetPosition");
|
257
|
+
rb_define_alias(ph_stepper, "set_target_position", "setTargetPosition");
|
258
|
+
rb_define_alias(ph_stepper, "current_position", "getCurrentPosition");
|
259
|
+
rb_define_alias(ph_stepper, "set_current_position", "setCurrentPosition");
|
260
|
+
rb_define_alias(ph_stepper, "position_min", "getPositionMin");
|
261
|
+
rb_define_alias(ph_stepper, "position_max", "getPositionMax");
|
262
|
+
rb_define_alias(ph_stepper, "current_limit", "getCurrentLimit");
|
263
|
+
rb_define_alias(ph_stepper, "set_current_limit", "setCurrentLimit");
|
264
|
+
rb_define_alias(ph_stepper, "current", "getCurrent");
|
265
|
+
rb_define_alias(ph_stepper, "current_min", "getCurrentMin");
|
266
|
+
rb_define_alias(ph_stepper, "current_max", "getCurrentMax");
|
267
|
+
rb_define_alias(ph_stepper, "engaged?", "getEngaged");
|
268
|
+
rb_define_alias(ph_stepper, "set_engaged", "setEngaged");
|
269
|
+
rb_define_alias(ph_stepper, "stopped?", "getStopped");
|
270
|
+
|
271
|
+
return ph_stepper;
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
|
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;
|
280
|
+
}
|
281
|
+
|
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);
|
287
|
+
}
|
288
|
+
|
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;
|
294
|
+
}
|
295
|
+
|
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);
|
301
|
+
}
|
302
|
+
|
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);
|
308
|
+
}
|
309
|
+
|
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);
|
315
|
+
}
|
316
|
+
|
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);
|
322
|
+
}
|
323
|
+
|
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;
|
328
|
+
}
|
329
|
+
|
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);
|
335
|
+
}
|
336
|
+
|
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)));
|
340
|
+
return Qnil;
|
341
|
+
}
|
342
|
+
|
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);
|
348
|
+
}
|
349
|
+
|
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);
|
355
|
+
}
|
356
|
+
|
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);
|
362
|
+
}
|
363
|
+
|
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);
|
369
|
+
}
|
370
|
+
|
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;
|
375
|
+
}
|
376
|
+
|
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);
|
382
|
+
}
|
383
|
+
|
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)));
|
387
|
+
return Qnil;
|
388
|
+
}
|
389
|
+
|
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);
|
395
|
+
}
|
396
|
+
|
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);
|
402
|
+
}
|
403
|
+
|
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), ¤t));
|
408
|
+
return rb_float_new(current);
|
409
|
+
}
|
410
|
+
|
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)));
|
414
|
+
return Qnil;
|
415
|
+
}
|
416
|
+
|
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), ¤t));
|
421
|
+
return rb_float_new(current);
|
422
|
+
}
|
423
|
+
|
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), ¤t));
|
428
|
+
return rb_float_new(current);
|
429
|
+
}
|
430
|
+
|
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), ¤t));
|
435
|
+
return rb_float_new(current);
|
436
|
+
}
|
437
|
+
|
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;
|
443
|
+
}
|
444
|
+
|
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;
|
449
|
+
}
|
450
|
+
|
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;
|
456
|
+
}
|
457
|
+
|
458
|
+
|
459
|
+
#ifdef PH_CALLBACK
|
460
|
+
VALUE ph_stepper_set_on_input_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_1;
|
463
|
+
if( TYPE(handler) == T_NIL ) {
|
464
|
+
callback_data->exit = true;
|
465
|
+
ph_raise(CPhidgetStepper_set_OnInputChange_Handler((CPhidgetStepperHandle)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(CPhidgetStepper_set_OnInputChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_input_change, (void *)callback_data));
|
472
|
+
ph_callback_thread(callback_data);
|
473
|
+
}
|
474
|
+
return Qnil;
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
VALUE ph_stepper_set_on_velocity_change_handler(VALUE self, VALUE handler) {
|
479
|
+
ph_data_t *ph = get_ph_data(self);
|
480
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_2;
|
481
|
+
if( TYPE(handler) == T_NIL ) {
|
482
|
+
callback_data->exit = true;
|
483
|
+
ph_raise(CPhidgetStepper_set_OnVelocityChange_Handler((CPhidgetStepperHandle)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(CPhidgetStepper_set_OnVelocityChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_velocity_change, (void *)callback_data));
|
490
|
+
ph_callback_thread(callback_data);
|
491
|
+
}
|
492
|
+
return Qnil;
|
493
|
+
}
|
494
|
+
|
495
|
+
|
496
|
+
VALUE ph_stepper_set_on_position_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_3;
|
499
|
+
if( TYPE(handler) == T_NIL ) {
|
500
|
+
callback_data->exit = true;
|
501
|
+
ph_raise(CPhidgetStepper_set_OnPositionChange_Handler((CPhidgetStepperHandle)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(CPhidgetStepper_set_OnPositionChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_position_change, (void *)callback_data));
|
508
|
+
ph_callback_thread(callback_data);
|
509
|
+
}
|
510
|
+
return Qnil;
|
511
|
+
}
|
512
|
+
|
513
|
+
|
514
|
+
VALUE ph_stepper_set_on_current_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_4;
|
517
|
+
if( TYPE(handler) == T_NIL ) {
|
518
|
+
callback_data->exit = true;
|
519
|
+
ph_raise(CPhidgetStepper_set_OnCurrentChange_Handler((CPhidgetStepperHandle)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(CPhidgetStepper_set_OnCurrentChange_Handler((CPhidgetStepperHandle)ph->handle, ph_stepper_on_current_change, (void *)callback_data));
|
526
|
+
ph_callback_thread(callback_data);
|
527
|
+
}
|
528
|
+
return Qnil;
|
529
|
+
}
|
530
|
+
|
531
|
+
|
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
|
+
|
538
|
+
|
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
|
+
}
|
544
|
+
|
545
|
+
|
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
|
+
}
|
551
|
+
|
552
|
+
|
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
|
+
}
|
558
|
+
|
559
|
+
#endif
|
560
|
+
|