phidgets4r 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,194 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestPhidgetsInterfaceKit < Test::Unit::TestCase
4
+
5
+ def setup
6
+ sleep 1
7
+ end
8
+
9
+ def test_001_create
10
+ assert_nothing_raised {
11
+ ik = Phidgets::InterfaceKit.new
12
+ ik.delete
13
+ }
14
+ end
15
+
16
+ def test_002_attach
17
+ assert_nothing_raised {
18
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
19
+ ik.close
20
+ ik.delete
21
+ }
22
+ end
23
+
24
+ def test_003_fail_attach
25
+ assert_raises (Phidgets::Exception) {
26
+ ik = Phidgets::InterfaceKit.new(1, 2000)
27
+ ik.delete
28
+ }
29
+ end
30
+
31
+ def test_004_get_device_name
32
+ assert_nothing_raised {
33
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
34
+ ik.getDeviceName
35
+ ik.close
36
+ ik.delete
37
+ }
38
+ end
39
+
40
+ def test_005_get_serial_number
41
+ assert_nothing_raised {
42
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
43
+ ik.getSerialNumber
44
+ ik.close
45
+ ik.delete
46
+ }
47
+ end
48
+
49
+ def test_006_get_device_version
50
+ assert_nothing_raised {
51
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
52
+ ik.getDeviceVersion
53
+ ik.close
54
+ ik.delete
55
+ }
56
+ end
57
+
58
+ def test_007_get_device_status
59
+ assert_nothing_raised {
60
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
61
+ ik.getDeviceStatus
62
+ ik.close
63
+ ik.delete
64
+ }
65
+ end
66
+
67
+ def test_008_get_device_type
68
+ assert_nothing_raised {
69
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
70
+ ik.getDeviceType
71
+ ik.close
72
+ ik.delete
73
+ }
74
+ end
75
+
76
+ def test_009_get_device_label
77
+ assert_nothing_raised {
78
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
79
+ ik.getDeviceLabel
80
+ ik.close
81
+ ik.delete
82
+ }
83
+ end
84
+
85
+ def test_010_get_device_id
86
+ assert_nothing_raised {
87
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
88
+ ik.getDeviceID
89
+ ik.close
90
+ ik.delete
91
+ }
92
+ end
93
+
94
+ def test_011_get_device_class
95
+ device_class = Phidgets::CLASS_NOTHING
96
+ assert_nothing_raised {
97
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
98
+ device_class = ik.getDeviceClass
99
+ ik.close
100
+ ik.delete
101
+ }
102
+ assert device_class == Phidgets::CLASS_INTERFACEKIT
103
+ end
104
+
105
+ def test_012_get_input_count
106
+ device_id = 0
107
+ count = -1
108
+ assert_nothing_raised {
109
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
110
+ device_id = ik.getDeviceID
111
+ count = ik.getInputCount
112
+ ik.close
113
+ ik.delete
114
+ }
115
+ case device_id
116
+ when Phidgets::ID_INTERFACEKIT_0_0_4
117
+ assert count == 0
118
+ when Phidgets::ID_INTERFACEKIT_0_0_8
119
+ assert count == 0
120
+ when Phidgets::ID_INTERFACEKIT_0_16_16
121
+ assert count == 16
122
+ when Phidgets::ID_INTERFACEKIT_8_8_8
123
+ assert count == 8
124
+ when Phidgets::ID_INTERFACEKIT_8_8_8_w_LCD
125
+ assert count == 8
126
+ when Phidgets::ID_INTERFACEKIT_0_8_8_w_LCD
127
+ assert count == 8
128
+ when Phidgets::ID_INTERFACEKIT_4_8_8
129
+ assert count == 8
130
+ else
131
+ flunk
132
+ end
133
+ end
134
+
135
+ def test_013_get_output_count
136
+ device_id = 0
137
+ count = -1
138
+ assert_nothing_raised {
139
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
140
+ device_id = ik.getDeviceID
141
+ count = ik.getOutputCount
142
+ ik.close
143
+ ik.delete
144
+ }
145
+ case device_id
146
+ when Phidgets::ID_INTERFACEKIT_0_0_4
147
+ assert count == 4
148
+ when Phidgets::ID_INTERFACEKIT_0_0_8
149
+ assert count == 8
150
+ when Phidgets::ID_INTERFACEKIT_0_16_16
151
+ assert count == 16
152
+ when Phidgets::ID_INTERFACEKIT_8_8_8
153
+ assert count == 8
154
+ when Phidgets::ID_INTERFACEKIT_8_8_8_w_LCD
155
+ assert count == 8
156
+ when Phidgets::ID_INTERFACEKIT_0_8_8_w_LCD
157
+ assert count == 8
158
+ when Phidgets::ID_INTERFACEKIT_4_8_8
159
+ assert count == 8
160
+ else
161
+ flunk
162
+ end
163
+ end
164
+
165
+ def test_014_get_sensor_count
166
+ device_id = 0
167
+ count = -1
168
+ assert_nothing_raised {
169
+ ik = Phidgets::InterfaceKit.new(-1, 2000)
170
+ device_id = ik.getDeviceID
171
+ count = ik.getSensorCount
172
+ ik.close
173
+ ik.delete
174
+ }
175
+ case device_id
176
+ when Phidgets::ID_INTERFACEKIT_0_0_4
177
+ assert count == 0
178
+ when Phidgets::ID_INTERFACEKIT_0_0_8
179
+ assert count == 0
180
+ when Phidgets::ID_INTERFACEKIT_0_16_16
181
+ assert count == 0
182
+ when Phidgets::ID_INTERFACEKIT_8_8_8
183
+ assert count == 8
184
+ when Phidgets::ID_INTERFACEKIT_8_8_8_w_LCD
185
+ assert count == 8
186
+ when Phidgets::ID_INTERFACEKIT_0_8_8_w_LCD
187
+ assert count == 0
188
+ when Phidgets::ID_INTERFACEKIT_4_8_8
189
+ assert count == 4
190
+ else
191
+ flunk
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,5 @@
1
+ ## Uncomment for which ever Phidget you have.
2
+ ## Hopefully we can continue to populate this list
3
+
4
+ #require File.dirname(__FILE__) + '/test_interfacekit.rb'
5
+ #require File.dirname(__FILE__) + '/test_servo.rb'
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestPhidgetsServo < Test::Unit::TestCase
4
+
5
+ def setup
6
+ sleep 1
7
+ end
8
+
9
+ def test_001_create
10
+ assert_nothing_raised {
11
+ servo = Phidgets::Servo.new
12
+ servo.delete
13
+ }
14
+ end
15
+
16
+ def test_002_attach
17
+ assert_nothing_raised {
18
+ servo = Phidgets::Servo.new(-1, 2000)
19
+ servo.close
20
+ servo.delete
21
+ }
22
+ end
23
+
24
+ def test_003_fail_attach
25
+ assert_raises (Phidgets::Exception) {
26
+ servo = Phidgets::Servo.new(1, 2000)
27
+ servo.delete
28
+ }
29
+ end
30
+
31
+ def test_004_get_device_name
32
+ assert_nothing_raised {
33
+ servo = Phidgets::Servo.new(-1, 2000)
34
+ servo.getDeviceName
35
+ servo.close
36
+ servo.delete
37
+ }
38
+ end
39
+
40
+ def test_005_get_serial_number
41
+ assert_nothing_raised {
42
+ servo = Phidgets::Servo.new(-1, 2000)
43
+ servo.getSerialNumber
44
+ servo.close
45
+ servo.delete
46
+ }
47
+ end
48
+
49
+ def test_006_get_device_version
50
+ assert_nothing_raised {
51
+ servo = Phidgets::Servo.new(-1, 2000)
52
+ servo.getDeviceVersion
53
+ servo.close
54
+ servo.delete
55
+ }
56
+ end
57
+
58
+ def test_007_get_device_status
59
+ assert_nothing_raised {
60
+ servo = Phidgets::Servo.new(-1, 2000)
61
+ servo.getDeviceStatus
62
+ servo.close
63
+ servo.delete
64
+ }
65
+ end
66
+
67
+ def test_008_get_device_type
68
+ assert_nothing_raised {
69
+ servo = Phidgets::Servo.new(-1, 2000)
70
+ servo.getDeviceType
71
+ servo.close
72
+ servo.delete
73
+ }
74
+ end
75
+
76
+ def test_009_get_device_label
77
+ assert_nothing_raised {
78
+ servo = Phidgets::Servo.new(-1, 2000)
79
+ servo.getDeviceLabel
80
+ servo.close
81
+ servo.delete
82
+ }
83
+ end
84
+
85
+ def test_010_get_device_id
86
+ assert_nothing_raised {
87
+ servo = Phidgets::Servo.new(-1, 2000)
88
+ servo.getDeviceID
89
+ servo.close
90
+ servo.delete
91
+ }
92
+ end
93
+
94
+ def test_011_get_device_class
95
+ device_class = Phidgets::CLASS_NOTHING
96
+ assert_nothing_raised {
97
+ servo = Phidgets::Servo.new(-1, 2000)
98
+ device_class = servo.getDeviceClass
99
+ servo.close
100
+ servo.delete
101
+ }
102
+ assert device_class == Phidgets::CLASS_SERVO
103
+ end
104
+
105
+ def test_012_get_motor_count
106
+ device_id = 0
107
+ count = -1
108
+ assert_nothing_raised {
109
+ servo = Phidgets::Servo.new(-1, 2000)
110
+ device_id = servo.getDeviceID
111
+ count = servo.getMotorCount
112
+ servo.close
113
+ servo.delete
114
+ }
115
+ assert 1 == count
116
+ end
117
+
118
+ def test_013_positions
119
+ device_id = 0
120
+ position = -1.0
121
+ max = -1
122
+ min = -1
123
+ engaged = -1
124
+
125
+ assert_nothing_raised {
126
+ servo = Phidgets::Servo.new(-1, 2000)
127
+ puts "device_id: #{servo.getDeviceID}"
128
+ puts "device_name: #{servo.getDeviceName}"
129
+ puts "status: #{servo.getDeviceStatus}"
130
+ max = servo.getPositionMax(0)
131
+ min = servo.getPositionMin(0)
132
+ puts "min: #{min} - max: #{max}"
133
+ servo.setPosition(0, 10.0)
134
+ sleep 3
135
+
136
+ position = servo.getPosition(0)
137
+ servo.close
138
+ servo.delete
139
+ }
140
+ puts "position: #{position}"
141
+ assert 0.0 == min
142
+ assert 220.0 == max
143
+ assert 10.0 == position
144
+ end
145
+
146
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phidgets4r
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Kit Plummer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-15 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Just a simple Ruby library to provide Ruby-style abstraction around the Phidgets C library. Fork of the RubyForge phidget project.
22
+ email: kitplummer@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - Rakefile
31
+ - README.rdoc
32
+ - GNU_GPL.txt
33
+ - lib/phidgets/common.rb
34
+ - lib/phidgets/interfacekit.rb
35
+ - lib/phidgets/rfid.rb
36
+ - lib/phidgets/servo.rb
37
+ - lib/phidgets.rb
38
+ - test/test_helper.rb
39
+ - test/test_interfacekit.rb
40
+ - test/test_phidgets.rb
41
+ - test/test_servo.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/kitplummer/phidgets4r
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements:
66
+ - none
67
+ rubyforge_project: phidgets4r
68
+ rubygems_version: 1.3.6
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Interact with Phidgets via Ruby.
72
+ test_files: []
73
+