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
@@ -0,0 +1,227 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
#define RESISTANCE_INPUT_RESISTANCE_CHANGE_CALLBACK 0
|
5
|
+
|
6
|
+
|
7
|
+
VALUE ph_resistance_init(VALUE self) {
|
8
|
+
ph_data_t *ph = get_ph_data(self);
|
9
|
+
ph_raise(PhidgetResistanceInput_create((PhidgetResistanceInputHandle *)(&(ph->handle))));
|
10
|
+
return self;
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE ph_resistance_get_data_interval(VALUE self) {
|
14
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetResistanceInput_getDataInterval);
|
15
|
+
}
|
16
|
+
|
17
|
+
VALUE ph_resistance_set_data_interval(VALUE self, VALUE interval) {
|
18
|
+
ph_raise(PhidgetResistanceInput_setDataInterval((PhidgetResistanceInputHandle)get_ph_handle(self), NUM2UINT(interval)));
|
19
|
+
return Qnil;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE ph_resistance_get_min_data_interval(VALUE self) {
|
23
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetResistanceInput_getMinDataInterval);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE ph_resistance_get_max_data_interval(VALUE self) {
|
27
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetResistanceInput_getMaxDataInterval);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE ph_resistance_get_resistance(VALUE self) {
|
31
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetResistanceInput_getResistance);
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE ph_resistance_get_min_resistance(VALUE self) {
|
35
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetResistanceInput_getMinResistance);
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE ph_resistance_get_max_resistance(VALUE self) {
|
39
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetResistanceInput_getMaxResistance);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE ph_resistance_get_resistance_change_trigger(VALUE self) {
|
43
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetResistanceInput_getResistanceChangeTrigger);
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE ph_resistance_set_resistance_change_trigger(VALUE self, VALUE change_trigger) {
|
47
|
+
ph_raise(PhidgetResistanceInput_setResistanceChangeTrigger((PhidgetResistanceInputHandle)get_ph_handle(self), NUM2DBL(change_trigger)));
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE ph_resistance_get_min_resistance_change_trigger(VALUE self) {
|
52
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetResistanceInput_getMinResistanceChangeTrigger);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE ph_resistance_get_max_resistance_change_trigger(VALUE self) {
|
56
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetResistanceInput_getMaxResistanceChangeTrigger);
|
57
|
+
}
|
58
|
+
|
59
|
+
VALUE ph_resistance_get_rtd_wire_setup(VALUE self) {
|
60
|
+
return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetResistanceInput_getRTDWireSetup);
|
61
|
+
}
|
62
|
+
|
63
|
+
VALUE ph_resistance_set_rtd_wire_setup(VALUE self, VALUE wire_setup) {
|
64
|
+
ph_raise(PhidgetResistanceInput_setRTDWireSetup((PhidgetResistanceInputHandle)get_ph_handle(self), NUM2INT(wire_setup)));
|
65
|
+
return Qnil;
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
void CCONV ph_resistance_on_resistance_change(PhidgetResistanceInputHandle phid, void *userPtr, double resistance) {
|
70
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
71
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
72
|
+
callback_data->arg1 = DBL2NUM(resistance);
|
73
|
+
callback_data->arg2 = Qnil;
|
74
|
+
callback_data->arg3 = Qnil;
|
75
|
+
callback_data->arg4 = Qnil;
|
76
|
+
sem_post(&callback_data->callback_called);
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
VALUE ph_resistance_set_on_resistance_change_handler(VALUE self, VALUE handler) {
|
81
|
+
ph_data_t *ph = get_ph_data(self);
|
82
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[RESISTANCE_INPUT_RESISTANCE_CHANGE_CALLBACK];
|
83
|
+
if( TYPE(handler) == T_NIL ) {
|
84
|
+
callback_data->callback = T_NIL;
|
85
|
+
callback_data->exit = true;
|
86
|
+
ph_raise(PhidgetResistanceInput_setOnResistanceChangeHandler((PhidgetResistanceInputHandle)ph->handle, NULL, (void *)NULL));
|
87
|
+
sem_post(&callback_data->callback_called);
|
88
|
+
} else {
|
89
|
+
callback_data->exit = false;
|
90
|
+
callback_data->phidget = self;
|
91
|
+
callback_data->callback = handler;
|
92
|
+
ph_raise(PhidgetResistanceInput_setOnResistanceChangeHandler((PhidgetResistanceInputHandle)ph->handle, ph_resistance_on_resistance_change, (void *)callback_data));
|
93
|
+
ph_callback_thread(callback_data);
|
94
|
+
}
|
95
|
+
return Qnil;
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
void Init_resistance() {
|
100
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
101
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
102
|
+
VALUE ph_resistance = rb_define_class_under(ph_module, "ResistanceInput", ph_common);
|
103
|
+
|
104
|
+
/* Document-method: new
|
105
|
+
* call-seq: new
|
106
|
+
*
|
107
|
+
* Creates a Phidget ResistanceInput object.
|
108
|
+
*/
|
109
|
+
rb_define_method(ph_resistance, "initialize", ph_resistance_init, 0);
|
110
|
+
|
111
|
+
/* Document-method: getDataInterval
|
112
|
+
* call-seq: getDataInterval -> interval
|
113
|
+
*
|
114
|
+
* The DataInterval is the time that must elapse before the channel will fire another ResistanceChange event.
|
115
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
116
|
+
* The timing between ResistanceChange events can also affected by the ResistanceChangeTrigger.
|
117
|
+
*/
|
118
|
+
rb_define_method(ph_resistance, "getDataInterval", ph_resistance_get_data_interval, 0);
|
119
|
+
rb_define_alias(ph_resistance, "data_interval", "getDataInterval");
|
120
|
+
|
121
|
+
/* Document-method: setDataInterval
|
122
|
+
* call-seq: setDataInterval(interval)
|
123
|
+
*
|
124
|
+
* The DataInterval is the time that must elapse before the channel will fire another ResistanceChange event.
|
125
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
126
|
+
* The timing between ResistanceChange events can also affected by the ResistanceChangeTrigger.
|
127
|
+
*/
|
128
|
+
rb_define_method(ph_resistance, "setDataInterval", ph_resistance_set_data_interval, 1);
|
129
|
+
rb_define_alias(ph_resistance, "data_interval=", "setDataInterval");
|
130
|
+
|
131
|
+
/* Document-method: getMinDataInterval
|
132
|
+
* call-seq: getMinDataInterval -> interval
|
133
|
+
*
|
134
|
+
* The minimum value that DataInterval can be set to.
|
135
|
+
*/
|
136
|
+
rb_define_method(ph_resistance, "getMinDataInterval", ph_resistance_get_min_data_interval, 0);
|
137
|
+
rb_define_alias(ph_resistance, "min_data_interval", "getMinDataInterval");
|
138
|
+
|
139
|
+
/* Document-method: getMaxDataInterval
|
140
|
+
* call-seq: getMaxDataInterval -> interval
|
141
|
+
*
|
142
|
+
* The maximum value that DataInterval can be set to.
|
143
|
+
*/
|
144
|
+
rb_define_method(ph_resistance, "getMaxDataInterval", ph_resistance_get_max_data_interval, 0);
|
145
|
+
rb_define_alias(ph_resistance, "max_data_interval", "getMaxDataInterval");
|
146
|
+
|
147
|
+
/* Document-method: getResistance
|
148
|
+
* call-seq: getResistance -> resistance
|
149
|
+
*
|
150
|
+
* The most recent resistance value that the channel has reported.
|
151
|
+
* This value will always be between MinResistance and MaxResistance.
|
152
|
+
*/
|
153
|
+
rb_define_method(ph_resistance, "getResistance", ph_resistance_get_resistance, 0);
|
154
|
+
rb_define_alias(ph_resistance, "resistance", "getResistance");
|
155
|
+
|
156
|
+
/* Document-method: getMinResistance
|
157
|
+
* call-seq: getMinResistance -> resistance
|
158
|
+
*
|
159
|
+
* The minimum value that the ResistanceChange event will report.
|
160
|
+
*/
|
161
|
+
rb_define_method(ph_resistance, "getMinResistance", ph_resistance_get_min_resistance, 0);
|
162
|
+
rb_define_alias(ph_resistance, "min_resistance", "getMinResistance");
|
163
|
+
|
164
|
+
/* Document-method: getMaxResistance
|
165
|
+
* call-seq: getMaxResistance -> resistance
|
166
|
+
*
|
167
|
+
* The maximum value that the ResistanceChange event will report.
|
168
|
+
*/
|
169
|
+
rb_define_method(ph_resistance, "getMaxResistance", ph_resistance_get_max_resistance, 0);
|
170
|
+
rb_define_alias(ph_resistance, "max_resistance", "getMaxResistance");
|
171
|
+
|
172
|
+
/* Document-method: getResistanceChangeTrigger
|
173
|
+
* call-seq: getResistanceChangeTrigger -> change_trigger
|
174
|
+
*
|
175
|
+
* The channel will not issue a ResistanceChange event until the resistance value has changed by the amount specified by the ResistanceChangeTrigger.
|
176
|
+
* Setting the ResistanceChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
177
|
+
*/
|
178
|
+
rb_define_method(ph_resistance, "getResistanceChangeTrigger", ph_resistance_get_resistance_change_trigger, 0);
|
179
|
+
rb_define_alias(ph_resistance, "resistance_change_trigger", "getResistanceChangeTrigger");
|
180
|
+
|
181
|
+
/* Document-method: setResistanceChangeTrigger
|
182
|
+
* call-seq: setResistanceChangeTrigger(change_trigger)
|
183
|
+
*
|
184
|
+
* The channel will not issue a ResistanceChange event until the resistance value has changed by the amount specified by the ResistanceChangeTrigger.
|
185
|
+
* Setting the ResistanceChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
186
|
+
*/
|
187
|
+
rb_define_method(ph_resistance, "setResistanceChangeTrigger", ph_resistance_set_resistance_change_trigger, 1);
|
188
|
+
rb_define_alias(ph_resistance, "resistance_change_trigger=", "setResistanceChangeTrigger");
|
189
|
+
|
190
|
+
/* Document-method: getMinResistanceChangeTrigger
|
191
|
+
* call-seq: getMinResistanceChangeTrigger -> change_trigger
|
192
|
+
*
|
193
|
+
* The minimum value that ResistanceChangeTrigger can be set to.
|
194
|
+
*/
|
195
|
+
rb_define_method(ph_resistance, "getMinResistanceChangeTrigger", ph_resistance_get_min_resistance_change_trigger, 0);
|
196
|
+
rb_define_alias(ph_resistance, "min_resistance_change_trigger", "getMinResistanceChangeTrigger");
|
197
|
+
|
198
|
+
/* Document-method: getMaxResistanceChangeTrigger
|
199
|
+
* call-seq: getMaxResistanceChangeTrigger -> change_trigger
|
200
|
+
*
|
201
|
+
* The maximum value that ResistanceChangeTrigger can be set to.
|
202
|
+
*/
|
203
|
+
rb_define_method(ph_resistance, "getMaxResistanceChangeTrigger", ph_resistance_get_max_resistance_change_trigger, 0);
|
204
|
+
rb_define_alias(ph_resistance, "max_resistance_change_trigger", "getMaxResistanceChangeTrigger");
|
205
|
+
|
206
|
+
/* Document-method: getRTDWireSetup
|
207
|
+
* call-seq: getRTDWireSetup -> wire_setup
|
208
|
+
*
|
209
|
+
* Select the RTD wiring configuration.
|
210
|
+
* More information about RTD wiring can be found in the user guide.
|
211
|
+
*/
|
212
|
+
rb_define_method(ph_resistance, "getRTDWireSetup", ph_resistance_get_rtd_wire_setup, 0);
|
213
|
+
rb_define_alias(ph_resistance, "rtd_wire_setup", "getRTDWireSetup");
|
214
|
+
|
215
|
+
/* Document-method: setRTDWireSetup
|
216
|
+
* call-seq: setRTDWireSetup(wire_setup)
|
217
|
+
*
|
218
|
+
* Select the RTD wiring configuration.
|
219
|
+
* More information about RTD wiring can be found in the user guide.
|
220
|
+
*/
|
221
|
+
rb_define_method(ph_resistance, "setRTDWireSetup", ph_resistance_set_rtd_wire_setup, 1);
|
222
|
+
rb_define_alias(ph_resistance, "rtd_wire_setup=", "setRTDWireSetup");
|
223
|
+
|
224
|
+
|
225
|
+
rb_define_private_method(ph_resistance, "ext_setOnResistanceChangeHandler", ph_resistance_set_on_resistance_change_handler, 1);
|
226
|
+
}
|
227
|
+
|
@@ -1,281 +1,167 @@
|
|
1
1
|
|
2
2
|
#include "phidgets.h"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
VALUE ph_rfid_get_output_count(VALUE self);
|
7
|
-
VALUE ph_rfid_get_output_state(VALUE self, VALUE index);
|
8
|
-
VALUE ph_rfid_set_output_state(VALUE self, VALUE index, VALUE state);
|
9
|
-
VALUE ph_rfid_get_antenna_on(VALUE self);
|
10
|
-
VALUE ph_rfid_set_antenna_on(VALUE self, VALUE on);
|
11
|
-
VALUE ph_rfid_get_led_on(VALUE self);
|
12
|
-
VALUE ph_rfid_set_led_on(VALUE self, VALUE on);
|
13
|
-
VALUE ph_rfid_get_last_tag(VALUE self);
|
14
|
-
VALUE ph_rfid_get_tag_status(VALUE self);
|
15
|
-
VALUE ph_rfid_write(VALUE self, VALUE tag, VALUE protocol, VALUE lock);
|
16
|
-
|
17
|
-
#ifdef PH_CALLBACK
|
18
|
-
VALUE ph_rfid_set_on_tag_handler(VALUE self, VALUE handler);
|
19
|
-
VALUE ph_rfid_set_on_tag_lost_handler(VALUE self, VALUE handler);
|
20
|
-
VALUE ph_rfid_set_on_output_change_handler(VALUE self, VALUE handler);
|
21
|
-
int ph_rfid_on_tag(CPhidgetRFIDHandle phid, void *userPtr, char *tagString, CPhidgetRFID_Protocol protocol);
|
22
|
-
int ph_rfid_on_tag_lost(CPhidgetRFIDHandle phid, void *userPtr, char *tagString, CPhidgetRFID_Protocol protocol);
|
23
|
-
int ph_rfid_on_output_change(CPhidgetRFIDHandle phid, void *userPtr, int index, int state);
|
24
|
-
#endif
|
25
|
-
|
26
|
-
|
27
|
-
void Init_rfid() {
|
28
|
-
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
29
|
-
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
30
|
-
VALUE ph_rfid = rb_define_class_under(ph_module, "RFID", ph_common);
|
31
|
-
|
32
|
-
/* EM4100 (EM4102) 40-bit */
|
33
|
-
rb_define_const(ph_rfid, "PROTOCOL_EM4100", INT2FIX(PHIDGET_RFID_PROTOCOL_EM4100));
|
34
|
-
/* ISO11785 FDX-B encoding (Animal ID) */
|
35
|
-
rb_define_const(ph_rfid, "PROTOCOL_ISO11785_FDX_B", INT2FIX(PHIDGET_RFID_PROTOCOL_ISO11785_FDX_B));
|
36
|
-
/* PhidgetTAG Protocol 24 character ASCII */
|
37
|
-
rb_define_const(ph_rfid, "PROTOCOL_PHIDGETS", INT2FIX(PHIDGET_RFID_PROTOCOL_PHIDGETS));
|
38
|
-
|
39
|
-
/* Document-method: new
|
40
|
-
* call-seq: new
|
41
|
-
*
|
42
|
-
* Creates a Phidget RFID object.
|
43
|
-
*/
|
44
|
-
rb_define_method(ph_rfid, "initialize", ph_rfid_init, 0);
|
45
|
-
|
46
|
-
/* Document-method: getOutputCount
|
47
|
-
* call-seq: getOutputCount -> count
|
48
|
-
*
|
49
|
-
* Gets the number of outputs supported by this board.
|
50
|
-
*/
|
51
|
-
rb_define_method(ph_rfid, "getOutputCount", ph_rfid_get_output_count, 0);
|
52
|
-
|
53
|
-
/* Document-method: getOutputState
|
54
|
-
* call-seq: getOutputState(index) -> true or false
|
55
|
-
*
|
56
|
-
* Gets the state of an output.
|
57
|
-
*/
|
58
|
-
rb_define_method(ph_rfid, "getOutputState", ph_rfid_get_output_state, 1);
|
59
|
-
|
60
|
-
/* Document-method: setOutputState
|
61
|
-
* call-seq: setOutputState(index, state)
|
62
|
-
*
|
63
|
-
* Sets the state of an output.
|
64
|
-
*/
|
65
|
-
rb_define_method(ph_rfid, "setOutputState", ph_rfid_set_output_state, 2);
|
66
|
-
|
67
|
-
/* Document-method: getAntennaOn
|
68
|
-
* call-seq: getAntennaOn -> true or false
|
69
|
-
*
|
70
|
-
* Gets the state of the antenna.
|
71
|
-
*/
|
72
|
-
rb_define_method(ph_rfid, "getAntennaOn", ph_rfid_get_antenna_on, 0);
|
73
|
-
|
74
|
-
/* Document-method: setAntennaOn
|
75
|
-
* call-seq: setAntennaOn(state)
|
76
|
-
*
|
77
|
-
* Sets the state of the antenna. Note that the antenna must be enabled before tags will be read.
|
78
|
-
*/
|
79
|
-
rb_define_method(ph_rfid, "setAntennaOn", ph_rfid_set_antenna_on, 1);
|
80
|
-
|
81
|
-
/* Document-method: getLEDOn
|
82
|
-
* call-seq: getLEDOn -> true or false
|
83
|
-
*
|
84
|
-
* Gets the state of the onboard LED.
|
85
|
-
*/
|
86
|
-
rb_define_method(ph_rfid, "getLEDOn", ph_rfid_get_led_on, 0);
|
87
|
-
|
88
|
-
/* Document-method: setLEDOn
|
89
|
-
* call-seq: setLEDOn(state)
|
90
|
-
*
|
91
|
-
* Sets the state of the onboard LED.
|
92
|
-
*/
|
93
|
-
rb_define_method(ph_rfid, "setLEDOn", ph_rfid_set_led_on, 1);
|
94
|
-
|
95
|
-
/* Document-method: getLastTag
|
96
|
-
* call-seq: getLastTag -> tag
|
97
|
-
*
|
98
|
-
* Gets the last tag read by the reader. This tag may or may not still be on the reader.
|
99
|
-
*/
|
100
|
-
rb_define_method(ph_rfid, "getLastTag", ph_rfid_get_last_tag, 0);
|
101
|
-
|
102
|
-
/* Document-method: getTagStatus
|
103
|
-
* call-seq: getTagStatus -> true or false
|
104
|
-
*
|
105
|
-
* Gets the tag present status. This is whether or not a tag is being read by the reader.
|
106
|
-
*/
|
107
|
-
rb_define_method(ph_rfid, "getTagStatus", ph_rfid_get_tag_status, 0);
|
108
|
-
|
109
|
-
/* Document-method: write
|
110
|
-
* call-seq: write(tag, protocol, lock)
|
111
|
-
*
|
112
|
-
* Program a tag. This requires a T5577 tag.
|
113
|
-
*/
|
114
|
-
rb_define_method(ph_rfid, "write", ph_rfid_write, 3);
|
115
|
-
|
116
|
-
#ifdef PH_CALLBACK
|
117
|
-
rb_define_private_method(ph_rfid, "ext_setOnTagHandler", ph_rfid_set_on_tag_handler, 1);
|
118
|
-
rb_define_private_method(ph_rfid, "ext_setOnTagLostHandler", ph_rfid_set_on_tag_lost_handler, 1);
|
119
|
-
rb_define_private_method(ph_rfid, "ext_setOnOutputChangeHandler", ph_rfid_set_on_output_change_handler, 1);
|
120
|
-
#endif
|
121
|
-
|
122
|
-
rb_define_alias(ph_rfid, "output_count", "getOutputCount");
|
123
|
-
rb_define_alias(ph_rfid, "output_state", "getOutputState");
|
124
|
-
rb_define_alias(ph_rfid, "set_output_state", "setOutputState");
|
125
|
-
rb_define_alias(ph_rfid, "antenna_on?", "getAntennaOn");
|
126
|
-
rb_define_alias(ph_rfid, "antenna_on=", "setAntennaOn");
|
127
|
-
rb_define_alias(ph_rfid, "led_on?", "getLEDOn");
|
128
|
-
rb_define_alias(ph_rfid, "led_on=", "setLEDOn");
|
129
|
-
rb_define_alias(ph_rfid, "last_tag", "getLastTag");
|
130
|
-
rb_define_alias(ph_rfid, "tag_status", "getTagStatus");
|
131
|
-
}
|
4
|
+
#define RFID_TAG_CALLBACK 0
|
5
|
+
#define RFID_TAG_LOST_CALLBACK 1
|
132
6
|
|
133
7
|
|
134
8
|
|
135
9
|
VALUE ph_rfid_init(VALUE self) {
|
136
10
|
ph_data_t *ph = get_ph_data(self);
|
137
|
-
ph_raise(
|
11
|
+
ph_raise(PhidgetRFID_create((PhidgetRFIDHandle *)(&(ph->handle))));
|
138
12
|
return self;
|
139
13
|
}
|
140
14
|
|
141
|
-
VALUE
|
142
|
-
|
143
|
-
int count;
|
144
|
-
ph_raise(CPhidgetRFID_getOutputCount(handle, &count));
|
145
|
-
return INT2FIX(count);
|
15
|
+
VALUE ph_rfid_get_antenna_enabled(VALUE self) {
|
16
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetRFID_getAntennaEnabled);
|
146
17
|
}
|
147
18
|
|
148
|
-
VALUE
|
149
|
-
|
150
|
-
int state;
|
151
|
-
ph_raise(CPhidgetRFID_getOutputState(handle, FIX2INT(index), &state));
|
152
|
-
return state == PTRUE ? Qtrue : Qfalse;
|
153
|
-
}
|
154
|
-
|
155
|
-
VALUE ph_rfid_set_output_state(VALUE self, VALUE index, VALUE state) {
|
156
|
-
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
157
|
-
ph_raise(CPhidgetRFID_setOutputState(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
|
19
|
+
VALUE ph_rfid_set_antenna_enabled(VALUE self, VALUE on) {
|
20
|
+
ph_raise(PhidgetRFID_setAntennaEnabled((PhidgetRFIDHandle)get_ph_handle(self), TYPE(on) == T_TRUE ? PTRUE : PFALSE));
|
158
21
|
return Qnil;
|
159
22
|
}
|
160
23
|
|
161
|
-
VALUE
|
162
|
-
|
163
|
-
|
164
|
-
ph_raise(
|
165
|
-
return
|
166
|
-
}
|
167
|
-
|
168
|
-
VALUE ph_rfid_set_antenna_on(VALUE self, VALUE on) {
|
169
|
-
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
170
|
-
ph_raise(CPhidgetRFID_setAntennaOn(handle, TYPE(on) == T_TRUE ? PTRUE : PFALSE));
|
171
|
-
return Qnil;
|
24
|
+
VALUE ph_rfid_get_last_tag(VALUE self) {
|
25
|
+
char tag[256];
|
26
|
+
PhidgetRFID_Protocol protocol;
|
27
|
+
ph_raise(PhidgetRFID_getLastTag((PhidgetRFIDHandle)get_ph_handle(self), tag, 256, &protocol));
|
28
|
+
return rb_ary_new3(2, rb_str_new2(tag), INT2NUM(protocol));
|
172
29
|
}
|
173
30
|
|
174
|
-
VALUE
|
175
|
-
|
176
|
-
int on;
|
177
|
-
ph_raise(CPhidgetRFID_getLEDOn(handle, &on));
|
178
|
-
return on == PTRUE ? Qtrue : Qfalse;
|
31
|
+
VALUE ph_rfid_get_tag_present(VALUE self) {
|
32
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetRFID_getTagPresent);
|
179
33
|
}
|
180
34
|
|
181
|
-
VALUE
|
182
|
-
|
183
|
-
ph_raise(CPhidgetRFID_setLEDOn(handle, TYPE(on) == T_TRUE ? PTRUE : PFALSE));
|
35
|
+
VALUE ph_rfid_write(VALUE self, VALUE tag, VALUE protocol, VALUE lock) {
|
36
|
+
ph_raise(PhidgetRFID_write((PhidgetRFIDHandle)get_ph_handle(self), StringValueCStr(tag), NUM2INT(protocol), TYPE(lock) == T_TRUE ? PTRUE : PFALSE));
|
184
37
|
return Qnil;
|
185
38
|
}
|
186
39
|
|
187
|
-
VALUE ph_rfid_get_last_tag(VALUE self) {
|
188
|
-
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
189
|
-
char *tag;
|
190
|
-
CPhidgetRFID_Protocol protocol;
|
191
|
-
ph_raise(CPhidgetRFID_getLastTag2(handle, &tag, &protocol));
|
192
|
-
return rb_ary_new3(2, rb_str_new2(tag), INT2FIX(protocol));
|
193
|
-
}
|
194
40
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
204
|
-
ph_raise(CPhidgetRFID_write(handle, StringValueCStr(tag), FIX2INT(protocol), TYPE(lock) == T_TRUE ? PTRUE : PFALSE));
|
205
|
-
return Qnil;
|
41
|
+
void CCONV ph_rfid_on_tag(PhidgetRFIDHandle phid, void *userPtr, const char *tagString, PhidgetRFID_Protocol protocol) {
|
42
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
43
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
44
|
+
callback_data->arg1 = rb_str_new2(tagString);
|
45
|
+
callback_data->arg2 = INT2NUM(protocol);
|
46
|
+
callback_data->arg3 = Qnil;
|
47
|
+
callback_data->arg4 = Qnil;
|
48
|
+
sem_post(&callback_data->callback_called);
|
206
49
|
}
|
207
50
|
|
208
|
-
#ifdef PH_CALLBACK
|
209
51
|
VALUE ph_rfid_set_on_tag_handler(VALUE self, VALUE handler) {
|
210
52
|
ph_data_t *ph = get_ph_data(self);
|
211
|
-
ph_callback_data_t *callback_data = &ph->
|
53
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[RFID_TAG_CALLBACK];
|
212
54
|
if( TYPE(handler) == T_NIL ) {
|
55
|
+
callback_data->callback = T_NIL;
|
213
56
|
callback_data->exit = true;
|
214
|
-
ph_raise(
|
57
|
+
ph_raise(PhidgetRFID_setOnTagHandler((PhidgetRFIDHandle)ph->handle, NULL, (void *)NULL));
|
58
|
+
sem_post(&callback_data->callback_called);
|
215
59
|
} else {
|
216
|
-
callback_data->called = false;
|
217
60
|
callback_data->exit = false;
|
218
61
|
callback_data->phidget = self;
|
219
62
|
callback_data->callback = handler;
|
220
|
-
ph_raise(
|
63
|
+
ph_raise(PhidgetRFID_setOnTagHandler((PhidgetRFIDHandle)ph->handle, ph_rfid_on_tag, (void *)callback_data));
|
221
64
|
ph_callback_thread(callback_data);
|
222
65
|
}
|
223
66
|
return Qnil;
|
224
67
|
}
|
225
68
|
|
226
|
-
|
227
|
-
|
228
|
-
ph_callback_data_t *callback_data =
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
callback_data->phidget = self;
|
236
|
-
callback_data->callback = handler;
|
237
|
-
ph_raise(CPhidgetRFID_set_OnTagLost2_Handler((CPhidgetRFIDHandle)ph->handle, ph_rfid_on_tag_lost, (void *)callback_data));
|
238
|
-
ph_callback_thread(callback_data);
|
239
|
-
}
|
240
|
-
return Qnil;
|
69
|
+
|
70
|
+
void CCONV ph_rfid_on_tag_lost(PhidgetRFIDHandle phid, void *userPtr, const char *tagString, PhidgetRFID_Protocol protocol) {
|
71
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
72
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
73
|
+
callback_data->arg1 = rb_str_new2(tagString);
|
74
|
+
callback_data->arg2 = INT2NUM(protocol);
|
75
|
+
callback_data->arg3 = Qnil;
|
76
|
+
callback_data->arg4 = Qnil;
|
77
|
+
sem_post(&callback_data->callback_called);
|
241
78
|
}
|
242
79
|
|
243
|
-
VALUE
|
80
|
+
VALUE ph_rfid_set_on_tag_lost_handler(VALUE self, VALUE handler) {
|
244
81
|
ph_data_t *ph = get_ph_data(self);
|
245
|
-
ph_callback_data_t *callback_data = &ph->
|
82
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[RFID_TAG_LOST_CALLBACK];
|
246
83
|
if( TYPE(handler) == T_NIL ) {
|
84
|
+
callback_data->callback = T_NIL;
|
247
85
|
callback_data->exit = true;
|
248
|
-
ph_raise(
|
86
|
+
ph_raise(PhidgetRFID_setOnTagLostHandler((PhidgetRFIDHandle)ph->handle, NULL, (void *)NULL));
|
87
|
+
sem_post(&callback_data->callback_called);
|
249
88
|
} else {
|
250
|
-
callback_data->called = false;
|
251
89
|
callback_data->exit = false;
|
252
90
|
callback_data->phidget = self;
|
253
91
|
callback_data->callback = handler;
|
254
|
-
ph_raise(
|
92
|
+
ph_raise(PhidgetRFID_setOnTagLostHandler((PhidgetRFIDHandle)ph->handle, ph_rfid_on_tag, (void *)callback_data));
|
255
93
|
ph_callback_thread(callback_data);
|
256
94
|
}
|
257
95
|
return Qnil;
|
258
96
|
}
|
259
97
|
|
260
98
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
}
|
99
|
+
void Init_rfid() {
|
100
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
101
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
102
|
+
VALUE ph_rfid = rb_define_class_under(ph_module, "RFID", ph_common);
|
266
103
|
|
104
|
+
/* EM4100 (EM4102) 40-bit */
|
105
|
+
rb_define_const(ph_rfid, "PROTOCOL_EM4100", INT2NUM(PROTOCOL_EM4100));
|
106
|
+
/* ISO11785 FDX-B encoding (Animal ID) */
|
107
|
+
rb_define_const(ph_rfid, "PROTOCOL_ISO11785_FDX_B", INT2NUM(PROTOCOL_ISO11785_FDX_B));
|
108
|
+
/* PhidgetTAG Protocol 24 character ASCII */
|
109
|
+
rb_define_const(ph_rfid, "PROTOCOL_PHIDGETS", INT2NUM(PROTOCOL_PHIDGETS));
|
267
110
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
111
|
+
/* Document-method: new
|
112
|
+
* call-seq: new
|
113
|
+
*
|
114
|
+
* Creates a Phidget RFID object.
|
115
|
+
*/
|
116
|
+
rb_define_method(ph_rfid, "initialize", ph_rfid_init, 0);
|
273
117
|
|
118
|
+
/* Document-method: getAntennaEnabled
|
119
|
+
* call-seq: getAntennaEnabled -> true or false
|
120
|
+
*
|
121
|
+
* The on/off state of the antenna.
|
122
|
+
* You can turn the antenna off to save power.
|
123
|
+
* You must turn the antenna on in order to detect and read RFID tags.
|
124
|
+
*/
|
125
|
+
rb_define_method(ph_rfid, "getAntennaEnabled", ph_rfid_get_antenna_enabled, 0);
|
126
|
+
rb_define_alias(ph_rfid, "antenna_enabled?", "getAntennaEnabled");
|
274
127
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
128
|
+
/* Document-method: setAntennaEnabled
|
129
|
+
* call-seq: setAntennaEnabled(state)
|
130
|
+
*
|
131
|
+
* The on/off state of the antenna.
|
132
|
+
* You can turn the antenna off to save power.
|
133
|
+
* You must turn the antenna on in order to detect and read RFID tags.
|
134
|
+
*/
|
135
|
+
rb_define_method(ph_rfid, "setAntennaEnabled", ph_rfid_set_antenna_enabled, 1);
|
136
|
+
rb_define_alias(ph_rfid, "antenna_enabled=", "setAntennaEnabled");
|
137
|
+
|
138
|
+
/* Document-method: getLastTag
|
139
|
+
* call-seq: getLastTag -> tag
|
140
|
+
*
|
141
|
+
* Gets the most recently read tag's data, even if that tag is no longer within read range.
|
142
|
+
* Only valid after at least one tag has been read.
|
143
|
+
*/
|
144
|
+
rb_define_method(ph_rfid, "getLastTag", ph_rfid_get_last_tag, 0);
|
145
|
+
rb_define_alias(ph_rfid, "last_tag", "getLastTag");
|
146
|
+
|
147
|
+
/* Document-method: getTagPresent
|
148
|
+
* call-seq: getTagPresent -> true or false
|
149
|
+
*
|
150
|
+
* This property is true if a compatibile RFID tag is being read by the reader.
|
151
|
+
* TagPresent will remain true until the tag is out of range and can no longer be read.
|
152
|
+
*/
|
153
|
+
rb_define_method(ph_rfid, "getTagPresent", ph_rfid_get_tag_present, 0);
|
154
|
+
rb_define_alias(ph_rfid, "tag_present?", "getTagPresent");
|
155
|
+
|
156
|
+
/* Document-method: write
|
157
|
+
* call-seq: write(tag, protocol, lock)
|
158
|
+
*
|
159
|
+
* Writes data to the tag being currently read by the reader.
|
160
|
+
* You cannot write to a read-only or locked tag.
|
161
|
+
*/
|
162
|
+
rb_define_method(ph_rfid, "write", ph_rfid_write, 3);
|
163
|
+
|
164
|
+
rb_define_private_method(ph_rfid, "ext_setOnTagHandler", ph_rfid_set_on_tag_handler, 1);
|
165
|
+
rb_define_private_method(ph_rfid, "ext_setOnTagLostHandler", ph_rfid_set_on_tag_lost_handler, 1);
|
279
166
|
}
|
280
|
-
#endif
|
281
167
|
|