phidgets 0.1.3 → 1.0.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.
- 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
@@ -1,249 +1,268 @@
|
|
1
1
|
|
2
2
|
#include "phidgets.h"
|
3
3
|
|
4
|
+
#define ENCODER_POSITION_CHANGE_CALLBACK 0
|
4
5
|
|
5
|
-
VALUE ph_encoder_init(VALUE self);
|
6
|
-
VALUE ph_encoder_get_input_count(VALUE self);
|
7
|
-
VALUE ph_encoder_get_input_state(VALUE self, VALUE index);
|
8
|
-
VALUE ph_encoder_get_encoder_count(VALUE self);
|
9
|
-
VALUE ph_encoder_get_position(VALUE self, VALUE index);
|
10
|
-
VALUE ph_encoder_set_position(VALUE self, VALUE index, VALUE position);
|
11
|
-
VALUE ph_encoder_get_index_position(VALUE self, VALUE index);
|
12
|
-
VALUE ph_encoder_get_enabled(VALUE self, VALUE index);
|
13
|
-
VALUE ph_encoder_set_enabled(VALUE self, VALUE index, VALUE state);
|
14
|
-
|
15
|
-
#ifdef PH_CALLBACK
|
16
|
-
VALUE ph_encoder_set_on_input_change_handler(VALUE self, VALUE handler);
|
17
|
-
VALUE ph_encoder_set_on_position_change_handler(VALUE self, VALUE handler);
|
18
|
-
VALUE ph_encoder_set_on_index_handler(VALUE self, VALUE handler);
|
19
|
-
int ph_encoder_on_input_change(CPhidgetEncoderHandle phid, void *userPtr, int index, int state);
|
20
|
-
int ph_encoder_on_position_change(CPhidgetEncoderHandle phid, void *userPtr, int index, int time, int change);
|
21
|
-
int ph_encoder_on_index(CPhidgetEncoderHandle phid, void *userPtr, int index, int index_pos);
|
22
|
-
#endif
|
23
6
|
|
7
|
+
VALUE ph_encoder_init(VALUE self) {
|
8
|
+
ph_data_t *ph = get_ph_data(self);
|
9
|
+
ph_raise(PhidgetEncoder_create((PhidgetEncoderHandle *)(&(ph->handle))));
|
10
|
+
return self;
|
11
|
+
}
|
24
12
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
VALUE ph_encoder = rb_define_class_under(ph_module, "Encoder", ph_common);
|
29
|
-
|
30
|
-
/* Document-method: new
|
31
|
-
* call-seq: new
|
32
|
-
*
|
33
|
-
* Creates a Phidget Encoder object.
|
34
|
-
*/
|
35
|
-
rb_define_method(ph_encoder, "initialize", ph_encoder_init, 0);
|
36
|
-
|
37
|
-
/* Document-method: getInputCount
|
38
|
-
* call-seq: getInputCount -> count
|
39
|
-
*
|
40
|
-
* Gets the number of digital inputs supported by this board.
|
41
|
-
*/
|
42
|
-
rb_define_method(ph_encoder, "getInputCount", ph_encoder_get_input_count, 0);
|
43
|
-
|
44
|
-
/* Document-method: getInputState
|
45
|
-
* call-seq: getInputState(index) -> true or false
|
46
|
-
*
|
47
|
-
* Gets the state of a digital input.
|
48
|
-
*/
|
49
|
-
rb_define_method(ph_encoder, "getInputState", ph_encoder_get_input_state, 1);
|
50
|
-
|
51
|
-
/* Document-method: getEncoderCount
|
52
|
-
* call-seq: getEncoderCount -> count
|
53
|
-
*
|
54
|
-
* Gets the number of encoder inputs supported by this board.
|
55
|
-
*/
|
56
|
-
rb_define_method(ph_encoder, "getEncoderCount", ph_encoder_get_encoder_count, 0);
|
57
|
-
|
58
|
-
/* Document-method: getPosition
|
59
|
-
* call-seq: getPosition(index) -> position
|
60
|
-
*
|
61
|
-
* Gets the current position of an encoder.
|
62
|
-
*/
|
63
|
-
rb_define_method(ph_encoder, "getPosition", ph_encoder_get_position, 1);
|
64
|
-
|
65
|
-
/* Document-method: setPosition
|
66
|
-
* call-seq: setPosition(index, position)
|
67
|
-
*
|
68
|
-
* Sets the current position of an encoder.
|
69
|
-
*/
|
70
|
-
rb_define_method(ph_encoder, "setPosition", ph_encoder_set_position, 2);
|
71
|
-
|
72
|
-
/* Document-method: getIndexPosition
|
73
|
-
* call-seq: getIndexPosition(index) -> position
|
74
|
-
*
|
75
|
-
* Gets the position of the last index pulse, as referenced to getPosition. This will raise Phidgets::Error::UnknownVal
|
76
|
-
* if there hasn't been an index event, or if the encoder doesn't support index.
|
77
|
-
*/
|
78
|
-
rb_define_method(ph_encoder, "getIndexPosition", ph_encoder_get_index_position, 1);
|
79
|
-
|
80
|
-
/* Document-method: getEnabled
|
81
|
-
* call-seq: getEnabled(index) -> true or false
|
82
|
-
*
|
83
|
-
* Gets the enabled state of an encoder. This is whether the encoder is powered or not.
|
84
|
-
*/
|
85
|
-
rb_define_method(ph_encoder, "getEnabled", ph_encoder_get_enabled, 1);
|
86
|
-
|
87
|
-
/* Document-method: setEnabled
|
88
|
-
* call-seq: setEnabled(index, state)
|
89
|
-
*
|
90
|
-
* Sets the enabled state of an encoder. This is whether the encoder is powered or not.
|
91
|
-
*/
|
92
|
-
rb_define_method(ph_encoder, "setEnabled", ph_encoder_set_enabled, 2);
|
13
|
+
VALUE ph_encoder_get_enabled(VALUE self) {
|
14
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetEncoder_getEnabled);
|
15
|
+
}
|
93
16
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
#endif
|
17
|
+
VALUE ph_encoder_set_enabled(VALUE self, VALUE state) {
|
18
|
+
ph_raise(PhidgetEncoder_setEnabled((PhidgetEncoderHandle)get_ph_handle(self), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
|
19
|
+
return Qnil;
|
20
|
+
}
|
99
21
|
|
100
|
-
|
101
|
-
|
102
|
-
rb_define_alias(ph_encoder, "encoder_count", "getEncoderCount");
|
103
|
-
rb_define_alias(ph_encoder, "position", "getPosition");
|
104
|
-
rb_define_alias(ph_encoder, "set_position", "setPosition");
|
105
|
-
rb_define_alias(ph_encoder, "index_position", "getIndexPosition");
|
106
|
-
rb_define_alias(ph_encoder, "enabled?", "getEnabled");
|
107
|
-
rb_define_alias(ph_encoder, "set_enabled", "setEnabled");
|
22
|
+
VALUE ph_encoder_get_data_interval(VALUE self) {
|
23
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getDataInterval);
|
108
24
|
}
|
109
25
|
|
26
|
+
VALUE ph_encoder_set_data_interval(VALUE self, VALUE interval) {
|
27
|
+
ph_raise(PhidgetEncoder_setDataInterval((PhidgetEncoderHandle)get_ph_handle(self), NUM2UINT(interval)));
|
28
|
+
return Qnil;
|
29
|
+
}
|
110
30
|
|
31
|
+
VALUE ph_encoder_get_min_data_interval(VALUE self) {
|
32
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMinDataInterval);
|
33
|
+
}
|
111
34
|
|
112
|
-
VALUE
|
113
|
-
|
114
|
-
ph_raise(CPhidgetEncoder_create((CPhidgetEncoderHandle *)(&(ph->handle))));
|
115
|
-
return self;
|
35
|
+
VALUE ph_encoder_get_max_data_interval(VALUE self) {
|
36
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMaxDataInterval);
|
116
37
|
}
|
117
38
|
|
118
|
-
VALUE
|
119
|
-
|
120
|
-
int count;
|
121
|
-
ph_raise(CPhidgetEncoder_getInputCount(handle, &count));
|
122
|
-
return INT2FIX(count);
|
39
|
+
VALUE ph_encoder_get_index_position(VALUE self) {
|
40
|
+
return ph_get_int64(get_ph_handle(self), (phidget_get_int64_func)PhidgetEncoder_getIndexPosition);
|
123
41
|
}
|
124
42
|
|
125
|
-
VALUE
|
126
|
-
|
127
|
-
int state;
|
128
|
-
ph_raise(CPhidgetEncoder_getInputState(handle, FIX2INT(index), &state));
|
129
|
-
return state == PTRUE ? Qtrue : Qfalse;
|
43
|
+
VALUE ph_encoder_get_io_mode(VALUE self) {
|
44
|
+
return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetEncoder_getIOMode);
|
130
45
|
}
|
131
46
|
|
132
|
-
VALUE
|
133
|
-
|
134
|
-
|
135
|
-
ph_raise(CPhidgetEncoder_getEncoderCount(handle, &count));
|
136
|
-
return INT2FIX(count);
|
47
|
+
VALUE ph_encoder_set_io_mode(VALUE self, VALUE mode) {
|
48
|
+
ph_raise(PhidgetEncoder_setIOMode((PhidgetEncoderHandle)get_ph_handle(self), NUM2INT(mode)));
|
49
|
+
return Qnil;
|
137
50
|
}
|
138
51
|
|
139
|
-
VALUE ph_encoder_get_position(VALUE self
|
140
|
-
|
141
|
-
int position;
|
142
|
-
ph_raise(CPhidgetEncoder_getPosition(handle, FIX2INT(index), &position));
|
143
|
-
return INT2FIX(position);
|
52
|
+
VALUE ph_encoder_get_position(VALUE self) {
|
53
|
+
return ph_get_int64(get_ph_handle(self), (phidget_get_int64_func)PhidgetEncoder_getPosition);
|
144
54
|
}
|
145
55
|
|
146
|
-
VALUE ph_encoder_set_position(VALUE self, VALUE
|
147
|
-
|
148
|
-
ph_raise(CPhidgetEncoder_setPosition(handle, FIX2INT(index), FIX2INT(position)));
|
56
|
+
VALUE ph_encoder_set_position(VALUE self, VALUE position) {
|
57
|
+
ph_raise(PhidgetEncoder_setPosition((PhidgetEncoderHandle)get_ph_handle(self), NUM2LL(position)));
|
149
58
|
return Qnil;
|
150
59
|
}
|
151
60
|
|
152
|
-
VALUE
|
153
|
-
|
154
|
-
int position;
|
155
|
-
ph_raise(CPhidgetEncoder_getIndexPosition(handle, FIX2INT(index), &position));
|
156
|
-
return INT2FIX(position);
|
61
|
+
VALUE ph_encoder_get_position_change_trigger(VALUE self) {
|
62
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getPositionChangeTrigger);
|
157
63
|
}
|
158
64
|
|
159
|
-
VALUE
|
160
|
-
|
161
|
-
|
162
|
-
ph_raise(CPhidgetEncoder_getEnabled(handle, FIX2INT(index), &state));
|
163
|
-
return state == PTRUE ? Qtrue : Qfalse;
|
65
|
+
VALUE ph_encoder_set_position_change_trigger(VALUE self, VALUE trigger) {
|
66
|
+
ph_raise(PhidgetEncoder_setPositionChangeTrigger((PhidgetEncoderHandle)get_ph_handle(self), NUM2UINT(trigger)));
|
67
|
+
return Qnil;
|
164
68
|
}
|
165
69
|
|
166
|
-
VALUE
|
167
|
-
|
168
|
-
ph_raise(CPhidgetEncoder_setEnabled(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
|
169
|
-
return Qnil;
|
70
|
+
VALUE ph_encoder_get_min_position_change_trigger(VALUE self) {
|
71
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMinPositionChangeTrigger);
|
170
72
|
}
|
171
73
|
|
74
|
+
VALUE ph_encoder_get_max_position_change_trigger(VALUE self) {
|
75
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMaxPositionChangeTrigger);
|
76
|
+
}
|
172
77
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
callback_data->exit = false;
|
183
|
-
callback_data->phidget = self;
|
184
|
-
callback_data->callback = handler;
|
185
|
-
ph_raise(CPhidgetEncoder_set_OnInputChange_Handler((CPhidgetEncoderHandle)ph->handle, ph_encoder_on_input_change, (void *)callback_data));
|
186
|
-
ph_callback_thread(callback_data);
|
187
|
-
}
|
188
|
-
return Qnil;
|
78
|
+
|
79
|
+
void CCONV ph_encoder_on_position_change(PhidgetEncoderHandle phid, void *userPtr, int position_change, double time_change, int index_triggered) {
|
80
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
81
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
82
|
+
callback_data->arg1 = INT2NUM(position_change);
|
83
|
+
callback_data->arg2 = DBL2NUM(time_change);
|
84
|
+
callback_data->arg3 = INT2NUM(index_triggered);
|
85
|
+
callback_data->arg4 = Qnil;
|
86
|
+
sem_post(&callback_data->callback_called);
|
189
87
|
}
|
190
88
|
|
191
89
|
|
192
90
|
VALUE ph_encoder_set_on_position_change_handler(VALUE self, VALUE handler) {
|
193
91
|
ph_data_t *ph = get_ph_data(self);
|
194
|
-
ph_callback_data_t *callback_data = &ph->
|
92
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[ENCODER_POSITION_CHANGE_CALLBACK];
|
195
93
|
if( TYPE(handler) == T_NIL ) {
|
94
|
+
callback_data->callback = T_NIL;
|
196
95
|
callback_data->exit = true;
|
197
|
-
ph_raise(
|
96
|
+
ph_raise(PhidgetEncoder_setOnPositionChangeHandler((PhidgetEncoderHandle)ph->handle, NULL, (void *)NULL));
|
97
|
+
sem_post(&callback_data->callback_called);
|
198
98
|
} else {
|
199
|
-
callback_data->called = false;
|
200
99
|
callback_data->exit = false;
|
201
100
|
callback_data->phidget = self;
|
202
101
|
callback_data->callback = handler;
|
203
|
-
ph_raise(
|
102
|
+
ph_raise(PhidgetEncoder_setOnPositionChangeHandler((PhidgetEncoderHandle)ph->handle, ph_encoder_on_position_change, (void *)callback_data));
|
204
103
|
ph_callback_thread(callback_data);
|
205
104
|
}
|
206
105
|
return Qnil;
|
207
106
|
}
|
208
107
|
|
209
108
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
callback_data->exit = true;
|
215
|
-
ph_raise(CPhidgetEncoder_set_OnIndex_Handler((CPhidgetEncoderHandle)ph->handle, NULL, (void *)NULL));
|
216
|
-
} else {
|
217
|
-
callback_data->called = false;
|
218
|
-
callback_data->exit = false;
|
219
|
-
callback_data->phidget = self;
|
220
|
-
callback_data->callback = handler;
|
221
|
-
ph_raise(CPhidgetEncoder_set_OnIndex_Handler((CPhidgetEncoderHandle)ph->handle, ph_encoder_on_index, (void *)callback_data));
|
222
|
-
ph_callback_thread(callback_data);
|
223
|
-
}
|
224
|
-
return Qnil;
|
225
|
-
}
|
109
|
+
void Init_encoder() {
|
110
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
111
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
112
|
+
VALUE ph_encoder = rb_define_class_under(ph_module, "Encoder", ph_common);
|
226
113
|
|
114
|
+
rb_define_const(ph_encoder, "IO_MODE_PUSH_PULL", INT2NUM(ENCODER_IO_MODE_PUSH_PULL));
|
115
|
+
rb_define_const(ph_encoder, "IO_MODE_LINE_DRIVER_2K2", INT2NUM(ENCODER_IO_MODE_LINE_DRIVER_2K2));
|
116
|
+
rb_define_const(ph_encoder, "IO_MODE_LINE_DRIVER_10K", INT2NUM(ENCODER_IO_MODE_LINE_DRIVER_10K));
|
117
|
+
rb_define_const(ph_encoder, "IO_MODE_OPEN_COLLECTOR_2K2", INT2NUM(ENCODER_IO_MODE_OPEN_COLLECTOR_2K2));
|
118
|
+
rb_define_const(ph_encoder, "IO_MODE_OPEN_COLLECTOR_10K", INT2NUM(ENCODER_IO_MODE_OPEN_COLLECTOR_10K));
|
227
119
|
|
228
|
-
int ph_encoder_on_input_change(CPhidgetEncoderHandle phid, void *userPtr, int index, int state) {
|
229
|
-
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
230
|
-
callback_data->called = true;
|
231
|
-
return EPHIDGET_OK;
|
232
|
-
}
|
233
120
|
|
121
|
+
/* Document-method: new
|
122
|
+
* call-seq: new
|
123
|
+
*
|
124
|
+
* Creates a Phidget Encoder object.
|
125
|
+
*/
|
126
|
+
rb_define_method(ph_encoder, "initialize", ph_encoder_init, 0);
|
127
|
+
|
128
|
+
/* Document-method: getEnabled
|
129
|
+
* call-seq: getEnabled -> true or false
|
130
|
+
*
|
131
|
+
* The enabled state of the encoder.
|
132
|
+
*/
|
133
|
+
rb_define_method(ph_encoder, "getEnabled", ph_encoder_get_enabled, 0);
|
134
|
+
rb_define_alias(ph_encoder, "enabled?", "getEnabled");
|
234
135
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
136
|
+
/* Document-method: setEnabled
|
137
|
+
* call-seq: setEnabled(state)
|
138
|
+
*
|
139
|
+
* The enabled state of the encoder.
|
140
|
+
*/
|
141
|
+
rb_define_method(ph_encoder, "setEnabled", ph_encoder_set_enabled, 1);
|
142
|
+
rb_define_alias(ph_encoder, "enabled=", "setEnabled");
|
240
143
|
|
144
|
+
/* Document-method: getDataInterval
|
145
|
+
* call-seq: getDataInterval -> interval
|
146
|
+
*
|
147
|
+
* The DataInterval is the time that must elapse before the channel will fire another PositionChange event.
|
148
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
149
|
+
* The timing between PositionChange events can also affected by the PositionChangeTrigger.
|
150
|
+
*/
|
151
|
+
rb_define_method(ph_encoder, "getDataInterval", ph_encoder_get_data_interval, 0);
|
152
|
+
rb_define_alias(ph_encoder, "data_interval", "getDataInterval");
|
241
153
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
154
|
+
/* Document-method: setDataInterval
|
155
|
+
* call-seq: setDataInterval(interval)
|
156
|
+
*
|
157
|
+
* The DataInterval is the time that must elapse before the channel will fire another PositionChange event.
|
158
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
159
|
+
* The timing between PositionChange events can also affected by the PositionChangeTrigger.
|
160
|
+
*/
|
161
|
+
rb_define_method(ph_encoder, "setDataInterval", ph_encoder_set_data_interval, 1);
|
162
|
+
rb_define_alias(ph_encoder, "data_interval=", "setDataInterval");
|
163
|
+
|
164
|
+
/* Document-method: getMinDataInterval
|
165
|
+
* call-seq: getMinDataInterval -> interval
|
166
|
+
*
|
167
|
+
* The minimum value that DataInterval can be set to.
|
168
|
+
*/
|
169
|
+
rb_define_method(ph_encoder, "getMinDataInterval", ph_encoder_get_min_data_interval, 0);
|
170
|
+
rb_define_alias(ph_encoder, "min_data_interval", "getMinDataInterval");
|
171
|
+
|
172
|
+
/* Document-method: getMaxDataInterval
|
173
|
+
* call-seq: getMaxDataInterval -> interval
|
174
|
+
*
|
175
|
+
* The maximum value that DataInterval can be set to.
|
176
|
+
*/
|
177
|
+
rb_define_method(ph_encoder, "getMaxDataInterval", ph_encoder_get_max_data_interval, 0);
|
178
|
+
rb_define_alias(ph_encoder, "max_data_interval", "getMaxDataInterval");
|
179
|
+
|
180
|
+
/* Document-method: getIndexPosition
|
181
|
+
* call-seq: getIndexPosition -> position
|
182
|
+
*
|
183
|
+
* The most recent position of the index channel calculated by the Phidgets library.
|
184
|
+
* The index channel will usually pulse once per rotation.
|
185
|
+
* Setting the encoder position will move the index position the same amount so their relative position stays the same.
|
186
|
+
* Index position is tracked locally as the last position at which the index was triggered.
|
187
|
+
* Setting position will only affect the local copy of the index position value. This means that index positions seen by multiple network applications may not agree.
|
188
|
+
*/
|
189
|
+
rb_define_method(ph_encoder, "getIndexPosition", ph_encoder_get_index_position, 0);
|
190
|
+
rb_define_alias(ph_encoder, "index_position", "getIndexPosition");
|
191
|
+
|
192
|
+
/* Document-method: getIOMode
|
193
|
+
* call-seq: getIOMode -> mode
|
194
|
+
*
|
195
|
+
* The encoder interface mode. Match the mode to the type of encoder you have attached.
|
196
|
+
* It is recommended to only change this when the encoder disabled in order to avoid unexpected results.
|
197
|
+
*/
|
198
|
+
rb_define_method(ph_encoder, "getIOMode", ph_encoder_get_io_mode, 0);
|
199
|
+
rb_define_alias(ph_encoder, "io_mode", "getIOMode");
|
200
|
+
|
201
|
+
/* Document-method: setIOMode
|
202
|
+
* call-seq: setIOMode(mode)
|
203
|
+
*
|
204
|
+
* The encoder interface mode. Match the mode to the type of encoder you have attached.
|
205
|
+
* It is recommended to only change this when the encoder disabled in order to avoid unexpected results.
|
206
|
+
*/
|
207
|
+
rb_define_method(ph_encoder, "setIOMode", ph_encoder_set_io_mode, 1);
|
208
|
+
rb_define_alias(ph_encoder, "io_mode=", "setIOMode");
|
209
|
+
|
210
|
+
/* Document-method: getPosition
|
211
|
+
* call-seq: getPosition -> position
|
212
|
+
*
|
213
|
+
* The most recent position value calculated by the Phidgets library.
|
214
|
+
* Position counts quadrature edges within a quadrature cycle. This means there are four counts per full quadrature cycle.
|
215
|
+
* Position is tracked locally as the total position change from the time the channel is opened.
|
216
|
+
* Setting position will only affect the local copy of the position value. This means that positions seen by multiple network applications may not agree.
|
217
|
+
*/
|
218
|
+
rb_define_method(ph_encoder, "getPosition", ph_encoder_get_position, 0);
|
219
|
+
rb_define_alias(ph_encoder, "position", "getPosition");
|
220
|
+
|
221
|
+
/* Document-method: setPosition
|
222
|
+
* call-seq: setPosition(position)
|
223
|
+
*
|
224
|
+
* The most recent position value calculated by the Phidgets library.
|
225
|
+
* Position counts quadrature edges within a quadrature cycle. This means there are four counts per full quadrature cycle.
|
226
|
+
* Position is tracked locally as the total position change from the time the channel is opened.
|
227
|
+
* Setting position will only affect the local copy of the position value. This means that positions seen by multiple network applications may not agree.
|
228
|
+
*/
|
229
|
+
rb_define_method(ph_encoder, "setPosition", ph_encoder_set_position, 1);
|
230
|
+
rb_define_alias(ph_encoder, "position=", "setPosition");
|
247
231
|
|
248
|
-
|
232
|
+
/* Document-method: getPositionChangeTrigger
|
233
|
+
* call-seq: getPositionChangeTrigger -> trigger
|
234
|
+
*
|
235
|
+
* The channel will not issue a PositionChange event until the position value has changed by the amount specified by the PositionChangeTrigger.
|
236
|
+
* Setting the PositionChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
237
|
+
*/
|
238
|
+
rb_define_method(ph_encoder, "getPositionChangeTrigger", ph_encoder_get_position_change_trigger, 0);
|
239
|
+
rb_define_alias(ph_encoder, "position_change_trigger", "getPositionChangeTrigger");
|
240
|
+
|
241
|
+
/* Document-method: setPositionChangeTrigger
|
242
|
+
* call-seq: setPositionChangeTrigger(trigger)
|
243
|
+
*
|
244
|
+
* The channel will not issue a PositionChange event until the position value has changed by the amount specified by the PositionChangeTrigger.
|
245
|
+
* Setting the PositionChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
246
|
+
*/
|
247
|
+
rb_define_method(ph_encoder, "setPositionChangeTrigger", ph_encoder_set_position_change_trigger, 1);
|
248
|
+
rb_define_alias(ph_encoder, "position_change_trigger=", "setPositionChangeTrigger");
|
249
|
+
|
250
|
+
/* Document-method: getMinPositionChangeTrigger
|
251
|
+
* call-seq: getMinPositionChangeTrigger -> trigger
|
252
|
+
*
|
253
|
+
* The minimum value that PositionChangeTrigger can be set to.
|
254
|
+
*/
|
255
|
+
rb_define_method(ph_encoder, "getMinPositionChangeTrigger", ph_encoder_get_min_position_change_trigger, 0);
|
256
|
+
rb_define_alias(ph_encoder, "min_position_change_trigger", "getMinPositionChangeTrigger");
|
257
|
+
|
258
|
+
/* Document-method: getMaxPositionChangeTrigger
|
259
|
+
* call-seq: getMaxPositionChangeTrigger -> trigger
|
260
|
+
*
|
261
|
+
* The maximum value that PositionChangeTrigger can be set to.
|
262
|
+
*/
|
263
|
+
rb_define_method(ph_encoder, "getMaxPositionChangeTrigger", ph_encoder_get_max_position_change_trigger, 0);
|
264
|
+
rb_define_alias(ph_encoder, "max_position_change_trigger", "getMaxPositionChangeTrigger");
|
265
|
+
|
266
|
+
rb_define_private_method(ph_encoder, "ext_setOnPositionChangeHandler", ph_encoder_set_on_position_change_handler, 1);
|
267
|
+
}
|
249
268
|
|