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/History.txt
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
+
== 0.1.0 2013-10-19
|
2
|
+
* Complete re-write as native C extension
|
3
|
+
|
4
|
+
== 0.0.6 2011-01-11
|
5
|
+
* Added skeleton classes for all the phidget types. This will at least allow the Manager class to see them
|
6
|
+
* Check library version when loading the gem and print a warning if the version may cause problems
|
7
|
+
* Updated library interface to conform to versions 2.1.6 and 2.1.7. Future versions should maintain backward compatability with at least 2.1.6
|
8
|
+
|
1
9
|
== 0.0.5 2010-10-28
|
2
10
|
* Added Manager class
|
3
11
|
* Added phidget executable
|
4
|
-
* Fixed a few bugs in the RFID class, but it is still untested
|
12
|
+
* Fixed a few bugs in the RFID class, but it is still untested
|
5
13
|
|
6
14
|
== 0.0.4 2010-09-10
|
7
15
|
* Updated for compatability with Ruby 1.9
|
@@ -15,7 +23,7 @@
|
|
15
23
|
== 0.0.2 2010-05-12
|
16
24
|
* Rewrote using DL/Importable
|
17
25
|
* Added some documentation
|
18
|
-
* Added support for Servo class
|
26
|
+
* Added support for Servo class
|
19
27
|
|
20
28
|
== 0.0.1 2009-03-27
|
21
29
|
* Initial release
|
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= phidgets
|
2
2
|
|
3
|
-
*
|
3
|
+
* https://github.com/csdehaan/phidgets
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
@@ -9,35 +9,51 @@ This gem provides a ruby interface to the phidgets library.
|
|
9
9
|
|
10
10
|
== FEATURES/PROBLEMS:
|
11
11
|
|
12
|
-
* This gem
|
12
|
+
* This gem compiles a c extension for the phidget library, so the library must be installed and the development files must be located
|
13
|
+
in a place that the compiler can find them. For windows the DevKit is required.
|
13
14
|
* The gem has been tested to work on both Linux and Windows.
|
14
|
-
*
|
15
|
-
*
|
16
|
-
If it guesses incorrectly please leave a message to let me know what your platform sets for Config::CONFIG['target_os'] and
|
17
|
-
what is the name of the phidgets library.
|
15
|
+
* Tested with Phidget Library version 2.1.8.20130618
|
16
|
+
* Callbacks do not work on Ruby versions earlier than 1.9. This is because native threads are required for them to work.
|
18
17
|
|
19
18
|
== SYNOPSIS:
|
20
19
|
|
21
20
|
require 'phidgets'
|
22
21
|
|
23
22
|
begin
|
24
|
-
ik = Phidgets::InterfaceKit.new
|
23
|
+
ik = Phidgets::InterfaceKit.new
|
24
|
+
ik.open -1
|
25
|
+
ik.wait_for_attachment
|
25
26
|
|
26
|
-
puts "Device Name = #{ik.
|
27
|
-
puts "Serial Number = #{ik.
|
28
|
-
puts "Device Version = #{ik.
|
27
|
+
puts "Device Name = #{ik.device_name}"
|
28
|
+
puts "Serial Number = #{ik.serial_number}"
|
29
|
+
puts "Device Version = #{ik.device_version}"
|
29
30
|
|
30
31
|
ik.close
|
31
32
|
|
32
|
-
rescue Phidgets::
|
33
|
-
puts
|
33
|
+
rescue Phidgets::Error => e
|
34
|
+
puts e
|
34
35
|
end
|
35
36
|
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
# Or using callbacks:
|
39
|
+
|
40
|
+
ik = Phidgets::InterfaceKit.new
|
41
|
+
ik.on_attach { |phid|
|
42
|
+
puts "Device Name = #{phid.device_name}"
|
43
|
+
puts "Serial Number = #{phid.serial_number}"
|
44
|
+
puts "Device Version = #{phid.device_version}"
|
45
|
+
}
|
46
|
+
|
47
|
+
ik.open -1
|
48
|
+
sleep 5
|
49
|
+
ik.close
|
50
|
+
|
51
|
+
|
52
|
+
# The gem also installs a command line program that will list all phidget devices that are attached, as well as allowing any
|
53
|
+
# valid method for a given phidget type to be called. For example:
|
39
54
|
|
40
|
-
To list all phidgets attached to the local computer:
|
55
|
+
# To list all phidgets attached to the local computer:
|
56
|
+
|
41
57
|
=> phidget list
|
42
58
|
----------------------------------------------------------------------
|
43
59
|
| SerialNumber | Device Name |
|
@@ -46,7 +62,8 @@ This gem provides a ruby interface to the phidgets library.
|
|
46
62
|
| 88103 | Phidget InterfaceKit 0/0/4 |
|
47
63
|
----------------------------------------------------------------------
|
48
64
|
|
49
|
-
To list all phidgets attached to a remote computer:
|
65
|
+
# To list all phidgets attached to a remote computer:
|
66
|
+
|
50
67
|
=> phidget 192.168.100.67 list
|
51
68
|
----------------------------------------------------------------------
|
52
69
|
| SerialNumber | Device Name |
|
@@ -54,16 +71,21 @@ This gem provides a ruby interface to the phidgets library.
|
|
54
71
|
| 73782 | Phidget InterfaceKit 0/0/8 |
|
55
72
|
----------------------------------------------------------------------
|
56
73
|
|
57
|
-
To call a method for a specific local phidget:
|
74
|
+
# To call a method for a specific local phidget:
|
58
75
|
=> phidget 73723 setOutputState 0 1
|
59
76
|
|
60
|
-
To call a method for a specific remote phidget:
|
77
|
+
# To call a method for a specific remote phidget:
|
61
78
|
=> phidget 192.168.100.67:73782 setOuputState 2 0
|
62
79
|
|
63
80
|
|
64
81
|
== REQUIREMENTS:
|
65
82
|
|
66
83
|
* The Phidgets library (http://www.phidgets.com/)
|
84
|
+
* For Windows the ruby DevKit is required
|
85
|
+
* The development header file and library must be placed in a location where the compiler can find them.
|
86
|
+
For Linux this should be done when running "make install" for the Phidget Library. For Windows the files
|
87
|
+
need to be copied from the install directory (\\Program Files\\Phidgets). phidget21.h can be copied to
|
88
|
+
RUBY_DIR\\include\\ruby-1.9.1. phidget21.lib can be copied to RUBY_DIR\\lib.
|
67
89
|
|
68
90
|
== INSTALL:
|
69
91
|
|
@@ -86,3 +108,4 @@ GNU General Public License for more details.
|
|
86
108
|
You should have received a copy of the GNU General Public License
|
87
109
|
along with this program; if not, write to the Free Software
|
88
110
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
111
|
+
|
data/Rakefile
CHANGED
@@ -1,20 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake/extensiontask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rdoc/task'
|
7
|
+
|
8
|
+
spec = Gem::Specification.load('phidgets.gemspec')
|
9
|
+
|
10
|
+
Rake::ExtensionTask.new 'phidgets', spec
|
11
|
+
|
12
|
+
Gem::PackageTask.new(spec) do |pkg|
|
13
|
+
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
RDOC_FILES = FileList["README.rdoc", "ext/phidgets/*.c", "lib/phidgets/*.rb"]
|
18
|
+
|
19
|
+
Rake::RDocTask.new do |rd|
|
20
|
+
rd.main = "README.rdoc"
|
21
|
+
rd.rdoc_dir = "doc/site/api"
|
22
|
+
rd.rdoc_files.include(RDOC_FILES)
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::RDocTask.new(:ri) do |rd|
|
26
|
+
rd.main = "README.rdoc"
|
27
|
+
rd.rdoc_dir = "doc/ri"
|
28
|
+
rd.options << "--ri-system"
|
29
|
+
rd.rdoc_files.include(RDOC_FILES)
|
30
|
+
end
|
31
|
+
|
data/bin/phidget
CHANGED
@@ -12,27 +12,25 @@ def usage
|
|
12
12
|
$stdout.puts
|
13
13
|
$stdout.puts ' Examples:'
|
14
14
|
$stdout.puts ' phidget list'
|
15
|
-
$stdout.puts ' phidget -1
|
16
|
-
$stdout.puts ' phidget 34619
|
15
|
+
$stdout.puts ' phidget -1 set_output_state 0 1'
|
16
|
+
$stdout.puts ' phidget 34619 device_name'
|
17
17
|
end
|
18
18
|
|
19
19
|
begin
|
20
|
-
|
21
|
-
host = nil
|
22
|
-
id = nil
|
20
|
+
args = {:port => 5001, :password => ''}
|
23
21
|
|
24
22
|
case ARGV[0]
|
25
23
|
when /^(-1|\d+)$/
|
26
|
-
|
24
|
+
args[:serial_number] = $1.to_i
|
27
25
|
when /^(\w|.+):(-1|\d+)$/
|
28
|
-
|
29
|
-
|
26
|
+
args[:address] = $1
|
27
|
+
args[:serial_number] = $2.to_i
|
30
28
|
when /^list$/i
|
31
|
-
list = true
|
29
|
+
args[:list] = true
|
32
30
|
when /^(\w|.+)$/
|
33
31
|
if ARGV[1].downcase == 'list'
|
34
|
-
list = true
|
35
|
-
|
32
|
+
args[:list] = true
|
33
|
+
args[:address] = $1
|
36
34
|
else
|
37
35
|
raise "Invalid Arguments."
|
38
36
|
end
|
@@ -41,58 +39,45 @@ begin
|
|
41
39
|
end
|
42
40
|
|
43
41
|
manager = Phidgets::Manager.new
|
42
|
+
manager.open(args)
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
else
|
48
|
-
manager.open
|
49
|
-
end
|
44
|
+
# give the manager some time to find the devices
|
45
|
+
args[:address] ? sleep(2) : sleep(1)
|
50
46
|
|
51
|
-
devices = manager.
|
47
|
+
devices = manager.attached_devices
|
52
48
|
manager.close
|
53
49
|
|
54
|
-
if devices.
|
55
|
-
$stdout.puts
|
56
|
-
$stdout.puts 'There are no phidgets attached.'
|
57
|
-
$stdout.puts
|
50
|
+
if devices.size == 0
|
51
|
+
$stdout.puts "\nThere are no phidgets attached.\n\n"
|
58
52
|
exit
|
59
53
|
end
|
60
54
|
|
61
|
-
if list
|
62
|
-
$stdout.puts
|
63
|
-
$stdout.puts "----------------------------------------------------------------------"
|
55
|
+
if args[:list]
|
56
|
+
$stdout.puts "\n----------------------------------------------------------------------"
|
64
57
|
$stdout.puts "| SerialNumber | Device Name |"
|
65
58
|
$stdout.puts "----------------------------------------------------------------------"
|
66
59
|
devices.each_pair { |serial,phidget|
|
60
|
+
phidget.open(args)
|
61
|
+
phidget.wait_for_attachment(2000)
|
67
62
|
d_str = "| #{serial}"
|
68
|
-
d_str += " " * (24 - d_str.length)
|
69
|
-
d_str += "| #{phidget.getDeviceName}"
|
63
|
+
d_str += " " * (24 - d_str.length) + "| #{phidget.device_name}"
|
70
64
|
d_str += " " * (69 - d_str.length) + "|"
|
71
65
|
$stdout.puts d_str
|
66
|
+
phidget.close
|
72
67
|
}
|
73
|
-
$stdout.puts "
|
74
|
-
$stdout.puts
|
68
|
+
$stdout.puts "----------------------------------------------------------------------\n"
|
75
69
|
|
76
70
|
else
|
77
|
-
phidget =
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
phidget.send(ARGV[1], ARGV[2])
|
84
|
-
when 4
|
85
|
-
phidget.send(ARGV[1], ARGV[2], ARGV[3])
|
86
|
-
else
|
87
|
-
raise "Invalid Arguments."
|
88
|
-
end
|
71
|
+
phidget = args[:serial_number] > 0 ? devices[args[:serial_number]] : devices.values[0]
|
72
|
+
args[:serial_number] = devices.keys[0] unless args[:serial_number] > 0
|
73
|
+
phidget.open(args)
|
74
|
+
phidget.wait_for_attachment(2000)
|
75
|
+
$stdout.puts eval("phidget.#{ARGV[1]}(#{ARGV[2..-1].join(',')})")
|
76
|
+
phidget.close
|
89
77
|
end
|
90
78
|
|
91
79
|
rescue SystemExit
|
92
80
|
rescue Exception => e
|
93
|
-
$stdout.puts "#{e}\n#{e.backtrace.join("\n")}"
|
94
|
-
$stdout.puts
|
95
|
-
usage
|
96
|
-
$stdout.puts
|
81
|
+
$stdout.puts "#{e}\n#{e.backtrace.join("\n")}\n#{usage}\n"
|
97
82
|
end
|
98
83
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
HEADER_DIRS = [ '/Library/Frameworks/Phidget21.framework/Headers' ]
|
4
|
+
|
5
|
+
find_header 'phidget21.h', *HEADER_DIRS
|
6
|
+
find_library 'libphidget21', 'CPhidget_getLibraryVersion', '/usr/lib/'
|
7
|
+
have_framework('Phidget21') unless RUBY_VERSION < '1.9.0'
|
8
|
+
have_library('phidget21')
|
9
|
+
dir_config("phidgets")
|
10
|
+
|
11
|
+
$CFLAGS += ' -DPH_CALLBACK' unless RUBY_VERSION < '1.9.0'
|
12
|
+
|
13
|
+
create_makefile("phidgets")
|
14
|
+
|
@@ -0,0 +1,272 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_errors[PHIDGET_ERROR_CODE_COUNT+1];
|
6
|
+
|
7
|
+
VALUE ph_get_library_version(VALUE self);
|
8
|
+
VALUE ph_enable_logging(VALUE self, VALUE level, VALUE output_file);
|
9
|
+
VALUE ph_disable_logging(VALUE self);
|
10
|
+
VALUE ph_log(VALUE self, VALUE level, VALUE msg_id, VALUE message);
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
void Init_phidgets() {
|
15
|
+
VALUE ph_module = rb_define_module("Phidgets");
|
16
|
+
VALUE ph_error;
|
17
|
+
VALUE ph_common;
|
18
|
+
|
19
|
+
rb_define_const(ph_module, "NOTATTACHED", INT2FIX(PHIDGET_NOTATTACHED));
|
20
|
+
rb_define_const(ph_module, "ATTACHED", INT2FIX(PHIDGET_ATTACHED));
|
21
|
+
|
22
|
+
rb_define_const(ph_module, "CLASS_ACCELEROMETER", INT2FIX(PHIDCLASS_ACCELEROMETER));
|
23
|
+
rb_define_const(ph_module, "CLASS_ADVANCEDSERVO", INT2FIX(PHIDCLASS_ADVANCEDSERVO));
|
24
|
+
rb_define_const(ph_module, "CLASS_ANALOG", INT2FIX(PHIDCLASS_ANALOG));
|
25
|
+
rb_define_const(ph_module, "CLASS_BRIDGE", INT2FIX(PHIDCLASS_BRIDGE));
|
26
|
+
rb_define_const(ph_module, "CLASS_ENCODER", INT2FIX(PHIDCLASS_ENCODER));
|
27
|
+
rb_define_const(ph_module, "CLASS_FREQUENCYCOUNTER", INT2FIX(PHIDCLASS_FREQUENCYCOUNTER));
|
28
|
+
rb_define_const(ph_module, "CLASS_GPS", INT2FIX(PHIDCLASS_GPS));
|
29
|
+
rb_define_const(ph_module, "CLASS_INTERFACEKIT", INT2FIX(PHIDCLASS_INTERFACEKIT));
|
30
|
+
rb_define_const(ph_module, "CLASS_IR", INT2FIX(PHIDCLASS_IR));
|
31
|
+
rb_define_const(ph_module, "CLASS_LED", INT2FIX(PHIDCLASS_LED));
|
32
|
+
rb_define_const(ph_module, "CLASS_MOTORCONTROL", INT2FIX(PHIDCLASS_MOTORCONTROL));
|
33
|
+
rb_define_const(ph_module, "CLASS_PHSENSOR", INT2FIX(PHIDCLASS_PHSENSOR));
|
34
|
+
rb_define_const(ph_module, "CLASS_RFID", INT2FIX(PHIDCLASS_RFID));
|
35
|
+
rb_define_const(ph_module, "CLASS_SERVO", INT2FIX(PHIDCLASS_SERVO));
|
36
|
+
rb_define_const(ph_module, "CLASS_SPATIAL", INT2FIX(PHIDCLASS_SPATIAL));
|
37
|
+
rb_define_const(ph_module, "CLASS_STEPPER", INT2FIX(PHIDCLASS_STEPPER));
|
38
|
+
rb_define_const(ph_module, "CLASS_TEMPERATURESENSOR", INT2FIX(PHIDCLASS_TEMPERATURESENSOR));
|
39
|
+
rb_define_const(ph_module, "CLASS_TEXTLCD", INT2FIX(PHIDCLASS_TEXTLCD));
|
40
|
+
rb_define_const(ph_module, "CLASS_TEXTLED", INT2FIX(PHIDCLASS_TEXTLED));
|
41
|
+
rb_define_const(ph_module, "CLASS_WEIGHTSENSOR", INT2FIX(PHIDCLASS_WEIGHTSENSOR));
|
42
|
+
|
43
|
+
rb_define_const(ph_module, "ID_ACCELEROMETER_3AXIS", INT2FIX(PHIDID_ACCELEROMETER_3AXIS));
|
44
|
+
rb_define_const(ph_module, "ID_ADVANCEDSERVO_1MOTOR", INT2FIX(PHIDID_ADVANCEDSERVO_1MOTOR));
|
45
|
+
rb_define_const(ph_module, "ID_ADVANCEDSERVO_8MOTOR", INT2FIX(PHIDID_ADVANCEDSERVO_8MOTOR));
|
46
|
+
rb_define_const(ph_module, "ID_ANALOG_4OUTPUT", INT2FIX(PHIDID_ANALOG_4OUTPUT));
|
47
|
+
rb_define_const(ph_module, "ID_BIPOLAR_STEPPER_1MOTOR", INT2FIX(PHIDID_BIPOLAR_STEPPER_1MOTOR));
|
48
|
+
rb_define_const(ph_module, "ID_BRIDGE_4INPUT", INT2FIX(PHIDID_BRIDGE_4INPUT));
|
49
|
+
rb_define_const(ph_module, "ID_ENCODER_1ENCODER_1INPUT", INT2FIX(PHIDID_ENCODER_1ENCODER_1INPUT));
|
50
|
+
rb_define_const(ph_module, "ID_ENCODER_HS_1ENCODER", INT2FIX(PHIDID_ENCODER_HS_1ENCODER));
|
51
|
+
rb_define_const(ph_module, "ID_ENCODER_HS_4ENCODER_4INPUT", INT2FIX(PHIDID_ENCODER_HS_4ENCODER_4INPUT));
|
52
|
+
rb_define_const(ph_module, "ID_FREQUENCYCOUNTER_2INPUT", INT2FIX(PHIDID_FREQUENCYCOUNTER_2INPUT));
|
53
|
+
rb_define_const(ph_module, "ID_GPS", INT2FIX(PHIDID_GPS));
|
54
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_0_0_4", INT2FIX(PHIDID_INTERFACEKIT_0_0_4));
|
55
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_0_0_8", INT2FIX(PHIDID_INTERFACEKIT_0_0_8));
|
56
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_0_16_16", INT2FIX(PHIDID_INTERFACEKIT_0_16_16));
|
57
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_2_2_2", INT2FIX(PHIDID_INTERFACEKIT_2_2_2));
|
58
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_8_8_8", INT2FIX(PHIDID_INTERFACEKIT_8_8_8));
|
59
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_8_8_8_w_LCD", INT2FIX(PHIDID_INTERFACEKIT_8_8_8_w_LCD));
|
60
|
+
rb_define_const(ph_module, "ID_IR", INT2FIX(PHIDID_IR));
|
61
|
+
rb_define_const(ph_module, "ID_LED_64_ADV", INT2FIX(PHIDID_LED_64_ADV));
|
62
|
+
rb_define_const(ph_module, "ID_LINEAR_TOUCH", INT2FIX(PHIDID_LINEAR_TOUCH));
|
63
|
+
rb_define_const(ph_module, "ID_MOTORCONTROL_1MOTOR", INT2FIX(PHIDID_MOTORCONTROL_1MOTOR));
|
64
|
+
rb_define_const(ph_module, "ID_MOTORCONTROL_HC_2MOTOR", INT2FIX(PHIDID_MOTORCONTROL_HC_2MOTOR));
|
65
|
+
rb_define_const(ph_module, "ID_RFID_2OUTPUT", INT2FIX(PHIDID_RFID_2OUTPUT));
|
66
|
+
rb_define_const(ph_module, "ID_RFID_2OUTPUT_READ_WRITE", INT2FIX(PHIDID_RFID_2OUTPUT_READ_WRITE));
|
67
|
+
rb_define_const(ph_module, "ID_ROTARY_TOUCH", INT2FIX(PHIDID_ROTARY_TOUCH));
|
68
|
+
rb_define_const(ph_module, "ID_SPATIAL_ACCEL_3AXIS", INT2FIX(PHIDID_SPATIAL_ACCEL_3AXIS));
|
69
|
+
rb_define_const(ph_module, "ID_SPATIAL_ACCEL_GYRO_COMPASS", INT2FIX(PHIDID_SPATIAL_ACCEL_GYRO_COMPASS));
|
70
|
+
rb_define_const(ph_module, "ID_TEMPERATURESENSOR", INT2FIX(PHIDID_TEMPERATURESENSOR));
|
71
|
+
rb_define_const(ph_module, "ID_TEMPERATURESENSOR_4", INT2FIX(PHIDID_TEMPERATURESENSOR_4));
|
72
|
+
rb_define_const(ph_module, "ID_TEMPERATURESENSOR_IR", INT2FIX(PHIDID_TEMPERATURESENSOR_IR));
|
73
|
+
rb_define_const(ph_module, "ID_TEXTLCD_2x20_w_8_8_8", INT2FIX(PHIDID_TEXTLCD_2x20_w_8_8_8));
|
74
|
+
rb_define_const(ph_module, "ID_TEXTLCD_ADAPTER", INT2FIX(PHIDID_TEXTLCD_ADAPTER));
|
75
|
+
rb_define_const(ph_module, "ID_UNIPOLAR_STEPPER_4MOTOR", INT2FIX(PHIDID_UNIPOLAR_STEPPER_4MOTOR));
|
76
|
+
rb_define_const(ph_module, "ID_ACCELEROMETER_2AXIS", INT2FIX(PHIDID_ACCELEROMETER_2AXIS));
|
77
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_0_8_8_w_LCD", INT2FIX(PHIDID_INTERFACEKIT_0_8_8_w_LCD));
|
78
|
+
rb_define_const(ph_module, "ID_INTERFACEKIT_4_8_8", INT2FIX(PHIDID_INTERFACEKIT_4_8_8));
|
79
|
+
rb_define_const(ph_module, "ID_LED_64", INT2FIX(PHIDID_LED_64));
|
80
|
+
rb_define_const(ph_module, "ID_MOTORCONTROL_LV_2MOTOR_4INPUT", INT2FIX(PHIDID_MOTORCONTROL_LV_2MOTOR_4INPUT));
|
81
|
+
rb_define_const(ph_module, "ID_PHSENSOR", INT2FIX(PHIDID_PHSENSOR));
|
82
|
+
rb_define_const(ph_module, "ID_RFID", INT2FIX(PHIDID_RFID));
|
83
|
+
rb_define_const(ph_module, "ID_SERVO_1MOTOR", INT2FIX(PHIDID_SERVO_1MOTOR));
|
84
|
+
rb_define_const(ph_module, "ID_SERVO_1MOTOR_OLD", INT2FIX(PHIDID_SERVO_1MOTOR_OLD));
|
85
|
+
rb_define_const(ph_module, "ID_SERVO_4MOTOR", INT2FIX(PHIDID_SERVO_4MOTOR));
|
86
|
+
rb_define_const(ph_module, "ID_SERVO_4MOTOR_OLD", INT2FIX(PHIDID_SERVO_4MOTOR_OLD));
|
87
|
+
rb_define_const(ph_module, "ID_TEXTLCD_2x20", INT2FIX(PHIDID_TEXTLCD_2x20));
|
88
|
+
rb_define_const(ph_module, "ID_TEXTLCD_2x20_w_0_8_8", INT2FIX(PHIDID_TEXTLCD_2x20_w_0_8_8));
|
89
|
+
rb_define_const(ph_module, "ID_TEXTLED_1x8", INT2FIX(PHIDID_TEXTLED_1x8));
|
90
|
+
rb_define_const(ph_module, "ID_TEXTLED_4x8", INT2FIX(PHIDID_TEXTLED_4x8));
|
91
|
+
rb_define_const(ph_module, "ID_WEIGHTSENSOR", INT2FIX(PHIDID_WEIGHTSENSOR));
|
92
|
+
rb_define_const(ph_module, "ID_FIRMWARE_UPGRADE", INT2FIX(PHIDID_FIRMWARE_UPGRADE));
|
93
|
+
|
94
|
+
rb_define_const(ph_module, "LOG_CRITICAL", INT2FIX(PHIDGET_LOG_CRITICAL));
|
95
|
+
rb_define_const(ph_module, "LOG_ERROR", INT2FIX(PHIDGET_LOG_ERROR));
|
96
|
+
rb_define_const(ph_module, "LOG_WARNING", INT2FIX(PHIDGET_LOG_WARNING));
|
97
|
+
rb_define_const(ph_module, "LOG_DEBUG", INT2FIX(PHIDGET_LOG_DEBUG));
|
98
|
+
rb_define_const(ph_module, "LOG_INFO", INT2FIX(PHIDGET_LOG_INFO));
|
99
|
+
rb_define_const(ph_module, "LOG_VERBOSE", INT2FIX(PHIDGET_LOG_VERBOSE));
|
100
|
+
|
101
|
+
ph_error = rb_define_class_under(ph_module, "Error", rb_eStandardError);
|
102
|
+
ph_errors[EPHIDGET_NOTFOUND] = rb_define_class_under(ph_error, "NotFound", ph_error);
|
103
|
+
ph_errors[EPHIDGET_NOMEMORY] = rb_define_class_under(ph_error, "NoMemory", ph_error);
|
104
|
+
ph_errors[EPHIDGET_UNEXPECTED] = rb_define_class_under(ph_error, "Unexpected", ph_error);
|
105
|
+
ph_errors[EPHIDGET_INVALIDARG] = rb_define_class_under(ph_error, "InvalidArg", ph_error);
|
106
|
+
ph_errors[EPHIDGET_NOTATTACHED] = rb_define_class_under(ph_error, "NotAttached", ph_error);
|
107
|
+
ph_errors[EPHIDGET_INTERRUPTED] = rb_define_class_under(ph_error, "Interrupted", ph_error);
|
108
|
+
ph_errors[EPHIDGET_INVALID] = rb_define_class_under(ph_error, "Invalid", ph_error);
|
109
|
+
ph_errors[EPHIDGET_NETWORK] = rb_define_class_under(ph_error, "Network", ph_error);
|
110
|
+
ph_errors[EPHIDGET_UNKNOWNVAL] = rb_define_class_under(ph_error, "UnknownVal", ph_error);
|
111
|
+
ph_errors[EPHIDGET_BADPASSWORD] = rb_define_class_under(ph_error, "BadPassword", ph_error);
|
112
|
+
ph_errors[EPHIDGET_UNSUPPORTED] = rb_define_class_under(ph_error, "Unsupported", ph_error);
|
113
|
+
ph_errors[EPHIDGET_DUPLICATE] = rb_define_class_under(ph_error, "Duplicate", ph_error);
|
114
|
+
ph_errors[EPHIDGET_TIMEOUT] = rb_define_class_under(ph_error, "Timeout", ph_error);
|
115
|
+
ph_errors[EPHIDGET_OUTOFBOUNDS] = rb_define_class_under(ph_error, "OutOfBounds", ph_error);
|
116
|
+
ph_errors[EPHIDGET_EVENT] = rb_define_class_under(ph_error, "Event", ph_error);
|
117
|
+
ph_errors[EPHIDGET_NETWORK_NOTCONNECTED] = rb_define_class_under(ph_error, "NetworkNotConnected", ph_error);
|
118
|
+
ph_errors[EPHIDGET_WRONGDEVICE] = rb_define_class_under(ph_error, "WrongDevice", ph_error);
|
119
|
+
ph_errors[EPHIDGET_CLOSED] = rb_define_class_under(ph_error, "Closed", ph_error);
|
120
|
+
ph_errors[EPHIDGET_BADVERSION] = rb_define_class_under(ph_error, "BadVersion", ph_error);
|
121
|
+
ph_errors[EPHIDGET_NOTIMPLEMENTED] = rb_define_class_under(ph_error, "NotImplemented", ph_error);
|
122
|
+
|
123
|
+
/*
|
124
|
+
* Document-method: getLibraryVersion
|
125
|
+
* call-seq: getLibraryVersion -> version
|
126
|
+
*
|
127
|
+
* Gets the library version. This contains a version number and a build date.
|
128
|
+
*/
|
129
|
+
rb_define_singleton_method(ph_module, "getLibraryVersion", ph_get_library_version, 0);
|
130
|
+
|
131
|
+
/*
|
132
|
+
* Document-method: library_version
|
133
|
+
* call-seq: library_version -> version
|
134
|
+
*
|
135
|
+
* Gets the library version. This contains a version number and a build date.
|
136
|
+
*/
|
137
|
+
rb_define_singleton_method(ph_module, "library_version", ph_get_library_version, 0);
|
138
|
+
|
139
|
+
/*
|
140
|
+
* Document-method: enableLogging
|
141
|
+
* call-seq: enableLogging(log_level, output_file)
|
142
|
+
*
|
143
|
+
* Enables logging.
|
144
|
+
*/
|
145
|
+
rb_define_singleton_method(ph_module, "enableLogging", ph_enable_logging, 2);
|
146
|
+
|
147
|
+
/*
|
148
|
+
* Document-method: enable_logging
|
149
|
+
* call-seq: enable_logging(log_level, output_file)
|
150
|
+
*
|
151
|
+
* Enables logging.
|
152
|
+
*/
|
153
|
+
rb_define_singleton_method(ph_module, "enable_logging", ph_enable_logging, 2);
|
154
|
+
|
155
|
+
/*
|
156
|
+
* Document-method: disableLogging
|
157
|
+
* call-seq: disableLogging
|
158
|
+
*
|
159
|
+
* Disables logging.
|
160
|
+
*/
|
161
|
+
rb_define_singleton_method(ph_module, "disableLogging", ph_disable_logging, 0);
|
162
|
+
|
163
|
+
/*
|
164
|
+
* Document-method: disable_logging
|
165
|
+
* call-seq: disable_logging
|
166
|
+
*
|
167
|
+
* Disables logging.
|
168
|
+
*/
|
169
|
+
rb_define_singleton_method(ph_module, "disable_logging", ph_disable_logging, 0);
|
170
|
+
|
171
|
+
/*
|
172
|
+
* Document-method: log
|
173
|
+
* call-seq: log(log_level, msg_id, msg)
|
174
|
+
*
|
175
|
+
* Appends a message to the log.
|
176
|
+
*/
|
177
|
+
rb_define_singleton_method(ph_module, "log", ph_log, 3);
|
178
|
+
|
179
|
+
Init_phidgets_dictionary(ph_module);
|
180
|
+
Init_phidgets_manager(ph_module);
|
181
|
+
ph_common = Init_phidgets_common(ph_module);
|
182
|
+
Init_phidgets_accel(ph_module, ph_common);
|
183
|
+
Init_phidgets_advservo(ph_module, ph_common);
|
184
|
+
Init_phidgets_analog(ph_module, ph_common);
|
185
|
+
Init_phidgets_bridge(ph_module, ph_common);
|
186
|
+
Init_phidgets_encoder(ph_module, ph_common);
|
187
|
+
Init_phidgets_freq(ph_module, ph_common);
|
188
|
+
Init_phidgets_gps(ph_module, ph_common);
|
189
|
+
Init_phidgets_ifkit(ph_module, ph_common);
|
190
|
+
Init_phidgets_ir(ph_module, ph_common);
|
191
|
+
Init_phidgets_led(ph_module, ph_common);
|
192
|
+
Init_phidgets_motor_control(ph_module, ph_common);
|
193
|
+
Init_phidgets_phsensor(ph_module, ph_common);
|
194
|
+
Init_phidgets_rfid(ph_module, ph_common);
|
195
|
+
Init_phidgets_servo(ph_module, ph_common);
|
196
|
+
Init_phidgets_spatial(ph_module, ph_common);
|
197
|
+
Init_phidgets_stepper(ph_module, ph_common);
|
198
|
+
Init_phidgets_temp(ph_module, ph_common);
|
199
|
+
Init_phidgets_textlcd(ph_module, ph_common);
|
200
|
+
Init_phidgets_textled(ph_module, ph_common);
|
201
|
+
Init_phidgets_weight(ph_module, ph_common);
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
ph_data_t *get_ph_data(VALUE self) {
|
206
|
+
ph_data_t *ph;
|
207
|
+
Data_Get_Struct(self, ph_data_t, ph);
|
208
|
+
return ph;
|
209
|
+
}
|
210
|
+
|
211
|
+
CPhidgetHandle get_ph_handle(VALUE self) {
|
212
|
+
ph_data_t *ph = get_ph_data(self);
|
213
|
+
return ph->handle;
|
214
|
+
}
|
215
|
+
|
216
|
+
void ph_raise(int err_code) {
|
217
|
+
if(err_code > EPHIDGET_OK && err_code < PHIDGET_ERROR_CODE_COUNT) {
|
218
|
+
const char *err_description;
|
219
|
+
CPhidget_getErrorDescription(err_code, &err_description);
|
220
|
+
rb_raise(ph_errors[err_code], err_description);
|
221
|
+
}
|
222
|
+
if(err_code == EPHIDGET_NOTIMPLEMENTED) {
|
223
|
+
rb_raise(ph_errors[EPHIDGET_NOTIMPLEMENTED], "This functionality has not been implemented yet");
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
VALUE ph_get_library_version(VALUE self) {
|
228
|
+
const char *lib_version;
|
229
|
+
ph_raise(CPhidget_getLibraryVersion(&lib_version));
|
230
|
+
return rb_str_new2(lib_version);
|
231
|
+
}
|
232
|
+
|
233
|
+
VALUE ph_enable_logging(VALUE self, VALUE level, VALUE output_file) {
|
234
|
+
ph_raise(CPhidget_enableLogging(FIX2INT(level), StringValueCStr(output_file)));
|
235
|
+
return Qnil;
|
236
|
+
}
|
237
|
+
|
238
|
+
VALUE ph_disable_logging(VALUE self) {
|
239
|
+
ph_raise(CPhidget_disableLogging());
|
240
|
+
return Qnil;
|
241
|
+
}
|
242
|
+
|
243
|
+
VALUE ph_log(VALUE self, VALUE level, VALUE msg_id, VALUE message) {
|
244
|
+
ph_raise(CPhidget_log(FIX2INT(level), StringValueCStr(msg_id), StringValueCStr(message)));
|
245
|
+
return Qnil;
|
246
|
+
}
|
247
|
+
|
248
|
+
|
249
|
+
#ifdef PH_CALLBACK
|
250
|
+
void ph_callback_thread(ph_callback_data_t *callback_data) {
|
251
|
+
while(! callback_data->exit) {
|
252
|
+
rb_thread_blocking_region(wait_for_callback, (void *)callback_data, cancel_wait_for_callback, (void *)callback_data);
|
253
|
+
if(TYPE(callback_data->callback) != T_NIL) rb_funcall(callback_data->callback, rb_intern("call"), 1, callback_data->phidget);
|
254
|
+
callback_data->called = false;
|
255
|
+
};
|
256
|
+
}
|
257
|
+
|
258
|
+
VALUE wait_for_callback(void *arg) {
|
259
|
+
ph_callback_data_t *callback_data = (ph_callback_data_t *)arg;
|
260
|
+
while(! callback_data->exit) {
|
261
|
+
usleep(PH_CALLBACK_POLLING_INTERVAL);
|
262
|
+
if(callback_data->called) return Qnil;
|
263
|
+
};
|
264
|
+
return Qnil;
|
265
|
+
}
|
266
|
+
|
267
|
+
void cancel_wait_for_callback(void *arg) {
|
268
|
+
ph_callback_data_t *callback_data = (ph_callback_data_t *)arg;
|
269
|
+
callback_data->exit = true;
|
270
|
+
}
|
271
|
+
#endif
|
272
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <stdbool.h>
|
3
|
+
#include <math.h>
|
4
|
+
#include <time.h>
|
5
|
+
#include <unistd.h>
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
#include <phidget21.h>
|
9
|
+
|
10
|
+
#ifndef _PHIDGETS_EXT_
|
11
|
+
#define _PHIDGETS_EXT_
|
12
|
+
|
13
|
+
|
14
|
+
#define PH_CALLBACK_POLLING_INTERVAL 100000
|
15
|
+
#define EPHIDGET_NOTIMPLEMENTED PHIDGET_ERROR_CODE_COUNT
|
16
|
+
|
17
|
+
|
18
|
+
#ifdef PH_CALLBACK
|
19
|
+
typedef struct ph_callback_data {
|
20
|
+
volatile bool called;
|
21
|
+
volatile bool exit;
|
22
|
+
VALUE phidget;
|
23
|
+
VALUE callback;
|
24
|
+
} ph_callback_data_t;
|
25
|
+
|
26
|
+
void ph_callback_thread(ph_callback_data_t *callback_data);
|
27
|
+
VALUE wait_for_callback(void *arg);
|
28
|
+
void cancel_wait_for_callback(void *arg);
|
29
|
+
#endif
|
30
|
+
|
31
|
+
|
32
|
+
typedef struct ph_data {
|
33
|
+
CPhidgetHandle handle;
|
34
|
+
#ifdef PH_CALLBACK
|
35
|
+
ph_callback_data_t attach_callback;
|
36
|
+
ph_callback_data_t detach_callback;
|
37
|
+
ph_callback_data_t server_connect_callback;
|
38
|
+
ph_callback_data_t server_disconnect_callback;
|
39
|
+
ph_callback_data_t dev_callback_1;
|
40
|
+
ph_callback_data_t dev_callback_2;
|
41
|
+
ph_callback_data_t dev_callback_3;
|
42
|
+
ph_callback_data_t dev_callback_4;
|
43
|
+
ph_callback_data_t dev_callback_5;
|
44
|
+
ph_callback_data_t dev_callback_6;
|
45
|
+
ph_callback_data_t dev_callback_7;
|
46
|
+
ph_callback_data_t dev_callback_8;
|
47
|
+
#endif
|
48
|
+
} ph_data_t;
|
49
|
+
|
50
|
+
|
51
|
+
void Init_phidgets();
|
52
|
+
VALUE Init_phidgets_dictionary(VALUE ph_module);
|
53
|
+
VALUE Init_phidgets_manager(VALUE ph_module);
|
54
|
+
VALUE Init_phidgets_common(VALUE ph_module);
|
55
|
+
VALUE Init_phidgets_accel(VALUE ph_module, VALUE ph_common);
|
56
|
+
VALUE Init_phidgets_advservo(VALUE ph_module, VALUE ph_common);
|
57
|
+
VALUE Init_phidgets_analog(VALUE ph_module, VALUE ph_common);
|
58
|
+
VALUE Init_phidgets_bridge(VALUE ph_module, VALUE ph_common);
|
59
|
+
VALUE Init_phidgets_encoder(VALUE ph_module, VALUE ph_common);
|
60
|
+
VALUE Init_phidgets_freq(VALUE ph_module, VALUE ph_common);
|
61
|
+
VALUE Init_phidgets_gps(VALUE ph_module, VALUE ph_common);
|
62
|
+
VALUE Init_phidgets_ifkit(VALUE ph_module, VALUE ph_common);
|
63
|
+
VALUE Init_phidgets_ir(VALUE ph_module, VALUE ph_common);
|
64
|
+
VALUE Init_phidgets_led(VALUE ph_module, VALUE ph_common);
|
65
|
+
VALUE Init_phidgets_motor_control(VALUE ph_module, VALUE ph_common);
|
66
|
+
VALUE Init_phidgets_phsensor(VALUE ph_module, VALUE ph_common);
|
67
|
+
VALUE Init_phidgets_rfid(VALUE ph_module, VALUE ph_common);
|
68
|
+
VALUE Init_phidgets_servo(VALUE ph_module, VALUE ph_common);
|
69
|
+
VALUE Init_phidgets_spatial(VALUE ph_module, VALUE ph_common);
|
70
|
+
VALUE Init_phidgets_stepper(VALUE ph_module, VALUE ph_common);
|
71
|
+
VALUE Init_phidgets_temp(VALUE ph_module, VALUE ph_common);
|
72
|
+
VALUE Init_phidgets_textlcd(VALUE ph_module, VALUE ph_common);
|
73
|
+
VALUE Init_phidgets_textled(VALUE ph_module, VALUE ph_common);
|
74
|
+
VALUE Init_phidgets_weight(VALUE ph_module, VALUE ph_common);
|
75
|
+
|
76
|
+
|
77
|
+
ph_data_t *get_ph_data(VALUE self);
|
78
|
+
CPhidgetHandle get_ph_handle(VALUE self);
|
79
|
+
void ph_raise(int err_code);
|
80
|
+
|
81
|
+
#endif
|
82
|
+
|