phidgets_native 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/Gemfile +3 -0
- data/Gemfile.lock +12 -0
- data/README.rdoc +176 -0
- data/Rakefile +31 -0
- data/examples/gps.rb +25 -0
- data/examples/interface_kit.rb +61 -0
- data/examples/lib/common.rb +51 -0
- data/examples/lib/console_table.rb +38 -0
- data/examples/list_all.rb +16 -0
- data/examples/spatial.rb +53 -0
- data/ext/phidgets_native/accelerometer_ruby.c +36 -0
- data/ext/phidgets_native/advancedservo_ruby.c +33 -0
- data/ext/phidgets_native/analog_ruby.c +34 -0
- data/ext/phidgets_native/bridge_ruby.c +32 -0
- data/ext/phidgets_native/device.c +68 -0
- data/ext/phidgets_native/device_ruby.c +404 -0
- data/ext/phidgets_native/encoder_ruby.c +34 -0
- data/ext/phidgets_native/extconf.rb +18 -0
- data/ext/phidgets_native/frequencycounter_ruby.c +32 -0
- data/ext/phidgets_native/gps.c +102 -0
- data/ext/phidgets_native/gps_ruby.c +212 -0
- data/ext/phidgets_native/interfacekit.c +203 -0
- data/ext/phidgets_native/interfacekit_ruby.c +507 -0
- data/ext/phidgets_native/ir_ruby.c +33 -0
- data/ext/phidgets_native/led_ruby.c +33 -0
- data/ext/phidgets_native/motorcontrol_ruby.c +32 -0
- data/ext/phidgets_native/phidgets_native.c +197 -0
- data/ext/phidgets_native/phidgets_native.h +320 -0
- data/ext/phidgets_native/phidgets_native_ruby.c +468 -0
- data/ext/phidgets_native/phsensor_ruby.c +32 -0
- data/ext/phidgets_native/rfid_ruby.c +31 -0
- data/ext/phidgets_native/servo_ruby.c +31 -0
- data/ext/phidgets_native/spatial.c +168 -0
- data/ext/phidgets_native/spatial_ruby.c +533 -0
- data/ext/phidgets_native/stepper_ruby.c +32 -0
- data/ext/phidgets_native/temperaturesensor_ruby.c +31 -0
- data/ext/phidgets_native/textlcd_ruby.c +31 -0
- data/ext/phidgets_native/textled_ruby.c +31 -0
- data/ext/phidgets_native/weightsensor_ruby.c +32 -0
- data/phidgets_native.gemspec +21 -0
- metadata +96 -0
@@ -0,0 +1,507 @@
|
|
1
|
+
#include "phidgets_native.h"
|
2
|
+
|
3
|
+
const char MSG_RATIOMETRIC_MUST_BE_BOOL[] = "ratiometric can only be either true or false";
|
4
|
+
const char MSG_SENSOR_INDEX_MUST_BE_FIXNUM[] = "analog sensor offset must be fixnum";
|
5
|
+
const char MSG_SENSOR_INDEX_TOO_HIGH[] = "no sensor available at the provided offset";
|
6
|
+
const char MSG_OUTPUT_INDEX_MUST_BE_FIXNUM[] = "output sensor offset must be fixnum";
|
7
|
+
const char MSG_OUTPUT_INDEX_TOO_HIGH[] = "no output available at the provided offset";
|
8
|
+
const char MSG_OUTPUT_VALUE_MUST_BE_BOOL[] = "output value must be true or false";
|
9
|
+
|
10
|
+
const char MSG_DATA_RATE_VALUE_MUST_BE_FIXNUM[] = "rate must be a fixnum";
|
11
|
+
const char MSG_DATA_RATE_EXCEEDS_LIMIT[] = "provided rate exceeds allowed limit";
|
12
|
+
const char MSG_CHANGE_TRIG_VALUE_MUST_BE_FIXNUM[] = "threshold must be a fixnum";
|
13
|
+
const char MSG_CHANGE_TRIG_EXCEEDS_LIMIT[] = "provided threshold exceeds allowed limit";
|
14
|
+
|
15
|
+
/*
|
16
|
+
* Document-class: PhidgetsNative::InterfaceKit < PhidgetsNative::Device
|
17
|
+
*
|
18
|
+
* This class provides functionality specific to the "InterfaceKit" device class.
|
19
|
+
* Primarily, this phidget reports the values of analog and digital inputs, and
|
20
|
+
* provides interfaces for outputing to analog and digital components.
|
21
|
+
*/
|
22
|
+
|
23
|
+
void Init_phidgets_native_interfacekit(VALUE m_Phidget) {
|
24
|
+
VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
|
25
|
+
|
26
|
+
VALUE c_InterfaceKit = rb_define_class_under(m_Phidget,"InterfaceKit",c_Device);
|
27
|
+
|
28
|
+
/*
|
29
|
+
* Document-method: new
|
30
|
+
* call-seq:
|
31
|
+
* new(serial_number)
|
32
|
+
*
|
33
|
+
* All phidget objects are created from the device serial number. Serial numbers
|
34
|
+
* are required to be Fixnums (aka "unsigned integers").
|
35
|
+
*/
|
36
|
+
rb_define_method(c_InterfaceKit, "initialize", interfacekit_initialize, 1);
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Document-method: close
|
40
|
+
* call-seq:
|
41
|
+
* close -> nil
|
42
|
+
*
|
43
|
+
* This method will unregister the phidget event handlers, and free up all
|
44
|
+
* API resources associated with the phidget. This is an optional, but useful
|
45
|
+
* way to remove the object's overhead before the GC kicks in and actually
|
46
|
+
* frees the resource.
|
47
|
+
*/
|
48
|
+
rb_define_method(c_InterfaceKit, "close", interfacekit_close, 0);
|
49
|
+
|
50
|
+
/*
|
51
|
+
* Document-method: input_sample_rates
|
52
|
+
* call-seq:
|
53
|
+
* input_sample_rates -> Array
|
54
|
+
*
|
55
|
+
* The interface kit object tracks the sample rate of each input individually.
|
56
|
+
* This method returns an array containing the sample rates of each digital sensor.
|
57
|
+
*/
|
58
|
+
rb_define_method(c_InterfaceKit, "input_sample_rates", interfacekit_input_sample_rates, 0);
|
59
|
+
|
60
|
+
/*
|
61
|
+
* Document-method: sensor_sample_rates
|
62
|
+
* call-seq:
|
63
|
+
* sensor_sample_rates -> Array
|
64
|
+
*
|
65
|
+
* The interface kit object tracks the sample rate of each sensor individually.
|
66
|
+
* This method returns an array containing the sample rates of each analog sensor.
|
67
|
+
*/
|
68
|
+
rb_define_method(c_InterfaceKit, "sensor_sample_rates", interfacekit_sensor_sample_rates, 0);
|
69
|
+
|
70
|
+
/*
|
71
|
+
* Document-method: input_count
|
72
|
+
* call-seq:
|
73
|
+
* input_count -> Fixnum
|
74
|
+
*
|
75
|
+
* Returns an integer which represents the number of digital inputs provided
|
76
|
+
* by this interface kit, or nil if the device has yet to be connected.
|
77
|
+
*/
|
78
|
+
rb_define_method(c_InterfaceKit, "input_count", interfacekit_input_count, 0);
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Document-method: output_count
|
82
|
+
* call-seq:
|
83
|
+
* output_count -> Fixnum
|
84
|
+
*
|
85
|
+
* Returns an integer which represents the number of digital outputs provided
|
86
|
+
* by this interface kit, or nil if the device has yet to be connected.
|
87
|
+
*/
|
88
|
+
rb_define_method(c_InterfaceKit, "output_count", interfacekit_output_count, 0);
|
89
|
+
|
90
|
+
/*
|
91
|
+
* Document-method: sensor_count
|
92
|
+
* call-seq:
|
93
|
+
* sensor_count -> Fixnum
|
94
|
+
*
|
95
|
+
* Returns an integer which represents the number of analog inputs provided
|
96
|
+
* by this interface kit, or nil if the device has yet to be connected.
|
97
|
+
*/
|
98
|
+
rb_define_method(c_InterfaceKit, "sensor_count", interfacekit_sensor_count, 0);
|
99
|
+
|
100
|
+
/*
|
101
|
+
* Document-method: ratiometric?
|
102
|
+
* call-seq:
|
103
|
+
* ratiometric? -> Boolean
|
104
|
+
*
|
105
|
+
* Returns true if the analog sensors are currently in ratiometric mode. False
|
106
|
+
* if the controller is set to a stable voltage reference. Read more about this
|
107
|
+
* feature in the {Analog Inputs Primer}[http://www.phidgets.com/docs/Analog_Input_Primer#Ratiometric_Configuration]
|
108
|
+
*/
|
109
|
+
rb_define_method(c_InterfaceKit, "ratiometric?", interfacekit_is_ratiometric, 0);
|
110
|
+
|
111
|
+
/*
|
112
|
+
* Document-method: ratiometric=
|
113
|
+
* call-seq:
|
114
|
+
* ratiometric=(Boolean state) -> Boolean
|
115
|
+
*
|
116
|
+
* Sets the analog sensor voltage reference to ratiometric mode on true, or
|
117
|
+
* stable on false. Read more about this feature in the
|
118
|
+
* {Analog Inputs Primer}[http://www.phidgets.com/docs/Analog_Input_Primer#Ratiometric_Configuration]
|
119
|
+
*/
|
120
|
+
rb_define_method(c_InterfaceKit, "ratiometric=", interfacekit_ratiometric_set, 1);
|
121
|
+
|
122
|
+
/*
|
123
|
+
* Document-method: data_rates_max
|
124
|
+
* call-seq:
|
125
|
+
* data_rates_max -> Array
|
126
|
+
*
|
127
|
+
* Returns an array of ints which specify the maximum data_rate value that can
|
128
|
+
* be configured on each analog input sensor, or nil if the device has yet to
|
129
|
+
* be connected.
|
130
|
+
*/
|
131
|
+
rb_define_method(c_InterfaceKit, "data_rates_max", interfacekit_data_rates_max, 0);
|
132
|
+
|
133
|
+
/*
|
134
|
+
* Document-method: data_rates_min
|
135
|
+
* call-seq:
|
136
|
+
* data_rates_min -> Array
|
137
|
+
*
|
138
|
+
* Returns an array of ints which specify the minimum data_rate value that can
|
139
|
+
* be configured on each analog input sensor, or nil if the device has yet to
|
140
|
+
* be connected.
|
141
|
+
*/
|
142
|
+
rb_define_method(c_InterfaceKit, "data_rates_min", interfacekit_data_rates_min, 0);
|
143
|
+
|
144
|
+
/*
|
145
|
+
* Document-method: data_rates
|
146
|
+
* call-seq:
|
147
|
+
* data_rates -> Array
|
148
|
+
*
|
149
|
+
* Returns an array of either ints or nils, which specify the current data_rate
|
150
|
+
* for each analog input sensor. A nil indicates that this input is in change_trigger
|
151
|
+
* mode. If the whole return value is nil, this means that the device hasn't been
|
152
|
+
* connected yet.
|
153
|
+
*/
|
154
|
+
rb_define_method(c_InterfaceKit, "data_rates", interfacekit_data_rates, 0);
|
155
|
+
|
156
|
+
/*
|
157
|
+
* Document-method: change_triggers
|
158
|
+
* call-seq:
|
159
|
+
* change_triggers -> Array
|
160
|
+
*
|
161
|
+
* Returns an array of either ints or nils, which specify the current change_trigger
|
162
|
+
* threshold for each analog input sensor. A nil indicates that this input is
|
163
|
+
* in data_rate mode. If the whole return value is nil, this means that the
|
164
|
+
* device hasn't been connected yet.
|
165
|
+
*/
|
166
|
+
rb_define_method(c_InterfaceKit, "change_triggers", interfacekit_change_triggers, 0);
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Document-method: inputs
|
170
|
+
* call-seq:
|
171
|
+
* inputs -> Array
|
172
|
+
*
|
173
|
+
* Returns an array of bools, which specify the current digital input states.
|
174
|
+
* A return of nil indicates that this device is unplugged
|
175
|
+
*/
|
176
|
+
rb_define_method(c_InterfaceKit, "inputs", interfacekit_inputs, 0);
|
177
|
+
|
178
|
+
/*
|
179
|
+
* Document-method: outputs
|
180
|
+
* call-seq:
|
181
|
+
* outputs -> Array
|
182
|
+
*
|
183
|
+
* Returns an array of bools, which specify the current digital output states.
|
184
|
+
* A return of nil indicates that this device is unplugged
|
185
|
+
*/
|
186
|
+
rb_define_method(c_InterfaceKit, "outputs", interfacekit_outputs, 0);
|
187
|
+
|
188
|
+
/*
|
189
|
+
* Document-method: sensors
|
190
|
+
* call-seq:
|
191
|
+
* sensors -> Array
|
192
|
+
*
|
193
|
+
* Returns an array of ints, which specify the current analog sensor states. A
|
194
|
+
* return of nil indicates that this device is unplugged
|
195
|
+
*/
|
196
|
+
rb_define_method(c_InterfaceKit, "sensors", interfacekit_sensors, 0);
|
197
|
+
|
198
|
+
/*
|
199
|
+
* Document-method: sensor_raw
|
200
|
+
* call-seq:
|
201
|
+
* sensor_raw(Fixnum) -> Fixnum
|
202
|
+
*
|
203
|
+
* This method returns the "raw" value of the sensor at the provided offset.
|
204
|
+
* For more information on raw sensor values read up on the
|
205
|
+
* CPhidgetInterfaceKit_getSensorRawValue[http://www.phidgets.com/documentation/web/cdoc/group__phidifkit.html]
|
206
|
+
* function.
|
207
|
+
*/
|
208
|
+
rb_define_method(c_InterfaceKit, "sensor_raw", interfacekit_sensor_raw, 1);
|
209
|
+
|
210
|
+
/*
|
211
|
+
* Document-method: output
|
212
|
+
* call-seq:
|
213
|
+
* output(Fixnum, Boolean) -> Boolean
|
214
|
+
*
|
215
|
+
* This method sets the value of the specified digital output at the provided
|
216
|
+
* Fixnum offset to the Boolean state (true is on, false is off). The return
|
217
|
+
* value is simply what was specified for the input state.
|
218
|
+
* For more information on output control, you can read up on the
|
219
|
+
* CPhidgetInterfaceKit_setOutputState[http://www.phidgets.com/documentation/web/cdoc/group__phidifkit.html]
|
220
|
+
* function.
|
221
|
+
*/
|
222
|
+
rb_define_method(c_InterfaceKit, "output", interfacekit_output_set, 2);
|
223
|
+
|
224
|
+
/*
|
225
|
+
* Document-method: data_rate
|
226
|
+
* call-seq:
|
227
|
+
* data_rate(Fixnum index, Fixnum rate) -> Fixnum
|
228
|
+
*
|
229
|
+
* This method sets the data rate for the analog sensor at the provided index
|
230
|
+
* to the rate specified. This rate must be between data_rate_min[index] and
|
231
|
+
* data_rate_max[index]. The return value is simply what was specified for
|
232
|
+
* the rate. Keep in mind that setting a data rate, reverts the change_trigger
|
233
|
+
* for that input to nil.
|
234
|
+
* For more information on how analog inputs are polled, you can read up on the
|
235
|
+
* Phidget {Analog Input Primer}[http://www.phidgets.com/docs/Analog_Input_Primer]
|
236
|
+
*/
|
237
|
+
rb_define_method(c_InterfaceKit, "data_rate", interfacekit_data_rate_set, 2);
|
238
|
+
|
239
|
+
/*
|
240
|
+
* Document-method: change_trigger
|
241
|
+
* call-seq:
|
242
|
+
* change_trigger(Fixnum index, Fixnum threshold) -> Fixnum
|
243
|
+
*
|
244
|
+
* This method sets the change trigger for the analog sensor at the provided
|
245
|
+
* index the specified threshold. This threshould must be between 1 and 1000.
|
246
|
+
* The return value is simply what was specified for the rate. Keep in mind
|
247
|
+
* that setting a data rate, reverts the data_rate for that input to nil.
|
248
|
+
* For more information on how analog inputs are polled, you can read up on the
|
249
|
+
* Phidget {Analog Input Primer}[http://www.phidgets.com/docs/Analog_Input_Primer]
|
250
|
+
*/
|
251
|
+
rb_define_method(c_InterfaceKit, "change_trigger", interfacekit_change_trigger_set, 2);
|
252
|
+
}
|
253
|
+
|
254
|
+
VALUE interfacekit_initialize(VALUE self, VALUE serial) {
|
255
|
+
PhidgetInfo *info = device_info(self);
|
256
|
+
|
257
|
+
InterfaceKitInfo *ifkit_info = ALLOC(InterfaceKitInfo);
|
258
|
+
memset(ifkit_info, 0, sizeof(InterfaceKitInfo));
|
259
|
+
ifkit_info->is_ratiometric = false;
|
260
|
+
ifkit_info->is_data_rates_known = false;
|
261
|
+
|
262
|
+
CPhidgetInterfaceKitHandle interfacekit = 0;
|
263
|
+
ensure(CPhidgetInterfaceKit_create(&interfacekit));
|
264
|
+
|
265
|
+
ensure(CPhidgetInterfaceKit_set_OnInputChange_Handler(interfacekit, interfacekit_on_digital_change, info));
|
266
|
+
ensure(CPhidgetInterfaceKit_set_OnSensorChange_Handler(interfacekit, interfacekit_on_analog_change, info));
|
267
|
+
|
268
|
+
info->handle = (CPhidgetHandle)interfacekit;
|
269
|
+
info->on_type_attach = interfacekit_on_attach;
|
270
|
+
info->on_type_detach = interfacekit_on_detach;
|
271
|
+
info->on_type_free = interfacekit_on_free;
|
272
|
+
info->type_info = ifkit_info;
|
273
|
+
|
274
|
+
return rb_call_super(1, &serial);
|
275
|
+
}
|
276
|
+
|
277
|
+
VALUE interfacekit_close(VALUE self) {
|
278
|
+
PhidgetInfo *info = device_info(self);
|
279
|
+
|
280
|
+
ensure(CPhidgetInterfaceKit_set_OnInputChange_Handler((CPhidgetInterfaceKitHandle) info->handle, NULL, NULL));
|
281
|
+
ensure(CPhidgetInterfaceKit_set_OnSensorChange_Handler((CPhidgetInterfaceKitHandle) info->handle, NULL, NULL));
|
282
|
+
|
283
|
+
return rb_call_super(0,NULL);
|
284
|
+
}
|
285
|
+
|
286
|
+
VALUE interfacekit_sensor_sample_rates(VALUE self) {
|
287
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
288
|
+
|
289
|
+
int *rates_in_hz = ALLOC_N(int, ifkit_info->analog_input_count);
|
290
|
+
for(int i=0; i<ifkit_info->analog_input_count; i++)
|
291
|
+
rates_in_hz[i] = ifkit_info->analog_sample_rates[i].in_hz;
|
292
|
+
|
293
|
+
VALUE ret = int_array_to_rb(rates_in_hz, ifkit_info->analog_input_count);
|
294
|
+
|
295
|
+
xfree(rates_in_hz);
|
296
|
+
|
297
|
+
return ret;
|
298
|
+
}
|
299
|
+
|
300
|
+
VALUE interfacekit_input_sample_rates(VALUE self) {
|
301
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
302
|
+
|
303
|
+
int *rates_in_hz = ALLOC_N(int, ifkit_info->analog_input_count);
|
304
|
+
for(int i=0; i<ifkit_info->digital_input_count; i++)
|
305
|
+
rates_in_hz[i] = ifkit_info->digital_sample_rates[i].in_hz;
|
306
|
+
|
307
|
+
VALUE ret = int_array_to_rb(rates_in_hz, ifkit_info->digital_input_count);
|
308
|
+
|
309
|
+
xfree(rates_in_hz);
|
310
|
+
|
311
|
+
return ret;
|
312
|
+
}
|
313
|
+
|
314
|
+
VALUE interfacekit_input_count(VALUE self) {
|
315
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
316
|
+
|
317
|
+
return (ifkit_info->is_digital_input_count_known) ?
|
318
|
+
INT2FIX(ifkit_info->digital_input_count) : Qnil;
|
319
|
+
}
|
320
|
+
|
321
|
+
VALUE interfacekit_output_count(VALUE self) {
|
322
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
323
|
+
|
324
|
+
return (ifkit_info->is_digital_output_count_known) ?
|
325
|
+
INT2FIX(ifkit_info->digital_output_count) : Qnil;
|
326
|
+
}
|
327
|
+
|
328
|
+
VALUE interfacekit_sensor_count(VALUE self) {
|
329
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
330
|
+
|
331
|
+
return (ifkit_info->is_analog_input_count_known) ?
|
332
|
+
INT2FIX(ifkit_info->analog_input_count) : Qnil;
|
333
|
+
}
|
334
|
+
|
335
|
+
VALUE interfacekit_is_ratiometric(VALUE self) {
|
336
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
337
|
+
|
338
|
+
return (ifkit_info->is_ratiometric) ? Qtrue : Qfalse;
|
339
|
+
}
|
340
|
+
|
341
|
+
VALUE interfacekit_ratiometric_set(VALUE self, VALUE is_ratiometric) {
|
342
|
+
PhidgetInfo *info = device_info(self);
|
343
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
344
|
+
|
345
|
+
if (TYPE(is_ratiometric) == T_TRUE)
|
346
|
+
ifkit_info->is_ratiometric = true;
|
347
|
+
else if (TYPE(is_ratiometric) == T_FALSE)
|
348
|
+
ifkit_info->is_ratiometric = false;
|
349
|
+
else
|
350
|
+
rb_raise(rb_eTypeError, MSG_RATIOMETRIC_MUST_BE_BOOL);
|
351
|
+
|
352
|
+
if (info->is_attached)
|
353
|
+
ensure(interfacekit_assert_ratiometric_state( info ));
|
354
|
+
|
355
|
+
return is_ratiometric;
|
356
|
+
}
|
357
|
+
|
358
|
+
VALUE interfacekit_data_rates_max(VALUE self) {
|
359
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
360
|
+
|
361
|
+
return (ifkit_info->is_data_rates_known) ?
|
362
|
+
int_array_to_rb(ifkit_info->data_rates_max, ifkit_info->analog_input_count) : Qnil;
|
363
|
+
}
|
364
|
+
|
365
|
+
VALUE interfacekit_data_rates_min(VALUE self) {
|
366
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
367
|
+
|
368
|
+
return (ifkit_info->is_data_rates_known) ?
|
369
|
+
int_array_to_rb(ifkit_info->data_rates_min, ifkit_info->analog_input_count) : Qnil;
|
370
|
+
}
|
371
|
+
|
372
|
+
VALUE interfacekit_data_rates(VALUE self) {
|
373
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
374
|
+
|
375
|
+
return (ifkit_info->is_data_rates_known) ?
|
376
|
+
int_array_zeronils_to_rb(ifkit_info->data_rates, ifkit_info->analog_input_count) : Qnil;
|
377
|
+
}
|
378
|
+
|
379
|
+
VALUE interfacekit_change_triggers(VALUE self) {
|
380
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
381
|
+
|
382
|
+
return (ifkit_info->is_data_rates_known) ?
|
383
|
+
int_array_to_rb(ifkit_info->sensor_change_triggers, ifkit_info->analog_input_count) : Qnil;
|
384
|
+
}
|
385
|
+
|
386
|
+
VALUE interfacekit_inputs(VALUE self) {
|
387
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
388
|
+
|
389
|
+
return phidgetbool_array_to_rb(ifkit_info->digital_input_states,
|
390
|
+
ifkit_info->digital_input_count);
|
391
|
+
}
|
392
|
+
|
393
|
+
VALUE interfacekit_outputs(VALUE self) {
|
394
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
395
|
+
|
396
|
+
return phidgetbool_array_to_rb(ifkit_info->digital_output_states,
|
397
|
+
ifkit_info->digital_output_count);
|
398
|
+
}
|
399
|
+
|
400
|
+
VALUE interfacekit_sensors(VALUE self) {
|
401
|
+
InterfaceKitInfo *ifkit_info = device_type_info(self);
|
402
|
+
|
403
|
+
return int_array_to_rb(ifkit_info->analog_input_states,
|
404
|
+
ifkit_info->analog_input_count);
|
405
|
+
}
|
406
|
+
|
407
|
+
VALUE interfacekit_sensor_raw(VALUE self, VALUE index) {
|
408
|
+
PhidgetInfo *info = device_info(self);
|
409
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
410
|
+
|
411
|
+
int ret;
|
412
|
+
|
413
|
+
if ((TYPE(index) != T_FIXNUM))
|
414
|
+
rb_raise(rb_eTypeError, MSG_SENSOR_INDEX_MUST_BE_FIXNUM);
|
415
|
+
|
416
|
+
int index_int = FIX2INT(index);
|
417
|
+
if ((ifkit_info->analog_input_count == 0) || (index_int > (ifkit_info->analog_input_count-1)))
|
418
|
+
rb_raise(rb_eTypeError, MSG_SENSOR_INDEX_TOO_HIGH);
|
419
|
+
|
420
|
+
ensure(CPhidgetInterfaceKit_getSensorRawValue(
|
421
|
+
(CPhidgetInterfaceKitHandle)info->handle,index_int,&ret));
|
422
|
+
|
423
|
+
return INT2FIX(ret);
|
424
|
+
}
|
425
|
+
|
426
|
+
VALUE interfacekit_output_set(VALUE self, VALUE index, VALUE is_on) {
|
427
|
+
PhidgetInfo *info = device_info(self);
|
428
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
429
|
+
|
430
|
+
if (TYPE(index) != T_FIXNUM)
|
431
|
+
rb_raise(rb_eTypeError, MSG_OUTPUT_INDEX_MUST_BE_FIXNUM);
|
432
|
+
|
433
|
+
int index_int = FIX2INT(index);
|
434
|
+
if ((ifkit_info->digital_output_count == 0) || (index_int > (ifkit_info->digital_output_count-1)))
|
435
|
+
rb_raise(rb_eTypeError, MSG_OUTPUT_INDEX_TOO_HIGH);
|
436
|
+
|
437
|
+
int phidget_bool;
|
438
|
+
|
439
|
+
if (TYPE(is_on) == T_TRUE)
|
440
|
+
phidget_bool = PTRUE;
|
441
|
+
else if (TYPE(is_on) == T_FALSE)
|
442
|
+
phidget_bool = PFALSE;
|
443
|
+
else
|
444
|
+
rb_raise(rb_eTypeError, MSG_OUTPUT_VALUE_MUST_BE_BOOL);
|
445
|
+
|
446
|
+
ensure(CPhidgetInterfaceKit_setOutputState(
|
447
|
+
(CPhidgetInterfaceKitHandle)info->handle, index_int, phidget_bool));
|
448
|
+
|
449
|
+
ifkit_info->digital_output_states[index_int] = phidget_bool;
|
450
|
+
|
451
|
+
return is_on;
|
452
|
+
}
|
453
|
+
|
454
|
+
VALUE interfacekit_data_rate_set(VALUE self, VALUE index, VALUE rate) {
|
455
|
+
PhidgetInfo *info = device_info(self);
|
456
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
457
|
+
|
458
|
+
if (TYPE(index) != T_FIXNUM)
|
459
|
+
rb_raise(rb_eTypeError, MSG_SENSOR_INDEX_MUST_BE_FIXNUM);
|
460
|
+
|
461
|
+
if (TYPE(rate) != T_FIXNUM)
|
462
|
+
rb_raise(rb_eTypeError, MSG_DATA_RATE_VALUE_MUST_BE_FIXNUM);
|
463
|
+
|
464
|
+
int index_int = FIX2INT(index);
|
465
|
+
if ((ifkit_info->analog_input_count == 0) || (index_int > (ifkit_info->analog_input_count-1)))
|
466
|
+
rb_raise(rb_eTypeError, MSG_SENSOR_INDEX_TOO_HIGH);
|
467
|
+
|
468
|
+
int rate_int = FIX2INT(rate);
|
469
|
+
if ((rate_int > ifkit_info->data_rates_min[index_int]) || (rate_int < ifkit_info->data_rates_max[index_int]))
|
470
|
+
rb_raise(rb_eTypeError, MSG_DATA_RATE_EXCEEDS_LIMIT);
|
471
|
+
|
472
|
+
ensure(CPhidgetInterfaceKit_setDataRate(
|
473
|
+
(CPhidgetInterfaceKitHandle)info->handle, index_int, rate_int));
|
474
|
+
|
475
|
+
ifkit_info->data_rates[index_int] = rate_int;
|
476
|
+
ifkit_info->sensor_change_triggers[index_int] = 0;
|
477
|
+
|
478
|
+
return rate;
|
479
|
+
}
|
480
|
+
|
481
|
+
VALUE interfacekit_change_trigger_set(VALUE self, VALUE index, VALUE rate_thresh) {
|
482
|
+
PhidgetInfo *info = device_info(self);
|
483
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
484
|
+
|
485
|
+
if (TYPE(index) != T_FIXNUM)
|
486
|
+
rb_raise(rb_eTypeError, MSG_SENSOR_INDEX_MUST_BE_FIXNUM);
|
487
|
+
|
488
|
+
if (TYPE(rate_thresh) != T_FIXNUM)
|
489
|
+
rb_raise(rb_eTypeError, MSG_CHANGE_TRIG_VALUE_MUST_BE_FIXNUM);
|
490
|
+
|
491
|
+
int index_int = FIX2INT(index);
|
492
|
+
if ((ifkit_info->analog_input_count == 0) || (index_int > (ifkit_info->analog_input_count-1)))
|
493
|
+
rb_raise(rb_eTypeError, MSG_SENSOR_INDEX_TOO_HIGH);
|
494
|
+
|
495
|
+
int rate_thresh_int = FIX2INT(rate_thresh);
|
496
|
+
// These limits are specified in the phidget documentation (and, just kind of make sense)
|
497
|
+
if ((rate_thresh_int < 1) || (rate_thresh_int > 1000))
|
498
|
+
rb_raise(rb_eTypeError, MSG_CHANGE_TRIG_EXCEEDS_LIMIT);
|
499
|
+
|
500
|
+
ensure(CPhidgetInterfaceKit_setSensorChangeTrigger(
|
501
|
+
(CPhidgetInterfaceKitHandle)info->handle, index_int, rate_thresh_int));
|
502
|
+
|
503
|
+
ifkit_info->data_rates[index_int] = 0;
|
504
|
+
ifkit_info->sensor_change_triggers[index_int] = rate_thresh_int;
|
505
|
+
|
506
|
+
return rate_thresh;
|
507
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#include "phidgets_native.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Document-class: PhidgetsNative::IR < PhidgetsNative::Device
|
5
|
+
*
|
6
|
+
* This class is a stub, and is currently in need of an actual implementation.
|
7
|
+
* Nonetheless, all of the methods from its parent class PhidgetsNative::Device are
|
8
|
+
* available.
|
9
|
+
*/
|
10
|
+
|
11
|
+
void Init_phidgets_native_ir(VALUE m_Phidget) {
|
12
|
+
VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
|
13
|
+
|
14
|
+
VALUE c_IR = rb_define_class_under(m_Phidget, "IR", c_Device);
|
15
|
+
|
16
|
+
/*
|
17
|
+
* Document-method: new
|
18
|
+
* call-seq:
|
19
|
+
* new(serial_number)
|
20
|
+
*
|
21
|
+
* All phidget objects are created from the device serial number. Serial numbers
|
22
|
+
* are required to be Fixnums (aka "unsigned integers").
|
23
|
+
*/
|
24
|
+
rb_define_method(c_IR, "initialize", ir_initialize, 1);
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE ir_initialize(VALUE self, VALUE serial) {
|
28
|
+
PhidgetInfo *info = device_info(self);
|
29
|
+
CPhidgetIRHandle ir = 0;
|
30
|
+
ensure(CPhidgetIR_create(&ir));
|
31
|
+
info->handle = (CPhidgetHandle)ir;
|
32
|
+
return rb_call_super(1, &serial);
|
33
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#include "phidgets_native.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Document-class: PhidgetsNative::LED < PhidgetsNative::Device
|
5
|
+
*
|
6
|
+
* This class is a stub, and is currently in need of an actual implementation.
|
7
|
+
* Nonetheless, all of the methods from its parent class PhidgetsNative::Device are
|
8
|
+
* available.
|
9
|
+
*/
|
10
|
+
|
11
|
+
void Init_phidgets_native_led(VALUE m_Phidget) {
|
12
|
+
VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
|
13
|
+
|
14
|
+
VALUE c_LED = rb_define_class_under(m_Phidget, "LED", c_Device);
|
15
|
+
|
16
|
+
/*
|
17
|
+
* Document-method: new
|
18
|
+
* call-seq:
|
19
|
+
* new(serial_number)
|
20
|
+
*
|
21
|
+
* All phidget objects are created from the device serial number. Serial numbers
|
22
|
+
* are required to be Fixnums (aka "unsigned integers").
|
23
|
+
*/
|
24
|
+
rb_define_method(c_LED, "initialize", led_initialize, 1);
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE led_initialize(VALUE self, VALUE serial) {
|
28
|
+
PhidgetInfo *info = device_info(self);
|
29
|
+
CPhidgetLEDHandle led = 0;
|
30
|
+
ensure(CPhidgetLED_create(&led));
|
31
|
+
info->handle = (CPhidgetHandle)led;
|
32
|
+
return rb_call_super(1, &serial);
|
33
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#include "phidgets_native.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Document-class: PhidgetsNative::MotorControl < PhidgetsNative::Device
|
5
|
+
*
|
6
|
+
* This class is a stub, and is currently in need of an actual implementation.
|
7
|
+
* Nonetheless, all of the methods from its parent class PhidgetsNative::Device are
|
8
|
+
* available.
|
9
|
+
*/
|
10
|
+
void Init_phidgets_native_motorcontrol(VALUE m_Phidget) {
|
11
|
+
VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
|
12
|
+
|
13
|
+
VALUE c_MotorControl = rb_define_class_under(m_Phidget, "MotorControl", c_Device);
|
14
|
+
|
15
|
+
/*
|
16
|
+
* Document-method: new
|
17
|
+
* call-seq:
|
18
|
+
* new(serial_number)
|
19
|
+
*
|
20
|
+
* All phidget objects are created from the device serial number. Serial numbers
|
21
|
+
* are required to be Fixnums (aka "unsigned integers").
|
22
|
+
*/
|
23
|
+
rb_define_method(c_MotorControl, "initialize", motorcontrol_initialize, 1);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE motorcontrol_initialize(VALUE self, VALUE serial) {
|
27
|
+
PhidgetInfo *info = device_info(self);
|
28
|
+
CPhidgetMotorControlHandle motorcontrol = 0;
|
29
|
+
ensure(CPhidgetMotorControl_create(&motorcontrol));
|
30
|
+
info->handle = (CPhidgetHandle)motorcontrol;
|
31
|
+
return rb_call_super(1, &serial);
|
32
|
+
}
|