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,107 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_textled_init(VALUE self);
|
6
|
+
VALUE ph_textled_get_row_count(VALUE self);
|
7
|
+
VALUE ph_textled_get_column_count(VALUE self);
|
8
|
+
VALUE ph_textled_get_brightness(VALUE self);
|
9
|
+
VALUE ph_textled_set_brightness(VALUE self, VALUE brightness);
|
10
|
+
VALUE ph_textled_set_display_string(VALUE self, VALUE index, VALUE string);
|
11
|
+
|
12
|
+
|
13
|
+
VALUE Init_phidgets_textled(VALUE ph_module, VALUE ph_common) {
|
14
|
+
VALUE ph_textled = rb_define_class_under(ph_module, "TextLED", ph_common);
|
15
|
+
|
16
|
+
/* Document-method: new
|
17
|
+
* call-seq: new
|
18
|
+
*
|
19
|
+
* Creates a Phidget TextLED object.
|
20
|
+
*/
|
21
|
+
rb_define_method(ph_textled, "initialize", ph_textled_init, 0);
|
22
|
+
|
23
|
+
/* Document-method: getRowCount
|
24
|
+
* call-seq: getRowCount -> count
|
25
|
+
*
|
26
|
+
* Gets the number of rows supported by this display.
|
27
|
+
*/
|
28
|
+
rb_define_method(ph_textled, "getRowCount", ph_textled_get_row_count, 0);
|
29
|
+
|
30
|
+
/* Document-method: getColumnCount
|
31
|
+
* call-seq: getColumnCount -> count
|
32
|
+
*
|
33
|
+
* Gets the number of columns per supported by this display.
|
34
|
+
*/
|
35
|
+
rb_define_method(ph_textled, "getColumnCount", ph_textled_get_column_count, 0);
|
36
|
+
|
37
|
+
/* Document-method: getBrightness
|
38
|
+
* call-seq: getBrightness -> brightness
|
39
|
+
*
|
40
|
+
* Gets the last set brightness value.
|
41
|
+
*/
|
42
|
+
rb_define_method(ph_textled, "getBrightness", ph_textled_get_brightness, 0);
|
43
|
+
|
44
|
+
/* Document-method: setBrightness
|
45
|
+
* call-seq: setBrightness(brightness)
|
46
|
+
*
|
47
|
+
* Sets the last set brightness value.
|
48
|
+
*/
|
49
|
+
rb_define_method(ph_textled, "setBrightness", ph_textled_set_brightness, 1);
|
50
|
+
|
51
|
+
/* Document-method: setDisplayString
|
52
|
+
* call-seq: setDisplayString(index, string)
|
53
|
+
*
|
54
|
+
* Sets a row on the display.
|
55
|
+
*/
|
56
|
+
rb_define_method(ph_textled, "setDisplayString", ph_textled_set_display_string, 2);
|
57
|
+
|
58
|
+
rb_define_alias(ph_textled, "row_count", "getRowCount");
|
59
|
+
rb_define_alias(ph_textled, "column_count", "getColumnCount");
|
60
|
+
rb_define_alias(ph_textled, "brightness", "getBrightness");
|
61
|
+
rb_define_alias(ph_textled, "brightness=", "setBrightness");
|
62
|
+
rb_define_alias(ph_textled, "display_string", "setDisplayString");
|
63
|
+
|
64
|
+
return ph_textled;
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
VALUE ph_textled_init(VALUE self) {
|
70
|
+
ph_data_t *ph = get_ph_data(self);
|
71
|
+
ph_raise(CPhidgetTextLED_create((CPhidgetTextLEDHandle *)(&(ph->handle))));
|
72
|
+
return self;
|
73
|
+
}
|
74
|
+
|
75
|
+
VALUE ph_textled_get_row_count(VALUE self) {
|
76
|
+
CPhidgetTextLEDHandle handle = (CPhidgetTextLEDHandle)get_ph_handle(self);
|
77
|
+
int count;
|
78
|
+
ph_raise(CPhidgetTextLED_getRowCount(handle, &count));
|
79
|
+
return INT2FIX(count);
|
80
|
+
}
|
81
|
+
|
82
|
+
VALUE ph_textled_get_column_count(VALUE self) {
|
83
|
+
CPhidgetTextLEDHandle handle = (CPhidgetTextLEDHandle)get_ph_handle(self);
|
84
|
+
int count;
|
85
|
+
ph_raise(CPhidgetTextLED_getColumnCount(handle, &count));
|
86
|
+
return INT2FIX(count);
|
87
|
+
}
|
88
|
+
|
89
|
+
VALUE ph_textled_get_brightness(VALUE self) {
|
90
|
+
CPhidgetTextLEDHandle handle = (CPhidgetTextLEDHandle)get_ph_handle(self);
|
91
|
+
int brightness;
|
92
|
+
ph_raise(CPhidgetTextLED_getBrightness(handle, &brightness));
|
93
|
+
return INT2FIX(brightness);
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUE ph_textled_set_brightness(VALUE self, VALUE brightness) {
|
97
|
+
CPhidgetTextLEDHandle handle = (CPhidgetTextLEDHandle)get_ph_handle(self);
|
98
|
+
ph_raise(CPhidgetTextLED_setBrightness(handle, FIX2INT(brightness)));
|
99
|
+
return Qnil;
|
100
|
+
}
|
101
|
+
|
102
|
+
VALUE ph_textled_set_display_string(VALUE self, VALUE index, VALUE string) {
|
103
|
+
CPhidgetTextLEDHandle handle = (CPhidgetTextLEDHandle)get_ph_handle(self);
|
104
|
+
ph_raise(CPhidgetTextLED_setDisplayString(handle, FIX2INT(index), StringValueCStr(string)));
|
105
|
+
return Qnil;
|
106
|
+
}
|
107
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_weight_init(VALUE self);
|
6
|
+
VALUE ph_weight_get_weight(VALUE self);
|
7
|
+
VALUE ph_weight_get_weight_change_trigger(VALUE self);
|
8
|
+
VALUE ph_weight_set_weight_change_trigger(VALUE self, VALUE trigger);
|
9
|
+
|
10
|
+
#ifdef PH_CALLBACK
|
11
|
+
VALUE ph_weight_set_on_weight_change_handler(VALUE self, VALUE handler);
|
12
|
+
int ph_weight_on_weight_change(CPhidgetWeightSensorHandle phid, void *userPtr, double weight);
|
13
|
+
#endif
|
14
|
+
|
15
|
+
|
16
|
+
VALUE Init_phidgets_weight(VALUE ph_module, VALUE ph_common) {
|
17
|
+
VALUE ph_weight = rb_define_class_under(ph_module, "WeightSensor", ph_common);
|
18
|
+
|
19
|
+
/* Document-method: new
|
20
|
+
* call-seq: new
|
21
|
+
*
|
22
|
+
* Creates a Phidget WeightSensor object.
|
23
|
+
*/
|
24
|
+
rb_define_method(ph_weight, "initialize", ph_weight_init, 0);
|
25
|
+
|
26
|
+
/* Document-method: getWeight
|
27
|
+
* call-seq: getWeight -> weight
|
28
|
+
*
|
29
|
+
* Gets the sensed weight.
|
30
|
+
*/
|
31
|
+
rb_define_method(ph_weight, "getWeight", ph_weight_get_weight, 0);
|
32
|
+
|
33
|
+
/* Document-method: getWeightChangeTrigger
|
34
|
+
* call-seq: getWeightChangeTrigger -> trigger
|
35
|
+
*
|
36
|
+
* Gets the weight change trigger.
|
37
|
+
*/
|
38
|
+
rb_define_method(ph_weight, "getWeightChangeTrigger", ph_weight_get_weight_change_trigger, 0);
|
39
|
+
|
40
|
+
/* Document-method: setWeightChangeTrigger
|
41
|
+
* call-seq: setWeightChangeTrigger(trigger)
|
42
|
+
*
|
43
|
+
* Sets the weight change trigger.
|
44
|
+
*/
|
45
|
+
rb_define_method(ph_weight, "setWeightChangeTrigger", ph_weight_set_weight_change_trigger, 1);
|
46
|
+
|
47
|
+
#ifdef PH_CALLBACK
|
48
|
+
rb_define_private_method(ph_weight, "ext_setOnWeightChangeHandler", ph_weight_set_on_weight_change_handler, 1);
|
49
|
+
#endif
|
50
|
+
|
51
|
+
rb_define_alias(ph_weight, "weight", "getWeight");
|
52
|
+
rb_define_alias(ph_weight, "weight_change_trigger", "getWeightChangeTrigger");
|
53
|
+
rb_define_alias(ph_weight, "weight_change_trigger=", "setWeightChangeTrigger");
|
54
|
+
|
55
|
+
return ph_weight;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
VALUE ph_weight_init(VALUE self) {
|
61
|
+
ph_data_t *ph = get_ph_data(self);
|
62
|
+
ph_raise(CPhidgetWeightSensor_create((CPhidgetWeightSensorHandle *)(&(ph->handle))));
|
63
|
+
return self;
|
64
|
+
}
|
65
|
+
|
66
|
+
VALUE ph_weight_get_weight(VALUE self) {
|
67
|
+
CPhidgetWeightSensorHandle handle = (CPhidgetWeightSensorHandle)get_ph_handle(self);
|
68
|
+
double weight;
|
69
|
+
ph_raise(CPhidgetWeightSensor_getWeight(handle, &weight));
|
70
|
+
return rb_float_new(weight);
|
71
|
+
}
|
72
|
+
|
73
|
+
VALUE ph_weight_get_weight_change_trigger(VALUE self) {
|
74
|
+
CPhidgetWeightSensorHandle handle = (CPhidgetWeightSensorHandle)get_ph_handle(self);
|
75
|
+
double trigger;
|
76
|
+
ph_raise(CPhidgetWeightSensor_getWeightChangeTrigger(handle, &trigger));
|
77
|
+
return rb_float_new(trigger);
|
78
|
+
}
|
79
|
+
|
80
|
+
VALUE ph_weight_set_weight_change_trigger(VALUE self, VALUE trigger) {
|
81
|
+
CPhidgetWeightSensorHandle handle = (CPhidgetWeightSensorHandle)get_ph_handle(self);
|
82
|
+
ph_raise(CPhidgetWeightSensor_setWeightChangeTrigger(handle, NUM2DBL(trigger)));
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
#ifdef PH_CALLBACK
|
88
|
+
VALUE ph_weight_set_on_weight_change_handler(VALUE self, VALUE handler) {
|
89
|
+
ph_data_t *ph = get_ph_data(self);
|
90
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_1;
|
91
|
+
if( TYPE(handler) == T_NIL ) {
|
92
|
+
callback_data->exit = true;
|
93
|
+
ph_raise(CPhidgetWeightSensor_set_OnWeightChange_Handler((CPhidgetWeightSensorHandle)ph->handle, NULL, (void *)NULL));
|
94
|
+
} else {
|
95
|
+
callback_data->called = false;
|
96
|
+
callback_data->exit = false;
|
97
|
+
callback_data->phidget = self;
|
98
|
+
callback_data->callback = handler;
|
99
|
+
ph_raise(CPhidgetWeightSensor_set_OnWeightChange_Handler((CPhidgetWeightSensorHandle)ph->handle, ph_weight_on_weight_change, (void *)callback_data));
|
100
|
+
ph_callback_thread(callback_data);
|
101
|
+
}
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
int ph_weight_on_weight_change(CPhidgetWeightSensorHandle phid, void *userPtr, double weight) {
|
107
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
108
|
+
callback_data->called = true;
|
109
|
+
return EPHIDGET_OK;
|
110
|
+
}
|
111
|
+
|
112
|
+
#endif
|
113
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class Accelerometer < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnAccelerationChangeHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Sets an acceleration change event handler. This is called when the acceleration changes by more then the change trigger.
|
12
|
+
#
|
13
|
+
def setOnAccelerationChangeHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_acceleration_change_thread.kill if defined? @on_acceleration_change_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_acceleration_change_thread = Thread.new {ext_setOnAccelerationChangeHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :on_acceleration_change :setOnAccelerationChangeHandler
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class AdvancedServo < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnVelocityChangeHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Sets a velocity change event handler. This is called when the velocity changes.
|
12
|
+
#
|
13
|
+
def setOnVelocityChangeHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_velocity_change_thread.kill if defined? @on_velocity_change_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_velocity_change_thread = Thread.new {ext_setOnVelocityChangeHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq:
|
20
|
+
# setOnPositionChangeHandler(proc=nil, &block)
|
21
|
+
#
|
22
|
+
# Sets a position change event handler. This is called when the position changes.
|
23
|
+
#
|
24
|
+
def setOnPositionChangeHandler(cb_proc = nil, &cb_block)
|
25
|
+
@on_position_change_thread.kill if defined? @on_position_change_thread
|
26
|
+
callback = cb_proc || cb_block
|
27
|
+
@on_position_change_thread = Thread.new {ext_setOnPositionChangeHandler(callback)}
|
28
|
+
end
|
29
|
+
|
30
|
+
# call-seq:
|
31
|
+
# setOnCurrentChangeHandler(proc=nil, &block)
|
32
|
+
#
|
33
|
+
# Sets a current change event handler. This is called when the current draw changes.
|
34
|
+
#
|
35
|
+
def setOnCurrentChangeHandler(cb_proc = nil, &cb_block)
|
36
|
+
@on_current_change_thread.kill if defined? @on_current_change_thread
|
37
|
+
callback = cb_proc || cb_block
|
38
|
+
@on_current_change_thread = Thread.new {ext_setOnCurrentChangeHandler(callback)}
|
39
|
+
end
|
40
|
+
|
41
|
+
alias :on_velocity_change :setOnVelocityChangeHandler
|
42
|
+
alias :on_position_change :setOnPositionChangeHandler
|
43
|
+
alias :on_current_change :setOnCurrentChangeHandler
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class Bridge < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnBridgeDataHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Sets a bridge data event handler. This is called at a set rate as defined by data rate.
|
12
|
+
#
|
13
|
+
def setOnBridgeDataHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_bridge_data_thread.kill if defined? @on_bridge_data_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_bridge_data_thread = Thread.new {ext_setOnBridgeDataHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :on_bridge_data :setOnBridgeDataHandler
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/phidgets/common.rb
CHANGED
@@ -1,200 +1,85 @@
|
|
1
1
|
|
2
2
|
module Phidgets
|
3
|
-
|
4
|
-
extern "int CPhidget_open(void *, int)"
|
5
|
-
extern "int CPhidget_openRemote(void *, int, void *, void *)"
|
6
|
-
extern "int CPhidget_openRemoteIP(void *, int, void *, int, void *)"
|
7
|
-
extern "int CPhidget_close(void *)"
|
8
|
-
extern "int CPhidget_delete(void *)"
|
9
|
-
extern "int CPhidget_getDeviceName(void *, void *)"
|
10
|
-
extern "int CPhidget_getSerialNumber(void *, int *)"
|
11
|
-
extern "int CPhidget_getDeviceVersion(void *, int *)"
|
12
|
-
extern "int CPhidget_getDeviceStatus(void *, int *)"
|
13
|
-
extern "int CPhidget_getDeviceType(void *, void *)"
|
14
|
-
extern "int CPhidget_getDeviceLabel(void *, void *)"
|
15
|
-
extern "int CPhidget_setDeviceLabel(void *, void *)"
|
16
|
-
extern "int CPhidget_waitForAttachment(void *, int)"
|
17
|
-
extern "int CPhidget_getServerID(void *, void *)"
|
18
|
-
extern "int CPhidget_getServerAddress(void *, void *, int *)"
|
19
|
-
extern "int CPhidget_getServerStatus(void *, int *)"
|
20
|
-
extern "int CPhidget_getDeviceID(void *, int *)"
|
21
|
-
extern "int CPhidget_getDeviceClass(void *, int *)"
|
22
|
-
|
23
3
|
class Common
|
24
4
|
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
# Gets the attached status of a Phidget.
|
101
|
-
def getDeviceStatus
|
102
|
-
stat = Phidgets.malloc(SIZEOF_INT)
|
103
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceStatus', @handle, stat.ref)
|
104
|
-
raise Phidgets::Exception.new(r) if r != 0
|
105
|
-
stat.free = nil
|
106
|
-
stat.to_i
|
107
|
-
end
|
108
|
-
|
109
|
-
# Gets the type (class) of a Phidget.
|
110
|
-
def getDeviceType
|
111
|
-
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
112
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceType', @handle, ptr.ref)
|
113
|
-
raise Phidgets::Exception.new(r) if r != 0
|
114
|
-
ptr.free = nil
|
115
|
-
ptr.to_s
|
116
|
-
end
|
117
|
-
|
118
|
-
# Gets the label of a Phidget.
|
119
|
-
def getDeviceLabel
|
120
|
-
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
121
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceLabel', @handle, ptr.ref)
|
122
|
-
raise Phidgets::Exception.new(r) if r != 0
|
123
|
-
ptr.free = nil
|
124
|
-
ptr.to_s
|
125
|
-
end
|
126
|
-
|
127
|
-
# Sets the label of a Phidget. Note that this is not supported on very old Phidgets, and not yet supported in Windows.
|
128
|
-
# === Parameters
|
129
|
-
# * _label_ = A string containing the label to be set.
|
130
|
-
def setDeviceLabel(label)
|
131
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_setDeviceLabel', @handle, label)
|
132
|
-
raise Phidgets::Exception.new(r) if r != 0
|
133
|
-
end
|
134
|
-
|
135
|
-
# Waits for attachment to happen. This can be called right after calling open, as an alternative to using the attach handler.
|
136
|
-
# === Parameters
|
137
|
-
# * _timeout_ = Time to wait for the attachment. Specify 0 to wait forever.
|
138
|
-
def waitForAttachment(timeout)
|
139
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_waitForAttachment', @handle, timeout.to_i)
|
140
|
-
raise Phidgets::Exception.new(r) if r != 0
|
141
|
-
end
|
142
|
-
|
143
|
-
# Gets the server ID of a remotely opened Phidget. This will fail if the Phidget was opened locally.
|
144
|
-
def getServerID
|
145
|
-
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
146
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getServerID', @handle, ptr.ref)
|
147
|
-
raise Phidgets::Exception.new(r) if r != 0
|
148
|
-
ptr.free = nil
|
149
|
-
ptr.to_s
|
150
|
-
end
|
151
|
-
|
152
|
-
# Gets the address and port of a remotely opened Phidget. This will fail if the Phidget was opened locally.
|
153
|
-
def getServerAddress
|
154
|
-
ptr = Phidgets.malloc(SIZEOF_VOIDP)
|
155
|
-
port = Phidgets.malloc(SIZEOF_INT)
|
156
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getServerAddress', @handle, ptr.ref, port.ref)
|
157
|
-
raise Phidgets::Exception.new(r) if r != 0
|
158
|
-
ptr.free = nil
|
159
|
-
port.free = nil
|
160
|
-
[ptr.to_s, port.to_i]
|
161
|
-
end
|
162
|
-
|
163
|
-
# Gets the connected to server status of a remotely opened Phidget. This will fail if the Phidget was opened locally.
|
164
|
-
def getServerStatus
|
165
|
-
stat = Phidgets.malloc(SIZEOF_INT)
|
166
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getServerStatus', @handle, stat.ref)
|
167
|
-
raise Phidgets::Exception.new(r) if r != 0
|
168
|
-
stat.free = nil
|
169
|
-
stat.to_i
|
170
|
-
end
|
171
|
-
|
172
|
-
# Gets the device ID of a Phidget.
|
173
|
-
def getDeviceID
|
174
|
-
dev = Phidgets.malloc(SIZEOF_INT)
|
175
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceID', @handle, dev.ref)
|
176
|
-
raise Phidgets::Exception.new(r) if r != 0
|
177
|
-
dev.free = nil
|
178
|
-
dev.to_i
|
179
|
-
end
|
5
|
+
# call-seq:
|
6
|
+
# open(args)
|
7
|
+
#
|
8
|
+
# Opens a Phidget. Will attempt to make the correct open call (openLabel, openRemote, openRemoteIP, etc)
|
9
|
+
# based on the arguments passed in. Args can either be a serial number or a hash of arguments. If it is a
|
10
|
+
# hash, the following keys may be used: :serial_number, :label, :server_id, :address, :port, :password.
|
11
|
+
#
|
12
|
+
def open(args)
|
13
|
+
args = {:serial_number => args.to_i} unless args.is_a? Hash
|
14
|
+
if args.key? :server_id
|
15
|
+
return open_remote(args[:serial_number], args[:server_id], args[:password]) if args.key? :serial_number
|
16
|
+
return open_label_remote(args[:label], args[:server_id], args[:password]) if args.key? :label
|
17
|
+
elsif args.key? :address
|
18
|
+
return open_remote_ip(args[:serial_number], args[:address], args[:port], args[:password]) if args.key? :serial_number
|
19
|
+
return open_label_remote_ip(args[:label], args[:address], args[:port], args[:password]) if args.key? :label
|
20
|
+
else
|
21
|
+
return ext_open(args[:serial_number]) if args.key? :serial_number
|
22
|
+
return open_label(args[:label]) if args.key? :label
|
23
|
+
end
|
24
|
+
raise Phidgets::Error::InvalidArg.new
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
unless RUBY_VERSION < '1.9.0'
|
29
|
+
|
30
|
+
# call-seq:
|
31
|
+
# setOnAttachHandler(proc=nil, &block)
|
32
|
+
#
|
33
|
+
# Sets an attach handler callback function. This is called when this Phidget is plugged into the system, and is ready for use.
|
34
|
+
#
|
35
|
+
def setOnAttachHandler(cb_proc = nil, &cb_block)
|
36
|
+
@on_attach_thread.kill if defined? @on_attach_thread
|
37
|
+
callback = cb_proc || cb_block
|
38
|
+
@on_attach_thread = Thread.new {ext_setOnAttachHandler(callback)}
|
39
|
+
end
|
40
|
+
|
41
|
+
# call-seq:
|
42
|
+
# setOnDetachHandler(proc=nil, &block)
|
43
|
+
#
|
44
|
+
# Sets a detach handler callback function. This is called when this Phidget is unplugged from the system.
|
45
|
+
#
|
46
|
+
def setOnDetachHandler(cb_proc = nil, &cb_block)
|
47
|
+
@on_detach_thread.kill if defined? @on_detach_thread
|
48
|
+
callback = cb_proc || cb_block
|
49
|
+
@on_detach_thread = Thread.new {ext_setOnDetachHandler(callback)}
|
50
|
+
end
|
51
|
+
|
52
|
+
# call-seq:
|
53
|
+
# setOnServerConnectHandler(proc=nil, &block)
|
54
|
+
#
|
55
|
+
# Sets a server connect handler callback function. This is used for opening Phidgets remotely,
|
56
|
+
# and is called when a connection to the sever has been made.
|
57
|
+
#
|
58
|
+
def setOnServerConnectHandler(cb_proc = nil, &cb_block)
|
59
|
+
@on_server_connect_thread.kill if defined? @on_server_connect_thread
|
60
|
+
callback = cb_proc || cb_block
|
61
|
+
@on_server_connect_thread = Thread.new {ext_setOnServerConnectHandler(callback)}
|
62
|
+
end
|
63
|
+
|
64
|
+
# call-seq:
|
65
|
+
# setOnServerDisconnectHandler(proc=nil, &block)
|
66
|
+
#
|
67
|
+
# Sets a server disconnect handler callback function. This is used for opening Phidgets remotely,
|
68
|
+
# and is called when a connection to the server has been lost.
|
69
|
+
#
|
70
|
+
def setOnServerDisconnectHandler(cb_proc = nil, &cb_block)
|
71
|
+
@on_server_disconnect_thread.kill if defined? @on_server_disconnect_thread
|
72
|
+
callback = cb_proc || cb_block
|
73
|
+
@on_server_disconnect_thread = Thread.new {ext_setOnServerDisconnectHandler(callback)}
|
74
|
+
end
|
75
|
+
|
76
|
+
alias :on_attach :setOnAttachHandler
|
77
|
+
alias :on_detach :setOnDetachHandler
|
78
|
+
alias :on_server_connect :setOnServerConnectHandler
|
79
|
+
alias :on_server_disconnect :setOnServerDisconnectHandler
|
180
80
|
|
181
|
-
# Gets the class of a Phidget.
|
182
|
-
def getDeviceClass
|
183
|
-
dev = Phidgets.malloc(SIZEOF_INT)
|
184
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'Phidget_getDeviceClass', @handle, dev.ref)
|
185
|
-
raise Phidgets::Exception.new(r) if r != 0
|
186
|
-
dev.free = nil
|
187
|
-
dev.to_i
|
188
|
-
end
|
189
|
-
|
190
|
-
|
191
|
-
private
|
192
|
-
|
193
|
-
def initialize
|
194
|
-
@handle = Phidgets.malloc(SIZEOF_VOIDP)
|
195
81
|
end
|
196
82
|
|
197
83
|
end
|
198
|
-
|
199
84
|
end
|
200
85
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
module Phidgets
|
3
|
+
class Dictionary
|
4
|
+
|
5
|
+
# call-seq:
|
6
|
+
# open(args)
|
7
|
+
#
|
8
|
+
# Opens a Dictionary. Will attempt to make the correct open call (openRemote, openRemoteIP) based
|
9
|
+
# on the arguments passed in. Args is a hash and the following keys may be used:
|
10
|
+
# :server_id, :address, :port, :password.
|
11
|
+
#
|
12
|
+
def open(args)
|
13
|
+
if args.key? :server_id
|
14
|
+
return open_remote(args[:server_id], args[:password])
|
15
|
+
elsif args.key? :address
|
16
|
+
return open_remote_ip(args[:address], args[:port], args[:password])
|
17
|
+
end
|
18
|
+
raise Phidgets::Error::InvalidArg.new
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
unless RUBY_VERSION < '1.9.0'
|
23
|
+
|
24
|
+
# call-seq:
|
25
|
+
# setOnServerConnectHandler(proc=nil, &block)
|
26
|
+
#
|
27
|
+
# Sets a server connect handler callback function. This is called when a connection to the sever has been made.
|
28
|
+
#
|
29
|
+
def setOnServerConnectHandler(cb_proc = nil, &cb_block)
|
30
|
+
@on_server_connect_thread.kill if defined? @on_server_connect_thread
|
31
|
+
callback = cb_proc || cb_block
|
32
|
+
@on_server_connect_thread = Thread.new {ext_setOnServerConnectHandler(callback)}
|
33
|
+
end
|
34
|
+
|
35
|
+
# call-seq:
|
36
|
+
# setOnServerDisconnectHandler(proc=nil, &block)
|
37
|
+
#
|
38
|
+
# Sets a server disconnect handler callback function. This is called when a connection to the server has been lost.
|
39
|
+
#
|
40
|
+
def setOnServerDisconnectHandler(cb_proc = nil, &cb_block)
|
41
|
+
@on_server_disconnect_thread.kill if defined? @on_server_disconnect_thread
|
42
|
+
callback = cb_proc || cb_block
|
43
|
+
@on_server_disconnect_thread = Thread.new {ext_setOnServerDisconnectHandler(callback)}
|
44
|
+
end
|
45
|
+
|
46
|
+
alias :on_server_connect :setOnServerConnectHandler
|
47
|
+
alias :on_server_disconnect :setOnServerDisconnectHandler
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|