phidgets 0.0.2 → 0.0.3

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 CHANGED
@@ -1,6 +1,12 @@
1
+ == 0.0.3 2010-08-09
2
+ * Moved the Phidgets::Exception class before the initialization code so that the init code can throw an exception
3
+ * Fixed bugs in Common::openRemote and Common::openRemoteIP that prevented them from being called
4
+ * Add ability to turn on/off logging in the C library (for debugging)
5
+
1
6
  == 0.0.2 2010-05-12
2
7
  * Rewrote using DL/Importable
3
8
  * Added some documentation
9
+ * Added support for Servo class.
4
10
 
5
11
  == 0.0.1 2009-03-27
6
12
  * Initial release
data/Manifest.txt CHANGED
@@ -2,12 +2,14 @@ GNU_GPL.txt
2
2
  History.txt
3
3
  Manifest.txt
4
4
  PostInstall.txt
5
+ README.txt
5
6
  README.rdoc
6
7
  Rakefile
7
8
  lib/phidgets.rb
8
9
  lib/phidgets/common.rb
9
10
  lib/phidgets/interfacekit.rb
10
11
  lib/phidgets/rfid.rb
12
+ lib/phidgets/servo.rb
11
13
  script/console
12
14
  script/destroy
13
15
  script/generate
data/README.rdoc CHANGED
@@ -12,28 +12,52 @@ This gem provides a ruby interface to the phidgets library.
12
12
  * This gem uses DL to call the c functions in the Phidgets shared library, so the library must be installed and working.
13
13
  * The gem has been tested to work on both Linux and Windows.
14
14
  * Not all the devices have been implemented, and not all of the devices that have been implemented have been fully tested.
15
- * The callback functionality of the Phidgets library is not working very well. Making multiple calls to the phidgets library from
16
- within a callback will cause an exception.
17
- * The gem will attempt to guess the name of the phidgets library based on the platform it is run on (Linux or Windows).
15
+ * The callback functionality of the Phidgets library is working but should be used with caution. I have found that the callback
16
+ will cause a stack overflow exception if it is too big (not sure exactly what the limit is, but it isn't much).
17
+ * The gem will attempt to guess the name of the phidgets library based on the platform it is run on (Linux, Windows or OS X).
18
+ If it guessesincorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
19
+ what is the name of the phidgets library.
18
20
 
19
21
  == SYNOPSIS:
20
22
 
21
- require 'phidgets'
23
+ require 'phidgets'
22
24
 
23
- begin
24
- ik = Phidgets::InterfaceKit.new(-1,2000)
25
+ begin
26
+ ik = Phidgets::InterfaceKit.new(-1,2000)
25
27
 
26
- puts "Device Name = #{ik.getDeviceName}"
27
- puts "Serial Number = #{ik.getSerialNumber}"
28
- puts "Device Version = #{ik.getDeviceVersion}"
28
+ puts "Device Name = #{ik.getDeviceName}"
29
+ puts "Serial Number = #{ik.getSerialNumber}"
30
+ puts "Device Version = #{ik.getDeviceVersion}"
29
31
 
30
- ik.close
32
+ ik.close
31
33
 
32
- rescue Phidgets::Exception => e
33
- puts "Phidgets Error (#{e.code}). #{e}"
34
+ rescue Phidgets::Exception => e
35
+ puts "Phidgets Error (#{e.code}). #{e}"
36
+ end
34
37
 
35
- end
38
+ === <b>or to use a callback:</b>
36
39
 
40
+ require 'phidgets'
41
+
42
+ def onConnect(handle, data)
43
+ # the ruby object passed in to the callback is converted to an object id.
44
+ # Now convert it back to an object reference
45
+ ik = ObjectSpace._id2ref(data.to_i)
46
+ puts ik.getDeviceName
47
+ return 0
48
+ end
49
+
50
+ begin
51
+ ik = Phidgets::InterfaceKit.new
52
+ ik.setOnAttachHandler("onConnect", ik)
53
+ ik.open
54
+
55
+ # do something else
56
+ sleep 4
57
+
58
+ rescue Phidgets::Exception => e
59
+ puts "Phidgets Error (#{e.code}). #{e}"
60
+ end
37
61
 
38
62
 
39
63
  == REQUIREMENTS:
@@ -46,7 +70,7 @@ end
46
70
 
47
71
  == LICENSE:
48
72
 
49
- Copyright (C) 2009-2010 Craig DeHaan
73
+ Copyright (C) 2009 Craig DeHaan
50
74
 
51
75
  This program is free software; you can redistribute it and/or
52
76
  modify it under the terms of the GNU General Public License
data/README.txt ADDED
@@ -0,0 +1,87 @@
1
+ = phidgets
2
+
3
+ * http://phidgets.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Phidgets are a set of "plug and play" building blocks for low cost USB sensing and control from your PC.
8
+ This gem provides a ruby interface to the phidgets library.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * This gem uses DL to call the c functions in the Phidgets shared library, so the library must be installed and working.
13
+ * The gem has been tested to work on both Linux and Windows.
14
+ * Not all the devices have been implemented, and not all of the devices that have been implemented have been fully tested.
15
+ * The callback functionality of the Phidgets library is working but should be used with caution. I have found that the callback
16
+ will cause a stack overflow exception if it is too big (not sure exactly what the limit is, but it isn't much).
17
+ * The gem will attempt to guess the name of the phidgets library based on the platform it is run on (Linux, Windows or OS X).
18
+ If it guessesincorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
19
+ what is the name of the phidgets library.
20
+
21
+ == SYNOPSIS:
22
+
23
+ require 'phidgets'
24
+
25
+ begin
26
+ ik = Phidgets::InterfaceKit.new(-1,2000)
27
+
28
+ puts "Device Name = #{ik.getDeviceName}"
29
+ puts "Serial Number = #{ik.getSerialNumber}"
30
+ puts "Device Version = #{ik.getDeviceVersion}"
31
+
32
+ ik.close
33
+
34
+ rescue Phidgets::Exception => e
35
+ puts "Phidgets Error (#{e.code}). #{e}"
36
+ end
37
+
38
+ === <b>or to use a callback:</b>
39
+
40
+ require 'phidgets'
41
+
42
+ def onConnect(handle, data)
43
+ # the ruby object passed in to the callback is converted to an object id.
44
+ # Now convert it back to an object reference
45
+ ik = ObjectSpace._id2ref(data.to_i)
46
+ puts ik.getDeviceName
47
+ return 0
48
+ end
49
+
50
+ begin
51
+ ik = Phidgets::InterfaceKit.new
52
+ ik.setOnAttachHandler("onConnect", ik)
53
+ ik.open
54
+
55
+ # do something else
56
+ sleep 4
57
+
58
+ rescue Phidgets::Exception => e
59
+ puts "Phidgets Error (#{e.code}). #{e}"
60
+ end
61
+
62
+
63
+ == REQUIREMENTS:
64
+
65
+ * The Phidgets library (http://www.phidgets.com/)
66
+
67
+ == INSTALL:
68
+
69
+ * sudo gem install phidgets
70
+
71
+ == LICENSE:
72
+
73
+ Copyright (C) 2009 Craig DeHaan
74
+
75
+ This program is free software; you can redistribute it and/or
76
+ modify it under the terms of the GNU General Public License
77
+ as published by the Free Software Foundation; either version 2
78
+ of the License, or (at your option) any later version.
79
+
80
+ This program is distributed in the hope that it will be useful,
81
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83
+ GNU General Public License for more details.
84
+
85
+ You should have received a copy of the GNU General Public License
86
+ along with this program; if not, write to the Free Software
87
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
data/lib/phidgets.rb CHANGED
@@ -4,7 +4,8 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  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
+ require File.dirname(__FILE__) + '/phidgets/servo.rb'
7
8
 
8
9
  module Phidgets
9
- VERSION = '0.0.2'
10
+ VERSION = '0.0.3'
10
11
  end
@@ -7,6 +7,9 @@ require 'rbconfig'
7
7
  module Phidgets
8
8
  extend DL::Importable
9
9
 
10
+ PFALSE = 0
11
+ PTRUE = 1
12
+
10
13
  NOTATTACHED = 0
11
14
  ATTACHED = 1
12
15
 
@@ -62,63 +65,12 @@ module Phidgets
62
65
  ID_TEXTLED_4x8 = 0x048
63
66
  ID_WEIGHTSENSOR = 0x072
64
67
 
65
- begin
66
- case Config::CONFIG['target_os']
67
- when 'linux'
68
- dlload 'libphidget21.so'
69
- when 'mswin32'
70
- dlload 'phidget21.dll'
71
- else
72
- raise Phidgets::Exception.new(Exception::EPHIDGET_LIBNAME)
73
- end
74
- rescue
75
- raise Phidgets::Exception.new(Exception::EPHIDGET_LOAD_LIB_FAIL)
76
- end
77
-
78
- extern "int CPhidget_openRemote(void *, int, void *, void *)"
79
- extern "int CPhidget_openRemoteIP(void *, int, void *, int, void *)"
80
- extern "int CPhidget_open(void *, int)"
81
- extern "int CPhidget_close(void *)"
82
- extern "int CPhidget_delete(void *)"
83
- extern "int CPhidget_set_OnDetach_Handler(void *, void *, void *)"
84
- extern "int CPhidget_set_OnAttach_Handler(void *, void *, void *)"
85
- extern "int CPhidget_set_OnServerConnect_Handler(void *, void *, void *)"
86
- extern "int CPhidget_set_OnServerDisconnect_Handler(void *, void *, void *)"
87
- extern "int CPhidget_set_OnError_Handler(void *, void *, void *)"
88
- extern "int CPhidget_getDeviceName(void *, void *)"
89
- extern "int CPhidget_getSerialNumber(void *, int *)"
90
- extern "int CPhidget_getDeviceVersion(void *, int *)"
91
- extern "int CPhidget_getDeviceStatus(void *, int *)"
92
- extern "int CPhidget_getLibraryVersion(void *)"
93
- extern "int CPhidget_getDeviceType(void *, void *)"
94
- extern "int CPhidget_getDeviceLabel(void *, void *)"
95
- extern "int CPhidget_setDeviceLabel(void *, void *)"
96
- extern "int CPhidget_getErrorDescription(int, void *)"
97
- extern "int CPhidget_waitForAttachment(void *, int)"
98
- extern "int CPhidget_getServerID(void *, void *)"
99
- extern "int CPhidget_getServerAddress(void *, void *, int *)"
100
- extern "int CPhidget_getServerStatus(void *, int *)"
101
- extern "int CPhidget_getDeviceID(void *, int *)"
102
- extern "int CPhidget_getDeviceClass(void *, int *)"
103
-
104
- # Gets the library version. This contains a version number and a build date.
105
- def Phidgets.getLibraryVersion
106
- ptr = DL.malloc(DL.sizeof('P'))
107
- r = cPhidget_getLibraryVersion(ptr.ref)
108
- raise Phidgets::Exception.new(r) if r != 0
109
- ptr.free = nil
110
- ptr.to_s
111
- end
112
-
113
- # Gets the description for an error code.
114
- def Phidgets.getErrorDescription(error_code)
115
- ptr = DL.malloc(DL.sizeof('P'))
116
- r = cPhidget_getErrorDescription(error_code, ptr.ref)
117
- raise Phidgets::Exception.new(r) if r != 0
118
- ptr.free = nil
119
- ptr.to_s
120
- end
121
-
68
+ PHIDGET_LOG_CRITICAL = 1
69
+ PHIDGET_LOG_ERROR = 2
70
+ PHIDGET_LOG_WARNING = 3
71
+ PHIDGET_LOG_DEBUG = 4
72
+ PHIDGET_LOG_INFO = 5
73
+ PHIDGET_LOG_VERBOSE = 6
122
74
 
123
75
  class Exception < RuntimeError
124
76
  attr_reader :code
@@ -195,27 +147,116 @@ module Phidgets
195
147
 
196
148
  end
197
149
 
150
+ begin
151
+ case Config::CONFIG['target_os']
152
+ when /linux/
153
+ dlload 'libphidget21.so'
154
+ when /mswin/
155
+ dlload 'phidget21.dll'
156
+ when /darwin/
157
+ dlload '/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21'
158
+ else
159
+ raise Phidgets::Exception.new(Exception::EPHIDGET_LIBNAME)
160
+ end
161
+ rescue
162
+ raise Phidgets::Exception.new(Exception::EPHIDGET_LOAD_LIB_FAIL)
163
+ end
164
+
165
+ extern "int CPhidget_openRemote(void *, int, void *, void *)"
166
+ extern "int CPhidget_openRemoteIP(void *, int, void *, int, void *)"
167
+ extern "int CPhidget_open(void *, int)"
168
+ extern "int CPhidget_close(void *)"
169
+ extern "int CPhidget_delete(void *)"
170
+ extern "int CPhidget_set_OnDetach_Handler(void *, void *, void *)"
171
+ extern "int CPhidget_set_OnAttach_Handler(void *, void *, void *)"
172
+ extern "int CPhidget_set_OnServerConnect_Handler(void *, void *, void *)"
173
+ extern "int CPhidget_set_OnServerDisconnect_Handler(void *, void *, void *)"
174
+ extern "int CPhidget_set_OnError_Handler(void *, void *, void *)"
175
+ extern "int CPhidget_getDeviceName(void *, void *)"
176
+ extern "int CPhidget_getSerialNumber(void *, int *)"
177
+ extern "int CPhidget_getDeviceVersion(void *, int *)"
178
+ extern "int CPhidget_getDeviceStatus(void *, int *)"
179
+ extern "int CPhidget_getLibraryVersion(void *)"
180
+ extern "int CPhidget_getDeviceType(void *, void *)"
181
+ extern "int CPhidget_getDeviceLabel(void *, void *)"
182
+ extern "int CPhidget_setDeviceLabel(void *, void *)"
183
+ extern "int CPhidget_getErrorDescription(int, void *)"
184
+ extern "int CPhidget_waitForAttachment(void *, int)"
185
+ extern "int CPhidget_getServerID(void *, void *)"
186
+ extern "int CPhidget_getServerAddress(void *, void *, int *)"
187
+ extern "int CPhidget_getServerStatus(void *, int *)"
188
+ extern "int CPhidget_getDeviceID(void *, int *)"
189
+ extern "int CPhidget_getDeviceClass(void *, int *)"
190
+ extern "int CPhidget_enableLogging(int, char *)"
191
+ extern "int CPhidget_disableLogging()"
192
+
193
+ # Gets the library version. This contains a version number and a build date.
194
+ def Phidgets.getLibraryVersion
195
+ ptr = DL.malloc(DL.sizeof('P'))
196
+ r = cPhidget_getLibraryVersion(ptr.ref)
197
+ raise Phidgets::Exception.new(r) if r != 0
198
+ ptr.free = nil
199
+ ptr.to_s
200
+ end
201
+
202
+ # Gets the description for an error code.
203
+ def Phidgets.getErrorDescription(error_code)
204
+ ptr = DL.malloc(DL.sizeof('P'))
205
+ r = cPhidget_getErrorDescription(error_code, ptr.ref)
206
+ raise Phidgets::Exception.new(r) if r != 0
207
+ ptr.free = nil
208
+ ptr.to_s
209
+ end
210
+
211
+ # Enables logging. Logging is provided mainly for debugging purposes. Enabling logging will output internal library
212
+ # information that can be used to find bugs with the help of Phidgetd Inc. Alternatively, the user can enable
213
+ # and write to the log for their own uses.
214
+ # === Parameters
215
+ # * _level_ = The highest level of logging to output. All lower levels will also be output.
216
+ # * _file_ = File to output log to. This should be a full pathname, not a relative pathname.
217
+ def Phidgets.enableLogging(level, file)
218
+ r = cPhidget_enableLogging(level, file)
219
+ raise Phidgets::Exception.new(r) if r != 0
220
+ end
221
+
222
+ # Disables logging.
223
+ def Phidgets.disableLogging
224
+ r = cPhidget_disableLogging
225
+ raise Phidgets::Exception.new(r) if r != 0
226
+ end
227
+
198
228
 
199
229
  class Common
200
- def initialize
201
- @handle = DL.malloc(DL.sizeof('P'))
202
- end
203
230
 
204
231
  # Opens a Phidget remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
232
+ # === Parameters
233
+ # * _serial_number_ = Serial number. Specify -1 to open any.
234
+ # * _server_ = Server ID. Specify nil to open any.
235
+ # * _password_ = Password. Can be nil if the server is running unsecured.
236
+ # * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
205
237
  def openRemote(serial_number=-1, server=nil, password=nil, timeout=0)
206
- r = cPhidget_openRemote(@handle, serial_number, server, password)
238
+ r = Phidgets.cPhidget_openRemote(@handle, serial_number, server, password)
207
239
  raise Phidgets::Exception.new(r) if r != 0
208
240
  waitForAttachment(timeout) if timeout > 0
209
241
  end
210
242
 
211
243
  # Opens a Phidget remotely by address and port.
244
+ # === Parameters
245
+ # * _serial_number_ = Serial number. Specify -1 to open any.
246
+ # * _address_ = Address. This can be a hostname or IP address.
247
+ # * _port_ = Port number. Default is 5001.
248
+ # * _password_ = Password. Can be nil if the server is running unsecured.
249
+ # * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
212
250
  def openRemoteIP(serial_number, address, port=5001, password=nil, timeout=0)
213
- r = cPhidget_openRemoteIP(@handle, serial_number, address, port, password)
251
+ r = Phidgets.cPhidget_openRemoteIP(@handle, serial_number, address, port, password)
214
252
  raise Phidgets::Exception.new(r) if r != 0
215
253
  waitForAttachment(timeout) if timeout > 0
216
254
  end
217
255
 
218
256
  # Opens a Phidget.
257
+ # === Parameters
258
+ # * _serial_number_ = Serial number. Specify -1 to open any.
259
+ # * _timeout_ = Time to wait for attachment. Specify 0 to not wait.
219
260
  def open(serial_number=-1, timeout=0)
220
261
  r = Phidgets.cPhidget_open(@handle, serial_number)
221
262
  raise Phidgets::Exception.new(r) if r != 0
@@ -236,32 +277,47 @@ module Phidgets
236
277
  end
237
278
 
238
279
  # Sets a detach handler callback function. This is called when this Phidget is unplugged from the system.
239
- def setOnDetachHandler(callback, data)
240
- r = Phidgets.cPhidget_set_OnDetach_Handler(@handle, createCallback(callback), DL::PtrData.new(data.object_id))
280
+ # === Parameters
281
+ # * _callback_func_ = Callback function.
282
+ # * _data_ = Data for use by the user - this object is passed back into the callback function.
283
+ def setOnDetachHandler(callback_func, data)
284
+ r = Phidgets.cPhidget_set_OnDetach_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
241
285
  raise Phidgets::Exception.new(r) if r != 0
242
286
  end
243
287
 
244
288
  # Sets an attach handler callback function. This is called when this Phidget is plugged into the system, and is ready for use.
245
- def setOnAttachHandler(callback, data)
246
- r = Phidgets.cPhidget_set_OnAttach_Handler(@handle, createCallback(callback), DL::PtrData.new(data.object_id))
289
+ # === Parameters
290
+ # * _callback_func_ = Callback function.
291
+ # * _data_ = Data for use by the user - this object is passed back into the callback function.
292
+ def setOnAttachHandler(callback_func, data)
293
+ r = Phidgets.cPhidget_set_OnAttach_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
247
294
  raise Phidgets::Exception.new(r) if r != 0
248
295
  end
249
296
 
250
297
  # Sets a server connect handler callback function. This is used for opening Phidgets remotely, and is called when a connection to the sever has been made.
251
- def setOnConnectHandler(callback, data)
252
- r = Phidgets.cPhidget_set_OnServerConnect_Handler(@handle, createCallback(callback), DL::PtrData.new(data.object_id))
298
+ # === Parameters
299
+ # * _callback_func_ = Callback function.
300
+ # * _data_ = Data for use by the user - this object is passed back into the callback function.
301
+ def setOnConnectHandler(callback_func, data)
302
+ r = Phidgets.cPhidget_set_OnServerConnect_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
253
303
  raise Phidgets::Exception.new(r) if r != 0
254
304
  end
255
305
 
256
306
  # Sets a server disconnect handler callback function. This is used for opening Phidgets remotely, and is called when a connection to the server has been lost.
257
- def setOnDisconnectHandler(callback, data)
258
- r = Phidgets.cPhidget_set_OnServerDisconnect_Handler(@handle, createCallback(callback), DL::PtrData.new(data.object_id))
307
+ # === Parameters
308
+ # * _callback_func_ = Callback function.
309
+ # * _data_ = Data for use by the user - this object is passed back into the callback function.
310
+ def setOnDisconnectHandler(callback_func, data)
311
+ r = Phidgets.cPhidget_set_OnServerDisconnect_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *)"), DL::PtrData.new(data.object_id))
259
312
  raise Phidgets::Exception.new(r) if r != 0
260
313
  end
261
314
 
262
315
  # Sets the error handler callback function. This is called when an asynchronous error occurs.
263
- def setOnErrorHandler(callback, data)
264
- r = Phidgets.cPhidget_set_OnError_Handler(@handle, createErrorCallback(callback), DL::PtrData.new(data.object_id))
316
+ # === Parameters
317
+ # * _callback_func_ = Callback function.
318
+ # * _data_ = Data for use by the user - this object is passed back into the callback function.
319
+ def setOnErrorHandler(callback_func, data)
320
+ r = Phidgets.cPhidget_set_OnError_Handler(@handle, Phidgets.callback("int #{callback_func}(void *, void *, int, const char *)"), DL::PtrData.new(data.object_id))
265
321
  raise Phidgets::Exception.new(r) if r != 0
266
322
  end
267
323
 
@@ -319,13 +375,17 @@ module Phidgets
319
375
  ptr.to_s
320
376
  end
321
377
 
322
- # Sets the label of a Phidget. Note that this is nut supported on very old Phidgets, and not yet supported in Windows.
378
+ # Sets the label of a Phidget. Note that this is not supported on very old Phidgets, and not yet supported in Windows.
379
+ # === Parameters
380
+ # * _label_ = A string containing the label to be set.
323
381
  def setDeviceLabel(label)
324
382
  r = Phidgets.cPhidget_setDeviceLabel(@handle, label)
325
383
  raise Phidgets::Exception.new(r) if r != 0
326
384
  end
327
385
 
328
- # Waits for attachment to happen. This can be called wirght after calling CPhidget_open, as an alternative to using the attach handler.
386
+ # Waits for attachment to happen. This can be called right after calling open, as an alternative to using the attach handler.
387
+ # === Parameters
388
+ # * _timeout_ = Time to wait for the attachment. Specify 0 to wait forever.
329
389
  def waitForAttachment(timeout)
330
390
  r = Phidgets.cPhidget_waitForAttachment(@handle, timeout)
331
391
  raise Phidgets::Exception.new(r) if r != 0
@@ -381,18 +441,8 @@ module Phidgets
381
441
 
382
442
  private
383
443
 
384
- def createCallback(callback)
385
- DL.callback('IPP') {|handle,data|
386
- data = ObjectSpace._id2ref(data.to_i)
387
- eval("#{callback}(data)")
388
- }
389
- end
390
-
391
- def createErrorCallback(callback)
392
- DL.callback('IPPIS') {|handle,data,error_code,error_string|
393
- data = ObjectSpace._id2ref(data.to_i)
394
- eval("#{callback}(data,error_code,error_string)")
395
- }
444
+ def initialize
445
+ @handle = DL.malloc(DL.sizeof('P'))
396
446
  end
397
447
 
398
448
  end
@@ -17,6 +17,10 @@ module Phidgets
17
17
 
18
18
  class InterfaceKit < Common
19
19
 
20
+ # Create a new interface kit object.
21
+ # === Parameters
22
+ # * _serial_number_ = Serial number of the phidget board to open. Specify -1 to open any.
23
+ # * _timeout_ = Time to wait for attachment. Specify 0 to not call open.
20
24
  def initialize(serial_number=-1, timeout=0)
21
25
  super()
22
26
  create
@@ -33,6 +37,8 @@ module Phidgets
33
37
  end
34
38
 
35
39
  # Gets the state of a digital input.
40
+ # === Parameters
41
+ # * _index_ = The input index.
36
42
  def getInputState(index)
37
43
  state = DL.malloc(DL.sizeof('I'))
38
44
  r = Phidgets.cPhidgetInterfaceKit_getInputState(@handle, index, state.ref)
@@ -51,6 +57,8 @@ module Phidgets
51
57
  end
52
58
 
53
59
  # Gets the state of a digital output.
60
+ # === Parameters
61
+ # * _index_ = The output index.
54
62
  def getOutputState(index)
55
63
  state = DL.malloc(DL.sizeof('I'))
56
64
  r = Phidgets.cPhidgetInterfaceKit_getOutputState(@handle, index, state.ref)
@@ -60,6 +68,9 @@ module Phidgets
60
68
  end
61
69
 
62
70
  # Sets the state of a digital output.
71
+ # === Parameters
72
+ # * _index_ = The output index.
73
+ # * _state_ = The output state. Possible values are PTRUE and PFALSE.
63
74
  def setOutputState(index, state)
64
75
  r = Phidgets.cPhidgetInterfaceKit_setOutputState(@handle, index, state)
65
76
  raise Phidgets::Exception.new(r) if r != 0
@@ -75,6 +86,8 @@ module Phidgets
75
86
  end
76
87
 
77
88
  # Gets a sensor value (0-1000).
89
+ # === Parameters
90
+ # * _index_ = The sensor index.
78
91
  def getSensorValue(index)
79
92
  state = DL.malloc(DL.sizeof('I'))
80
93
  r = Phidgets.cPhidgetInterfaceKit_getSensorValue(@handle, index, state.ref)
@@ -84,6 +97,8 @@ module Phidgets
84
97
  end
85
98
 
86
99
  # Gets a sensor raw value (12-bit).
100
+ # === Parameters
101
+ # * _index_ = The sensor index.
87
102
  def getSensorRawValue(index)
88
103
  state = DL.malloc(DL.sizeof('I'))
89
104
  r = Phidgets.cPhidgetInterfaceKit_getSensorRawValue(@handle, index, state.ref)
@@ -102,6 +117,8 @@ module Phidgets
102
117
  end
103
118
 
104
119
  # Sets the ratiometric state for this board.
120
+ # === Parameters
121
+ # * _ratiometric_ = The ratiometric state. Possible values are PTRUE and PFALSE.
105
122
  def setRatiometric(ratiometric)
106
123
  r = Phidgets.cPhidgetInterfaceKit_setRatiometric(@handle, ratiometric)
107
124
  raise Phidgets::Exception.new(r) if r != 0
data/lib/phidgets/rfid.rb CHANGED
@@ -18,6 +18,10 @@ module Phidgets
18
18
 
19
19
  class RFID < Common
20
20
 
21
+ # Create a new rfid object.
22
+ # === Parameters
23
+ # * _serial_number_ = Serial number of the phidget board to open. Specify -1 to open any.
24
+ # * _timeout_ = Time to wait for attachment. Specify 0 to not call open.
21
25
  def initialize(serial_number=-1, timeout=0)
22
26
  super()
23
27
  create
@@ -34,6 +38,8 @@ module Phidgets
34
38
  end
35
39
 
36
40
  # Gets the state of an output.
41
+ # === Parameters
42
+ # * _index_ = The output index.
37
43
  def getOutputState(index)
38
44
  state = DL.malloc(DL.sizeof('I'))
39
45
  r = Phidgets.cPhidgetRFID_getOutputState(@handle, index, state.ref)
@@ -43,6 +49,9 @@ module Phidgets
43
49
  end
44
50
 
45
51
  # Sets the state of an output.
52
+ # === Parameters
53
+ # * _index_ = The output index.
54
+ # * _state_ = The output state. Possible values are PTRUE and PFALSE.
46
55
  def setOutputState(index, state)
47
56
  r = Phidgets.cPhidgetRFID_setOutputState(@handle, index, state)
48
57
  raise Phidgets::Exception.new(r) if r != 0
@@ -58,6 +67,8 @@ module Phidgets
58
67
  end
59
68
 
60
69
  # Sets the state of the antenna. Note that the antenna must be enabled before tags will be read.
70
+ # === Parameters
71
+ # * _state_ = The antenna state. Possible values are PTRUE and PFALSE.
61
72
  def setAntennaOn(state)
62
73
  r = Phidgets.cPhidgetRFID_setAntennaOn(@handle, state)
63
74
  raise Phidgets::Exception.new(r) if r != 0
@@ -73,6 +84,8 @@ module Phidgets
73
84
  end
74
85
 
75
86
  # Sets the state of the onboard LED.
87
+ # === Parameters
88
+ # * _state_ = The LED state. Possible values are PTRUE and PFALSE.
76
89
  def setLedOn(state)
77
90
  r = Phidgets.cPhidgetRFID_setLEDOn(@handle, state)
78
91
  raise Phidgets::Exception.new(r) if r != 0
@@ -0,0 +1,106 @@
1
+
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
+ class Servo < Common
14
+
15
+ # Create a new servo object.
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
24
+
25
+ # Gets the number of motors supported by this controller.
26
+ def getMotorCount
27
+ cnt = DL.malloc(DL.sizeof('I'))
28
+ r = Phidgets.cPhidgetServo_getMotorCount(@handle, cnt.ref)
29
+ raise Phidgets::Exception.new(r) if r != 0
30
+ cnt.free = nil
31
+ cnt.to_i
32
+ end
33
+
34
+ # Gets the current position of a motor.
35
+ # === Parameters
36
+ # * _index_ = The motor index.
37
+ def getPosition(index)
38
+ pos = DL.malloc(DL.sizeof('D'))
39
+ r = Phidgets.cPhidgetServo_getPosition(@handle, index, 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.cPhidgetServo_setPosition(@handle, index, position)
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 = DL.malloc(DL.sizeof('D'))
59
+ r = Phidgets.cPhidgetServo_getPositionMax(@handle, index, 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 = DL.malloc(DL.sizeof('D'))
70
+ r = Phidgets.cPhidgetServo_getPositionMin(@handle, index, 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 = DL.malloc(DL.sizeof('I'))
81
+ r = Phidgets.cPhidgetServo_getEngaged(@handle, index, 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.cPhidgetServo_setEngaged(@handle, index, state)
93
+ raise Phidgets::Exception.new(r) if r != 0
94
+ end
95
+
96
+ private
97
+
98
+ # Creates a Phidget Servo handle.
99
+ def create
100
+ r = Phidgets.cPhidgetServo_create(@handle.ref)
101
+ raise Phidgets::Exception.new(r) if r != 0
102
+ end
103
+
104
+ end
105
+
106
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phidgets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig DeHaan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-02 00:00:00 -04:00
12
+ date: 2010-08-09 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -46,17 +46,20 @@ extra_rdoc_files:
46
46
  - History.txt
47
47
  - Manifest.txt
48
48
  - PostInstall.txt
49
+ - README.txt
49
50
  files:
50
51
  - GNU_GPL.txt
51
52
  - History.txt
52
53
  - Manifest.txt
53
54
  - PostInstall.txt
55
+ - README.txt
54
56
  - README.rdoc
55
57
  - Rakefile
56
58
  - lib/phidgets.rb
57
59
  - lib/phidgets/common.rb
58
60
  - lib/phidgets/interfacekit.rb
59
61
  - lib/phidgets/rfid.rb
62
+ - lib/phidgets/servo.rb
60
63
  - script/console
61
64
  - script/destroy
62
65
  - script/generate