phidgets 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +10 -2
- data/README.rdoc +41 -18
- data/Rakefile +31 -20
- data/bin/phidget +29 -44
- data/ext/phidgets/extconf.rb +14 -0
- data/ext/phidgets/phidgets.c +272 -0
- data/ext/phidgets/phidgets.h +82 -0
- data/ext/phidgets/phidgets_accelerometer.c +165 -0
- data/ext/phidgets/phidgets_advanced_servo.c +567 -0
- data/ext/phidgets/phidgets_analog.c +139 -0
- data/ext/phidgets/phidgets_bridge.c +263 -0
- data/ext/phidgets/phidgets_common.c +454 -0
- data/ext/phidgets/phidgets_dictionary.c +279 -0
- data/ext/phidgets/phidgets_encoder.c +249 -0
- data/ext/phidgets/phidgets_frequency_counter.c +241 -0
- data/ext/phidgets/phidgets_gps.c +235 -0
- data/ext/phidgets/phidgets_interface_kit.c +340 -0
- data/ext/phidgets/phidgets_ir.c +251 -0
- data/ext/phidgets/phidgets_led.c +178 -0
- data/ext/phidgets/phidgets_manager.c +366 -0
- data/ext/phidgets/phidgets_motor_control.c +642 -0
- data/ext/phidgets/phidgets_phsensor.c +208 -0
- data/ext/phidgets/phidgets_rfid.c +281 -0
- data/ext/phidgets/phidgets_servo.c +276 -0
- data/ext/phidgets/phidgets_spatial.c +369 -0
- data/ext/phidgets/phidgets_stepper.c +560 -0
- data/ext/phidgets/phidgets_temp_sensor.c +295 -0
- data/ext/phidgets/phidgets_text_lcd.c +381 -0
- data/ext/phidgets/phidgets_text_led.c +107 -0
- data/ext/phidgets/phidgets_weight_sensor.c +113 -0
- data/lib/phidgets/accelerometer.rb +25 -0
- data/lib/phidgets/advanced_servo.rb +49 -0
- data/lib/phidgets/analog.rb +8 -0
- data/lib/phidgets/bridge.rb +25 -0
- data/lib/phidgets/common.rb +75 -190
- data/lib/phidgets/dictionary.rb +53 -0
- data/lib/phidgets/encoder.rb +49 -0
- data/lib/phidgets/frequency_counter.rb +25 -0
- data/lib/phidgets/gps.rb +37 -0
- data/lib/phidgets/interfacekit.rb +38 -128
- data/lib/phidgets/ir.rb +50 -0
- data/lib/phidgets/led.rb +8 -0
- data/lib/phidgets/manager.rb +67 -119
- data/lib/phidgets/motor_control.rb +110 -0
- data/lib/phidgets/ph_sensor.rb +25 -0
- data/lib/phidgets/rfid.rb +38 -111
- data/lib/phidgets/servo.rb +12 -95
- data/lib/phidgets/spatial.rb +25 -0
- data/lib/phidgets/stepper.rb +61 -0
- data/lib/phidgets/temperature_sensor.rb +25 -0
- data/lib/phidgets/text_lcd.rb +8 -0
- data/lib/phidgets/text_led.rb +8 -0
- data/lib/phidgets/weight_sensor.rb +25 -0
- data/lib/phidgets.rb +22 -3
- data/phidgets.gemspec +42 -0
- data/test/test_accelerometer.rb +47 -0
- data/test/test_advanced_servo.rb +152 -0
- data/test/test_analog.rb +45 -0
- data/test/test_bridge.rb +77 -0
- data/test/test_common.rb +167 -0
- data/test/test_dictionary.rb +82 -0
- data/test/test_encoder.rb +67 -0
- data/test/test_frequency_counter.rb +67 -0
- data/test/test_gps.rb +67 -0
- data/test/test_helper.rb +1 -0
- data/test/test_interfacekit.rb +86 -182
- data/test/test_ir.rb +57 -0
- data/test/test_led.rb +55 -0
- data/test/test_manager.rb +94 -0
- data/test/test_motor_control.rb +172 -0
- data/test/test_phidgets.rb +14 -6
- data/test/test_phsensor.rb +62 -0
- data/test/test_rfid.rb +77 -0
- data/test/test_servo.rb +67 -0
- data/test/test_spatial.rb +112 -0
- data/test/test_stepper.rb +163 -0
- data/test/test_temp_sensor.rb +87 -0
- data/test/test_text_lcd.rb +115 -0
- data/test/test_text_led.rb +35 -0
- data/test/test_weight_sensor.rb +32 -0
- metadata +165 -75
- data/Manifest.txt +0 -21
- data/PostInstall.txt +0 -3
- data/README.txt +0 -87
- data/lib/phidgets/phidgets.rb +0 -225
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
@@ -0,0 +1,208 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_phsensor_init(VALUE self);
|
6
|
+
VALUE ph_phsensor_get_ph(VALUE self);
|
7
|
+
VALUE ph_phsensor_get_ph_min(VALUE self);
|
8
|
+
VALUE ph_phsensor_get_ph_max(VALUE self);
|
9
|
+
VALUE ph_phsensor_get_ph_change_trigger(VALUE self);
|
10
|
+
VALUE ph_phsensor_set_ph_change_trigger(VALUE self, VALUE trigger);
|
11
|
+
VALUE ph_phsensor_get_potential(VALUE self);
|
12
|
+
VALUE ph_phsensor_get_potential_min(VALUE self);
|
13
|
+
VALUE ph_phsensor_get_potential_max(VALUE self);
|
14
|
+
VALUE ph_phsensor_set_temperature(VALUE self, VALUE temperature);
|
15
|
+
|
16
|
+
#ifdef PH_CALLBACK
|
17
|
+
VALUE ph_phsensor_set_on_ph_change_handler(VALUE self, VALUE handler);
|
18
|
+
int ph_phsensor_on_ph_change(CPhidgetPHSensorHandle phid, void *userPtr, double ph);
|
19
|
+
#endif
|
20
|
+
|
21
|
+
|
22
|
+
VALUE Init_phidgets_phsensor(VALUE ph_module, VALUE ph_common) {
|
23
|
+
VALUE ph_phsensor = rb_define_class_under(ph_module, "PHSensor", ph_common);
|
24
|
+
|
25
|
+
/* Document-method: new
|
26
|
+
* call-seq: new
|
27
|
+
*
|
28
|
+
* Creates a Phidget PHSensor object.
|
29
|
+
*/
|
30
|
+
rb_define_method(ph_phsensor, "initialize", ph_phsensor_init, 0);
|
31
|
+
|
32
|
+
/* Document-method: getPH
|
33
|
+
* call-seq: getPH -> ph
|
34
|
+
*
|
35
|
+
* Gets the sensed PH.
|
36
|
+
*/
|
37
|
+
rb_define_method(ph_phsensor, "getPH", ph_phsensor_get_ph, 0);
|
38
|
+
|
39
|
+
/* Document-method: getPHMin
|
40
|
+
* call-seq: getPHMin -> ph
|
41
|
+
*
|
42
|
+
* Gets the minimum PH that the sensor could report.
|
43
|
+
*/
|
44
|
+
rb_define_method(ph_phsensor, "getPHMin", ph_phsensor_get_ph_min, 0);
|
45
|
+
|
46
|
+
/* Document-method: getPHMax
|
47
|
+
* call-seq: getPHMax -> ph
|
48
|
+
*
|
49
|
+
* Gets the maximum PH that the sensor could report.
|
50
|
+
*/
|
51
|
+
rb_define_method(ph_phsensor, "getPHMax", ph_phsensor_get_ph_max, 0);
|
52
|
+
|
53
|
+
/* Document-method: getPHChangeTrigger
|
54
|
+
* call-seq: getPHChangeTrigger -> trigger
|
55
|
+
*
|
56
|
+
* Gets the PH change trigger.
|
57
|
+
*/
|
58
|
+
rb_define_method(ph_phsensor, "getPHChangeTrigger", ph_phsensor_get_ph_change_trigger, 0);
|
59
|
+
|
60
|
+
/* Document-method: setPHChangeTrigger
|
61
|
+
* call-seq: setPHChangeTrigger(trigger)
|
62
|
+
*
|
63
|
+
* Sets the PH change trigger.
|
64
|
+
*/
|
65
|
+
rb_define_method(ph_phsensor, "setPHChangeTrigger", ph_phsensor_set_ph_change_trigger, 1);
|
66
|
+
|
67
|
+
/* Document-method: getPotential
|
68
|
+
* call-seq: getPotential -> potential
|
69
|
+
*
|
70
|
+
* Gets the sensed potential.
|
71
|
+
*/
|
72
|
+
rb_define_method(ph_phsensor, "getPotential", ph_phsensor_get_potential, 0);
|
73
|
+
|
74
|
+
/* Document-method: getPotentialMin
|
75
|
+
* call-seq: getPotentialMin -> potential
|
76
|
+
*
|
77
|
+
* Gets the minimum potential that can be sensed.
|
78
|
+
*/
|
79
|
+
rb_define_method(ph_phsensor, "getPotentialMin", ph_phsensor_get_potential_min, 0);
|
80
|
+
|
81
|
+
/* Document-method: getPotentialMax
|
82
|
+
* call-seq: getPotentialMax -> potential
|
83
|
+
*
|
84
|
+
* Gets the maximum potential that can be sensed.
|
85
|
+
*/
|
86
|
+
rb_define_method(ph_phsensor, "getPotentialMax", ph_phsensor_get_potential_max, 0);
|
87
|
+
|
88
|
+
/* Document-method: setTemperature
|
89
|
+
* call-seq: setTemperature(temperature)
|
90
|
+
*
|
91
|
+
* Sets the temperature to be used for PH calculations.
|
92
|
+
*/
|
93
|
+
rb_define_method(ph_phsensor, "setTemperature", ph_phsensor_set_temperature, 1);
|
94
|
+
|
95
|
+
#ifdef PH_CALLBACK
|
96
|
+
rb_define_private_method(ph_phsensor, "ext_setOnPHChangeHandler", ph_phsensor_set_on_ph_change_handler, 1);
|
97
|
+
#endif
|
98
|
+
|
99
|
+
rb_define_alias(ph_phsensor, "ph", "getPH");
|
100
|
+
rb_define_alias(ph_phsensor, "ph_min", "getPHMin");
|
101
|
+
rb_define_alias(ph_phsensor, "ph_max", "getPHMax");
|
102
|
+
rb_define_alias(ph_phsensor, "ph_change_trigger", "getPHChangeTrigger");
|
103
|
+
rb_define_alias(ph_phsensor, "ph_change_trigger=", "setPHChangeTrigger");
|
104
|
+
rb_define_alias(ph_phsensor, "potential", "getPotential");
|
105
|
+
rb_define_alias(ph_phsensor, "potential_min", "getPotentialMin");
|
106
|
+
rb_define_alias(ph_phsensor, "potential_max", "getPotentialMax");
|
107
|
+
rb_define_alias(ph_phsensor, "temperature=", "setTemperature");
|
108
|
+
|
109
|
+
return ph_phsensor;
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
VALUE ph_phsensor_init(VALUE self) {
|
115
|
+
ph_data_t *ph = get_ph_data(self);
|
116
|
+
ph_raise(CPhidgetPHSensor_create((CPhidgetPHSensorHandle *)(&(ph->handle))));
|
117
|
+
return self;
|
118
|
+
}
|
119
|
+
|
120
|
+
VALUE ph_phsensor_get_ph(VALUE self) {
|
121
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
122
|
+
double ph;
|
123
|
+
ph_raise(CPhidgetPHSensor_getPH(handle, &ph));
|
124
|
+
return rb_float_new(ph);
|
125
|
+
}
|
126
|
+
|
127
|
+
VALUE ph_phsensor_get_ph_min(VALUE self) {
|
128
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
129
|
+
double ph;
|
130
|
+
ph_raise(CPhidgetPHSensor_getPHMin(handle, &ph));
|
131
|
+
return rb_float_new(ph);
|
132
|
+
}
|
133
|
+
|
134
|
+
VALUE ph_phsensor_get_ph_max(VALUE self) {
|
135
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
136
|
+
double ph;
|
137
|
+
ph_raise(CPhidgetPHSensor_getPHMax(handle, &ph));
|
138
|
+
return rb_float_new(ph);
|
139
|
+
}
|
140
|
+
|
141
|
+
VALUE ph_phsensor_get_ph_change_trigger(VALUE self) {
|
142
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
143
|
+
double trigger;
|
144
|
+
ph_raise(CPhidgetPHSensor_getPHChangeTrigger(handle, &trigger));
|
145
|
+
return rb_float_new(trigger);
|
146
|
+
}
|
147
|
+
|
148
|
+
VALUE ph_phsensor_set_ph_change_trigger(VALUE self, VALUE trigger) {
|
149
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
150
|
+
ph_raise(CPhidgetPHSensor_setPHChangeTrigger(handle, NUM2DBL(trigger)));
|
151
|
+
return Qnil;
|
152
|
+
}
|
153
|
+
|
154
|
+
VALUE ph_phsensor_get_potential(VALUE self) {
|
155
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
156
|
+
double potential;
|
157
|
+
ph_raise(CPhidgetPHSensor_getPotential(handle, &potential));
|
158
|
+
return rb_float_new(potential);
|
159
|
+
}
|
160
|
+
|
161
|
+
VALUE ph_phsensor_get_potential_min(VALUE self) {
|
162
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
163
|
+
double potential;
|
164
|
+
ph_raise(CPhidgetPHSensor_getPotentialMin(handle, &potential));
|
165
|
+
return rb_float_new(potential);
|
166
|
+
}
|
167
|
+
|
168
|
+
VALUE ph_phsensor_get_potential_max(VALUE self) {
|
169
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
170
|
+
double potential;
|
171
|
+
ph_raise(CPhidgetPHSensor_getPotentialMax(handle, &potential));
|
172
|
+
return rb_float_new(potential);
|
173
|
+
}
|
174
|
+
|
175
|
+
VALUE ph_phsensor_set_temperature(VALUE self, VALUE temperature) {
|
176
|
+
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
177
|
+
ph_raise(CPhidgetPHSensor_setTemperature(handle, NUM2DBL(temperature)));
|
178
|
+
return Qnil;
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
#ifdef PH_CALLBACK
|
183
|
+
VALUE ph_phsensor_set_on_ph_change_handler(VALUE self, VALUE handler) {
|
184
|
+
ph_data_t *ph = get_ph_data(self);
|
185
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_1;
|
186
|
+
if( TYPE(handler) == T_NIL ) {
|
187
|
+
callback_data->exit = true;
|
188
|
+
ph_raise(CPhidgetPHSensor_set_OnPHChange_Handler((CPhidgetPHSensorHandle)ph->handle, NULL, (void *)NULL));
|
189
|
+
} else {
|
190
|
+
callback_data->called = false;
|
191
|
+
callback_data->exit = false;
|
192
|
+
callback_data->phidget = self;
|
193
|
+
callback_data->callback = handler;
|
194
|
+
ph_raise(CPhidgetPHSensor_set_OnPHChange_Handler((CPhidgetPHSensorHandle)ph->handle, ph_phsensor_on_ph_change, (void *)callback_data));
|
195
|
+
ph_callback_thread(callback_data);
|
196
|
+
}
|
197
|
+
return Qnil;
|
198
|
+
}
|
199
|
+
|
200
|
+
|
201
|
+
int ph_phsensor_on_ph_change(CPhidgetPHSensorHandle phid, void *userPtr, double ph) {
|
202
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
203
|
+
callback_data->called = true;
|
204
|
+
return EPHIDGET_OK;
|
205
|
+
}
|
206
|
+
|
207
|
+
#endif
|
208
|
+
|
@@ -0,0 +1,281 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_rfid_init(VALUE self);
|
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
|
+
VALUE Init_phidgets_rfid(VALUE ph_module, VALUE ph_common) {
|
28
|
+
VALUE ph_rfid = rb_define_class_under(ph_module, "RFID", ph_common);
|
29
|
+
|
30
|
+
/* EM4100 (EM4102) 40-bit */
|
31
|
+
rb_define_const(ph_rfid, "PROTOCOL_EM4100", INT2FIX(PHIDGET_RFID_PROTOCOL_EM4100));
|
32
|
+
/* ISO11785 FDX-B encoding (Animal ID) */
|
33
|
+
rb_define_const(ph_rfid, "PROTOCOL_ISO11785_FDX_B", INT2FIX(PHIDGET_RFID_PROTOCOL_ISO11785_FDX_B));
|
34
|
+
/* PhidgetTAG Protocol 24 character ASCII */
|
35
|
+
rb_define_const(ph_rfid, "PROTOCOL_PHIDGETS", INT2FIX(PHIDGET_RFID_PROTOCOL_PHIDGETS));
|
36
|
+
|
37
|
+
/* Document-method: new
|
38
|
+
* call-seq: new
|
39
|
+
*
|
40
|
+
* Creates a Phidget RFID object.
|
41
|
+
*/
|
42
|
+
rb_define_method(ph_rfid, "initialize", ph_rfid_init, 0);
|
43
|
+
|
44
|
+
/* Document-method: getOutputCount
|
45
|
+
* call-seq: getOutputCount -> count
|
46
|
+
*
|
47
|
+
* Gets the number of outputs supported by this board.
|
48
|
+
*/
|
49
|
+
rb_define_method(ph_rfid, "getOutputCount", ph_rfid_get_output_count, 0);
|
50
|
+
|
51
|
+
/* Document-method: getOutputState
|
52
|
+
* call-seq: getOutputState(index) -> true or false
|
53
|
+
*
|
54
|
+
* Gets the state of an output.
|
55
|
+
*/
|
56
|
+
rb_define_method(ph_rfid, "getOutputState", ph_rfid_get_output_state, 1);
|
57
|
+
|
58
|
+
/* Document-method: setOutputState
|
59
|
+
* call-seq: setOutputState(index, state)
|
60
|
+
*
|
61
|
+
* Sets the state of an output.
|
62
|
+
*/
|
63
|
+
rb_define_method(ph_rfid, "setOutputState", ph_rfid_set_output_state, 2);
|
64
|
+
|
65
|
+
/* Document-method: getAntennaOn
|
66
|
+
* call-seq: getAntennaOn -> true or false
|
67
|
+
*
|
68
|
+
* Gets the state of the antenna.
|
69
|
+
*/
|
70
|
+
rb_define_method(ph_rfid, "getAntennaOn", ph_rfid_get_antenna_on, 0);
|
71
|
+
|
72
|
+
/* Document-method: setAntennaOn
|
73
|
+
* call-seq: setAntennaOn(state)
|
74
|
+
*
|
75
|
+
* Sets the state of the antenna. Note that the antenna must be enabled before tags will be read.
|
76
|
+
*/
|
77
|
+
rb_define_method(ph_rfid, "setAntennaOn", ph_rfid_set_antenna_on, 1);
|
78
|
+
|
79
|
+
/* Document-method: getLEDOn
|
80
|
+
* call-seq: getLEDOn -> true or false
|
81
|
+
*
|
82
|
+
* Gets the state of the onboard LED.
|
83
|
+
*/
|
84
|
+
rb_define_method(ph_rfid, "getLEDOn", ph_rfid_get_led_on, 0);
|
85
|
+
|
86
|
+
/* Document-method: setLEDOn
|
87
|
+
* call-seq: setLEDOn(state)
|
88
|
+
*
|
89
|
+
* Sets the state of the onboard LED.
|
90
|
+
*/
|
91
|
+
rb_define_method(ph_rfid, "setLEDOn", ph_rfid_set_led_on, 1);
|
92
|
+
|
93
|
+
/* Document-method: getLastTag
|
94
|
+
* call-seq: getLastTag -> tag
|
95
|
+
*
|
96
|
+
* Gets the last tag read by the reader. This tag may or may not still be on the reader.
|
97
|
+
*/
|
98
|
+
rb_define_method(ph_rfid, "getLastTag", ph_rfid_get_last_tag, 0);
|
99
|
+
|
100
|
+
/* Document-method: getTagStatus
|
101
|
+
* call-seq: getTagStatus -> true or false
|
102
|
+
*
|
103
|
+
* Gets the tag present status. This is whether or not a tag is being read by the reader.
|
104
|
+
*/
|
105
|
+
rb_define_method(ph_rfid, "getTagStatus", ph_rfid_get_tag_status, 0);
|
106
|
+
|
107
|
+
/* Document-method: write
|
108
|
+
* call-seq: write(tag, protocol, lock)
|
109
|
+
*
|
110
|
+
* Program a tag. This requires a T5577 tag.
|
111
|
+
*/
|
112
|
+
rb_define_method(ph_rfid, "write", ph_rfid_write, 3);
|
113
|
+
|
114
|
+
#ifdef PH_CALLBACK
|
115
|
+
rb_define_private_method(ph_rfid, "ext_setOnTagHandler", ph_rfid_set_on_tag_handler, 1);
|
116
|
+
rb_define_private_method(ph_rfid, "ext_setOnTagLostHandler", ph_rfid_set_on_tag_lost_handler, 1);
|
117
|
+
rb_define_private_method(ph_rfid, "ext_setOnOutputChangeHandler", ph_rfid_set_on_output_change_handler, 1);
|
118
|
+
#endif
|
119
|
+
|
120
|
+
rb_define_alias(ph_rfid, "output_count", "getOutputCount");
|
121
|
+
rb_define_alias(ph_rfid, "output_state", "getOutputState");
|
122
|
+
rb_define_alias(ph_rfid, "set_output_state", "setOutputState");
|
123
|
+
rb_define_alias(ph_rfid, "antenna_on?", "getAntennaOn");
|
124
|
+
rb_define_alias(ph_rfid, "antenna_on=", "setAntennaOn");
|
125
|
+
rb_define_alias(ph_rfid, "led_on?", "getLEDOn");
|
126
|
+
rb_define_alias(ph_rfid, "led_on=", "setLEDOn");
|
127
|
+
rb_define_alias(ph_rfid, "last_tag", "getLastTag");
|
128
|
+
rb_define_alias(ph_rfid, "tag_status", "getTagStatus");
|
129
|
+
|
130
|
+
return ph_rfid;
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
VALUE ph_rfid_init(VALUE self) {
|
136
|
+
ph_data_t *ph = get_ph_data(self);
|
137
|
+
ph_raise(CPhidgetRFID_create((CPhidgetRFIDHandle *)(&(ph->handle))));
|
138
|
+
return self;
|
139
|
+
}
|
140
|
+
|
141
|
+
VALUE ph_rfid_get_output_count(VALUE self) {
|
142
|
+
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
143
|
+
int count;
|
144
|
+
ph_raise(CPhidgetRFID_getOutputCount(handle, &count));
|
145
|
+
return INT2FIX(count);
|
146
|
+
}
|
147
|
+
|
148
|
+
VALUE ph_rfid_get_output_state(VALUE self, VALUE index) {
|
149
|
+
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
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));
|
158
|
+
return Qnil;
|
159
|
+
}
|
160
|
+
|
161
|
+
VALUE ph_rfid_get_antenna_on(VALUE self) {
|
162
|
+
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
163
|
+
int on;
|
164
|
+
ph_raise(CPhidgetRFID_getAntennaOn(handle, &on));
|
165
|
+
return on == PTRUE ? Qtrue : Qfalse;
|
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;
|
172
|
+
}
|
173
|
+
|
174
|
+
VALUE ph_rfid_get_led_on(VALUE self) {
|
175
|
+
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
176
|
+
int on;
|
177
|
+
ph_raise(CPhidgetRFID_getLEDOn(handle, &on));
|
178
|
+
return on == PTRUE ? Qtrue : Qfalse;
|
179
|
+
}
|
180
|
+
|
181
|
+
VALUE ph_rfid_set_led_on(VALUE self, VALUE on) {
|
182
|
+
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
183
|
+
ph_raise(CPhidgetRFID_setLEDOn(handle, TYPE(on) == T_TRUE ? PTRUE : PFALSE));
|
184
|
+
return Qnil;
|
185
|
+
}
|
186
|
+
|
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
|
+
|
195
|
+
VALUE ph_rfid_get_tag_status(VALUE self) {
|
196
|
+
CPhidgetRFIDHandle handle = (CPhidgetRFIDHandle)get_ph_handle(self);
|
197
|
+
int status;
|
198
|
+
ph_raise(CPhidgetRFID_getTagStatus(handle, &status));
|
199
|
+
return status == PTRUE ? Qtrue : Qfalse;
|
200
|
+
}
|
201
|
+
|
202
|
+
VALUE ph_rfid_write(VALUE self, VALUE tag, VALUE protocol, VALUE lock) {
|
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;
|
206
|
+
}
|
207
|
+
|
208
|
+
#ifdef PH_CALLBACK
|
209
|
+
VALUE ph_rfid_set_on_tag_handler(VALUE self, VALUE handler) {
|
210
|
+
ph_data_t *ph = get_ph_data(self);
|
211
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_1;
|
212
|
+
if( TYPE(handler) == T_NIL ) {
|
213
|
+
callback_data->exit = true;
|
214
|
+
ph_raise(CPhidgetRFID_set_OnTag2_Handler((CPhidgetRFIDHandle)ph->handle, NULL, (void *)NULL));
|
215
|
+
} else {
|
216
|
+
callback_data->called = false;
|
217
|
+
callback_data->exit = false;
|
218
|
+
callback_data->phidget = self;
|
219
|
+
callback_data->callback = handler;
|
220
|
+
ph_raise(CPhidgetRFID_set_OnTag2_Handler((CPhidgetRFIDHandle)ph->handle, ph_rfid_on_tag, (void *)callback_data));
|
221
|
+
ph_callback_thread(callback_data);
|
222
|
+
}
|
223
|
+
return Qnil;
|
224
|
+
}
|
225
|
+
|
226
|
+
VALUE ph_rfid_set_on_tag_lost_handler(VALUE self, VALUE handler) {
|
227
|
+
ph_data_t *ph = get_ph_data(self);
|
228
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_2;
|
229
|
+
if( TYPE(handler) == T_NIL ) {
|
230
|
+
callback_data->exit = true;
|
231
|
+
ph_raise(CPhidgetRFID_set_OnTagLost2_Handler((CPhidgetRFIDHandle)ph->handle, NULL, (void *)NULL));
|
232
|
+
} else {
|
233
|
+
callback_data->called = false;
|
234
|
+
callback_data->exit = false;
|
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;
|
241
|
+
}
|
242
|
+
|
243
|
+
VALUE ph_rfid_set_on_output_change_handler(VALUE self, VALUE handler) {
|
244
|
+
ph_data_t *ph = get_ph_data(self);
|
245
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_3;
|
246
|
+
if( TYPE(handler) == T_NIL ) {
|
247
|
+
callback_data->exit = true;
|
248
|
+
ph_raise(CPhidgetRFID_set_OnOutputChange_Handler((CPhidgetRFIDHandle)ph->handle, NULL, (void *)NULL));
|
249
|
+
} else {
|
250
|
+
callback_data->called = false;
|
251
|
+
callback_data->exit = false;
|
252
|
+
callback_data->phidget = self;
|
253
|
+
callback_data->callback = handler;
|
254
|
+
ph_raise(CPhidgetRFID_set_OnOutputChange_Handler((CPhidgetRFIDHandle)ph->handle, ph_rfid_on_output_change, (void *)callback_data));
|
255
|
+
ph_callback_thread(callback_data);
|
256
|
+
}
|
257
|
+
return Qnil;
|
258
|
+
}
|
259
|
+
|
260
|
+
|
261
|
+
int ph_rfid_on_tag(CPhidgetRFIDHandle phid, void *userPtr, char *tagString, CPhidgetRFID_Protocol protocol) {
|
262
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
263
|
+
callback_data->called = true;
|
264
|
+
return EPHIDGET_OK;
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
int ph_rfid_on_tag_lost(CPhidgetRFIDHandle phid, void *userPtr, char *tagString, CPhidgetRFID_Protocol protocol) {
|
269
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
270
|
+
callback_data->called = true;
|
271
|
+
return EPHIDGET_OK;
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
int ph_rfid_on_output_change(CPhidgetRFIDHandle phid, void *userPtr, int index, int state) {
|
276
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
277
|
+
callback_data->called = true;
|
278
|
+
return EPHIDGET_OK;
|
279
|
+
}
|
280
|
+
#endif
|
281
|
+
|