phidgets-ffi 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,56 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
|
4
|
+
attach_function :CPhidgetStepper_create, [:phid], :int
|
5
|
+
attach_function :CPhidgetStepper_getInputCount, [:phid, :pointer], :int
|
6
|
+
attach_function :CPhidgetStepper_getInputState, [:phid, :int, :pointer], :int
|
7
|
+
attach_function :CPhidgetStepper_getMotorCount, [:phid, :pointer], :int
|
8
|
+
attach_function :CPhidgetStepper_getAcceleration, [:phid, :int, :pointer], :int
|
9
|
+
attach_function :CPhidgetStepper_setAcceleration, [:phid, :int, :double], :int
|
10
|
+
attach_function :CPhidgetStepper_getAccelerationMax, [:phid, :int, :pointer], :int
|
11
|
+
attach_function :CPhidgetStepper_getAccelerationMin, [:phid, :int, :pointer], :int
|
12
|
+
attach_function :CPhidgetStepper_getVelocityLimit, [:phid, :int, :pointer], :int
|
13
|
+
attach_function :CPhidgetStepper_setVelocityLimit, [:phid, :int, :double], :int
|
14
|
+
attach_function :CPhidgetStepper_getVelocity, [:phid, :int, :pointer], :int
|
15
|
+
attach_function :CPhidgetStepper_getVelocityMax, [:phid, :int, :pointer], :int
|
16
|
+
attach_function :CPhidgetStepper_getVelocityMin, [:phid, :int, :pointer], :int
|
17
|
+
attach_function :CPhidgetStepper_getTargetPosition, [:phid, :int, :pointer], :int
|
18
|
+
attach_function :CPhidgetStepper_setTargetPosition, [:phid, :int, :long_long], :int
|
19
|
+
attach_function :CPhidgetStepper_getCurrentPosition, [:phid, :int, :pointer], :int
|
20
|
+
attach_function :CPhidgetStepper_setCurrentPosition, [:phid, :int, :long_long], :int
|
21
|
+
attach_function :CPhidgetStepper_getPositionMax, [:phid, :int, :long_long], :int
|
22
|
+
attach_function :CPhidgetStepper_getPositionMin, [:phid, :int, :long_long], :int
|
23
|
+
attach_function :CPhidgetStepper_getCurrentLimit, [:phid, :int, :pointer], :int
|
24
|
+
attach_function :CPhidgetStepper_setCurrentLimit, [:phid, :int, :double], :int
|
25
|
+
attach_function :CPhidgetStepper_getCurrent, [:phid, :int, :pointer], :int
|
26
|
+
attach_function :CPhidgetStepper_getCurrentMax, [:phid, :int, :pointer], :int
|
27
|
+
attach_function :CPhidgetStepper_getCurrentMin, [:phid, :int, :pointer], :int
|
28
|
+
attach_function :CPhidgetStepper_getEngaged, [:phid, :int, :pointer], :int
|
29
|
+
attach_function :CPhidgetStepper_setEngaged, [:phid, :int, :int], :int
|
30
|
+
attach_function :CPhidgetStepper_getStopped, [:phid, :int, :pointer], :int
|
31
|
+
|
32
|
+
callback :CPhidgetStepper_set_OnInputChange_Callback, [:phid, :user_ptr, :int, :int], :int
|
33
|
+
attach_function :CPhidgetStepper_set_OnInputChange_Handler, [:phid, :CPhidgetStepper_set_OnInputChange_Callback, :user_ptr], :int
|
34
|
+
|
35
|
+
callback :CPhidgetStepper_set_OnVelocityChange_Callback, [:phid, :user_ptr, :int, :double], :int
|
36
|
+
attach_function :CPhidgetStepper_set_OnVelocityChange_Handler, [:phid, :CPhidgetStepper_set_OnVelocityChange_Callback, :user_ptr], :int
|
37
|
+
|
38
|
+
callback :CPhidgetStepper_set_OnPositionChange_Callback, [:phid, :user_ptr, :int, :long_long], :int
|
39
|
+
attach_function :CPhidgetStepper_set_OnPositionChange_Handler, [:phid, :CPhidgetStepper_set_OnPositionChange_Callback, :user_ptr], :int
|
40
|
+
|
41
|
+
callback :CPhidgetStepper_set_OnCurrentChange_Callback, [:phid, :user_ptr, :int, :double], :int
|
42
|
+
attach_function :CPhidgetStepper_set_OnCurrentChange_Handler, [:phid, :CPhidgetStepper_set_OnCurrentChange_Callback, :user_ptr], :int
|
43
|
+
|
44
|
+
module CPhidgetStepper
|
45
|
+
def self.method_missing(method, *args, &block)
|
46
|
+
if ::Phidgets::FFI.respond_to?("CPhidgetStepper_#{method}".to_sym)
|
47
|
+
if (rs = ::Phidgets::FFI.send("CPhidgetStepper_#{method}".to_sym, *args, &block)) != 0
|
48
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
49
|
+
end
|
50
|
+
else
|
51
|
+
super(method, *args, &block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
|
4
|
+
TemperatureSensorThermocoupleTypes = enum(
|
5
|
+
:thermocouple_type_k_type, 1,
|
6
|
+
:thermocouple_type_j_type,
|
7
|
+
:thermocouple_type_e_type,
|
8
|
+
:thermocouple_type_t_type
|
9
|
+
)
|
10
|
+
|
11
|
+
attach_function :CPhidgetTemperatureSensor_create, [:phid], :int
|
12
|
+
attach_function :CPhidgetTemperatureSensor_getTemperatureInputCount, [:phid, :pointer], :int
|
13
|
+
attach_function :CPhidgetTemperatureSensor_getTemperature, [:phid, :int, :pointer], :int
|
14
|
+
attach_function :CPhidgetTemperatureSensor_getTemperatureMax, [:phid, :int, :pointer], :int
|
15
|
+
attach_function :CPhidgetTemperatureSensor_getTemperatureMin, [:phid, :int, :pointer], :int
|
16
|
+
attach_function :CPhidgetTemperatureSensor_getTemperatureChangeTrigger, [:phid, :int, :pointer], :int
|
17
|
+
attach_function :CPhidgetTemperatureSensor_setTemperatureChangeTrigger, [:phid, :int, :double], :int
|
18
|
+
attach_function :CPhidgetTemperatureSensor_getPotential, [:phid, :int, :pointer], :int
|
19
|
+
attach_function :CPhidgetTemperatureSensor_getPotentialMax, [:phid, :int, :pointer], :int
|
20
|
+
attach_function :CPhidgetTemperatureSensor_getPotentialMin, [:phid, :int, :pointer], :int
|
21
|
+
attach_function :CPhidgetTemperatureSensor_getAmbientTemperature, [:phid, :pointer], :int
|
22
|
+
attach_function :CPhidgetTemperatureSensor_getAmbientTemperatureMax, [:phid, :pointer], :int
|
23
|
+
attach_function :CPhidgetTemperatureSensor_getAmbientTemperatureMin, [:phid, :pointer], :int
|
24
|
+
attach_function :CPhidgetTemperatureSensor_getThermocoupleType, [:phid, :int, :pointer], :int
|
25
|
+
attach_function :CPhidgetTemperatureSensor_setThermocoupleType, [:phid, :int, TemperatureSensorThermocoupleTypes], :int
|
26
|
+
|
27
|
+
callback :CPhidgetTemperatureSensor_set_OnTemperatureChange_Callback, [:phid, :user_ptr, :int, :double], :int
|
28
|
+
attach_function :CPhidgetTemperatureSensor_set_OnTemperatureChange_Handler, [:phid, :CPhidgetTemperatureSensor_set_OnTemperatureChange_Callback, :user_ptr], :int
|
29
|
+
|
30
|
+
module CPhidgetTemperatureSensor
|
31
|
+
def self.method_missing(method, *args, &block)
|
32
|
+
if ::Phidgets::FFI.respond_to?("CPhidgetTemperatureSensor_#{method}".to_sym)
|
33
|
+
if (rs = ::Phidgets::FFI.send("CPhidgetTemperatureSensor_#{method}".to_sym, *args, &block)) != 0
|
34
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
super(method, *args, &block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
|
4
|
+
TextLCDScreenSizes = enum(
|
5
|
+
:screen_size_none, 1,
|
6
|
+
:screen_size_1x8,
|
7
|
+
:screen_size_2x8,
|
8
|
+
:screen_size_1x16,
|
9
|
+
:screen_size_2x16,
|
10
|
+
:screen_size_4x16,
|
11
|
+
:screen_size_2x20,
|
12
|
+
:screen_size_4x20,
|
13
|
+
:screen_size_2x24,
|
14
|
+
:screen_size_1x40,
|
15
|
+
:screen_size_2x40,
|
16
|
+
:screen_size_4x40,
|
17
|
+
:screen_size_unknown
|
18
|
+
)
|
19
|
+
|
20
|
+
attach_function :CPhidgetTextLCD_create, [:phid], :int
|
21
|
+
attach_function :CPhidgetTextLCD_getRowCount, [:phid, :pointer], :int
|
22
|
+
attach_function :CPhidgetTextLCD_getColumnCount, [:phid, :pointer], :int
|
23
|
+
attach_function :CPhidgetTextLCD_getBacklight, [:phid, :pointer], :int
|
24
|
+
attach_function :CPhidgetTextLCD_setBacklight, [:phid, :int], :int
|
25
|
+
attach_function :CPhidgetTextLCD_getBrightness, [:phid, :pointer], :int
|
26
|
+
attach_function :CPhidgetTextLCD_setBrightness, [:phid, :int], :int
|
27
|
+
attach_function :CPhidgetTextLCD_getContrast, [:phid, :pointer], :int
|
28
|
+
attach_function :CPhidgetTextLCD_setContrast, [:phid, :int], :int
|
29
|
+
attach_function :CPhidgetTextLCD_getCursorOn, [:phid, :pointer], :int
|
30
|
+
attach_function :CPhidgetTextLCD_setCursorOn, [:phid, :int], :int
|
31
|
+
attach_function :CPhidgetTextLCD_getCursorBlink, [:phid, :pointer], :int
|
32
|
+
attach_function :CPhidgetTextLCD_setCursorBlink, [:phid, :int], :int
|
33
|
+
attach_function :CPhidgetTextLCD_setCustomCharacter, [:phid, :int, :int, :int], :int
|
34
|
+
attach_function :CPhidgetTextLCD_setDisplayCharacter, [:phid, :int, :int, :uchar], :int
|
35
|
+
attach_function :CPhidgetTextLCD_setDisplayString, [:phid, :int, :pointer], :int
|
36
|
+
attach_function :CPhidgetTextLCD_getScreenCount, [:phid, :pointer], :int
|
37
|
+
attach_function :CPhidgetTextLCD_getScreen, [:phid, :pointer], :int
|
38
|
+
attach_function :CPhidgetTextLCD_setScreen, [:phid, :int], :int
|
39
|
+
attach_function :CPhidgetTextLCD_getScreenSize, [:phid, :pointer], :int
|
40
|
+
attach_function :CPhidgetTextLCD_setScreenSize, [:phid, TextLCDScreenSizes], :int
|
41
|
+
attach_function :CPhidgetTextLCD_initialize, [:phid], :int
|
42
|
+
|
43
|
+
module CPhidgetTextLCD
|
44
|
+
def self.method_missing(method, *args, &block)
|
45
|
+
if ::Phidgets::FFI.respond_to?("CPhidgetTextLCD_#{method}".to_sym)
|
46
|
+
if (rs = ::Phidgets::FFI.send("CPhidgetTextLCD_#{method}".to_sym, *args, &block)) != 0
|
47
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
super(method, *args, &block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module Phidgets
|
2
|
+
|
3
|
+
# This class represents a PhidgetFrequencyCounter.
|
4
|
+
class FrequencyCounter
|
5
|
+
|
6
|
+
Klass = Phidgets::FFI::CPhidgetFrequencyCounter
|
7
|
+
include Phidgets::Common
|
8
|
+
|
9
|
+
# Collection of frequency counter inputs
|
10
|
+
# @return [FrequencyCounterInputs]
|
11
|
+
attr_reader :inputs
|
12
|
+
|
13
|
+
attr_reader :attributes
|
14
|
+
|
15
|
+
# The attributes of a PhidgetFrequencyCounter
|
16
|
+
def attributes
|
17
|
+
super.merge({
|
18
|
+
:inputs => inputs.size,
|
19
|
+
})
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sets an count handler callback function. This is called when ticks are counted on an frequency counter input, or when the timeout expires
|
23
|
+
#
|
24
|
+
# @param [String] obj Object to pass to the callback function. This is optional.
|
25
|
+
# @param [Proc] Block When the callback is executed, the device and object are yielded to this block.
|
26
|
+
# @example
|
27
|
+
# fc.on_count do |device, input, time, count, obj|
|
28
|
+
# puts "Channel #{input.index}: #{count} pulses in #{time} microseconds"
|
29
|
+
# end
|
30
|
+
# As this runs in it's own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
|
31
|
+
# @return [Boolean] returns true or raises an error
|
32
|
+
def on_count(obj=nil, &block)
|
33
|
+
@on_count_obj = obj
|
34
|
+
@on_count = Proc.new { |device, obj_ptr, index, time, counts|
|
35
|
+
yield self, @inputs[index], time, counts, object_for(obj_ptr)
|
36
|
+
}
|
37
|
+
Klass.set_OnCount_Handler(@handle, @on_count, pointer_for(obj))
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# This class represents a frequency counter input for a PhidgetFrequencyCounter. All the properties of a frequency counter input are stored and modified in this class.
|
42
|
+
class FrequencyCounterInputs
|
43
|
+
Klass = Phidgets::FFI::CPhidgetFrequencyCounter
|
44
|
+
|
45
|
+
private
|
46
|
+
def initialize(handle, index)
|
47
|
+
@handle, @index = handle, index.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
public
|
51
|
+
|
52
|
+
# @return [Integer] returns index of the frequency counter input, or raises an error.
|
53
|
+
def index
|
54
|
+
@index
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean] returns the enabled state of a frequency counter input, or raises an error.
|
58
|
+
def enabled
|
59
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
60
|
+
Klass.getEnabled(@handle, @index, ptr)
|
61
|
+
(ptr.get_int(0) == 0) ? false : true
|
62
|
+
end
|
63
|
+
|
64
|
+
# Sets the enabled state of a frequency counter input, or raises an error.
|
65
|
+
# @param [Boolean] new_state new state
|
66
|
+
# @return [Boolean] returns enabled state of a frequency counter input, or raises an error.
|
67
|
+
def enabled=(new_state)
|
68
|
+
tmp = new_state ? 1 : 0
|
69
|
+
Klass.setEnabled(@handle, @index, tmp)
|
70
|
+
new_state
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [Phidgets::FFI::FrequencyCounterFilterTypes] returns the filter type of the frequency counter input, or raises an error.
|
74
|
+
def filter_type
|
75
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
76
|
+
Klass.getFilter(@handle, @index, ptr)
|
77
|
+
Phidgets::FFI::FrequencyCounterFilterTypes[ptr.get_int(0)]
|
78
|
+
end
|
79
|
+
|
80
|
+
# Sets the filter type of the frequency counter input, or raises an error.
|
81
|
+
# @param [Phidgets::FFI::FrequencyCounterFilterTypes] new_filter new filter
|
82
|
+
# @return [Phidgets::FFI::FrequencyCounterFilterTypes] returns the filter type of the frequency counter input, or raises an error.
|
83
|
+
def filter_type=(new_filter)
|
84
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
85
|
+
Klass.setFilter(@handle, @index, Phidgets::FFI::FrequencyCounterFilterTypes[new_filter])
|
86
|
+
new_filter
|
87
|
+
end
|
88
|
+
|
89
|
+
# @return [Integer] returns the measured frequency of the frequency counter input, in Hz, or raises an error.
|
90
|
+
def frequency
|
91
|
+
ptr = ::FFI::MemoryPointer.new(:double)
|
92
|
+
Klass.getFrequency(@handle, @index, ptr)
|
93
|
+
ptr.get_double(0)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @return [Integer] returns the timeout for the frequency counter input, in microseconds, or raises an error.
|
97
|
+
def timeout
|
98
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
99
|
+
Klass.getTimeout(@handle, @index, ptr)
|
100
|
+
ptr.get_int(0)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Sets the timeout for the frequency counter input, in microseconds, or raises an error.
|
104
|
+
# @param [Integer] new_timeout new timeout
|
105
|
+
# @return [Integer] returns timeout of the frequency counter input, or raises an error.
|
106
|
+
def timeout=(new_timeout)
|
107
|
+
Klass.setTimeout(@handle, @index, new_timeout.to_i)
|
108
|
+
new_timeout.to_i
|
109
|
+
end
|
110
|
+
|
111
|
+
# @return [Integer] returns the number of ticks counted since last reset, or raises an error.
|
112
|
+
def total_count
|
113
|
+
ptr = ::FFI::MemoryPointer.new(:long)
|
114
|
+
Klass.getTotalCount(@handle, @index, ptr)
|
115
|
+
ptr.get_long(0)
|
116
|
+
end
|
117
|
+
|
118
|
+
# @return [Integer] returns the total time since last reset, in microseconds, or raises an error.
|
119
|
+
def total_time
|
120
|
+
ptr = ::FFI::MemoryPointer.new(:long_long)
|
121
|
+
Klass.getTotalTime(@handle, @index, ptr)
|
122
|
+
ptr.get_long_long(0)
|
123
|
+
end
|
124
|
+
|
125
|
+
end #FrequencyCounterInputs
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def load_device_attributes
|
130
|
+
load_inputs
|
131
|
+
end
|
132
|
+
|
133
|
+
def load_inputs
|
134
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
135
|
+
Klass.getFrequencyInputCount(@handle, ptr)
|
136
|
+
|
137
|
+
@inputs = []
|
138
|
+
ptr.get_int(0).times do |i|
|
139
|
+
@inputs << FrequencyCounterInputs.new(@handle, i)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def remove_specific_event_handlers
|
144
|
+
Klass.set_OnCount_Handler(@handle, nil, nil)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
module Phidgets
|
2
|
+
|
3
|
+
# This class represents a PhidgetGPS.
|
4
|
+
class GPS
|
5
|
+
|
6
|
+
Klass = Phidgets::FFI::CPhidgetGPS
|
7
|
+
include Phidgets::Common
|
8
|
+
|
9
|
+
# This represents the GPS date structure, in UTC
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
#
|
13
|
+
# puts gps.date[:year]
|
14
|
+
# puts gps.date[:month]
|
15
|
+
# puts gps.date[:date]
|
16
|
+
class GPS_date < ::FFI::Struct
|
17
|
+
|
18
|
+
# Day
|
19
|
+
# @return [Integer] returns the day
|
20
|
+
attr_reader :day
|
21
|
+
|
22
|
+
# Month
|
23
|
+
# @return [Integer] returns the month
|
24
|
+
attr_reader :month
|
25
|
+
|
26
|
+
# Milliseconds
|
27
|
+
# @return [Integer] returns the milliseconds
|
28
|
+
attr_reader :year
|
29
|
+
|
30
|
+
layout :day, :short,
|
31
|
+
:month, :short,
|
32
|
+
:year, :short
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# This represents the GPS time structure, in UTC
|
37
|
+
#
|
38
|
+
# Examples:
|
39
|
+
#
|
40
|
+
# puts gps.time[:hours]
|
41
|
+
# puts gps.time[:minutes]
|
42
|
+
# puts gps.time[:seconds]
|
43
|
+
# puts gps.time[:milliseconds]
|
44
|
+
class GPS_time < ::FFI::Struct
|
45
|
+
|
46
|
+
# Milliseconds
|
47
|
+
# @return [Integer] returns the milliseconds
|
48
|
+
attr_reader :milliseconds
|
49
|
+
|
50
|
+
# Seconds
|
51
|
+
# @return [Integer] returns the seconds
|
52
|
+
attr_reader :seconds
|
53
|
+
|
54
|
+
# Minutes
|
55
|
+
# @return [Integer] returns the minutes
|
56
|
+
attr_reader :minutes
|
57
|
+
|
58
|
+
# Hours
|
59
|
+
# @return [Integer] returns the hours
|
60
|
+
attr_reader :hours
|
61
|
+
|
62
|
+
layout :milliseconds, :short,
|
63
|
+
:seconds, :short,
|
64
|
+
:minutes, :short,
|
65
|
+
:hours, :short
|
66
|
+
end
|
67
|
+
|
68
|
+
attr_reader :attributes
|
69
|
+
|
70
|
+
# The attributes of a PhidgetGPS
|
71
|
+
def attributes
|
72
|
+
super.merge({
|
73
|
+
|
74
|
+
})
|
75
|
+
end
|
76
|
+
|
77
|
+
# Sets an position fix status change handler callback function. This is called when the position fix status changes.
|
78
|
+
#
|
79
|
+
# @param [String] obj Object to pass to the callback function. This is optional.
|
80
|
+
# @param [Proc] Block When the callback is executed, the device and object are yielded to this block.
|
81
|
+
# @example
|
82
|
+
# gps.on_position_fix_status_change do |device, fix_status, obj|
|
83
|
+
# puts "Position fix status changed to: #{fix_status}"
|
84
|
+
# end
|
85
|
+
# As this runs in it's own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
|
86
|
+
# @return [Boolean] returns true or raises an error
|
87
|
+
def on_position_fix_status_change(obj=nil, &block)
|
88
|
+
@on_position_fix_status_change_obj = obj
|
89
|
+
@on_position_fix_status_change = Proc.new { |device, obj_ptr, fix_status|
|
90
|
+
yield self, (fix_status == 0 ? false : true), object_for(obj_ptr)
|
91
|
+
}
|
92
|
+
Klass.set_OnPositionFixStatusChange_Handler(@handle, @on_position_fix_status_change, pointer_for(obj))
|
93
|
+
end
|
94
|
+
|
95
|
+
# Sets position change handler callback function. This is called when the latitude, longitude, or altitude changes.
|
96
|
+
#
|
97
|
+
# @param [String] obj Object to pass to the callback function. This is optional.
|
98
|
+
# @param [Proc] Block When the callback is executed, the device and object are yielded to this block.
|
99
|
+
# @example
|
100
|
+
# gps.on_position_change do |device, lat, long, alt, obj|
|
101
|
+
# puts "Latitude: #{lat} degrees, longitude: #{long} degrees, altitude: #{alt} m"
|
102
|
+
# end
|
103
|
+
# As this runs in it's own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
|
104
|
+
# @return [Boolean] returns true or raises an error
|
105
|
+
def on_position_change(obj=nil, &block)
|
106
|
+
@on_position_change_obj = obj
|
107
|
+
@on_position_change = Proc.new { |device, obj_ptr, lat, long, alt|
|
108
|
+
yield self, lat, long, alt, object_for(obj_ptr)
|
109
|
+
}
|
110
|
+
Klass.set_OnPositionChange_Handler(@handle, @on_position_change, pointer_for(obj))
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Float] returns the latitude in degrees, or raises an error.
|
114
|
+
def latitude
|
115
|
+
ptr = ::FFI::MemoryPointer.new(:double)
|
116
|
+
Klass.getLatitude(@handle, ptr)
|
117
|
+
ptr.get_double(0)
|
118
|
+
end
|
119
|
+
|
120
|
+
# @return [Float] returns the longitude in degrees or raises an error.
|
121
|
+
def longitude
|
122
|
+
ptr = ::FFI::MemoryPointer.new(:double)
|
123
|
+
Klass.getLongitude(@handle, ptr)
|
124
|
+
ptr.get_double(0)
|
125
|
+
end
|
126
|
+
|
127
|
+
# @return [Float] returns the altitude in meters, or raises an error.
|
128
|
+
def altitude
|
129
|
+
ptr = ::FFI::MemoryPointer.new(:double)
|
130
|
+
Klass.getAltitude(@handle, ptr)
|
131
|
+
ptr.get_double(0)
|
132
|
+
end
|
133
|
+
|
134
|
+
# @return [Float] returns the heading in degrees or raises an error.
|
135
|
+
def heading
|
136
|
+
ptr = ::FFI::MemoryPointer.new(:double)
|
137
|
+
Klass.getHeading(@handle, ptr)
|
138
|
+
ptr.get_double(0)
|
139
|
+
end
|
140
|
+
|
141
|
+
# @return [Float] returns the velocity in km/h, in or raises an error.
|
142
|
+
def velocity
|
143
|
+
ptr = ::FFI::MemoryPointer.new(:double)
|
144
|
+
Klass.getVelocity(@handle, ptr)
|
145
|
+
ptr.get_double(0)
|
146
|
+
end
|
147
|
+
|
148
|
+
# @return [GPS_date] returns the date in UTC, in or raises an error.
|
149
|
+
def date
|
150
|
+
ptr = ::FFI::MemoryPointer.new 6 #2 bytes for each short
|
151
|
+
Klass.getDate(@handle, ptr)
|
152
|
+
obj = GPS_date.new(ptr)
|
153
|
+
end
|
154
|
+
|
155
|
+
# @return [GPS_time] returns the time in UTC, in or raises an error.
|
156
|
+
def time
|
157
|
+
ptr = ::FFI::MemoryPointer.new 8 #2 bytes for each short
|
158
|
+
Klass.getTime(@handle, ptr)
|
159
|
+
obj = GPS_time.new(ptr)
|
160
|
+
end
|
161
|
+
|
162
|
+
# @return [Boolean] returns state of the digital input, or raises an error.
|
163
|
+
def position_fix_status
|
164
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
165
|
+
Klass.getPositionFixStatus(@handle, ptr)
|
166
|
+
(ptr.get_int(0) == 0) ? false : true
|
167
|
+
end
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
def load_device_attributes
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
def remove_specific_event_handlers
|
176
|
+
Klass.set_OnPositionChange_Handler(@handle, nil, nil)
|
177
|
+
Klass.set_OnPositionFixStatusChange_Handler(@handle, nil, nil)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|