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
data/lib/phidgets/phidgets.rb
DELETED
@@ -1,225 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'dl'
|
3
|
-
require 'dl/import'
|
4
|
-
require 'rbconfig'
|
5
|
-
|
6
|
-
|
7
|
-
module Phidgets
|
8
|
-
|
9
|
-
if RUBY_VERSION < "1.9"
|
10
|
-
extend DL::Importable
|
11
|
-
SIZEOF_INT = DL.sizeof('I')
|
12
|
-
SIZEOF_VOIDP = DL.sizeof('P')
|
13
|
-
SIZEOF_DOUBLE = DL.sizeof('D')
|
14
|
-
FUNCTION_PREFIX = 'c'
|
15
|
-
def Phidgets.malloc size
|
16
|
-
DL.malloc(size)
|
17
|
-
end
|
18
|
-
else
|
19
|
-
extend DL::Importer
|
20
|
-
SIZEOF_INT = DL::SIZEOF_INT
|
21
|
-
SIZEOF_VOIDP = DL::SIZEOF_VOIDP
|
22
|
-
SIZEOF_DOUBLE = DL::SIZEOF_DOUBLE
|
23
|
-
FUNCTION_PREFIX = 'C'
|
24
|
-
def Phidgets.malloc size
|
25
|
-
DL::CPtr.malloc(size)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
PFALSE = 0
|
30
|
-
PTRUE = 1
|
31
|
-
|
32
|
-
NOTATTACHED = 0
|
33
|
-
ATTACHED = 1
|
34
|
-
|
35
|
-
CLASS_NOTHING = 1
|
36
|
-
CLASS_ACCELEROMETER = 2
|
37
|
-
CLASS_ADVANCEDSERVO = 3
|
38
|
-
CLASS_ENCODER = 4
|
39
|
-
CLASS_GPS = 5
|
40
|
-
CLASS_GYROSCOPE = 6
|
41
|
-
CLASS_INTERFACEKIT = 7
|
42
|
-
CLASS_LED = 8
|
43
|
-
CLASS_MOTORCONTROL = 9
|
44
|
-
CLASS_PHSENSOR = 10
|
45
|
-
CLASS_RFID = 11
|
46
|
-
CLASS_SERVO = 12
|
47
|
-
CLASS_STEPPER = 13
|
48
|
-
CLASS_TEMPERATURESENSOR = 14
|
49
|
-
CLASS_TEXTLCD = 15
|
50
|
-
CLASS_TEXTLED = 16
|
51
|
-
CLASS_WEIGHTSENSOR = 17
|
52
|
-
|
53
|
-
ID_ACCELEROMETER_2AXIS = 0x071
|
54
|
-
ID_ACCELEROMETER_3AXIS = 0x07E
|
55
|
-
ID_ADVANCEDSERVO_8MOTOR = 0x03A
|
56
|
-
ID_BIPOLAR_STEPPER_1MOTOR = 0x07B
|
57
|
-
ID_ENCODER_1ENCODER_1INPUT = 0x04B
|
58
|
-
ID_ENCODER_HS_1ENCODER = 0x080
|
59
|
-
ID_INTERFACEKIT_0_0_4 = 0x040
|
60
|
-
ID_INTERFACEKIT_0_0_8 = 0x081
|
61
|
-
ID_INTERFACEKIT_0_16_16 = 0x044
|
62
|
-
ID_INTERFACEKIT_8_8_8 = 0x045
|
63
|
-
ID_INTERFACEKIT_8_8_8_w_LCD = 0x07D
|
64
|
-
ID_LED_64 = 0x04A
|
65
|
-
ID_LINEAR_TOUCH = 0x076
|
66
|
-
ID_MOTORCONTROL_HC_2MOTOR = 0x059
|
67
|
-
ID_MOTORCONTROL_LV_2MOTOR_4INPUT = 0x058
|
68
|
-
ID_PHSENSOR = 0x074
|
69
|
-
ID_RFID_2OUTPUT = 0x031
|
70
|
-
ID_ROTARY_TOUCH = 0x077
|
71
|
-
ID_SERVO_1MOTOR = 0x039
|
72
|
-
ID_TEMPERATURESENSOR = 0x070
|
73
|
-
ID_TEXTLCD_2x20_w_8_8_8 = 0x17D
|
74
|
-
ID_UNIPOLAR_STEPPER_4MOTOR = 0x07A
|
75
|
-
ID_INTERFACEKIT_0_8_8_w_LCD = 0x053
|
76
|
-
ID_INTERFACEKIT_4_8_8 = 0x004
|
77
|
-
ID_RFID = 0x030
|
78
|
-
ID_SERVO_1MOTOR_OLD = 0x002
|
79
|
-
ID_SERVO_4MOTOR = 0x038
|
80
|
-
ID_SERVO_4MOTOR_OLD = 0x003
|
81
|
-
ID_TEXTLCD_2x20 = 0x052
|
82
|
-
ID_TEXTLCD_2x20_w_0_8_8 = 0x153
|
83
|
-
ID_TEXTLED_1x8 = 0x049
|
84
|
-
ID_TEXTLED_4x8 = 0x048
|
85
|
-
ID_WEIGHTSENSOR = 0x072
|
86
|
-
|
87
|
-
PHIDGET_LOG_CRITICAL = 1
|
88
|
-
PHIDGET_LOG_ERROR = 2
|
89
|
-
PHIDGET_LOG_WARNING = 3
|
90
|
-
PHIDGET_LOG_DEBUG = 4
|
91
|
-
PHIDGET_LOG_INFO = 5
|
92
|
-
PHIDGET_LOG_VERBOSE = 6
|
93
|
-
|
94
|
-
class Exception < RuntimeError
|
95
|
-
attr_reader :code
|
96
|
-
|
97
|
-
EPHIDGET_LOAD_LIB_FAIL = -2
|
98
|
-
EPHIDGET_LIBNAME = -1
|
99
|
-
EPHIDGET_NOTFOUND = 1
|
100
|
-
EPHIDGET_NOMEMORY = 2
|
101
|
-
EPHIDGET_UNEXPECTED = 3
|
102
|
-
EPHIDGET_INVALIDARG = 4
|
103
|
-
EPHIDGET_NOTATTACHED = 5
|
104
|
-
EPHIDGET_INTERRUPTED = 6
|
105
|
-
EPHIDGET_INVALID = 7
|
106
|
-
EPHIDGET_NETWORK = 8
|
107
|
-
EPHIDGET_UNKNOWNVAL = 9
|
108
|
-
EPHIDGET_BADPASSWORD = 10
|
109
|
-
EPHIDGET_UNSUPPORTED = 11
|
110
|
-
EPHIDGET_DUPLICATE = 12
|
111
|
-
EPHIDGET_TIMEOUT = 13
|
112
|
-
EPHIDGET_OUTOFBOUNDS = 14
|
113
|
-
EPHIDGET_EVENT = 15
|
114
|
-
EPHIDGET_NETWORK_NOTCONNECTED = 16
|
115
|
-
EPHIDGET_WRONGDEVICE = 17
|
116
|
-
EPHIDGET_CLOSED = 18
|
117
|
-
EPHIDGET_BADVERSION = 19
|
118
|
-
|
119
|
-
def initialize(code)
|
120
|
-
@code = code
|
121
|
-
case code
|
122
|
-
when EPHIDGET_LOAD_LIB_FAIL
|
123
|
-
super('Failed to load Phidgets Library')
|
124
|
-
when EPHIDGET_LIBNAME
|
125
|
-
super('Unable to determine Phidgets Library name.')
|
126
|
-
when EPHIDGET_NOTFOUND
|
127
|
-
super('A Phidget matching the type and or serial number could not be found.')
|
128
|
-
when EPHIDGET_NOMEMORY
|
129
|
-
super('Memory could not be allocated.')
|
130
|
-
when EPHIDGET_UNEXPECTED
|
131
|
-
super('Unexpected Error. Contact Phidgets Inc. for support.')
|
132
|
-
when EPHIDGET_INVALIDARG
|
133
|
-
super('Invalid argument passed to function.')
|
134
|
-
when EPHIDGET_NOTATTACHED
|
135
|
-
super('Phidget not physically attached.')
|
136
|
-
when EPHIDGET_INTERRUPTED
|
137
|
-
super('Read/Write operation was interrupted.')
|
138
|
-
when EPHIDGET_INVALID
|
139
|
-
super('The Error Code is not defined.')
|
140
|
-
when EPHIDGET_NETWORK
|
141
|
-
super('Network Error.')
|
142
|
-
when EPHIDGET_UNKNOWNVAL
|
143
|
-
super('Value is Unknown (State not yet received from device, or not yet set by user).')
|
144
|
-
when EPHIDGET_BADPASSWORD
|
145
|
-
super('Authorization Failed.')
|
146
|
-
when EPHIDGET_UNSUPPORTED
|
147
|
-
super('Not Supported.')
|
148
|
-
when EPHIDGET_DUPLICATE
|
149
|
-
super('Duplicated request.')
|
150
|
-
when EPHIDGET_TIMEOUT
|
151
|
-
super('Given timeout has been exceeded.')
|
152
|
-
when EPHIDGET_OUTOFBOUNDS
|
153
|
-
super('Index out of Bounds.')
|
154
|
-
when EPHIDGET_EVENT
|
155
|
-
super('A non-null error code was returned from an event handler.')
|
156
|
-
when EPHIDGET_NETWORK_NOTCONNECTED
|
157
|
-
super('A connection to the server does not exist.')
|
158
|
-
when EPHIDGET_WRONGDEVICE
|
159
|
-
super('Function is not applicable for this device.')
|
160
|
-
when EPHIDGET_CLOSED
|
161
|
-
super('Phidget handle was closed.')
|
162
|
-
when EPHIDGET_BADVERSION
|
163
|
-
super("Webservice and Client protocol versions don't match. Update to newest release.")
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
begin
|
170
|
-
case Config::CONFIG['target_os']
|
171
|
-
when /linux/
|
172
|
-
dlload 'libphidget21.so'
|
173
|
-
when /mswin/, /mingw/
|
174
|
-
dlload 'phidget21.dll'
|
175
|
-
when /darwin/
|
176
|
-
dlload '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
|
177
|
-
else
|
178
|
-
raise Phidgets::Exception.new(Exception::EPHIDGET_LIBNAME)
|
179
|
-
end
|
180
|
-
rescue
|
181
|
-
raise Phidgets::Exception.new(Exception::EPHIDGET_LOAD_LIB_FAIL)
|
182
|
-
end
|
183
|
-
|
184
|
-
extern "int CPhidget_getLibraryVersion(void *)"
|
185
|
-
extern "int CPhidget_getErrorDescription(int, void *)"
|
186
|
-
extern "int CPhidget_enableLogging(int, char *)"
|
187
|
-
extern "int CPhidget_disableLogging()"
|
188
|
-
|
189
|
-
# Gets the library version. This contains a version number and a build date.
|
190
|
-
def Phidgets.getLibraryVersion
|
191
|
-
ptr = malloc(SIZEOF_VOIDP)
|
192
|
-
r = self.send(FUNCTION_PREFIX + 'Phidget_getLibraryVersion', ptr.ref)
|
193
|
-
raise Phidgets::Exception.new(r) if r != 0
|
194
|
-
ptr.free = nil
|
195
|
-
ptr.to_s
|
196
|
-
end
|
197
|
-
|
198
|
-
# Gets the description for an error code.
|
199
|
-
def Phidgets.getErrorDescription(error_code)
|
200
|
-
ptr = malloc(SIZEOF_VOIDP)
|
201
|
-
r = self.send(FUNCTION_PREFIX + 'Phidget_getErrorDescription', error_code.to_i, ptr.ref)
|
202
|
-
raise Phidgets::Exception.new(r) if r != 0
|
203
|
-
ptr.free = nil
|
204
|
-
ptr.to_s
|
205
|
-
end
|
206
|
-
|
207
|
-
# Enables logging. Logging is provided mainly for debugging purposes. Enabling logging will output internal library
|
208
|
-
# information that can be used to find bugs with the help of Phidgetd Inc. Alternatively, the user can enable
|
209
|
-
# and write to the log for their own uses.
|
210
|
-
# === Parameters
|
211
|
-
# * _level_ = The highest level of logging to output. All lower levels will also be output.
|
212
|
-
# * _file_ = File to output log to. This should be a full pathname, not a relative pathname.
|
213
|
-
def Phidgets.enableLogging(level, file)
|
214
|
-
r = self.send(FUNCTION_PREFIX + 'Phidget_enableLogging', level.to_i, file)
|
215
|
-
raise Phidgets::Exception.new(r) if r != 0
|
216
|
-
end
|
217
|
-
|
218
|
-
# Disables logging.
|
219
|
-
def Phidgets.disableLogging
|
220
|
-
r = self.send(FUNCTION_PREFIX + 'Phidget_disableLogging')
|
221
|
-
raise Phidgets::Exception.new(r) if r != 0
|
222
|
-
end
|
223
|
-
|
224
|
-
end
|
225
|
-
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/phidgets.rb'}"
|
9
|
-
puts "Loading phidgets gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|