phidgets-ffi 0.1.2 → 0.1.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/examples/HelloWorld.rb +3 -3
- data/examples/accelerometer.rb +6 -7
- data/examples/advanced_servo.rb +6 -10
- data/examples/analog.rb +9 -10
- data/examples/bridge.rb +10 -12
- data/examples/dictionary.rb +28 -25
- data/examples/encoder.rb +15 -12
- data/examples/frequency_counter.rb +11 -12
- data/examples/gps.rb +15 -17
- data/examples/interface_kit_with_block.rb +10 -16
- data/examples/interface_kit_without_block.rb +17 -18
- data/examples/ir.rb +38 -45
- data/examples/led.rb +8 -7
- data/examples/manager.rb +3 -5
- data/examples/motor_control.rb +19 -24
- data/examples/raw-ffi/dictionary.rb +1 -1
- data/examples/raw-ffi/interface_kit.rb +1 -1
- data/examples/raw-ffi/library_version.rb +0 -1
- data/examples/raw-ffi/manager.rb +3 -3
- data/examples/rfid.rb +11 -13
- data/examples/servo.rb +4 -6
- data/examples/spatial.rb +17 -18
- data/examples/stepper.rb +16 -18
- data/examples/temperature_sensor.rb +8 -10
- data/examples/text_lcd.rb +22 -24
- data/lib/phidgets-ffi/ffi/common.rb +1 -1
- data/lib/phidgets-ffi/ffi/manager.rb +1 -1
- data/lib/phidgets-ffi/version.rb +1 -1
- metadata +2 -2
@@ -6,8 +6,7 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
|
|
6
6
|
puts "Wait for PhidgetInterfaceKit to attach..."
|
7
7
|
|
8
8
|
begin
|
9
|
-
Phidgets::InterfaceKit.new do |ifkit|
|
10
|
-
|
9
|
+
Phidgets::InterfaceKit.new do |ifkit|
|
11
10
|
puts "Device attributes: #{ifkit.attributes} attached"
|
12
11
|
puts "Class: #{ifkit.device_class}"
|
13
12
|
puts "Id: #{ifkit.id}"
|
@@ -16,8 +15,8 @@ Phidgets::InterfaceKit.new do |ifkit|
|
|
16
15
|
puts "# Digital inputs: #{ifkit.inputs.size}"
|
17
16
|
puts "# Digital outputs: #{ifkit.outputs.size}"
|
18
17
|
puts "# Analog inputs: #{ifkit.sensors.size}"
|
19
|
-
|
20
|
-
sleep 1
|
18
|
+
|
19
|
+
sleep 1
|
21
20
|
|
22
21
|
if(ifkit.sensors.size > 0)
|
23
22
|
ifkit.ratiometric = false
|
@@ -26,16 +25,16 @@ Phidgets::InterfaceKit.new do |ifkit|
|
|
26
25
|
|
27
26
|
puts "Sensivity: #{ifkit.sensors[0].sensitivity}"
|
28
27
|
puts "Data rate: #{ifkit.sensors[0].data_rate}"
|
29
|
-
puts "Data rate max: #{ifkit.sensors[0].data_rate_max}"
|
30
|
-
puts "Data rate min: #{ifkit.sensors[0].data_rate_min}"
|
31
|
-
puts "Sensor value[0]: #{ifkit.sensors[0].to_i}"
|
28
|
+
puts "Data rate max: #{ifkit.sensors[0].data_rate_max}"
|
29
|
+
puts "Data rate min: #{ifkit.sensors[0].data_rate_min}"
|
30
|
+
puts "Sensor value[0]: #{ifkit.sensors[0].to_i}"
|
32
31
|
puts "Raw sensor value[0]: #{ifkit.sensors[0].raw_value}"
|
33
|
-
|
32
|
+
|
34
33
|
ifkit.outputs[0].state = true
|
35
34
|
sleep 1 #allow time for digital output 0's state to be set
|
36
35
|
puts "Is digital output 0's state on? ... #{ifkit.outputs[0].on?}"
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
ifkit.on_detach do |device, obj|
|
40
39
|
puts "#{device.attributes.inspect} detached"
|
41
40
|
end
|
@@ -51,18 +50,13 @@ Phidgets::InterfaceKit.new do |ifkit|
|
|
51
50
|
ifkit.on_output_change do |device, output, state, obj|
|
52
51
|
puts "Output #{output.index}'s state has changed to #{state}"
|
53
52
|
end
|
54
|
-
|
53
|
+
|
55
54
|
ifkit.on_sensor_change do |device, input, value, obj|
|
56
55
|
puts "Sensor #{input.index}'s value has changed to #{value}"
|
57
|
-
end
|
56
|
+
end
|
58
57
|
|
59
58
|
sleep 10
|
60
59
|
end
|
61
60
|
rescue Phidgets::Error::Timeout => e
|
62
61
|
puts "Exception caught: #{e.message}"
|
63
62
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
@@ -3,39 +3,38 @@ require 'phidgets-ffi'
|
|
3
3
|
|
4
4
|
puts "Library Version: #{Phidgets::FFI.library_version}"
|
5
5
|
|
6
|
-
ifkit = Phidgets::InterfaceKit.new
|
7
|
-
|
6
|
+
ifkit = Phidgets::InterfaceKit.new
|
7
|
+
|
8
8
|
ifkit.on_attach do |device, obj|
|
9
|
-
|
10
|
-
|
11
|
-
puts "Class: #{device.device_class}"
|
9
|
+
puts "Device attributes: #{device.attributes} attached"
|
10
|
+
puts "Class: #{device.device_class}"
|
12
11
|
puts "Id: #{device.id}"
|
13
12
|
puts "Serial number: #{device.serial_number}"
|
14
13
|
puts "Version: #{device.version}"
|
15
14
|
puts "# Digital inputs: #{device.inputs.size}"
|
16
15
|
puts "# Digital outputs: #{device.outputs.size}"
|
17
16
|
puts "# Analog inputs: #{device.sensors.size}"
|
18
|
-
|
19
|
-
sleep 1
|
17
|
+
|
18
|
+
sleep 1
|
20
19
|
|
21
20
|
if(device.sensors.size > 0)
|
22
21
|
device.ratiometric = false
|
23
|
-
|
22
|
+
device.sensors[0].data_rate = 64
|
24
23
|
device.sensors[0].sensitivity = 15
|
25
24
|
|
26
25
|
puts "Sensivity: #{device.sensors[0].sensitivity}"
|
27
26
|
puts "Data rate: #{device.sensors[0].data_rate}"
|
28
|
-
puts "Data rate max: #{device.sensors[0].data_rate_max}"
|
29
|
-
puts "Data rate min: #{device.sensors[0].data_rate_min}"
|
30
|
-
puts "Sensor value[0]: #{device.sensors[0].to_i}"
|
27
|
+
puts "Data rate max: #{device.sensors[0].data_rate_max}"
|
28
|
+
puts "Data rate min: #{device.sensors[0].data_rate_min}"
|
29
|
+
puts "Sensor value[0]: #{device.sensors[0].to_i}"
|
31
30
|
puts "Raw sensor value[0]: #{device.sensors[0].raw_value}"
|
32
|
-
|
31
|
+
|
33
32
|
device.outputs[0].state = true
|
34
33
|
sleep 1 #allow time for digital output 0's state to be set
|
35
34
|
puts "Is digital output 0's state on? ... #{device.outputs[0].on?}"
|
36
|
-
|
35
|
+
end
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
ifkit.on_detach do |device, obj|
|
40
39
|
puts "#{device.attributes.inspect} detached"
|
41
40
|
end
|
@@ -45,16 +44,16 @@ ifkit.on_error do |device, obj, code, description|
|
|
45
44
|
end
|
46
45
|
|
47
46
|
ifkit.on_input_change do |device, input, state, obj|
|
48
|
-
|
47
|
+
puts "Input #{input.index}'s state has changed to #{state}"
|
49
48
|
end
|
50
49
|
|
51
50
|
ifkit.on_output_change do |device, output, state, obj|
|
52
|
-
|
51
|
+
puts "Output #{output.index}'s state has changed to #{state}"
|
53
52
|
end
|
54
|
-
|
53
|
+
|
55
54
|
ifkit.on_sensor_change do |device, input, value, obj|
|
56
55
|
puts "Sensor #{input.index}'s value has changed to #{value}"
|
57
|
-
end
|
56
|
+
end
|
58
57
|
|
59
58
|
sleep 10
|
60
59
|
ifkit.close
|
data/examples/ir.rb
CHANGED
@@ -6,34 +6,32 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
|
|
6
6
|
ir = Phidgets::IR.new
|
7
7
|
|
8
8
|
puts "Wait for PhidgetIR to attached..."
|
9
|
-
|
9
|
+
|
10
10
|
#The following method runs when the PhidgetIR is attached to the system
|
11
11
|
ir.on_attach do |device, obj|
|
12
|
-
|
13
|
-
|
14
|
-
puts "Class: #{device.device_class}"
|
12
|
+
puts "Device attributes: #{device.attributes} attached"
|
13
|
+
puts "Class: #{device.device_class}"
|
15
14
|
puts "Id: #{device.id}"
|
16
15
|
puts "Serial number: #{device.serial_number}"
|
17
16
|
puts "Version: #{device.version}"
|
18
17
|
|
19
18
|
#example of sending RAW Data - this was captured from an Apple remote Volume UP command
|
20
19
|
volume_up_raw_data = [
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
5.times do
|
20
|
+
9040, 4590, 540, 630, 550, 1740, 550, 1750, 550, 1740,
|
21
|
+
550, 620, 550, 1750, 550, 1740, 550, 1750, 550, 1740,
|
22
|
+
550, 1740, 560, 1740, 540, 630, 550, 620, 550, 620,
|
23
|
+
540, 630, 550, 1750, 550, 1740, 560, 1740, 550, 620,
|
24
|
+
550, 1740, 550, 620, 550, 620, 560, 610, 550, 620,
|
25
|
+
550, 1750, 550, 1740, 550, 620, 550, 1740, 550, 1750,
|
26
|
+
550, 620, 550, 620, 550, 620, 540]
|
27
|
+
|
28
|
+
5.times do
|
30
29
|
puts 'Transmiting raw data ...'
|
31
30
|
device.transmit_raw(volume_up_raw_data, 67, 38000, 33, 110000)
|
32
31
|
sleep 0.2
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
|
-
|
34
|
+
|
37
35
|
ir.on_detach do |device, obj|
|
38
36
|
puts "#{device.attributes.inspect} detached"
|
39
37
|
end
|
@@ -44,52 +42,50 @@ end
|
|
44
42
|
|
45
43
|
ir.on_code do |device, data, data_length, bit_count, repeat, obj|
|
46
44
|
puts "Code #{data} received, length: #{data_length}, bit count: #{bit_count}, repeat: #{repeat}"
|
47
|
-
end
|
45
|
+
end
|
48
46
|
|
49
47
|
ir.on_learn do |device, data, data_length, code_info, obj|
|
50
48
|
print "\n-------------------Learned Code---------------------\n"
|
51
|
-
|
52
|
-
puts "Code: #{data}"
|
49
|
+
|
50
|
+
puts "Code: #{data}"
|
53
51
|
puts "Data length: #{data_length}"
|
54
52
|
puts "Bit count: #{code_info[:bit_count]}"
|
55
|
-
puts "Encoding: #{code_info[:encoding]}"
|
56
|
-
puts "Length: #{code_info[:length]}"
|
53
|
+
puts "Encoding: #{code_info[:encoding]}"
|
54
|
+
puts "Length: #{code_info[:length]}"
|
57
55
|
puts "Gap: #{code_info[:gap]}"
|
58
56
|
puts "Trail: #{code_info[:trail]}"
|
59
57
|
puts "Header: #{code_info[:header][0]}, #{code_info[:header][1]}"
|
60
58
|
puts "One: #{code_info[:one][0]}, #{code_info[:one][1]}"
|
61
|
-
puts "Zero: #{code_info[:zero][0]}, #{code_info[:zero][1]}"
|
59
|
+
puts "Zero: #{code_info[:zero][0]}, #{code_info[:zero][1]}"
|
62
60
|
puts "Min repeat: #{code_info[:min_repeat]}"
|
63
|
-
|
61
|
+
|
64
62
|
printf 'Toggle mask: '
|
65
63
|
16.times do |i|
|
66
64
|
print "#{code_info[:toggle_mask][i]}, "
|
67
65
|
end
|
68
|
-
|
66
|
+
|
69
67
|
puts ''
|
70
|
-
|
68
|
+
|
71
69
|
puts "Carrier frequency: #{code_info[:carrier_frequency]}"
|
72
70
|
print "Duty cycle: #{code_info[:duty_cycle]} \n\n"
|
73
71
|
|
74
|
-
end
|
72
|
+
end
|
75
73
|
|
76
74
|
ir.on_raw_data do |device, raw_data, data_length, obj|
|
77
75
|
print "Raw data: "
|
76
|
+
|
78
77
|
data_length.times do |i|
|
79
78
|
print "#{raw_data[i]}, "
|
80
79
|
end
|
81
|
-
|
80
|
+
|
82
81
|
puts ''
|
83
|
-
|
84
|
-
end
|
82
|
+
end
|
85
83
|
|
86
|
-
|
87
|
-
puts "Please transmit a code now ..."
|
84
|
+
puts "Please transmit a code now ..."
|
88
85
|
sleep 10
|
89
86
|
|
90
87
|
if(ir.attached?)
|
91
|
-
|
92
|
-
apple_volume_down = ["77", "E1", "B0", "F0"]
|
88
|
+
apple_volume_down = ["77", "E1", "B0", "F0"]
|
93
89
|
apple_volume_code_info = Phidgets::IR::IR_code_info.new
|
94
90
|
apple_volume_code_info[:bit_count] = 32
|
95
91
|
apple_volume_code_info[:encoding] = Phidgets::FFI::IREncoding[:encoding_space]
|
@@ -110,15 +106,14 @@ if(ir.attached?)
|
|
110
106
|
5.times do
|
111
107
|
puts 'Transmitting data ...'
|
112
108
|
ir.transmit apple_volume_down, apple_volume_code_info
|
113
|
-
|
109
|
+
sleep 0.2
|
114
110
|
end
|
115
|
-
|
116
111
|
rescue Phidgets::Error::Timeout => e
|
117
112
|
puts "Exception caught: #{e.message}"
|
118
113
|
end
|
119
|
-
|
114
|
+
|
120
115
|
5.times do
|
121
|
-
begin
|
116
|
+
begin
|
122
117
|
puts ''
|
123
118
|
raw_data, raw_data_length = ir.read_raw_data
|
124
119
|
|
@@ -126,30 +121,28 @@ if(ir.attached?)
|
|
126
121
|
raw_data_length.times do |i|
|
127
122
|
print "#{raw_data[i]},"
|
128
123
|
end
|
129
|
-
|
124
|
+
|
130
125
|
puts ''
|
131
|
-
puts "Data length: #{raw_data_length}"
|
132
|
-
|
126
|
+
puts "Data length: #{raw_data_length}"
|
127
|
+
|
133
128
|
puts ''
|
134
129
|
data, data_length, bit_count = ir.last_code
|
135
|
-
|
136
|
-
print 'Last code: '
|
130
|
+
|
131
|
+
print 'Last code: '
|
137
132
|
print "#{data}"
|
138
133
|
puts ''
|
139
134
|
puts "Data length: #{data_length}"
|
140
135
|
puts "Bit count: #{bit_count}"
|
141
|
-
|
136
|
+
|
142
137
|
puts ''
|
143
138
|
sleep 0.2
|
144
139
|
puts '----------------------------------------------------'
|
145
|
-
|
140
|
+
|
146
141
|
puts 'Transmitting the last code that was received'
|
147
142
|
ir.transmit data, apple_volume_code_info
|
148
|
-
|
149
143
|
rescue Phidgets::Error::UnknownVal => e
|
150
144
|
puts "Exception caught: #{e.message}"
|
151
145
|
end
|
152
|
-
|
153
146
|
end
|
154
147
|
end
|
155
148
|
|
data/examples/led.rb
CHANGED
@@ -6,21 +6,20 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
|
|
6
6
|
led = Phidgets::LED.new
|
7
7
|
|
8
8
|
puts "Wait for PhidgetLED to attached..."
|
9
|
-
|
9
|
+
|
10
10
|
#The following method runs when the PhidgetLED is attached to the system
|
11
11
|
led.on_attach do |device, obj|
|
12
|
-
|
13
|
-
|
14
|
-
puts "Class: #{device.device_class}"
|
12
|
+
puts "Device attributes: #{device.attributes} attached"
|
13
|
+
puts "Class: #{device.device_class}"
|
15
14
|
puts "Id: #{device.id}"
|
16
15
|
puts "Serial number: #{device.serial_number}"
|
17
16
|
puts "Version: #{device.version}"
|
18
17
|
puts "# LEDs: #{device.leds.size}"
|
19
|
-
|
18
|
+
|
20
19
|
device.current_limit = Phidgets::FFI::LEDCurrentLimit[:current_limit_20mA]
|
21
20
|
device.voltage = Phidgets::FFI::LEDVoltage[:voltage_3_9V]
|
22
21
|
end
|
23
|
-
|
22
|
+
|
24
23
|
led.on_detach do |device, obj|
|
25
24
|
puts "#{device.attributes.inspect} detached"
|
26
25
|
end
|
@@ -36,14 +35,16 @@ if(led.attached?)
|
|
36
35
|
i.current_limit = 20
|
37
36
|
i.brightness = 50
|
38
37
|
end
|
38
|
+
|
39
39
|
sleep 1
|
40
40
|
led.leds.each do |i|
|
41
41
|
i.brightness = 100
|
42
42
|
end
|
43
|
+
|
43
44
|
sleep 1
|
44
45
|
led.leds.each do |i|
|
45
46
|
i.current_limit = 2
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
led.close
|
50
|
+
led.close
|
data/examples/manager.rb
CHANGED
@@ -2,20 +2,18 @@ require 'rubygems'
|
|
2
2
|
require 'phidgets-ffi'
|
3
3
|
|
4
4
|
Phidgets::Manager.new do |manager|
|
5
|
-
|
6
5
|
manager.devices.size.times do |i|
|
7
6
|
puts "Attached: #{Phidgets::Common.name(manager.devices[i])}, serial number: #{Phidgets::Common.serial_number(manager.devices[i])}"
|
8
7
|
end
|
8
|
+
|
9
9
|
puts ''
|
10
10
|
|
11
11
|
manager.on_attach do |device_ptr, obj|
|
12
|
-
|
13
|
-
|
12
|
+
puts "Attaching #{Phidgets::Common.name(device_ptr)}, serial number: #{Phidgets::Common.serial_number(device_ptr)}"
|
14
13
|
end
|
15
14
|
|
16
15
|
manager.on_detach do |device_ptr, obj|
|
17
|
-
|
18
|
-
|
16
|
+
puts "Detaching #{Phidgets::Common.name(device_ptr)}, serial number: #{Phidgets::Common.serial_number(device_ptr)}"
|
19
17
|
end
|
20
18
|
|
21
19
|
puts "You have 20 seconds to plug/unplug USB devices and watch the callbacks execute"
|
data/examples/motor_control.rb
CHANGED
@@ -6,11 +6,11 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
|
|
6
6
|
mc = Phidgets::MotorControl.new
|
7
7
|
|
8
8
|
puts "Wait for PhidgetMotorControl to attached..."
|
9
|
-
|
9
|
+
|
10
10
|
mc.on_attach do |device, obj|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
puts 'attach event'
|
12
|
+
puts "Device attributes: #{device.attributes} attached"
|
13
|
+
puts "Class: #{device.device_class}"
|
14
14
|
puts "Id: #{device.id}"
|
15
15
|
puts "Serial number: #{device.serial_number}"
|
16
16
|
puts "Version: #{device.version}"
|
@@ -31,66 +31,63 @@ end
|
|
31
31
|
|
32
32
|
mc.on_input_change do |device, input, state|
|
33
33
|
puts "Digital Input #{input.index}'s state changed to #{state}"
|
34
|
-
end
|
34
|
+
end
|
35
35
|
|
36
36
|
=begin
|
37
37
|
mc.on_sensor_update do |device, sensor, value|
|
38
38
|
puts "Analog Sensor #{sensor.index}'s value is #{value}"
|
39
|
-
end
|
39
|
+
end
|
40
40
|
=end
|
41
41
|
|
42
42
|
mc.on_velocity_change do |device, motor, velocity|
|
43
43
|
puts "Motor #{motor.index}'s velocity changed to #{velocity}"
|
44
|
-
end
|
44
|
+
end
|
45
45
|
|
46
46
|
mc.on_current_change do |device, motor, current|
|
47
47
|
puts "Motor #{motor.index}'s current changed to #{current}"
|
48
|
-
end
|
48
|
+
end
|
49
49
|
|
50
50
|
=begin
|
51
51
|
mc.on_current_update do |device, motor, current|
|
52
52
|
puts "Motor #{motor.index}'s current is #{current}"
|
53
|
-
end
|
53
|
+
end
|
54
54
|
=end
|
55
55
|
|
56
56
|
=begin
|
57
57
|
mc.on_back_emf_update do |device, motor, voltage|
|
58
58
|
puts "Motor #{motor.index}'s back EMF is #{voltage}"
|
59
|
-
end
|
59
|
+
end
|
60
60
|
=end
|
61
61
|
|
62
62
|
mc.on_position_change do |device, encoder, time, position|
|
63
63
|
puts "Encoder #{encoder.index}'s position changed to #{position} in #{time}"
|
64
|
-
end
|
64
|
+
end
|
65
65
|
|
66
66
|
=begin
|
67
67
|
mc.on_position_update do |device, encoder, position|
|
68
68
|
puts "Encoder #{encoder.index}'s position is #{position}"
|
69
|
-
end
|
69
|
+
end
|
70
70
|
=end
|
71
71
|
|
72
72
|
sleep 5
|
73
73
|
|
74
74
|
if(mc.attached?)
|
75
|
-
|
76
75
|
if(mc.id.to_s == "motor_control_1motor")
|
77
|
-
|
78
76
|
mc.ratiometric = true
|
79
77
|
|
80
78
|
puts "Digital input: #{mc.inputs.inspect}"
|
81
79
|
|
82
80
|
puts "Encoder: #{mc.encoders.inspect}"
|
83
|
-
|
81
|
+
|
84
82
|
puts "Analog sensor: #{mc.sensors[0].inspect}"
|
85
|
-
puts "Analog sensor: #{mc.sensors[1].inspect}"
|
86
|
-
|
83
|
+
puts "Analog sensor: #{mc.sensors[1].inspect}"
|
84
|
+
|
87
85
|
puts "Motor current: #{mc.motors[0].current}"
|
88
86
|
|
89
87
|
mc.motors[0].acceleration = (mc.motors[0].acceleration_max)/2
|
90
88
|
mc.motors[0].back_emf_sensing = true
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
end
|
90
|
+
|
94
91
|
puts "Motor acceleration min: #{mc.motors[0].acceleration_min}"
|
95
92
|
puts "Motor acceleration max: #{mc.motors[0].acceleration_max}"
|
96
93
|
|
@@ -98,11 +95,9 @@ if(mc.attached?)
|
|
98
95
|
100.times do |i|
|
99
96
|
mc.motors[0].velocity = i
|
100
97
|
sleep 0.1
|
101
|
-
|
102
98
|
end
|
103
|
-
|
99
|
+
|
104
100
|
mc.motors[0].velocity = 0
|
105
|
-
|
101
|
+
|
106
102
|
sleep 2
|
107
103
|
end
|
108
|
-
|