phidgets-ffi 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/.gitignore +3 -0
- data/LICENSE +1 -1
- data/README.rdoc +92 -42
- data/examples/accelerometer.rb +39 -0
- data/examples/advanced_servo.rb +94 -0
- data/examples/analog.rb +43 -0
- data/examples/bridge.rb +57 -0
- data/examples/dictionary.rb +46 -31
- data/examples/encoder.rb +59 -0
- data/examples/frequency_counter.rb +63 -0
- data/examples/gps.rb +91 -0
- data/examples/interface_kit_with_block.rb +68 -0
- data/examples/interface_kit_without_block.rb +60 -0
- data/examples/ir.rb +157 -0
- data/examples/led.rb +36 -0
- data/examples/manager.rb +16 -10
- data/examples/motor_control.rb +108 -0
- data/examples/{ffi → raw-ffi}/dictionary.rb +11 -1
- data/examples/{ffi → raw-ffi}/interface_kit.rb +19 -2
- data/examples/{ffi → raw-ffi}/library_version.rb +0 -0
- data/examples/{ffi → raw-ffi}/log.rb +0 -0
- data/examples/{ffi → raw-ffi}/manager.rb +6 -3
- data/examples/rfid.rb +63 -0
- data/examples/servo.rb +45 -30
- data/examples/spatial.rb +75 -0
- data/examples/stepper.rb +87 -0
- data/examples/temperature_sensor.rb +49 -0
- data/examples/text_lcd.rb +101 -0
- data/lib/phidgets-ffi.rb +34 -3
- data/lib/phidgets-ffi/accelerometer.rb +122 -0
- data/lib/phidgets-ffi/advanced_servo.rb +304 -0
- data/lib/phidgets-ffi/analog.rb +111 -0
- data/lib/phidgets-ffi/bridge.rb +167 -0
- data/lib/phidgets-ffi/common.rb +506 -103
- data/lib/phidgets-ffi/dictionary.rb +136 -23
- data/lib/phidgets-ffi/encoder.rb +196 -0
- data/lib/phidgets-ffi/error.rb +8 -3
- data/lib/phidgets-ffi/ffi/accelerometer.rb +30 -0
- data/lib/phidgets-ffi/ffi/advanced_servo.rb +73 -0
- data/lib/phidgets-ffi/ffi/analog.rb +29 -0
- data/lib/phidgets-ffi/ffi/bridge.rb +44 -0
- data/lib/phidgets-ffi/ffi/common.rb +51 -34
- data/lib/phidgets-ffi/ffi/constants.rb +3 -1
- data/lib/phidgets-ffi/ffi/dictionary.rb +25 -20
- data/lib/phidgets-ffi/ffi/encoder.rb +32 -0
- data/lib/phidgets-ffi/ffi/frequency_counter.rb +38 -0
- data/lib/phidgets-ffi/ffi/gps.rb +32 -0
- data/lib/phidgets-ffi/ffi/interface_kit.rb +26 -23
- data/lib/phidgets-ffi/ffi/ir.rb +50 -0
- data/lib/phidgets-ffi/ffi/led.rb +40 -0
- data/lib/phidgets-ffi/ffi/log.rb +7 -6
- data/lib/phidgets-ffi/ffi/manager.rb +35 -20
- data/lib/phidgets-ffi/ffi/motor_control.rb +66 -0
- data/lib/phidgets-ffi/ffi/rfid.rb +36 -0
- data/lib/phidgets-ffi/ffi/servo.rb +16 -15
- data/lib/phidgets-ffi/ffi/spatial.rb +40 -0
- data/lib/phidgets-ffi/ffi/stepper.rb +56 -0
- data/lib/phidgets-ffi/ffi/temperature_sensor.rb +42 -0
- data/lib/phidgets-ffi/ffi/text_lcd.rb +55 -0
- data/lib/phidgets-ffi/frequency_counter.rb +148 -0
- data/lib/phidgets-ffi/gps.rb +181 -0
- data/lib/phidgets-ffi/interface_kit.rb +205 -92
- data/lib/phidgets-ffi/ir.rb +290 -0
- data/lib/phidgets-ffi/led.rb +112 -0
- data/lib/phidgets-ffi/log.rb +14 -2
- data/lib/phidgets-ffi/manager.rb +143 -26
- data/lib/phidgets-ffi/motor_control.rb +497 -0
- data/lib/phidgets-ffi/phidgets-ffi.rb +15 -2
- data/lib/phidgets-ffi/rfid.rb +220 -0
- data/lib/phidgets-ffi/servo.rb +103 -61
- data/lib/phidgets-ffi/spatial.rb +306 -0
- data/lib/phidgets-ffi/stepper.rb +370 -0
- data/lib/phidgets-ffi/temperature_sensor.rb +157 -0
- data/lib/phidgets-ffi/text_lcd.rb +298 -0
- data/lib/phidgets-ffi/version.rb +1 -1
- data/phidgets-ffi.gemspec +2 -2
- metadata +89 -76
- data/examples/ffi/servo.rb +0 -67
- data/examples/interface_kit.rb +0 -20
data/examples/encoder.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'phidgets-ffi'
|
3
|
+
|
4
|
+
puts "Library Version: #{Phidgets::FFI.library_version}"
|
5
|
+
|
6
|
+
en = Phidgets::Encoder.new
|
7
|
+
|
8
|
+
puts "Wait for PhidgetEncoder to attached..."
|
9
|
+
|
10
|
+
#The following method runs when the PhidgetEncoder is attached to the system
|
11
|
+
en.on_attach do |device, obj|
|
12
|
+
|
13
|
+
puts "Device attributes: #{device.attributes} attached"
|
14
|
+
puts "Class: #{device.device_class}"
|
15
|
+
puts "Id: #{device.id}"
|
16
|
+
puts "Serial number: #{device.serial_number}"
|
17
|
+
puts "Version: #{device.version}"
|
18
|
+
puts "# Digital Inputs: #{en.inputs.size}"
|
19
|
+
puts "# Encoders: #{device.encoders.size}"
|
20
|
+
|
21
|
+
begin
|
22
|
+
en.encoders[0].enabled = true #some encoders do not support the enable feature
|
23
|
+
rescue Phidgets::Error::Unsupported => e
|
24
|
+
puts "Exception caught: #{e.message}"
|
25
|
+
end
|
26
|
+
|
27
|
+
sleep 1
|
28
|
+
|
29
|
+
en.encoders[0].position = 200
|
30
|
+
|
31
|
+
begin
|
32
|
+
puts "Index Position: #{en.encoders[0].index_position}"
|
33
|
+
rescue Phidgets::Error::UnknownVal => e
|
34
|
+
puts "Exception caught: #{e.message}"
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "Position: #{en.encoders[0].position}"
|
38
|
+
end
|
39
|
+
|
40
|
+
en.on_detach do |device, obj|
|
41
|
+
puts "#{device.attributes.inspect} detached"
|
42
|
+
end
|
43
|
+
|
44
|
+
en.on_error do |device, obj, code, description|
|
45
|
+
puts "Error #{code}: #{description}"
|
46
|
+
end
|
47
|
+
|
48
|
+
en.on_input_change do |device, input, state, obj|
|
49
|
+
puts "Input #{input.index}'s state has changed to #{state}"
|
50
|
+
end
|
51
|
+
|
52
|
+
en.on_position_change do |device, encoder, time, position_change, obj|
|
53
|
+
|
54
|
+
puts "Encoder #{encoder.index} -- Position: #{device.encoders[encoder.index].position} -- Relative Change: #{position_change} -- Elapsed Time: #{time}"
|
55
|
+
end
|
56
|
+
|
57
|
+
sleep 10
|
58
|
+
|
59
|
+
en.close
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'phidgets-ffi'
|
3
|
+
|
4
|
+
puts "Library Version: #{Phidgets::FFI.library_version}"
|
5
|
+
|
6
|
+
fc = Phidgets::FrequencyCounter.new
|
7
|
+
|
8
|
+
puts "Wait for PhidgetFrequncyCounter to attached..."
|
9
|
+
|
10
|
+
#The following method runs when the PhidgetFrequencyCounter is attached to the system
|
11
|
+
fc.on_attach do |device, obj|
|
12
|
+
|
13
|
+
puts "Device attributes: #{device.attributes} attached"
|
14
|
+
puts "Class: #{device.device_class}"
|
15
|
+
puts "Id: #{device.id}"
|
16
|
+
puts "Serial number: #{device.serial_number}"
|
17
|
+
puts "Version: #{device.version}"
|
18
|
+
puts "# Inputs: #{device.inputs.size}"
|
19
|
+
|
20
|
+
device.inputs[0].enabled = true
|
21
|
+
|
22
|
+
device.inputs[0].filter_type = Phidgets::FFI::FrequencyCounterFilterTypes[:filter_type_zero_crossing]
|
23
|
+
|
24
|
+
device.inputs[0].timeout = 100018
|
25
|
+
|
26
|
+
sleep 1
|
27
|
+
|
28
|
+
puts "Enabled: #{device.inputs[0].enabled}"
|
29
|
+
puts "Filter Type: #{device.inputs[0].filter_type}"
|
30
|
+
puts "Timeout: #{device.inputs[0].timeout}"
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
fc.on_detach do |device, obj|
|
35
|
+
puts "#{device.attributes.inspect} detached"
|
36
|
+
end
|
37
|
+
|
38
|
+
fc.on_error do |device, obj, code, description|
|
39
|
+
puts "Error #{code}: #{description}"
|
40
|
+
end
|
41
|
+
|
42
|
+
fc.on_count do |device, input, time, count, obj|
|
43
|
+
puts "Channel #{input.index}: #{count} pulses in #{time} microseconds"
|
44
|
+
end
|
45
|
+
|
46
|
+
sleep 5
|
47
|
+
|
48
|
+
if(fc.attached?)
|
49
|
+
5.times do
|
50
|
+
begin
|
51
|
+
puts "Frequency[0]: #{fc.inputs[0].frequency}"
|
52
|
+
puts "Total count: #{fc.inputs[0].total_count}"
|
53
|
+
puts "Total time: #{fc.inputs[0].total_time} microseconds"
|
54
|
+
puts ''
|
55
|
+
rescue Phidgets::Error::UnknownVal => e
|
56
|
+
puts "Exception caught: #{e.message}"
|
57
|
+
end
|
58
|
+
sleep 0.5
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
sleep 1
|
63
|
+
fc.close
|
data/examples/gps.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'phidgets-ffi'
|
3
|
+
|
4
|
+
puts "Library Version: #{Phidgets::FFI.library_version}"
|
5
|
+
|
6
|
+
gps = Phidgets::GPS.new
|
7
|
+
|
8
|
+
puts "Wait for PhidgetGPS to attached..."
|
9
|
+
|
10
|
+
#The following method runs when the PhidgetGPS is attached to the system
|
11
|
+
gps.on_attach do |device, obj|
|
12
|
+
|
13
|
+
puts "Device attributes: #{device.attributes} attached"
|
14
|
+
puts "Class: #{device.device_class}"
|
15
|
+
puts "Id: #{device.id}"
|
16
|
+
puts "Serial number: #{device.serial_number}"
|
17
|
+
puts "Version: #{device.version}"
|
18
|
+
|
19
|
+
puts "Waiting for position fix status to be acquired"
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
gps.on_detach do |device, obj|
|
24
|
+
puts "#{device.attributes.inspect} detached"
|
25
|
+
end
|
26
|
+
|
27
|
+
gps.on_error do |device, obj, code, description|
|
28
|
+
puts "Error #{code}: #{description}"
|
29
|
+
end
|
30
|
+
|
31
|
+
gps.on_position_fix_status_change do |device, fix_status, obj|
|
32
|
+
puts "Position fix status changed to: #{fix_status}"
|
33
|
+
end
|
34
|
+
|
35
|
+
gps.on_position_change do |device, lat, long, alt, obj|
|
36
|
+
puts "Latitude: #{lat} degrees, longitude: #{long} degrees, altitude: #{alt} m"
|
37
|
+
end
|
38
|
+
|
39
|
+
sleep 5
|
40
|
+
|
41
|
+
if(gps.attached?)
|
42
|
+
5.times do
|
43
|
+
begin
|
44
|
+
puts "Latitude: #{gps.latitude} degrees"
|
45
|
+
rescue Phidgets::Error::UnknownVal => e
|
46
|
+
puts "Exception caught: #{e.message}"
|
47
|
+
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
puts "Longitude: #{gps.longitude} degrees"
|
51
|
+
rescue Phidgets::Error::UnknownVal => e
|
52
|
+
puts "Exception caught: #{e.message}"
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
puts "Altitude: #{gps.altitude} m"
|
57
|
+
rescue Phidgets::Error::UnknownVal => e
|
58
|
+
puts "Exception caught: #{e.message}"
|
59
|
+
end
|
60
|
+
|
61
|
+
begin
|
62
|
+
puts "Heading: #{gps.heading} degrees"
|
63
|
+
rescue Phidgets::Error::UnknownVal => e
|
64
|
+
puts "Exception caught: #{e.message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
puts "Velocity: #{gps.velocity} km/h"
|
69
|
+
rescue Phidgets::Error::UnknownVal => e
|
70
|
+
puts "Exception caught: #{e.message}"
|
71
|
+
end
|
72
|
+
|
73
|
+
begin
|
74
|
+
puts "GPS Time(UTC): #{gps.time[:hours]}:#{gps.time[:minutes]}:#{gps.time[:seconds]}:#{gps.time[:milliseconds]}"
|
75
|
+
rescue Phidgets::Error::UnknownVal => e
|
76
|
+
puts "Exception caught: #{e.message}"
|
77
|
+
end
|
78
|
+
|
79
|
+
begin
|
80
|
+
puts "GPS Date(UTC): #{gps.date[:month]}/#{gps.date[:day]}/#{gps.date[:year]}"
|
81
|
+
rescue Phidgets::Error::UnknownVal => e
|
82
|
+
puts "Exception caught: #{e.message}"
|
83
|
+
end
|
84
|
+
|
85
|
+
puts ''
|
86
|
+
sleep 0.5
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
sleep 50
|
91
|
+
gps.close
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'phidgets-ffi'
|
3
|
+
|
4
|
+
puts "Library Version: #{Phidgets::FFI.library_version}"
|
5
|
+
|
6
|
+
puts "Wait for PhidgetInterfaceKit to attach..."
|
7
|
+
|
8
|
+
begin
|
9
|
+
Phidgets::InterfaceKit.new do |ifkit|
|
10
|
+
|
11
|
+
puts "Device attributes: #{ifkit.attributes} attached"
|
12
|
+
puts "Class: #{ifkit.device_class}"
|
13
|
+
puts "Id: #{ifkit.id}"
|
14
|
+
puts "Serial number: #{ifkit.serial_number}"
|
15
|
+
puts "Version: #{ifkit.version}"
|
16
|
+
puts "# Digital inputs: #{ifkit.inputs.size}"
|
17
|
+
puts "# Digital outputs: #{ifkit.outputs.size}"
|
18
|
+
puts "# Analog inputs: #{ifkit.sensors.size}"
|
19
|
+
|
20
|
+
sleep 1
|
21
|
+
|
22
|
+
if(ifkit.sensors.size > 0)
|
23
|
+
ifkit.ratiometric = false
|
24
|
+
ifkit.sensors[0].data_rate = 64
|
25
|
+
ifkit.sensors[0].sensitivity = 15
|
26
|
+
|
27
|
+
puts "Sensivity: #{ifkit.sensors[0].sensitivity}"
|
28
|
+
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}"
|
32
|
+
puts "Raw sensor value[0]: #{ifkit.sensors[0].raw_value}"
|
33
|
+
|
34
|
+
ifkit.outputs[0].state = true
|
35
|
+
sleep 1 #allow time for digital output 0's state to be set
|
36
|
+
puts "Is digital output 0's state on? ... #{ifkit.outputs[0].on?}"
|
37
|
+
end
|
38
|
+
|
39
|
+
ifkit.on_detach do |device, obj|
|
40
|
+
puts "#{device.attributes.inspect} detached"
|
41
|
+
end
|
42
|
+
|
43
|
+
ifkit.on_error do |device, obj, code, description|
|
44
|
+
puts "Error #{code}: #{description}"
|
45
|
+
end
|
46
|
+
|
47
|
+
ifkit.on_input_change do |device, input, state, obj|
|
48
|
+
puts "Input #{input.index}'s state has changed to #{state}"
|
49
|
+
end
|
50
|
+
|
51
|
+
ifkit.on_output_change do |device, output, state, obj|
|
52
|
+
puts "Output #{output.index}'s state has changed to #{state}"
|
53
|
+
end
|
54
|
+
|
55
|
+
ifkit.on_sensor_change do |device, input, value, obj|
|
56
|
+
puts "Sensor #{input.index}'s value has changed to #{value}"
|
57
|
+
end
|
58
|
+
|
59
|
+
sleep 10
|
60
|
+
end
|
61
|
+
rescue Phidgets::Error::Timeout => e
|
62
|
+
puts "Exception caught: #{e.message}"
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'phidgets-ffi'
|
3
|
+
|
4
|
+
puts "Library Version: #{Phidgets::FFI.library_version}"
|
5
|
+
|
6
|
+
ifkit = Phidgets::InterfaceKit.new
|
7
|
+
|
8
|
+
ifkit.on_attach do |device, obj|
|
9
|
+
|
10
|
+
puts "Device attributes: #{device.attributes} attached"
|
11
|
+
puts "Class: #{device.device_class}"
|
12
|
+
puts "Id: #{device.id}"
|
13
|
+
puts "Serial number: #{device.serial_number}"
|
14
|
+
puts "Version: #{device.version}"
|
15
|
+
puts "# Digital inputs: #{device.inputs.size}"
|
16
|
+
puts "# Digital outputs: #{device.outputs.size}"
|
17
|
+
puts "# Analog inputs: #{device.sensors.size}"
|
18
|
+
|
19
|
+
sleep 1
|
20
|
+
|
21
|
+
if(device.sensors.size > 0)
|
22
|
+
device.ratiometric = false
|
23
|
+
device.sensors[0].data_rate = 64
|
24
|
+
device.sensors[0].sensitivity = 15
|
25
|
+
|
26
|
+
puts "Sensivity: #{device.sensors[0].sensitivity}"
|
27
|
+
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}"
|
31
|
+
puts "Raw sensor value[0]: #{device.sensors[0].raw_value}"
|
32
|
+
|
33
|
+
device.outputs[0].state = true
|
34
|
+
sleep 1 #allow time for digital output 0's state to be set
|
35
|
+
puts "Is digital output 0's state on? ... #{device.outputs[0].on?}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ifkit.on_detach do |device, obj|
|
40
|
+
puts "#{device.attributes.inspect} detached"
|
41
|
+
end
|
42
|
+
|
43
|
+
ifkit.on_error do |device, obj, code, description|
|
44
|
+
puts "Error #{code}: #{description}"
|
45
|
+
end
|
46
|
+
|
47
|
+
ifkit.on_input_change do |device, input, state, obj|
|
48
|
+
puts "Input #{input.index}'s state has changed to #{state}"
|
49
|
+
end
|
50
|
+
|
51
|
+
ifkit.on_output_change do |device, output, state, obj|
|
52
|
+
puts "Output #{output.index}'s state has changed to #{state}"
|
53
|
+
end
|
54
|
+
|
55
|
+
ifkit.on_sensor_change do |device, input, value, obj|
|
56
|
+
puts "Sensor #{input.index}'s value has changed to #{value}"
|
57
|
+
end
|
58
|
+
|
59
|
+
sleep 10
|
60
|
+
ifkit.close
|
data/examples/ir.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'phidgets-ffi'
|
3
|
+
|
4
|
+
puts "Library Version: #{Phidgets::FFI.library_version}"
|
5
|
+
|
6
|
+
ir = Phidgets::IR.new
|
7
|
+
|
8
|
+
puts "Wait for PhidgetIR to attached..."
|
9
|
+
|
10
|
+
#The following method runs when the PhidgetIR is attached to the system
|
11
|
+
ir.on_attach do |device, obj|
|
12
|
+
|
13
|
+
puts "Device attributes: #{device.attributes} attached"
|
14
|
+
puts "Class: #{device.device_class}"
|
15
|
+
puts "Id: #{device.id}"
|
16
|
+
puts "Serial number: #{device.serial_number}"
|
17
|
+
puts "Version: #{device.version}"
|
18
|
+
|
19
|
+
#example of sending RAW Data - this was captured from an Apple remote Volume UP command
|
20
|
+
volume_up_raw_data = [
|
21
|
+
9040, 4590, 540, 630, 550, 1740, 550, 1750, 550, 1740,
|
22
|
+
550, 620, 550, 1750, 550, 1740, 550, 1750, 550, 1740,
|
23
|
+
550, 1740, 560, 1740, 540, 630, 550, 620, 550, 620,
|
24
|
+
540, 630, 550, 1750, 550, 1740, 560, 1740, 550, 620,
|
25
|
+
550, 1740, 550, 620, 550, 620, 560, 610, 550, 620,
|
26
|
+
550, 1750, 550, 1740, 550, 620, 550, 1740, 550, 1750,
|
27
|
+
550, 620, 550, 620, 550, 620, 540]
|
28
|
+
|
29
|
+
5.times do
|
30
|
+
puts 'Transmiting raw data ...'
|
31
|
+
device.transmit_raw(volume_up_raw_data, 67, 38000, 33, 110000)
|
32
|
+
sleep 0.2
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
ir.on_detach do |device, obj|
|
38
|
+
puts "#{device.attributes.inspect} detached"
|
39
|
+
end
|
40
|
+
|
41
|
+
ir.on_error do |device, obj, code, description|
|
42
|
+
puts "Error #{code}: #{description}"
|
43
|
+
end
|
44
|
+
|
45
|
+
ir.on_code do |device, data, data_length, bit_count, repeat, obj|
|
46
|
+
puts "Code #{data} received, length: #{data_length}, bit count: #{bit_count}, repeat: #{repeat}"
|
47
|
+
end
|
48
|
+
|
49
|
+
ir.on_learn do |device, data, data_length, code_info, obj|
|
50
|
+
print "\n-------------------Learned Code---------------------\n"
|
51
|
+
|
52
|
+
puts "Code: #{data}"
|
53
|
+
puts "Data length: #{data_length}"
|
54
|
+
puts "Bit count: #{code_info[:bit_count]}"
|
55
|
+
puts "Encoding: #{code_info[:encoding]}"
|
56
|
+
puts "Length: #{code_info[:length]}"
|
57
|
+
puts "Gap: #{code_info[:gap]}"
|
58
|
+
puts "Trail: #{code_info[:trail]}"
|
59
|
+
puts "Header: #{code_info[:header][0]}, #{code_info[:header][1]}"
|
60
|
+
puts "One: #{code_info[:one][0]}, #{code_info[:one][1]}"
|
61
|
+
puts "Zero: #{code_info[:zero][0]}, #{code_info[:zero][1]}"
|
62
|
+
puts "Min repeat: #{code_info[:min_repeat]}"
|
63
|
+
|
64
|
+
printf 'Toggle mask: '
|
65
|
+
16.times do |i|
|
66
|
+
print "#{code_info[:toggle_mask][i]}, "
|
67
|
+
end
|
68
|
+
|
69
|
+
puts ''
|
70
|
+
|
71
|
+
puts "Carrier frequency: #{code_info[:carrier_frequency]}"
|
72
|
+
print "Duty cycle: #{code_info[:duty_cycle]} \n\n"
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
ir.on_raw_data do |device, raw_data, data_length, obj|
|
77
|
+
print "Raw data: "
|
78
|
+
data_length.times do |i|
|
79
|
+
print "#{raw_data[i]}, "
|
80
|
+
end
|
81
|
+
|
82
|
+
puts ''
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
puts "Please transmit a code now ..."
|
88
|
+
sleep 10
|
89
|
+
|
90
|
+
if(ir.attached?)
|
91
|
+
|
92
|
+
apple_volume_down = ["77", "E1", "B0", "F0"]
|
93
|
+
apple_volume_code_info = Phidgets::IR::IR_code_info.new
|
94
|
+
apple_volume_code_info[:bit_count] = 32
|
95
|
+
apple_volume_code_info[:encoding] = Phidgets::FFI::IREncoding[:encoding_space]
|
96
|
+
apple_volume_code_info[:length] = Phidgets::FFI::IRLength[:length_constant]
|
97
|
+
apple_volume_code_info[:gap] = 232
|
98
|
+
apple_volume_code_info[:trail] = 432
|
99
|
+
apple_volume_code_info[:header][0] = 9080
|
100
|
+
apple_volume_code_info[:header][1] = 4604
|
101
|
+
apple_volume_code_info[:one][0] = 550
|
102
|
+
apple_volume_code_info[:one][1] = 1753
|
103
|
+
apple_volume_code_info[:zero][0] = 550
|
104
|
+
apple_volume_code_info[:zero][1] = 623
|
105
|
+
apple_volume_code_info[:min_repeat] = 0
|
106
|
+
apple_volume_code_info[:carrier_frequency] = 38000
|
107
|
+
apple_volume_code_info[:duty_cycle] = 50
|
108
|
+
|
109
|
+
begin
|
110
|
+
5.times do
|
111
|
+
puts 'Transmitting data ...'
|
112
|
+
ir.transmit apple_volume_down, apple_volume_code_info
|
113
|
+
sleep 0.2
|
114
|
+
end
|
115
|
+
|
116
|
+
rescue Phidgets::Error::Timeout => e
|
117
|
+
puts "Exception caught: #{e.message}"
|
118
|
+
end
|
119
|
+
|
120
|
+
5.times do
|
121
|
+
begin
|
122
|
+
puts ''
|
123
|
+
raw_data, raw_data_length = ir.read_raw_data
|
124
|
+
|
125
|
+
print "Last raw data: "
|
126
|
+
raw_data_length.times do |i|
|
127
|
+
print "#{raw_data[i]},"
|
128
|
+
end
|
129
|
+
|
130
|
+
puts ''
|
131
|
+
puts "Data length: #{raw_data_length}"
|
132
|
+
|
133
|
+
puts ''
|
134
|
+
data, data_length, bit_count = ir.last_code
|
135
|
+
|
136
|
+
print 'Last code: '
|
137
|
+
print "#{data}"
|
138
|
+
puts ''
|
139
|
+
puts "Data length: #{data_length}"
|
140
|
+
puts "Bit count: #{bit_count}"
|
141
|
+
|
142
|
+
puts ''
|
143
|
+
sleep 0.2
|
144
|
+
puts '----------------------------------------------------'
|
145
|
+
|
146
|
+
puts 'Transmitting the last code that was received'
|
147
|
+
ir.transmit data, apple_volume_code_info
|
148
|
+
|
149
|
+
rescue Phidgets::Error::UnknownVal => e
|
150
|
+
puts "Exception caught: #{e.message}"
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
sleep 1
|
157
|
+
ir.close
|