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.
Files changed (41) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +12 -0
  3. data/README.rdoc +176 -0
  4. data/Rakefile +31 -0
  5. data/examples/gps.rb +25 -0
  6. data/examples/interface_kit.rb +61 -0
  7. data/examples/lib/common.rb +51 -0
  8. data/examples/lib/console_table.rb +38 -0
  9. data/examples/list_all.rb +16 -0
  10. data/examples/spatial.rb +53 -0
  11. data/ext/phidgets_native/accelerometer_ruby.c +36 -0
  12. data/ext/phidgets_native/advancedservo_ruby.c +33 -0
  13. data/ext/phidgets_native/analog_ruby.c +34 -0
  14. data/ext/phidgets_native/bridge_ruby.c +32 -0
  15. data/ext/phidgets_native/device.c +68 -0
  16. data/ext/phidgets_native/device_ruby.c +404 -0
  17. data/ext/phidgets_native/encoder_ruby.c +34 -0
  18. data/ext/phidgets_native/extconf.rb +18 -0
  19. data/ext/phidgets_native/frequencycounter_ruby.c +32 -0
  20. data/ext/phidgets_native/gps.c +102 -0
  21. data/ext/phidgets_native/gps_ruby.c +212 -0
  22. data/ext/phidgets_native/interfacekit.c +203 -0
  23. data/ext/phidgets_native/interfacekit_ruby.c +507 -0
  24. data/ext/phidgets_native/ir_ruby.c +33 -0
  25. data/ext/phidgets_native/led_ruby.c +33 -0
  26. data/ext/phidgets_native/motorcontrol_ruby.c +32 -0
  27. data/ext/phidgets_native/phidgets_native.c +197 -0
  28. data/ext/phidgets_native/phidgets_native.h +320 -0
  29. data/ext/phidgets_native/phidgets_native_ruby.c +468 -0
  30. data/ext/phidgets_native/phsensor_ruby.c +32 -0
  31. data/ext/phidgets_native/rfid_ruby.c +31 -0
  32. data/ext/phidgets_native/servo_ruby.c +31 -0
  33. data/ext/phidgets_native/spatial.c +168 -0
  34. data/ext/phidgets_native/spatial_ruby.c +533 -0
  35. data/ext/phidgets_native/stepper_ruby.c +32 -0
  36. data/ext/phidgets_native/temperaturesensor_ruby.c +31 -0
  37. data/ext/phidgets_native/textlcd_ruby.c +31 -0
  38. data/ext/phidgets_native/textled_ruby.c +31 -0
  39. data/ext/phidgets_native/weightsensor_ruby.c +32 -0
  40. data/phidgets_native.gemspec +21 -0
  41. metadata +96 -0
@@ -0,0 +1,468 @@
1
+ #include "phidgets_native.h"
2
+
3
+ /*
4
+ * Document-class: PhidgetsNative::NotFoundError
5
+ *
6
+ * This exception is raised when the library receives a EPHIDGET_NOTFOUNDERROR
7
+ * error.
8
+ */
9
+
10
+ /*
11
+ * Document-class: PhidgetsNative::NoMemoryError
12
+ *
13
+ * This exception is raised when the library receives a EPHIDGET_NOMEMORYERROR
14
+ * error.
15
+ */
16
+
17
+ /*
18
+ * Document-class: PhidgetsNative::UnexpectedError
19
+ *
20
+ * This exception is raised when the library receives a EPHIDGET_UNEXPECTEDERROR
21
+ * error.
22
+ */
23
+
24
+ /*
25
+ * Document-class: PhidgetsNative::InvalidArgError
26
+ *
27
+ * This exception is raised when the library receives a EPHIDGET_INVALIDARGERROR
28
+ * error.
29
+ */
30
+
31
+ /*
32
+ * Document-class: PhidgetsNative::NotAttachedError
33
+ *
34
+ * This exception is raised when the library receives a EPHIDGET_NOTATTACHEDERROR
35
+ * error.
36
+ */
37
+
38
+ /*
39
+ * Document-class: PhidgetsNative::InterruptedError
40
+ *
41
+ * This exception is raised when the library receives a EPHIDGET_INTERRUPTEDERROR
42
+ * error.
43
+ */
44
+
45
+ /*
46
+ * Document-class: PhidgetsNative::InvalidError
47
+ *
48
+ * This exception is raised when the library receives a EPHIDGET_INVALIDERROR
49
+ * error.
50
+ */
51
+
52
+ /*
53
+ * Document-class: PhidgetsNative::NetworkError
54
+ *
55
+ * This exception is raised when the library receives a EPHIDGET_NETWORKERROR
56
+ * error.
57
+ */
58
+
59
+ /*
60
+ * Document-class: PhidgetsNative::UnknownValError
61
+ *
62
+ * This exception is raised when the library receives a EPHIDGET_UNKNOWNVALERROR
63
+ * error.
64
+ */
65
+
66
+ /*
67
+ * Document-class: PhidgetsNative::BadPasswordError
68
+ *
69
+ * This exception is raised when the library receives a EPHIDGET_BADPASSWORDERROR
70
+ * error.
71
+ */
72
+
73
+ /*
74
+ * Document-class: PhidgetsNative::UnsupportedError
75
+ *
76
+ * This exception is raised when the library receives a EPHIDGET_UNSUPPORTEDERROR
77
+ * error.
78
+ */
79
+
80
+ /*
81
+ * Document-class: PhidgetsNative::DuplicateError
82
+ *
83
+ * This exception is raised when the library receives a EPHIDGET_DUPLICATEERROR
84
+ * error.
85
+ */
86
+
87
+ /*
88
+ * Document-class: PhidgetsNative::TimeoutError
89
+ *
90
+ * This exception is raised when the library receives a EPHIDGET_TIMEOUTERROR
91
+ * error.
92
+ */
93
+
94
+ /*
95
+ * Document-class: PhidgetsNative::OutOfBoundsError
96
+ *
97
+ * This exception is raised when the library receives a EPHIDGET_OUTOFBOUNDSERROR
98
+ * error.
99
+ */
100
+
101
+ /*
102
+ * Document-class: PhidgetsNative::EventError
103
+ *
104
+ * This exception is raised when the library receives a EPHIDGET_EVENTERROR
105
+ * error.
106
+ */
107
+
108
+ /*
109
+ * Document-class: PhidgetsNative::NetworkNotConnectedError
110
+ *
111
+ * This exception is raised when the library receives a EPHIDGET_NETWORKNOTCONNECTEDERROR
112
+ * error.
113
+ */
114
+
115
+ /*
116
+ * Document-class: PhidgetsNative::WrongDeviceError
117
+ *
118
+ * This exception is raised when the library receives a EPHIDGET_WRONGDEVICEERROR
119
+ * error.
120
+ */
121
+
122
+ /*
123
+ * Document-class: PhidgetsNative::ClosedError
124
+ *
125
+ * This exception is raised when the library receives a EPHIDGET_CLOSEDERROR
126
+ * error.
127
+ */
128
+
129
+ /*
130
+ * Document-class: PhidgetsNative::BadVersionError
131
+ *
132
+ * This exception is raised when the library receives a EPHIDGET_BADVERSIONERROR
133
+ * error.
134
+ */
135
+
136
+ /*
137
+ * Document-class: PhidgetsNative::UnhandledError
138
+ *
139
+ * This exception is raised when the library receives a EPHIDGET_UNHANDLEDERROR
140
+ * error.
141
+ */
142
+
143
+ const char MSG_INVALID_LOG_LEVEL[] = "unrecognized log_level, must be one of :critical, :error, :warning, :debug, :info, or :verbose";
144
+ const char MSG_FILE_PATH_MUST_BE_STRING[] = "file_path must be string, or nil";
145
+ const char MSG_INVALID_MESSAGE_STRING[] = "message must be a string";
146
+ const char MSG_UNSUPPORTED_DEVICE_ENUMERATED[] = "enumerated an unsupported phidget device";
147
+
148
+ void Init_phidgets_native() {
149
+ const char *phidget_library_version;
150
+
151
+ ensure(CPhidget_getLibraryVersion(&phidget_library_version));
152
+
153
+ /*
154
+ * Mostly a container module for all of our objects. Singleton methods provide
155
+ * logging and enumeration features.
156
+ */
157
+ VALUE m_Phidget = rb_define_module("PhidgetsNative");
158
+
159
+ // We need to require the time library for the gps code
160
+ rb_funcall(m_Phidget, rb_intern("require"), 1, rb_str_new2("time"));
161
+
162
+ /*
163
+ * This constant is a string which reflects the version of the phidget library being used.
164
+ */
165
+ rb_define_const(m_Phidget, "LIBRARY_VERSION", rb_str_new2(phidget_library_version));
166
+
167
+ /*
168
+ * Document-method: enable_logging!
169
+ * call-seq:
170
+ * enable_logging!(log_level, file_path = nil) -> nil
171
+ *
172
+ * This method will enable logging within the Phidget library. The log_level
173
+ * parameter indicates the highest degree of desired output verbosity. Logged
174
+ * data will be that which is less than or equal to this level. Currently, the
175
+ * supported verbosity levels, in ascending order of verbosity are as follows:
176
+ * * :critical
177
+ * * :error
178
+ * * :warning
179
+ * * :debug
180
+ * * :info
181
+ * * :verbose
182
+ * Be sure to specify a symbol, and not a string.
183
+ *
184
+ * The optional file_path parameter can be used to divert logging output to a
185
+ * file, instead of the default behavior of logging to stdout. Be advised that
186
+ * only absolute path names appear to be supported by the library at this time.
187
+ */
188
+ rb_define_singleton_method(m_Phidget, "enable_logging!", phidget_enable_logging, -1);
189
+
190
+ /*
191
+ * Document-method: log
192
+ * call-seq:
193
+ * log(log_level, message) -> nil
194
+ *
195
+ * Logs an event of type log_level to the Phidget log, citing the provided message.
196
+ * Supported log_levels are declared in the enable_logging! method.
197
+ */
198
+ rb_define_singleton_method(m_Phidget, "log", phidget_log, 2);
199
+
200
+ /*
201
+ * Document-method: disable_logging!
202
+ * call-seq:
203
+ * disable_logging! -> nil
204
+ *
205
+ * This method will disable logging within the Phidget library, if logging was
206
+ * previously enabled.
207
+ */
208
+ rb_define_singleton_method(m_Phidget, "disable_logging!", phidget_disable_logging, 0);
209
+
210
+ /*
211
+ * Document-method: all
212
+ * call-seq:
213
+ * all -> nil
214
+ *
215
+ * This method will return an array of Phidget objects. These objects all the
216
+ * represent all the Phidgets which are currently connected to your computer.
217
+ */
218
+ rb_define_singleton_method(m_Phidget, "all", phidget_all, 0);
219
+
220
+
221
+ // Phidget Library Exceptions :
222
+ VALUE c_PhidgetNotFound = rb_define_class_under(m_Phidget, "NotFoundError", rb_eStandardError);
223
+ VALUE c_PhidgetNoMemory = rb_define_class_under(m_Phidget, "NoMemoryError", rb_eStandardError);
224
+ VALUE c_PhidgetUnexpected = rb_define_class_under(m_Phidget, "UnexpectedError", rb_eStandardError);
225
+ VALUE c_PhidgetInvalidArg = rb_define_class_under(m_Phidget, "InvalidArgError", rb_eStandardError);
226
+ VALUE c_PhidgetNotAttached = rb_define_class_under(m_Phidget, "NotAttachedError", rb_eStandardError);
227
+ VALUE c_PhidgetInterrupted = rb_define_class_under(m_Phidget, "InterruptedError", rb_eStandardError);
228
+ VALUE c_PhidgetInvalid = rb_define_class_under(m_Phidget, "InvalidError", rb_eStandardError);
229
+ VALUE c_PhidgetNetwork = rb_define_class_under(m_Phidget, "NetworkError", rb_eStandardError);
230
+ VALUE c_PhidgetUnknownVal = rb_define_class_under(m_Phidget, "UnknownValError", rb_eStandardError);
231
+ VALUE c_PhidgetBadPassword = rb_define_class_under(m_Phidget, "BadPasswordError", rb_eStandardError);
232
+ VALUE c_PhidgetUnsupported = rb_define_class_under(m_Phidget, "UnsupportedError", rb_eStandardError);
233
+ VALUE c_PhidgetDuplicate = rb_define_class_under(m_Phidget, "DuplicateError", rb_eStandardError);
234
+ VALUE c_PhidgetTimeout = rb_define_class_under(m_Phidget, "TimeoutError", rb_eStandardError);
235
+ VALUE c_PhidgetOutOfBounds = rb_define_class_under(m_Phidget, "OutOfBoundsError", rb_eStandardError);
236
+ VALUE c_PhidgetEvent = rb_define_class_under(m_Phidget, "EventError", rb_eStandardError);
237
+ VALUE c_PhidgetNetworkNotConnected = rb_define_class_under(m_Phidget, "NetworkNotConnectedError", rb_eStandardError);
238
+ VALUE c_PhidgetWrongDevice = rb_define_class_under(m_Phidget, "WrongDeviceError", rb_eStandardError);
239
+ VALUE c_PhidgetClosed = rb_define_class_under(m_Phidget, "ClosedError", rb_eStandardError);
240
+ VALUE c_PhidgetBadVersion = rb_define_class_under(m_Phidget, "BadVersionError", rb_eStandardError);
241
+ VALUE c_PhidgetUnhandled = rb_define_class_under(m_Phidget, "UnhandledError", rb_eStandardError);
242
+
243
+ // Phidget Device Classes
244
+ Init_phidgets_native_device(m_Phidget);
245
+ Init_phidgets_native_accelerometer(m_Phidget);
246
+ Init_phidgets_native_advancedservo(m_Phidget);
247
+ Init_phidgets_native_analog(m_Phidget);
248
+ Init_phidgets_native_bridge(m_Phidget);
249
+ Init_phidgets_native_encoder(m_Phidget);
250
+ Init_phidgets_native_frequencycounter(m_Phidget);
251
+ Init_phidgets_native_gps(m_Phidget);
252
+ Init_phidgets_native_interfacekit(m_Phidget);
253
+ Init_phidgets_native_ir(m_Phidget);
254
+ Init_phidgets_native_led(m_Phidget);
255
+ Init_phidgets_native_motorcontrol(m_Phidget);
256
+ Init_phidgets_native_phsensor(m_Phidget);
257
+ Init_phidgets_native_rfid(m_Phidget);
258
+ Init_phidgets_native_servo(m_Phidget);
259
+ Init_phidgets_native_spatial(m_Phidget);
260
+ Init_phidgets_native_stepper(m_Phidget);
261
+ Init_phidgets_native_temperaturesensor(m_Phidget);
262
+ Init_phidgets_native_textlcd(m_Phidget);
263
+ Init_phidgets_native_textled(m_Phidget);
264
+ Init_phidgets_native_weightsensor(m_Phidget);
265
+ }
266
+
267
+
268
+ CPhidgetLog_level sym_to_log_level(VALUE log_sym) {
269
+ const char *log_level_str;
270
+
271
+ if (TYPE(log_sym) != T_SYMBOL)
272
+ rb_raise(rb_eTypeError, MSG_INVALID_LOG_LEVEL);
273
+
274
+ log_level_str = rb_id2name(SYM2ID(log_sym));
275
+
276
+ if (strcmp("critical", log_level_str) == 0)
277
+ return PHIDGET_LOG_CRITICAL;
278
+ else if (strcmp("error", log_level_str) == 0)
279
+ return PHIDGET_LOG_ERROR;
280
+ else if (strcmp("warning", log_level_str) == 0)
281
+ return PHIDGET_LOG_WARNING;
282
+ else if (strcmp("debug", log_level_str) == 0)
283
+ return PHIDGET_LOG_DEBUG;
284
+ else if (strcmp("info", log_level_str) == 0)
285
+ return PHIDGET_LOG_INFO;
286
+ else if (strcmp("verbose", log_level_str) == 0)
287
+ return PHIDGET_LOG_VERBOSE;
288
+
289
+ rb_raise(rb_eTypeError, MSG_INVALID_LOG_LEVEL);
290
+
291
+ return 0;
292
+ }
293
+
294
+ VALUE phidget_enable_logging(int argc, VALUE *argv, VALUE class) {
295
+ VALUE log_level;
296
+ VALUE file_path;
297
+
298
+ CPhidgetLog_level phidget_log_level;
299
+ const char *file_path_str;
300
+
301
+ rb_scan_args(argc, argv, "11", &log_level, &file_path);
302
+
303
+ phidget_log_level = sym_to_log_level(log_level);
304
+
305
+ if (TYPE(file_path) == T_STRING)
306
+ file_path_str = StringValueCStr(file_path);
307
+ else if( TYPE(file_path) == T_NIL)
308
+ file_path_str = NULL;
309
+ else
310
+ rb_raise(rb_eTypeError, MSG_FILE_PATH_MUST_BE_STRING);
311
+
312
+ ensure(CPhidget_enableLogging(phidget_log_level,file_path_str));
313
+
314
+ return Qnil;
315
+ }
316
+
317
+ VALUE phidget_disable_logging(VALUE class) {
318
+ ensure(CPhidget_disableLogging());
319
+
320
+ return Qnil;
321
+ }
322
+
323
+ VALUE phidget_log(VALUE class, VALUE log_level, VALUE message) {
324
+ CPhidgetLog_level phidget_log_level;
325
+
326
+ if (TYPE(message) != T_STRING) rb_raise(rb_eTypeError, MSG_INVALID_MESSAGE_STRING);
327
+
328
+ phidget_log_level = sym_to_log_level(log_level);
329
+
330
+ // I really don't know what that second parameter does. It doesn't seem too useful.
331
+ ensure(CPhidget_log(phidget_log_level, "N/A", "%s", StringValueCStr(message)));
332
+
333
+ return Qnil;
334
+ }
335
+
336
+ VALUE phidget_all(VALUE class) {
337
+ int num_devices = 0;
338
+ int *serial_number;
339
+ const char **device_type;
340
+ CPhidget_DeviceClass *device_class;
341
+
342
+ CPhidgetHandle *handles;
343
+ CPhidgetManagerHandle man_handle = 0;
344
+
345
+ // First we enumerate all the devices and note the serial and type:
346
+ ensure(CPhidgetManager_create(&man_handle));
347
+ ensure(CPhidgetManager_open(man_handle));
348
+
349
+ // I'm not sure that this is the "right" amount of time, but it seems to do
350
+ // well enough:
351
+ usleep(500000);
352
+
353
+ ensure(CPhidgetManager_getAttachedDevices(man_handle, &handles, &num_devices));
354
+
355
+ serial_number = ALLOC_N(int, num_devices);
356
+ device_type = ALLOC_N(const char*, num_devices);
357
+ device_class = ALLOC_N(CPhidget_DeviceClass, num_devices);
358
+
359
+ for( int i=0; i<num_devices; i++) {
360
+ ensure(CPhidget_getSerialNumber(handles[i], &serial_number[i]));
361
+ ensure(CPhidget_getDeviceType(handles[i], &device_type[i]));
362
+ ensure(CPhidget_getDeviceClass(handles[i], &device_class[i]));
363
+ }
364
+
365
+ // Then we free the Phidget library resources
366
+ ensure(CPhidgetManager_freeAttachedDevicesArray(handles));
367
+ ensure(CPhidgetManager_close(man_handle));
368
+ ensure(CPhidgetManager_delete(man_handle));
369
+
370
+ // So it *seems* that if we don't sleep here, that sometimes the wait_for_attachment
371
+ // below will segfault. I'm guessing that there's a thread still running for a short
372
+ // bit, after we call the delete on the manager, which conflicts with the device
373
+ // handle below
374
+ usleep(500000);
375
+
376
+ // And start constructing the ruby return value:
377
+ VALUE devices = rb_ary_new2(num_devices);
378
+ VALUE phidget_module = rb_const_get(rb_cObject, rb_intern("PhidgetsNative"));
379
+
380
+ for(int i=0; i<num_devices; i++) {
381
+ ID class_const;
382
+ VALUE c_Exception;
383
+ VALUE device_klass;
384
+ VALUE device_instance;
385
+
386
+ VALUE *args = ALLOC_N(VALUE, 1);
387
+ args[0] = INT2FIX(serial_number[i]);
388
+
389
+ switch (device_class[i]) {
390
+ case PHIDCLASS_ACCELEROMETER:
391
+ class_const = rb_intern("Accelerometer");
392
+ break;
393
+ case PHIDCLASS_ADVANCEDSERVO:
394
+ class_const = rb_intern("AdvancedServo");
395
+ break;
396
+ case PHIDCLASS_ANALOG:
397
+ class_const = rb_intern("Analog");
398
+ break;
399
+ case PHIDCLASS_BRIDGE:
400
+ class_const = rb_intern("Bridge");
401
+ break;
402
+ case PHIDCLASS_ENCODER:
403
+ class_const = rb_intern("Encoder");
404
+ break;
405
+ case PHIDCLASS_FREQUENCYCOUNTER:
406
+ class_const = rb_intern("FrequencyCounter");
407
+ break;
408
+ case PHIDCLASS_GPS:
409
+ class_const = rb_intern("GPS");
410
+ break;
411
+ case PHIDCLASS_INTERFACEKIT:
412
+ class_const = rb_intern("InterfaceKit");
413
+ break;
414
+ case PHIDCLASS_IR:
415
+ class_const = rb_intern("IR");
416
+ break;
417
+ case PHIDCLASS_LED:
418
+ class_const = rb_intern("LED");
419
+ break;
420
+ case PHIDCLASS_MOTORCONTROL:
421
+ class_const = rb_intern("MotorControl");
422
+ break;
423
+ case PHIDCLASS_PHSENSOR:
424
+ class_const = rb_intern("PHSensor");
425
+ break;
426
+ case PHIDCLASS_RFID:
427
+ class_const = rb_intern("RFID");
428
+ break;
429
+ case PHIDCLASS_SERVO:
430
+ class_const = rb_intern("Servo");
431
+ break;
432
+ case PHIDCLASS_SPATIAL:
433
+ class_const = rb_intern("Spatial");
434
+ break;
435
+ case PHIDCLASS_STEPPER:
436
+ class_const = rb_intern("Stepper");
437
+ break;
438
+ case PHIDCLASS_TEMPERATURESENSOR:
439
+ class_const = rb_intern("TemperatureSensor");
440
+ break;
441
+ case PHIDCLASS_TEXTLCD:
442
+ class_const = rb_intern("TextLCD");
443
+ break;
444
+ case PHIDCLASS_TEXTLED:
445
+ class_const = rb_intern("TextLED");
446
+ break;
447
+ case PHIDCLASS_WEIGHTSENSOR:
448
+ class_const = rb_intern("WeightSensor");
449
+ break;
450
+ default:
451
+ c_Exception = rb_const_get(phidget_module, rb_intern("UnsupportedError"));
452
+ rb_raise(c_Exception, "%s \"%s\"", MSG_UNSUPPORTED_DEVICE_ENUMERATED, device_type[i]);
453
+ }
454
+
455
+ device_klass = rb_const_get(phidget_module, class_const);
456
+ device_instance = rb_class_new_instance(1, args, device_klass);
457
+ rb_funcall(device_instance, rb_intern("wait_for_attachment"), 1, INT2FIX(1000));
458
+ rb_ary_store(devices, i, device_instance);
459
+
460
+ xfree(args);
461
+ }
462
+
463
+ xfree(serial_number);
464
+ xfree(device_type);
465
+ xfree(device_class);
466
+
467
+ return devices;
468
+ }
@@ -0,0 +1,32 @@
1
+ #include "phidgets_native.h"
2
+
3
+ /*
4
+ * Document-class: PhidgetsNative::PHSensor < 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_phsensor(VALUE m_Phidget) {
11
+ VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
12
+
13
+ VALUE c_PHSensor = rb_define_class_under(m_Phidget, "PHSensor", 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_PHSensor, "initialize", phsensor_initialize, 1);
24
+ }
25
+
26
+ VALUE phsensor_initialize(VALUE self, VALUE serial) {
27
+ PhidgetInfo *info = device_info(self);
28
+ CPhidgetPHSensorHandle phsensor = 0;
29
+ ensure(CPhidgetPHSensor_create(&phsensor));
30
+ info->handle = (CPhidgetHandle)phsensor ;
31
+ return rb_call_super(1, &serial);
32
+ }
@@ -0,0 +1,31 @@
1
+ #include "phidgets_native.h"
2
+
3
+ /*
4
+ * Document-class: PhidgetsNative::RFID < 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_rfid(VALUE m_Phidget) {
11
+ VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
12
+ VALUE c_RFID = rb_define_class_under(m_Phidget, "RFID", c_Device);
13
+
14
+ /*
15
+ * Document-method: new
16
+ * call-seq:
17
+ * new(serial_number)
18
+ *
19
+ * All phidget objects are created from the device serial number. Serial numbers
20
+ * are required to be Fixnums (aka "unsigned integers").
21
+ */
22
+ rb_define_method(c_RFID, "initialize", rfid_initialize, 1);
23
+ }
24
+
25
+ VALUE rfid_initialize(VALUE self, VALUE serial) {
26
+ PhidgetInfo *info = device_info(self);
27
+ CPhidgetRFIDHandle rfid = 0;
28
+ ensure(CPhidgetRFID_create(&rfid));
29
+ info->handle = (CPhidgetHandle)rfid;
30
+ return rb_call_super(1, &serial);
31
+ }
@@ -0,0 +1,31 @@
1
+ #include "phidgets_native.h"
2
+
3
+ /*
4
+ * Document-class: PhidgetsNative::Servo < 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_servo(VALUE m_Phidget) {
11
+ VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
12
+ VALUE c_Servo = rb_define_class_under(m_Phidget, "Servo", c_Device);
13
+
14
+ /*
15
+ * Document-method: new
16
+ * call-seq:
17
+ * new(serial_number)
18
+ *
19
+ * All phidget objects are created from the device serial number. Serial numbers
20
+ * are required to be Fixnums (aka "unsigned integers").
21
+ */
22
+ rb_define_method(c_Servo, "initialize", servo_initialize, 1);
23
+ }
24
+
25
+ VALUE servo_initialize(VALUE self, VALUE serial) {
26
+ PhidgetInfo *info = device_info(self);
27
+ CPhidgetServoHandle servo = 0;
28
+ ensure(CPhidgetServo_create(&servo));
29
+ info->handle = (CPhidgetHandle)servo;
30
+ return rb_call_super(1, &serial);
31
+ }