phidgets 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +3 -0
- data/README.rdoc +32 -43
- data/Rakefile +4 -2
- data/bin/phidget +18 -72
- data/ext/phidgets/extconf.rb +5 -8
- data/ext/phidgets/phidgets.c +708 -173
- data/ext/phidgets/phidgets.h +54 -35
- data/ext/phidgets/phidgets_accelerometer.c +193 -109
- data/ext/phidgets/phidgets_bldc_motor.c +529 -0
- data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
- data/ext/phidgets/phidgets_common.c +570 -315
- data/ext/phidgets/phidgets_current_input.c +229 -0
- data/ext/phidgets/phidgets_dc_motor.c +562 -0
- data/ext/phidgets/phidgets_dictionary.c +154 -213
- data/ext/phidgets/phidgets_digital_input.c +127 -0
- data/ext/phidgets/phidgets_digital_output.c +288 -0
- data/ext/phidgets/phidgets_distance_sensor.c +295 -0
- data/ext/phidgets/phidgets_encoder.c +211 -192
- data/ext/phidgets/phidgets_frequency_counter.c +310 -177
- data/ext/phidgets/phidgets_gps.c +226 -164
- data/ext/phidgets/phidgets_gyroscope.c +195 -0
- data/ext/phidgets/phidgets_hub.c +39 -0
- data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
- data/ext/phidgets/phidgets_ir.c +211 -171
- data/ext/phidgets/phidgets_lcd.c +512 -0
- data/ext/phidgets/phidgets_light_sensor.c +200 -0
- data/ext/phidgets/phidgets_log.c +263 -0
- data/ext/phidgets/phidgets_magnetometer.c +279 -0
- data/ext/phidgets/phidgets_manager.c +86 -297
- data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
- data/ext/phidgets/phidgets_phsensor.c +200 -152
- data/ext/phidgets/phidgets_power_guard.c +144 -0
- data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
- data/ext/phidgets/phidgets_rc_servo.c +672 -0
- data/ext/phidgets/phidgets_resistance_input.c +227 -0
- data/ext/phidgets/phidgets_rfid.c +107 -221
- data/ext/phidgets/phidgets_sound_sensor.c +284 -0
- data/ext/phidgets/phidgets_spatial.c +124 -318
- data/ext/phidgets/phidgets_stepper.c +457 -430
- data/ext/phidgets/phidgets_temp_sensor.c +223 -228
- data/ext/phidgets/phidgets_voltage_input.c +428 -0
- data/ext/phidgets/phidgets_voltage_output.c +167 -0
- data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
- data/lib/phidgets.rb +21 -14
- data/lib/phidgets/accelerometer.rb +11 -15
- data/lib/phidgets/bldc_motor.rb +45 -0
- data/lib/phidgets/capacitive_touch.rb +33 -0
- data/lib/phidgets/common.rb +40 -69
- data/lib/phidgets/current_input.rb +21 -0
- data/lib/phidgets/dc_motor.rb +45 -0
- data/lib/phidgets/dictionary.rb +30 -39
- data/lib/phidgets/digital_input.rb +21 -0
- data/lib/phidgets/digital_output.rb +56 -0
- data/lib/phidgets/distance_sensor.rb +33 -0
- data/lib/phidgets/encoder.rb +1 -29
- data/lib/phidgets/frequency_counter.rb +23 -14
- data/lib/phidgets/gps.rb +34 -26
- data/lib/phidgets/gyroscope.rb +21 -0
- data/lib/phidgets/humidity_sensor.rb +21 -0
- data/lib/phidgets/ir.rb +34 -39
- data/lib/phidgets/light_sensor.rb +21 -0
- data/lib/phidgets/magnetometer.rb +21 -0
- data/lib/phidgets/manager.rb +18 -66
- data/lib/phidgets/motor_position_controller.rb +45 -0
- data/lib/phidgets/ph_sensor.rb +2 -6
- data/lib/phidgets/pressure_sensor.rb +21 -0
- data/lib/phidgets/rc_servo.rb +58 -0
- data/lib/phidgets/resistance_input.rb +21 -0
- data/lib/phidgets/rfid.rb +22 -38
- data/lib/phidgets/sound_sensor.rb +21 -0
- data/lib/phidgets/spatial.rb +11 -15
- data/lib/phidgets/stepper.rb +48 -50
- data/lib/phidgets/temperature_sensor.rb +11 -15
- data/lib/phidgets/version.rb +5 -0
- data/lib/phidgets/voltage_input.rb +34 -0
- data/lib/phidgets/voltage_output.rb +23 -0
- data/lib/phidgets/voltage_ratio_input.rb +34 -0
- data/phidgets.gemspec +3 -22
- data/test/test_accelerometer.rb +42 -23
- data/test/test_bldc_motor.rb +134 -0
- data/test/test_capacitive_touch.rb +82 -0
- data/test/test_common.rb +125 -108
- data/test/test_current_input.rb +62 -0
- data/test/test_dc_motor.rb +146 -0
- data/test/test_dictionary.rb +22 -54
- data/test/test_digital_input.rb +30 -0
- data/test/test_digital_output.rb +70 -0
- data/test/test_distance_sensor.rb +76 -0
- data/test/test_encoder.rb +45 -38
- data/test/test_frequency_counter.rb +71 -36
- data/test/test_gps.rb +29 -38
- data/test/test_gyroscope.rb +54 -0
- data/test/test_helper.rb +0 -1
- data/test/test_hub.rb +14 -0
- data/test/test_humidity_sensor.rb +58 -0
- data/test/test_ir.rb +34 -34
- data/test/test_lcd.rb +146 -0
- data/test/test_light_sensor.rb +58 -0
- data/test/test_magnetometer.rb +78 -0
- data/test/test_manager.rb +10 -79
- data/test/test_motor_control.rb +146 -108
- data/test/test_phidgets.rb +2 -14
- data/test/test_phsensor.rb +46 -34
- data/test/test_power_guard.rb +42 -0
- data/test/test_pressure_sensor.rb +58 -0
- data/test/test_rc_servo.rb +174 -0
- data/test/test_resistance_input.rb +66 -0
- data/test/test_rfid.rb +15 -54
- data/test/test_sound_sensor.rb +78 -0
- data/test/test_spatial.rb +19 -85
- data/test/test_stepper.rb +89 -98
- data/test/test_temp_sensor.rb +42 -47
- data/test/test_voltage_input.rb +102 -0
- data/test/test_voltage_output.rb +46 -0
- data/test/test_voltage_ratio_input.rb +102 -0
- metadata +72 -89
- data/ext/phidgets/phidgets_advanced_servo.c +0 -567
- data/ext/phidgets/phidgets_analog.c +0 -139
- data/ext/phidgets/phidgets_bridge.c +0 -263
- data/ext/phidgets/phidgets_interface_kit.c +0 -340
- data/ext/phidgets/phidgets_led.c +0 -178
- data/ext/phidgets/phidgets_motor_control.c +0 -642
- data/ext/phidgets/phidgets_servo.c +0 -276
- data/ext/phidgets/phidgets_text_lcd.c +0 -381
- data/ext/phidgets/phidgets_text_led.c +0 -107
- data/ext/phidgets/phidgets_weight_sensor.c +0 -113
- data/lib/phidgets/advanced_servo.rb +0 -49
- data/lib/phidgets/analog.rb +0 -8
- data/lib/phidgets/bridge.rb +0 -25
- data/lib/phidgets/interfacekit.rb +0 -49
- data/lib/phidgets/led.rb +0 -8
- data/lib/phidgets/motor_control.rb +0 -110
- data/lib/phidgets/servo.rb +0 -23
- data/lib/phidgets/text_lcd.rb +0 -8
- data/lib/phidgets/text_led.rb +0 -8
- data/lib/phidgets/weight_sensor.rb +0 -25
- data/test/test_advanced_servo.rb +0 -152
- data/test/test_analog.rb +0 -45
- data/test/test_bridge.rb +0 -77
- data/test/test_interfacekit.rb +0 -97
- data/test/test_led.rb +0 -55
- data/test/test_servo.rb +0 -67
- data/test/test_text_lcd.rb +0 -115
- data/test/test_text_led.rb +0 -35
- data/test/test_weight_sensor.rb +0 -32
data/ext/phidgets/phidgets_led.c
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
|
2
|
-
#include "phidgets.h"
|
3
|
-
|
4
|
-
|
5
|
-
VALUE ph_led_init(VALUE self);
|
6
|
-
VALUE ph_led_get_led_count(VALUE self);
|
7
|
-
VALUE ph_led_get_current_limit(VALUE self);
|
8
|
-
VALUE ph_led_set_current_limit(VALUE self, VALUE limit);
|
9
|
-
VALUE ph_led_get_voltage(VALUE self);
|
10
|
-
VALUE ph_led_set_voltage(VALUE self, VALUE voltage);
|
11
|
-
VALUE ph_led_get_brightness(VALUE self, VALUE index);
|
12
|
-
VALUE ph_led_set_brightness(VALUE self, VALUE index, VALUE brightness);
|
13
|
-
VALUE ph_led_get_current_limit_indexed(VALUE self, VALUE index);
|
14
|
-
VALUE ph_led_set_current_limit_indexed(VALUE self, VALUE index, VALUE limit);
|
15
|
-
|
16
|
-
|
17
|
-
void Init_led() {
|
18
|
-
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
19
|
-
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
20
|
-
VALUE ph_led = rb_define_class_under(ph_module, "LED", ph_common);
|
21
|
-
|
22
|
-
rb_define_const(ph_led, "CURRENT_LIMIT_20mA", INT2FIX(PHIDGET_LED_CURRENT_LIMIT_20mA));
|
23
|
-
rb_define_const(ph_led, "CURRENT_LIMIT_40mA", INT2FIX(PHIDGET_LED_CURRENT_LIMIT_40mA));
|
24
|
-
rb_define_const(ph_led, "CURRENT_LIMIT_60mA", INT2FIX(PHIDGET_LED_CURRENT_LIMIT_60mA));
|
25
|
-
rb_define_const(ph_led, "CURRENT_LIMIT_80mA", INT2FIX(PHIDGET_LED_CURRENT_LIMIT_80mA));
|
26
|
-
rb_define_const(ph_led, "VOLTAGE_1_7V", INT2FIX(PHIDGET_LED_VOLTAGE_1_7V));
|
27
|
-
rb_define_const(ph_led, "VOLTAGE_2_75V", INT2FIX(PHIDGET_LED_VOLTAGE_2_75V));
|
28
|
-
rb_define_const(ph_led, "VOLTAGE_3_9V", INT2FIX(PHIDGET_LED_VOLTAGE_3_9V));
|
29
|
-
rb_define_const(ph_led, "VOLTAGE_5_0V", INT2FIX(PHIDGET_LED_VOLTAGE_5_0V));
|
30
|
-
|
31
|
-
/* Document-method: new
|
32
|
-
* call-seq: new
|
33
|
-
*
|
34
|
-
* Creates a Phidget LED object.
|
35
|
-
*/
|
36
|
-
rb_define_method(ph_led, "initialize", ph_led_init, 0);
|
37
|
-
|
38
|
-
/* Document-method: getLEDCount
|
39
|
-
* call-seq: getLEDCount -> count
|
40
|
-
*
|
41
|
-
* Gets the number of LEDs supported by this board.
|
42
|
-
*/
|
43
|
-
rb_define_method(ph_led, "getLEDCount", ph_led_get_led_count, 0);
|
44
|
-
|
45
|
-
/* Document-method: getCurrentLimit
|
46
|
-
* call-seq: getCurrentLimit -> limit
|
47
|
-
*
|
48
|
-
* Gets the current limit. This is for all ouputs.
|
49
|
-
*/
|
50
|
-
rb_define_method(ph_led, "getCurrentLimit", ph_led_get_current_limit, 0);
|
51
|
-
|
52
|
-
/* Document-method: setCurrentLimit
|
53
|
-
* call-seq: setCurrentLimit(limit)
|
54
|
-
*
|
55
|
-
* Sets the current limit. This is for all ouputs.
|
56
|
-
*/
|
57
|
-
rb_define_method(ph_led, "setCurrentLimit", ph_led_set_current_limit, 1);
|
58
|
-
|
59
|
-
/* Document-method: getVoltage
|
60
|
-
* call-seq: getVoltage -> voltage
|
61
|
-
*
|
62
|
-
* Gets the output voltage. This is for all ouputs.
|
63
|
-
*/
|
64
|
-
rb_define_method(ph_led, "getVoltage", ph_led_get_voltage, 0);
|
65
|
-
|
66
|
-
/* Document-method: setVoltage
|
67
|
-
* call-seq: setVoltage(voltage)
|
68
|
-
*
|
69
|
-
* Sets the output voltage. This is for all ouputs.
|
70
|
-
*/
|
71
|
-
rb_define_method(ph_led, "setVoltage", ph_led_set_voltage, 1);
|
72
|
-
|
73
|
-
/* Document-method: getBrightness
|
74
|
-
* call-seq: getBrightness(index) -> brightness
|
75
|
-
*
|
76
|
-
* Gets the brightness of an LED.
|
77
|
-
*/
|
78
|
-
rb_define_method(ph_led, "getBrightness", ph_led_get_brightness, 1);
|
79
|
-
|
80
|
-
/* Document-method: setBrightness
|
81
|
-
* call-seq: setBrightness(index, brightness)
|
82
|
-
*
|
83
|
-
* Sets the brightness of an LED.
|
84
|
-
*/
|
85
|
-
rb_define_method(ph_led, "setBrightness", ph_led_set_brightness, 2);
|
86
|
-
|
87
|
-
/* Document-method: getCurrentLimitIndexed
|
88
|
-
* call-seq: getCurrentLimitIndexed(index) -> limit
|
89
|
-
*
|
90
|
-
* Gets the current limit of an LED.
|
91
|
-
*/
|
92
|
-
rb_define_method(ph_led, "getCurrentLimitIndexed", ph_led_get_current_limit_indexed, 1);
|
93
|
-
|
94
|
-
/* Document-method: setCurrentLimitIndexed
|
95
|
-
* call-seq: setCurrentLimitIndexed(index, limit)
|
96
|
-
*
|
97
|
-
* Sets the current limit of an LED.
|
98
|
-
*/
|
99
|
-
rb_define_method(ph_led, "setCurrentLimitIndexed", ph_led_set_current_limit_indexed, 2);
|
100
|
-
|
101
|
-
rb_define_alias(ph_led, "led_count", "getLEDCount");
|
102
|
-
rb_define_alias(ph_led, "current_limit", "getCurrentLimit");
|
103
|
-
rb_define_alias(ph_led, "current_limit=", "setCurrentLimit");
|
104
|
-
rb_define_alias(ph_led, "voltage", "getVoltage");
|
105
|
-
rb_define_alias(ph_led, "voltage=", "setVoltage");
|
106
|
-
rb_define_alias(ph_led, "brightness", "getBrightness");
|
107
|
-
rb_define_alias(ph_led, "set_brightness", "setBrightness");
|
108
|
-
rb_define_alias(ph_led, "current_limit_indexed", "getCurrentLimitIndexed");
|
109
|
-
rb_define_alias(ph_led, "set_current_limit_indexed", "setCurrentLimitIndexed");
|
110
|
-
}
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
VALUE ph_led_init(VALUE self) {
|
115
|
-
ph_data_t *ph = get_ph_data(self);
|
116
|
-
ph_raise(CPhidgetLED_create((CPhidgetLEDHandle *)(&(ph->handle))));
|
117
|
-
return self;
|
118
|
-
}
|
119
|
-
|
120
|
-
VALUE ph_led_get_led_count(VALUE self) {
|
121
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
122
|
-
int count;
|
123
|
-
ph_raise(CPhidgetLED_getLEDCount(handle, &count));
|
124
|
-
return INT2FIX(count);
|
125
|
-
}
|
126
|
-
|
127
|
-
VALUE ph_led_get_current_limit(VALUE self) {
|
128
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
129
|
-
CPhidgetLED_CurrentLimit limit;
|
130
|
-
ph_raise(CPhidgetLED_getCurrentLimit(handle, &limit));
|
131
|
-
return INT2FIX(limit);
|
132
|
-
}
|
133
|
-
|
134
|
-
VALUE ph_led_set_current_limit(VALUE self, VALUE limit) {
|
135
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
136
|
-
ph_raise(CPhidgetLED_setCurrentLimit(handle, FIX2INT(limit)));
|
137
|
-
return Qnil;
|
138
|
-
}
|
139
|
-
|
140
|
-
VALUE ph_led_get_voltage(VALUE self) {
|
141
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
142
|
-
CPhidgetLED_Voltage voltage;
|
143
|
-
ph_raise(CPhidgetLED_getVoltage(handle, &voltage));
|
144
|
-
return INT2FIX(voltage);
|
145
|
-
}
|
146
|
-
|
147
|
-
VALUE ph_led_set_voltage(VALUE self, VALUE voltage) {
|
148
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
149
|
-
ph_raise(CPhidgetLED_setVoltage(handle, FIX2INT(voltage)));
|
150
|
-
return Qnil;
|
151
|
-
}
|
152
|
-
|
153
|
-
VALUE ph_led_get_brightness(VALUE self, VALUE index) {
|
154
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
155
|
-
double brightness;
|
156
|
-
ph_raise(CPhidgetLED_getBrightness(handle, FIX2INT(index), &brightness));
|
157
|
-
return rb_float_new(brightness);
|
158
|
-
}
|
159
|
-
|
160
|
-
VALUE ph_led_set_brightness(VALUE self, VALUE index, VALUE brightness) {
|
161
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
162
|
-
ph_raise(CPhidgetLED_setBrightness(handle, FIX2INT(index), NUM2DBL(brightness)));
|
163
|
-
return Qnil;
|
164
|
-
}
|
165
|
-
|
166
|
-
VALUE ph_led_get_current_limit_indexed(VALUE self, VALUE index) {
|
167
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
168
|
-
double limit;
|
169
|
-
ph_raise(CPhidgetLED_getCurrentLimitIndexed(handle, FIX2INT(index), &limit));
|
170
|
-
return rb_float_new(limit);
|
171
|
-
}
|
172
|
-
|
173
|
-
VALUE ph_led_set_current_limit_indexed(VALUE self, VALUE index, VALUE limit) {
|
174
|
-
CPhidgetLEDHandle handle = (CPhidgetLEDHandle)get_ph_handle(self);
|
175
|
-
ph_raise(CPhidgetLED_setCurrentLimitIndexed(handle, FIX2INT(index), NUM2DBL(limit)));
|
176
|
-
return Qnil;
|
177
|
-
}
|
178
|
-
|
@@ -1,642 +0,0 @@
|
|
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
|
-
void Init_motor_control() {
|
52
|
-
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
53
|
-
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
54
|
-
VALUE ph_motor = rb_define_class_under(ph_module, "MotorControl", ph_common);
|
55
|
-
|
56
|
-
/* Document-method: new
|
57
|
-
* call-seq: new
|
58
|
-
*
|
59
|
-
* Creates a Phidget MotorControl object.
|
60
|
-
*/
|
61
|
-
rb_define_method(ph_motor, "initialize", ph_motor_init, 0);
|
62
|
-
|
63
|
-
/* Document-method: getMotorCount
|
64
|
-
* call-seq: getMotorCount -> count
|
65
|
-
*
|
66
|
-
* Gets the number of motors supported by this controller.
|
67
|
-
*/
|
68
|
-
rb_define_method(ph_motor, "getMotorCount", ph_motor_get_motor_count, 0);
|
69
|
-
|
70
|
-
/* Document-method: getVelocity
|
71
|
-
* call-seq: getVelocity(index) -> velocity
|
72
|
-
*
|
73
|
-
* Gets the current velocity of a motor.
|
74
|
-
*/
|
75
|
-
rb_define_method(ph_motor, "getVelocity", ph_motor_get_velocity, 1);
|
76
|
-
|
77
|
-
/* Document-method: setVelocity
|
78
|
-
* call-seq: setVelocity(index, velocity)
|
79
|
-
*
|
80
|
-
* Sets the velocity of a motor.
|
81
|
-
*/
|
82
|
-
rb_define_method(ph_motor, "setVelocity", ph_motor_set_velocity, 2);
|
83
|
-
|
84
|
-
/* Document-method: getAcceleration
|
85
|
-
* call-seq: getAcceleration(index) -> acceleration
|
86
|
-
*
|
87
|
-
* Gets the last set acceleration of a motor.
|
88
|
-
*/
|
89
|
-
rb_define_method(ph_motor, "getAcceleration", ph_motor_get_acceleration, 1);
|
90
|
-
|
91
|
-
/* Document-method: getAccelerationMin
|
92
|
-
* call-seq: getAccelerationMin(index) -> acceleration
|
93
|
-
*
|
94
|
-
* Gets the minimum acceleration supported by a motor.
|
95
|
-
*/
|
96
|
-
rb_define_method(ph_motor, "getAccelerationMin", ph_motor_get_acceleration_min, 1);
|
97
|
-
|
98
|
-
/* Document-method: getAccelerationMax
|
99
|
-
* call-seq: getAccelerationMax(index) -> acceleration
|
100
|
-
*
|
101
|
-
* Gets the maximum acceleration supported by a motor
|
102
|
-
*/
|
103
|
-
rb_define_method(ph_motor, "getAccelerationMax", ph_motor_get_acceleration_max, 1);
|
104
|
-
|
105
|
-
/* Document-method: setAcceleration
|
106
|
-
* call-seq: setAcceleration(index, acceleration)
|
107
|
-
*
|
108
|
-
* Sets the acceleration of a motor.
|
109
|
-
*/
|
110
|
-
rb_define_method(ph_motor, "setAcceleration", ph_motor_set_acceleration, 2);
|
111
|
-
|
112
|
-
/* Document-method: getCurrent
|
113
|
-
* call-seq: getCurrent(index) -> current
|
114
|
-
*
|
115
|
-
* Gets the current current draw for a motor.
|
116
|
-
*/
|
117
|
-
rb_define_method(ph_motor, "getCurrent", ph_motor_get_current, 1);
|
118
|
-
|
119
|
-
/* Document-method: getInputCount
|
120
|
-
* call-seq: getInputCount -> count
|
121
|
-
*
|
122
|
-
* Gets the number of digital inputs supported by this board.
|
123
|
-
*/
|
124
|
-
rb_define_method(ph_motor, "getInputCount", ph_motor_get_input_count, 0);
|
125
|
-
|
126
|
-
/* Document-method: getInputState
|
127
|
-
* call-seq: getInputState(index) -> true or false
|
128
|
-
*
|
129
|
-
* Gets the state of a digital input.
|
130
|
-
*/
|
131
|
-
rb_define_method(ph_motor, "getInputState", ph_motor_get_input_state, 1);
|
132
|
-
|
133
|
-
/* Document-method: getEncoderCount
|
134
|
-
* call-seq: getEncoderCount -> count
|
135
|
-
*
|
136
|
-
* Gets the number of encoder inputs supported by this board.
|
137
|
-
*/
|
138
|
-
rb_define_method(ph_motor, "getEncoderCount", ph_motor_get_encoder_count, 0);
|
139
|
-
|
140
|
-
/* Document-method: getEncoderPosition
|
141
|
-
* call-seq: getEncoderPosition(index) -> position
|
142
|
-
*
|
143
|
-
* Gets the position of an encoder. This position starts at 0 every time the phidget is opened.
|
144
|
-
*/
|
145
|
-
rb_define_method(ph_motor, "getEncoderPosition", ph_motor_get_encoder_position, 1);
|
146
|
-
|
147
|
-
/* Document-method: setEncoderPosition
|
148
|
-
* call-seq: setEncoderPosition(index, position)
|
149
|
-
*
|
150
|
-
* Sets the encoder position. This can be used to set the position to a known value,
|
151
|
-
* and should only be called when the encoder is not moving.
|
152
|
-
*/
|
153
|
-
rb_define_method(ph_motor, "setEncoderPosition", ph_motor_set_encoder_position, 2);
|
154
|
-
|
155
|
-
/* Document-method: getBackEMF
|
156
|
-
* call-seq: getBackEMF(index) -> voltage
|
157
|
-
*
|
158
|
-
* Gets the Back EMF voltage for a motor.
|
159
|
-
*/
|
160
|
-
rb_define_method(ph_motor, "getBackEMF", ph_motor_get_back_emf, 1);
|
161
|
-
|
162
|
-
/* Document-method: getBackEMFSensingState
|
163
|
-
* call-seq: getBackEMFSensingState(index) -> true or false
|
164
|
-
*
|
165
|
-
* Gets the Back EMF sensing state for a motor.
|
166
|
-
*/
|
167
|
-
rb_define_method(ph_motor, "getBackEMFSensingState", ph_motor_get_back_emf_sensing_state, 1);
|
168
|
-
|
169
|
-
/* Document-method: setBackEMFSensingState
|
170
|
-
* call-seq: setBackEMFSensingState(index, state)
|
171
|
-
*
|
172
|
-
* Sets the Back EMF sensing state for a motor.
|
173
|
-
*/
|
174
|
-
rb_define_method(ph_motor, "setBackEMFSensingState", ph_motor_set_back_emf_sensing_state, 2);
|
175
|
-
|
176
|
-
/* Document-method: getSupplyVoltage
|
177
|
-
* call-seq: getSupplyVoltage -> voltage
|
178
|
-
*
|
179
|
-
* Gets the Supply voltage for the motors. This could be higher then the actual supply voltage.
|
180
|
-
*/
|
181
|
-
rb_define_method(ph_motor, "getSupplyVoltage", ph_motor_get_supply_voltage, 0);
|
182
|
-
|
183
|
-
/* Document-method: getBraking
|
184
|
-
* call-seq: getBraking(index) -> braking
|
185
|
-
*
|
186
|
-
* Gets the Braking value for a motor.
|
187
|
-
*/
|
188
|
-
rb_define_method(ph_motor, "getBraking", ph_motor_get_braking, 1);
|
189
|
-
|
190
|
-
/* Document-method: setBraking
|
191
|
-
* call-seq: setBraking(index, braking)
|
192
|
-
*
|
193
|
-
* Sets the Braking value for a motor. This is applied when velocity is 0. Default is 0%.
|
194
|
-
*/
|
195
|
-
rb_define_method(ph_motor, "setBraking", ph_motor_set_braking, 2);
|
196
|
-
|
197
|
-
/* Document-method: getSensorCount
|
198
|
-
* call-seq: getSensorCount -> count
|
199
|
-
*
|
200
|
-
* Gets the number of sensor inputs supported by this board.
|
201
|
-
*/
|
202
|
-
rb_define_method(ph_motor, "getSensorCount", ph_motor_get_sensor_count, 0);
|
203
|
-
|
204
|
-
/* Document-method: getSensorValue
|
205
|
-
* call-seq: getSensorValue(index) -> value
|
206
|
-
*
|
207
|
-
* Gets the value of a sensor.
|
208
|
-
*/
|
209
|
-
rb_define_method(ph_motor, "getSensorValue", ph_motor_get_sensor_value, 1);
|
210
|
-
|
211
|
-
/* Document-method: getSensorRawValue
|
212
|
-
* call-seq: getSensorRawValue(index) -> value
|
213
|
-
*
|
214
|
-
* Gets the raw value of a sensor (12-bit).
|
215
|
-
*/
|
216
|
-
rb_define_method(ph_motor, "getSensorRawValue", ph_motor_get_sensor_raw_value, 1);
|
217
|
-
|
218
|
-
/* Document-method: getRatiometric
|
219
|
-
* call-seq: getRatiometric -> true or false
|
220
|
-
*
|
221
|
-
* Gets the ratiometric state.
|
222
|
-
*/
|
223
|
-
rb_define_method(ph_motor, "getRatiometric", ph_motor_get_ratiometric, 0);
|
224
|
-
|
225
|
-
/* Document-method: setRatiometric
|
226
|
-
* call-seq: setRatiometric(state)
|
227
|
-
*
|
228
|
-
* Sets the ratiometric state. This controls the voltage reference used for sampling the analog sensors.
|
229
|
-
*/
|
230
|
-
rb_define_method(ph_motor, "setRatiometric", ph_motor_set_ratiometric, 1);
|
231
|
-
|
232
|
-
#ifdef PH_CALLBACK
|
233
|
-
rb_define_private_method(ph_motor, "ext_setOnVelocityChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
|
234
|
-
rb_define_private_method(ph_motor, "ext_setOnCurrentChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
|
235
|
-
rb_define_private_method(ph_motor, "ext_setOnCurrentUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
|
236
|
-
rb_define_private_method(ph_motor, "ext_setOnInputChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
|
237
|
-
rb_define_private_method(ph_motor, "ext_setOnEncoderPositionChangeHandler", ph_motor_set_on_velocity_change_handler, 1);
|
238
|
-
rb_define_private_method(ph_motor, "ext_setOnEncoderPositionUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
|
239
|
-
rb_define_private_method(ph_motor, "ext_setOnBackEMFUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
|
240
|
-
rb_define_private_method(ph_motor, "ext_setOnSensorUpdateHandler", ph_motor_set_on_velocity_change_handler, 1);
|
241
|
-
#endif
|
242
|
-
|
243
|
-
rb_define_alias(ph_motor, "motor_count", "getMotorCount");
|
244
|
-
rb_define_alias(ph_motor, "velocity", "getVelocity");
|
245
|
-
rb_define_alias(ph_motor, "set_velocity", "setVelocity");
|
246
|
-
rb_define_alias(ph_motor, "acceleration", "getAcceleration");
|
247
|
-
rb_define_alias(ph_motor, "acceleration_min", "getAccelerationMin");
|
248
|
-
rb_define_alias(ph_motor, "acceleration_max", "getAccelerationMax");
|
249
|
-
rb_define_alias(ph_motor, "set_acceleration", "setAcceleration");
|
250
|
-
rb_define_alias(ph_motor, "current", "getCurrent");
|
251
|
-
rb_define_alias(ph_motor, "input_count", "getInputCount");
|
252
|
-
rb_define_alias(ph_motor, "input_state", "getInputState");
|
253
|
-
rb_define_alias(ph_motor, "encoder_count", "getEncoderCount");
|
254
|
-
rb_define_alias(ph_motor, "encoder_position", "getEncoderPosition");
|
255
|
-
rb_define_alias(ph_motor, "set_encoder_position", "setEncoderPosition");
|
256
|
-
rb_define_alias(ph_motor, "back_emf", "getBackEMF");
|
257
|
-
rb_define_alias(ph_motor, "back_emf_sensing_state", "getBackEMFSensingState");
|
258
|
-
rb_define_alias(ph_motor, "set_back_emf_sensing_state", "setBackEMFSensingState");
|
259
|
-
rb_define_alias(ph_motor, "supply_voltage", "getSupplyVoltage");
|
260
|
-
rb_define_alias(ph_motor, "braking", "getBraking");
|
261
|
-
rb_define_alias(ph_motor, "set_braking", "setBraking");
|
262
|
-
rb_define_alias(ph_motor, "sensor_count", "getSensorCount");
|
263
|
-
rb_define_alias(ph_motor, "sensor_value", "getSensorValue");
|
264
|
-
rb_define_alias(ph_motor, "sensor_raw_value", "getSensorRawValue");
|
265
|
-
rb_define_alias(ph_motor, "ratiometric?", "getRatiometric");
|
266
|
-
rb_define_alias(ph_motor, "ratiometric=", "setRatiometric");
|
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), ¤t));
|
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
|
-
|