phidgets4r 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/phidgets/common.rb +13 -4
- data/lib/phidgets/interfacekit.rb +0 -3
- data/lib/phidgets/manager.rb +64 -0
- data/lib/phidgets/rfid.rb +0 -3
- data/lib/phidgets/servo.rb +0 -3
- data/lib/phidgets4r.rb +2 -1
- data/test/test_helper.rb +1 -1
- data/test/test_manager.rb +19 -0
- data/test/test_phidgets.rb +1 -1
- metadata +11 -4
data/lib/phidgets/common.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'dl'
|
3
2
|
require 'rbconfig'
|
4
3
|
|
@@ -164,12 +163,14 @@ module Phidgets
|
|
164
163
|
@@server_status = nil
|
165
164
|
@@device_id = nil
|
166
165
|
@@device_class = nil
|
167
|
-
|
166
|
+
|
168
167
|
def initialize
|
169
168
|
if @@libname == nil
|
170
169
|
case Config::CONFIG['target_os']
|
171
170
|
when 'linux'
|
172
171
|
@@libname = 'libphidget21.so'
|
172
|
+
when 'linux-eabi'
|
173
|
+
@@libname = 'libphidget21.so'
|
173
174
|
when 'mswin32'
|
174
175
|
@@libname = 'phidget21.dll'
|
175
176
|
when 'darwin10.2.0'
|
@@ -188,7 +189,6 @@ module Phidgets
|
|
188
189
|
end
|
189
190
|
|
190
191
|
@handle = DL.malloc(DL.sizeof('P'))
|
191
|
-
|
192
192
|
end
|
193
193
|
|
194
194
|
private
|
@@ -260,6 +260,15 @@ module Phidgets
|
|
260
260
|
arg_ptr.to_s
|
261
261
|
end
|
262
262
|
|
263
|
+
def call_IPp(sym_name, func_name, arg1)
|
264
|
+
sym_name = sym(func_name, 'IPp') if sym_name == nil
|
265
|
+
arg_ptr = DL.malloc(DL.sizeof('P'))
|
266
|
+
r,rs = sym_name.call(arg1, arg_ptr.ref)
|
267
|
+
raise Phidgets::Exception.new(r) if r != 0
|
268
|
+
arg_ptr.free = nil
|
269
|
+
arg_ptr
|
270
|
+
end
|
271
|
+
|
263
272
|
def createCallback(callback)
|
264
273
|
DL.callback('IPP') {|handle,data|
|
265
274
|
data = ObjectSpace._id2ref(data.to_i)
|
@@ -400,7 +409,7 @@ module Phidgets
|
|
400
409
|
def getDeviceClass
|
401
410
|
call_IPi(@@device_class, 'CPhidget_getDeviceClass', @handle)
|
402
411
|
end
|
403
|
-
|
412
|
+
|
404
413
|
end
|
405
414
|
|
406
415
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Phidgets
|
2
|
+
|
3
|
+
class Manager < Common
|
4
|
+
|
5
|
+
@@create = nil
|
6
|
+
@@open = nil
|
7
|
+
@@close = nil
|
8
|
+
@@delete = nil
|
9
|
+
@@getdevices = nil
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super()
|
13
|
+
|
14
|
+
@manhandle = DL.malloc(DL.sizeof('P'))
|
15
|
+
|
16
|
+
create
|
17
|
+
open
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
@@create = sym('CPhidgetManager_create', 'Ip') if @@create == nil
|
23
|
+
r, rs = @@create.call(@manhandle.ref)
|
24
|
+
raise Phidgets::Exception.new(r) if r != 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def open
|
28
|
+
call_IX(@@open, 'CPhidgetManager_open', 'IP', @manhandle)
|
29
|
+
end
|
30
|
+
|
31
|
+
def close
|
32
|
+
call_IX(@@close, 'CPhidgetManager_close', 'IP', @manhandle)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete
|
36
|
+
call_IX(@@delete, 'CPhidgetManager_delete', 'IP', @manhandle)
|
37
|
+
end
|
38
|
+
|
39
|
+
def setOnDetachHandler(callback, data)
|
40
|
+
call_IXXX(@@detach_handler, 'CPhidgetManager_set_OnDetach_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
41
|
+
end
|
42
|
+
|
43
|
+
def setOnAttachHandler(callback, data)
|
44
|
+
call_IXXX(@@attach_handler, 'CPhidgetManager_set_OnAttach_Handler', 'IPPP', @handle, createCallback(callback), DL::PtrData.new(data.object_id))
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_attached_devices
|
48
|
+
|
49
|
+
@devices = DL.malloc(DL.sizeof('P'))
|
50
|
+
@numDevices = DL.malloc(DL.sizeof('I'))
|
51
|
+
|
52
|
+
puts "|- # -|- Type -|- Serial No. -|- Version -|\n"
|
53
|
+
puts "|-------|----------------------------------|--------------|------------|\n"
|
54
|
+
@@getdevices = sym('CPhidgetManager_getAttachedDevices', 'IPPP') if @@getdevices == nil
|
55
|
+
r, rs = @@getdevices.call(@manhandle, @devices.ref, @numDevices.ref)
|
56
|
+
raise Phidgets::Exception.new(r) if r != 0
|
57
|
+
@numDevices.free = nil
|
58
|
+
puts "Num Devices: #{@numDevices.to_i}"
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/lib/phidgets/rfid.rb
CHANGED
data/lib/phidgets/servo.rb
CHANGED
data/lib/phidgets4r.rb
CHANGED
@@ -5,7 +5,8 @@ require File.dirname(__FILE__) + '/phidgets/common.rb'
|
|
5
5
|
require File.dirname(__FILE__) + '/phidgets/interfacekit.rb'
|
6
6
|
require File.dirname(__FILE__) + '/phidgets/rfid.rb'
|
7
7
|
require File.dirname(__FILE__) + '/phidgets/servo.rb'
|
8
|
+
#require File.dirname(__FILE__) + '/phidgets/manager.rb'
|
8
9
|
|
9
10
|
module Phidgets
|
10
|
-
VERSION = '0.0.
|
11
|
+
VERSION = '0.0.5'
|
11
12
|
end
|
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestPhidgetsManager < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
sleep 1
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_001_display_devices
|
10
|
+
assert_nothing_raised {
|
11
|
+
man = Phidgets::Manager.new
|
12
|
+
devices = man.get_attached_devices
|
13
|
+
sleep 1
|
14
|
+
puts "Sleeping Before Delete!"
|
15
|
+
#man.delete
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/test/test_phidgets.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phidgets4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Kit Plummer
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-17 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -32,11 +33,13 @@ files:
|
|
32
33
|
- GNU_GPL.txt
|
33
34
|
- lib/phidgets/common.rb
|
34
35
|
- lib/phidgets/interfacekit.rb
|
36
|
+
- lib/phidgets/manager.rb
|
35
37
|
- lib/phidgets/rfid.rb
|
36
38
|
- lib/phidgets/servo.rb
|
37
39
|
- lib/phidgets4r.rb
|
38
40
|
- test/test_helper.rb
|
39
41
|
- test/test_interfacekit.rb
|
42
|
+
- test/test_manager.rb
|
40
43
|
- test/test_phidgets.rb
|
41
44
|
- test/test_servo.rb
|
42
45
|
has_rdoc: true
|
@@ -49,23 +52,27 @@ rdoc_options: []
|
|
49
52
|
require_paths:
|
50
53
|
- lib
|
51
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
52
56
|
requirements:
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
55
60
|
segments:
|
56
61
|
- 0
|
57
62
|
version: "0"
|
58
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
59
65
|
requirements:
|
60
66
|
- - ">="
|
61
67
|
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
62
69
|
segments:
|
63
70
|
- 0
|
64
71
|
version: "0"
|
65
72
|
requirements:
|
66
73
|
- none
|
67
74
|
rubyforge_project: phidgets4r
|
68
|
-
rubygems_version: 1.3.
|
75
|
+
rubygems_version: 1.3.7
|
69
76
|
signing_key:
|
70
77
|
specification_version: 3
|
71
78
|
summary: Interact with Phidgets via Ruby.
|