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,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class PHSensor < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnPHChangeHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Set a PH change handler. This is called when the PH changes by more then the change trigger.
|
12
|
+
#
|
13
|
+
def setOnPHChangeHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_ph_change_thread.kill if defined? @on_ph_change_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_ph_change_thread = Thread.new {ext_setOnPHChangeHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :on_ph_change :setOnPHChangeHandler
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/phidgets/rfid.rb
CHANGED
@@ -1,122 +1,49 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
module Phidgets
|
4
|
-
|
5
|
-
extern "int CPhidgetRFID_create(void *)"
|
6
|
-
extern "int CPhidgetRFID_getOutputCount(void *, int *)"
|
7
|
-
extern "int CPhidgetRFID_getOutputState(void *, int, int *)"
|
8
|
-
extern "int CPhidgetRFID_setOutputState(void *, int, int)"
|
9
|
-
extern "int CPhidgetRFID_getAntennaOn(void *, int *)"
|
10
|
-
extern "int CPhidgetRFID_setAntennaOn(void *, int)"
|
11
|
-
extern "int CPhidgetRFID_getLEDOn(void *, int *)"
|
12
|
-
extern "int CPhidgetRFID_setLEDOn(void *, int)"
|
13
|
-
extern "int CPhidgetRFID_getLastTag(void *, void *)"
|
14
|
-
extern "int CPhidgetRFID_getTagStatus(void *, int *)"
|
15
|
-
|
16
|
-
|
17
4
|
class RFID < Common
|
18
5
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
# Gets the state of the antenna.
|
59
|
-
def getAntennaOn
|
60
|
-
state = Phidgets.malloc(SIZEOF_INT)
|
61
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getAntennaOn', @handle, state.ref)
|
62
|
-
raise Phidgets::Exception.new(r) if r != 0
|
63
|
-
state.free = nil
|
64
|
-
state.to_i
|
65
|
-
end
|
66
|
-
|
67
|
-
# Sets the state of the antenna. Note that the antenna must be enabled before tags will be read.
|
68
|
-
# === Parameters
|
69
|
-
# * _state_ = The antenna state. Possible values are PTRUE and PFALSE.
|
70
|
-
def setAntennaOn(state)
|
71
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setAntennaOn', @handle, state.to_i)
|
72
|
-
raise Phidgets::Exception.new(r) if r != 0
|
73
|
-
end
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnTagHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Set a tag handler. This is called when a tag is first detected by the reader.
|
12
|
+
#
|
13
|
+
def setOnTagHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_tag_thread.kill if defined? @on_tag_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_tag_thread = Thread.new {ext_setOnTagHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq:
|
20
|
+
# setOnTagLostHandler(proc=nil, &block)
|
21
|
+
#
|
22
|
+
# Set a tag lost handler. This is called when a tag is no longer detected by the reader.
|
23
|
+
#
|
24
|
+
def setOnTagLostHandler(cb_proc = nil, &cb_block)
|
25
|
+
@on_tag_lost_thread.kill if defined? @on_tag_lost_thread
|
26
|
+
callback = cb_proc || cb_block
|
27
|
+
@on_tag_lost_thread = Thread.new {ext_setOnTagLostHandler(callback)}
|
28
|
+
end
|
29
|
+
|
30
|
+
# call-seq:
|
31
|
+
# setOnOutputChangeHandler(proc=nil, &block)
|
32
|
+
#
|
33
|
+
# Set an output change handler. This is called when an output changes.
|
34
|
+
#
|
35
|
+
def setOnOutputChangeHandler(cb_proc = nil, &cb_block)
|
36
|
+
@on_output_change_thread.kill if defined? @on_output_change_thread
|
37
|
+
callback = cb_proc || cb_block
|
38
|
+
@on_output_change_thread = Thread.new {ext_setOnOutputChangeHandler(callback)}
|
39
|
+
end
|
40
|
+
|
41
|
+
alias :on_tag :setOnTagHandler
|
42
|
+
alias :on_tag_lost :setOnTagLostHandler
|
43
|
+
alias :on_output_change :setOnOutputChangeHandler
|
74
44
|
|
75
|
-
# Gets the state of the onboard LED.
|
76
|
-
def getLedOn
|
77
|
-
state = Phidgets.malloc(SIZEOF_INT)
|
78
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getLEDOn', @handle, state.ref)
|
79
|
-
raise Phidgets::Exception.new(r) if r != 0
|
80
|
-
state.free = nil
|
81
|
-
state.to_i
|
82
|
-
end
|
83
|
-
|
84
|
-
# Sets the state of the onboard LED.
|
85
|
-
# === Parameters
|
86
|
-
# * _state_ = The LED state. Possible values are PTRUE and PFALSE.
|
87
|
-
def setLedOn(state)
|
88
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_setLEDOn', @handle, state.to_i)
|
89
|
-
raise Phidgets::Exception.new(r) if r != 0
|
90
|
-
end
|
91
|
-
|
92
|
-
# Gets the last tag read by the reader. This tag may or may not still be on the reader.
|
93
|
-
def getLastTag
|
94
|
-
tag = Phidgets.malloc(SIZEOF_VOIDP)
|
95
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getLastTag', @handle, tag.ref)
|
96
|
-
raise Phidgets::Exception.new(r) if r != 0
|
97
|
-
tag.free = nil
|
98
|
-
tag.to_s
|
99
|
-
end
|
100
|
-
|
101
|
-
# Gets the tag present status. This is whether or not a tag is being read by the reader.
|
102
|
-
def getTagStatus
|
103
|
-
stat = Phidgets.malloc(SIZEOF_INT)
|
104
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_getTagStatus', @handle, stat.ref)
|
105
|
-
raise Phidgets::Exception.new(r) if r != 0
|
106
|
-
stat.free = nil
|
107
|
-
stat.to_i
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
private
|
112
|
-
|
113
|
-
# Creates a Phidget RFID handle.
|
114
|
-
def create
|
115
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetRFID_create', @handle.ref)
|
116
|
-
raise Phidgets::Exception.new(r) if r != 0
|
117
45
|
end
|
118
46
|
|
119
47
|
end
|
120
|
-
|
121
48
|
end
|
122
49
|
|
data/lib/phidgets/servo.rb
CHANGED
@@ -1,106 +1,23 @@
|
|
1
1
|
|
2
2
|
module Phidgets
|
3
|
-
|
4
|
-
extern "int CPhidgetServo_create(void *)"
|
5
|
-
extern "int CPhidgetServo_getMotorCount(void *, int *)"
|
6
|
-
extern "int CPhidgetServo_getPosition(void *, int, double *)"
|
7
|
-
extern "int CPhidgetServo_setPosition(void *, int, double)"
|
8
|
-
extern "int CPhidgetServo_getPositionMax(void *, int, double *)"
|
9
|
-
extern "int CPhidgetServo_getPositionMin(void *, int, double *)"
|
10
|
-
extern "int CPhidgetServo_getEngaged(void *, int, int *)"
|
11
|
-
extern "int CPhidgetServo_setEngaged(void *, int, int)"
|
12
|
-
|
13
3
|
class Servo < Common
|
14
4
|
|
15
|
-
|
16
|
-
# === Parameters
|
17
|
-
# * _serial_number_ = Serial number of the phidget board to open. Specify -1 to open any.
|
18
|
-
# * _timeout_ = Time to wait for attachment. Specify 0 to not call open.
|
19
|
-
def initialize(serial_number=-1, timeout=0)
|
20
|
-
super()
|
21
|
-
create
|
22
|
-
open(serial_number, timeout) if timeout > 0
|
23
|
-
end
|
5
|
+
unless RUBY_VERSION < '1.9.0'
|
24
6
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
7
|
+
# call-seq:
|
8
|
+
# setOnPositionChangeHandler(proc=nil, &block)
|
9
|
+
#
|
10
|
+
# Sets a position change event handler. This is called when the position changes.
|
11
|
+
#
|
12
|
+
def setOnPositionChangeHandler(cb_proc = nil, &cb_block)
|
13
|
+
@on_position_change_thread.kill if defined? @on_position_change_thread
|
14
|
+
callback = cb_proc || cb_block
|
15
|
+
@on_position_change_thread = Thread.new {ext_setOnPositionChangeHandler(callback)}
|
16
|
+
end
|
33
17
|
|
34
|
-
|
35
|
-
# === Parameters
|
36
|
-
# * _index_ = The motor index.
|
37
|
-
def getPosition(index)
|
38
|
-
pos = Phidgets.malloc(SIZEOF_DOUBLE)
|
39
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPosition', @handle, index.to_i, pos.ref)
|
40
|
-
raise Phidgets::Exception.new(r) if r != 0
|
41
|
-
pos.free = nil
|
42
|
-
pos.to_f
|
43
|
-
end
|
44
|
-
|
45
|
-
# Sets the current position of a motor.
|
46
|
-
# === Parameters
|
47
|
-
# * _index_ = The motor index.
|
48
|
-
# * _position = The motor position.
|
49
|
-
def setPosition(index, position)
|
50
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setPosition', @handle, index.to_i, position.to_f)
|
51
|
-
raise Phidgets::Exception.new(r) if r != 0
|
52
|
-
end
|
53
|
-
|
54
|
-
# Gets the maximum position that a motor can be set to.
|
55
|
-
# === Parameters
|
56
|
-
# * _index_ = The motor index.
|
57
|
-
def getPositionMax(index)
|
58
|
-
pos = Phidgets.malloc(SIZEOF_DOUBLE)
|
59
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMax', @handle, index.to_i, pos.ref)
|
60
|
-
raise Phidgets::Exception.new(r) if r != 0
|
61
|
-
pos.free = nil
|
62
|
-
pos.to_f
|
63
|
-
end
|
64
|
-
|
65
|
-
# Gets the minimum position that a motor can be set to.
|
66
|
-
# === Parameters
|
67
|
-
# * _index_ = The motor index.
|
68
|
-
def getPositionMin(index)
|
69
|
-
pos = Phidgets.malloc(SIZEOF_DOUBLE)
|
70
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getPositionMin', @handle, index.to_i, pos.ref)
|
71
|
-
raise Phidgets::Exception.new(r) if r != 0
|
72
|
-
pos.free = nil
|
73
|
-
pos.to_f
|
74
|
-
end
|
75
|
-
|
76
|
-
# Gets the engaged state of a motor. This is whether the motor is powered or not.
|
77
|
-
# === Parameters
|
78
|
-
# * _index_ = The motor index.
|
79
|
-
def getEngaged(index)
|
80
|
-
eng = Phidgets.malloc(SIZEOF_INT)
|
81
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_getEngaged', @handle, index.to_i, eng.ref)
|
82
|
-
raise Phidgets::Exception.new(r) if r != 0
|
83
|
-
eng.free = nil
|
84
|
-
eng.to_i
|
85
|
-
end
|
86
|
-
|
87
|
-
# Sets the engaged state of a motor. This is whether the motor is powered or not.
|
88
|
-
# === Parameters
|
89
|
-
# * _index_ = The motor index.
|
90
|
-
# * _state_ = The engaged state. Possible values are PTRUE and PFALSE.
|
91
|
-
def setEngaged(index, state)
|
92
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_setEngaged', @handle, index.to_i, state.to_i)
|
93
|
-
raise Phidgets::Exception.new(r) if r != 0
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
18
|
+
alias :on_position_change :setOnPositionChangeHandler
|
97
19
|
|
98
|
-
# Creates a Phidget Servo handle.
|
99
|
-
def create
|
100
|
-
r = Phidgets.send(FUNCTION_PREFIX + 'PhidgetServo_create', @handle.ref)
|
101
|
-
raise Phidgets::Exception.new(r) if r != 0
|
102
20
|
end
|
103
21
|
|
104
22
|
end
|
105
|
-
|
106
23
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class Spatial < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnSpatialDataHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Set a Data event handler. This is called at getDataRate, up to 8ms.
|
12
|
+
#
|
13
|
+
def setOnSpatialDataHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_spatial_data_thread.kill if defined? @on_spatial_data_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_spatial_data_thread = Thread.new {ext_setOnSpatialDataHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :on_spatial_data :setOnSpatialDataHandler
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class Stepper < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnInputChangeHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Set a digital input change handler. This is called when a digital input changes.
|
12
|
+
#
|
13
|
+
def setOnInputChangeHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_input_change_thread.kill if defined? @on_input_change_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_input_change_thread = Thread.new {ext_setOnInputChangeHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq:
|
20
|
+
# setOnVelocityChangeHandler(proc=nil, &block)
|
21
|
+
#
|
22
|
+
# Sets a velocity change event handler. This is called when the velocity changes.
|
23
|
+
#
|
24
|
+
def setOnVelocityChangeHandler(cb_proc = nil, &cb_block)
|
25
|
+
@on_velocity_change_thread.kill if defined? @on_velocity_change_thread
|
26
|
+
callback = cb_proc || cb_block
|
27
|
+
@on_velocity_change_thread = Thread.new {ext_setOnVelocityChangeHandler(callback)}
|
28
|
+
end
|
29
|
+
|
30
|
+
# call-seq:
|
31
|
+
# setOnPositionChangeHandler(proc=nil, &block)
|
32
|
+
#
|
33
|
+
# Sets a position change event handler. This is called when the position changes.
|
34
|
+
#
|
35
|
+
def setOnPositionChangeHandler(cb_proc = nil, &cb_block)
|
36
|
+
@on_position_change_thread.kill if defined? @on_position_change_thread
|
37
|
+
callback = cb_proc || cb_block
|
38
|
+
@on_position_change_thread = Thread.new {ext_setOnPositionChangeHandler(callback)}
|
39
|
+
end
|
40
|
+
|
41
|
+
# call-seq:
|
42
|
+
# setOnCurrentChangeHandler(proc=nil, &block)
|
43
|
+
#
|
44
|
+
# Sets a current change event handler. This is called when the current draw changes.
|
45
|
+
#
|
46
|
+
def setOnCurrentChangeHandler(cb_proc = nil, &cb_block)
|
47
|
+
@on_current_change_thread.kill if defined? @on_current_change_thread
|
48
|
+
callback = cb_proc || cb_block
|
49
|
+
@on_current_change_thread = Thread.new {ext_setOnCurrentChangeHandler(callback)}
|
50
|
+
end
|
51
|
+
|
52
|
+
alias :on_input_change :setOnInputChangeHandler
|
53
|
+
alias :on_velocity_change :setOnVelocityChangeHandler
|
54
|
+
alias :on_position_change :setOnPositionChangeHandler
|
55
|
+
alias :on_current_change :setOnCurrentChangeHandler
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class TemperatureSensor < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnTemperatureChangeHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Set a temperature change handler. This is called when the temperature changes by more then the change trigger.
|
12
|
+
#
|
13
|
+
def setOnTemperatureChangeHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_temperature_change_thread.kill if defined? @on_temperature_change_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_temperature_change_thread = Thread.new {ext_setOnTemperatureChangeHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :on_temperature_change :setOnTemperatureChangeHandler
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Phidgets
|
4
|
+
class WeightSensor < Common
|
5
|
+
|
6
|
+
unless RUBY_VERSION < '1.9.0'
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# setOnWeightChangeHandler(proc=nil, &block)
|
10
|
+
#
|
11
|
+
# Set a weight change handler. This is called when the weight changes by more then the change trigger.
|
12
|
+
#
|
13
|
+
def setOnWeightChangeHandler(cb_proc = nil, &cb_block)
|
14
|
+
@on_weight_change_thread.kill if defined? @on_weight_change_thread
|
15
|
+
callback = cb_proc || cb_block
|
16
|
+
@on_weight_change_thread = Thread.new {ext_setOnWeightChangeHandler(callback)}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :on_weight_change :setOnWeightChangeHandler
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/phidgets.rb
CHANGED
@@ -1,13 +1,32 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
require File.dirname(__FILE__) + '/phidgets/phidgets.
|
4
|
+
require File.dirname(__FILE__) + '/phidgets.so' if FileTest.exists? "#{File.dirname(__FILE__)}/phidgets.so"
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/phidgets/dictionary.rb'
|
7
|
+
require File.dirname(__FILE__) + '/phidgets/manager.rb'
|
5
8
|
require File.dirname(__FILE__) + '/phidgets/common.rb'
|
9
|
+
require File.dirname(__FILE__) + '/phidgets/accelerometer.rb'
|
10
|
+
require File.dirname(__FILE__) + '/phidgets/advanced_servo.rb'
|
11
|
+
require File.dirname(__FILE__) + '/phidgets/analog.rb'
|
12
|
+
require File.dirname(__FILE__) + '/phidgets/bridge.rb'
|
13
|
+
require File.dirname(__FILE__) + '/phidgets/encoder.rb'
|
14
|
+
require File.dirname(__FILE__) + '/phidgets/frequency_counter.rb'
|
15
|
+
require File.dirname(__FILE__) + '/phidgets/gps.rb'
|
6
16
|
require File.dirname(__FILE__) + '/phidgets/interfacekit.rb'
|
17
|
+
require File.dirname(__FILE__) + '/phidgets/ir.rb'
|
18
|
+
require File.dirname(__FILE__) + '/phidgets/led.rb'
|
19
|
+
require File.dirname(__FILE__) + '/phidgets/motor_control.rb'
|
20
|
+
require File.dirname(__FILE__) + '/phidgets/ph_sensor.rb'
|
7
21
|
require File.dirname(__FILE__) + '/phidgets/rfid.rb'
|
8
22
|
require File.dirname(__FILE__) + '/phidgets/servo.rb'
|
9
|
-
require File.dirname(__FILE__) + '/phidgets/
|
23
|
+
require File.dirname(__FILE__) + '/phidgets/spatial.rb'
|
24
|
+
require File.dirname(__FILE__) + '/phidgets/stepper.rb'
|
25
|
+
require File.dirname(__FILE__) + '/phidgets/temperature_sensor.rb'
|
26
|
+
require File.dirname(__FILE__) + '/phidgets/text_lcd.rb'
|
27
|
+
require File.dirname(__FILE__) + '/phidgets/text_led.rb'
|
28
|
+
require File.dirname(__FILE__) + '/phidgets/weight_sensor.rb'
|
10
29
|
|
11
30
|
module Phidgets
|
12
|
-
VERSION = '0.0
|
31
|
+
VERSION = '0.1.0'
|
13
32
|
end
|
data/phidgets.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "phidgets"
|
5
|
+
s.version = "0.1.0"
|
6
|
+
s.authors = ["Craig DeHaan"]
|
7
|
+
s.email = ["cdehaan2@cfl.rr.com"]
|
8
|
+
s.homepage = "https://github.com/csdehaan/phidgets"
|
9
|
+
s.summary = "Phidgets are a set of \"plug and play\" building blocks for low cost USB sensing and control from your PC.\nThis gem provides a ruby interface to the phidgets library."
|
10
|
+
s.description = s.summary
|
11
|
+
|
12
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
13
|
+
s.executables = ["phidget"]
|
14
|
+
s.extensions = ["ext/phidgets/extconf.rb"]
|
15
|
+
s.extra_rdoc_files = ["GNU_GPL.txt", "History.txt", "README.rdoc"]
|
16
|
+
s.files = Dir.glob("bin/*") +
|
17
|
+
Dir.glob("ext/**/*.{c,h}") +
|
18
|
+
Dir.glob("lib/**/*.rb")+
|
19
|
+
Dir.glob("test/*.rb")+
|
20
|
+
%w(Rakefile GNU_GPL.txt History.txt README.rdoc phidgets.gemspec)
|
21
|
+
s.test_files = Dir.glob("test/*.rb")
|
22
|
+
s.post_install_message = "For more information on phidgets, see http://www.phidgets.com/"
|
23
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
24
|
+
s.require_paths = ["lib", "ext/phidgets"]
|
25
|
+
s.rubygems_version = "1.8.25"
|
26
|
+
|
27
|
+
if s.respond_to? :specification_version then
|
28
|
+
s.specification_version = 3
|
29
|
+
|
30
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
31
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
|
32
|
+
s.add_development_dependency("rake-compiler")
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<rdoc>, ["~> 3.10"])
|
35
|
+
s.add_dependency("rake-compiler")
|
36
|
+
end
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<rdoc>, ["~> 3.10"])
|
39
|
+
s.add_dependency("rake-compiler")
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestPhidgetsAccelerometer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_create
|
6
|
+
assert_nothing_raised {Phidgets::Accelerometer.new}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_get_axis_count
|
10
|
+
accel = Phidgets::Accelerometer.new
|
11
|
+
assert_raise(Phidgets::Error::NotAttached) {accel.axis_count}
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_acceleration
|
15
|
+
accel = Phidgets::Accelerometer.new
|
16
|
+
assert_raise(Phidgets::Error::NotAttached) {accel.acceleration 1}
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_acceleration_min
|
20
|
+
accel = Phidgets::Accelerometer.new
|
21
|
+
assert_raise(Phidgets::Error::NotAttached) {accel.acceleration_min 1}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_get_acceleration_max
|
25
|
+
accel = Phidgets::Accelerometer.new
|
26
|
+
assert_raise(Phidgets::Error::NotAttached) {accel.acceleration_max 1}
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_get_acceleration_change_trigger
|
30
|
+
accel = Phidgets::Accelerometer.new
|
31
|
+
assert_raise(Phidgets::Error::NotAttached) {accel.acceleration_change_trigger 1}
|
32
|
+
end
|
33
|
+
|
34
|
+
unless RUBY_VERSION < '1.9.0'
|
35
|
+
def test_set_acceleration_change_trigger
|
36
|
+
accel = Phidgets::Accelerometer.new
|
37
|
+
assert_raise(Phidgets::Error::NotAttached) {accel.set_acceleration_change_trigger 1, 2.5}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_set_on_acceleration_change
|
41
|
+
accel = Phidgets::Accelerometer.new
|
42
|
+
assert_nothing_raised {accel.on_acceleration_change {puts 'hello'}}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|