Class: Phidgets::GPS
Overview
This class represents a PhidgetGPS.
Defined Under Namespace
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetGPS
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetGPS.
Instance Method Summary collapse
-
#altitude ⇒ Float
Returns the altitude in meters, or raises an error.
-
#date ⇒ GPS_date
Returns the date in UTC, in or raises an error.
-
#heading ⇒ Float
Returns the heading in degrees or raises an error.
-
#latitude ⇒ Float
Returns the latitude in degrees, or raises an error.
-
#longitude ⇒ Float
Returns the longitude in degrees or raises an error.
-
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets position change handler callback function.
-
#on_position_fix_status_change(obj = nil, &block) ⇒ Boolean
Sets an position fix status change handler callback function.
-
#position_fix_status ⇒ Boolean
Returns state of the digital input, or raises an error.
-
#time ⇒ GPS_time
Returns the time in UTC, in or raises an error.
-
#velocity ⇒ Float
Returns the velocity in km/h, in or raises an error.
Methods included from Common
#attached?, #attached_to_server?, attributes, #close, #detached?, #detached_to_server?, device_class, #device_class, device_id, #id, #initialize, #label, #label=, #name, #on_attach, #on_detach, #on_error, #on_server_connect, #on_server_disconnect, #on_sleep, #on_wake, #serial_number, #server_address, server_address, #server_id, server_id, server_status, #type, #version, #wait_for_attachment
Instance Attribute Details
#attributes ⇒ Object (readonly)
The attributes of a PhidgetGPS
71 72 73 |
# File 'lib/phidgets-ffi/gps.rb', line 71 def attributes @attributes end |
Instance Method Details
#altitude ⇒ Float
Returns the altitude in meters, or raises an error.
128 129 130 131 132 |
# File 'lib/phidgets-ffi/gps.rb', line 128 def altitude ptr = ::FFI::MemoryPointer.new(:double) Klass.getAltitude(@handle, ptr) ptr.get_double(0) end |
#date ⇒ GPS_date
Returns the date in UTC, in or raises an error.
149 150 151 152 153 |
# File 'lib/phidgets-ffi/gps.rb', line 149 def date ptr = ::FFI::MemoryPointer.new 6 #2 bytes for each short Klass.getDate(@handle, ptr) obj = GPS_date.new(ptr) end |
#heading ⇒ Float
Returns the heading in degrees or raises an error.
135 136 137 138 139 |
# File 'lib/phidgets-ffi/gps.rb', line 135 def heading ptr = ::FFI::MemoryPointer.new(:double) Klass.getHeading(@handle, ptr) ptr.get_double(0) end |
#latitude ⇒ Float
Returns the latitude in degrees, or raises an error.
114 115 116 117 118 |
# File 'lib/phidgets-ffi/gps.rb', line 114 def latitude ptr = ::FFI::MemoryPointer.new(:double) Klass.getLatitude(@handle, ptr) ptr.get_double(0) end |
#longitude ⇒ Float
Returns the longitude in degrees or raises an error.
121 122 123 124 125 |
# File 'lib/phidgets-ffi/gps.rb', line 121 def longitude ptr = ::FFI::MemoryPointer.new(:double) Klass.getLongitude(@handle, ptr) ptr.get_double(0) end |
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets position change handler callback function. This is called when the latitude, longitude, or altitude changes.
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.
105 106 107 108 109 110 111 |
# File 'lib/phidgets-ffi/gps.rb', line 105 def on_position_change(obj=nil, &block) @on_position_change_obj = obj @on_position_change = Proc.new { |device, obj_ptr, lat, long, alt| yield self, lat, long, alt, object_for(obj_ptr) } Klass.set_OnPositionChange_Handler(@handle, @on_position_change, pointer_for(obj)) end |
#on_position_fix_status_change(obj = nil, &block) ⇒ Boolean
Sets an position fix status change handler callback function. This is called when the position fix status changes.
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.
87 88 89 90 91 92 93 |
# File 'lib/phidgets-ffi/gps.rb', line 87 def on_position_fix_status_change(obj=nil, &block) @on_position_fix_status_change_obj = obj @on_position_fix_status_change = Proc.new { |device, obj_ptr, fix_status| yield self, (fix_status == 0 ? false : true), object_for(obj_ptr) } Klass.set_OnPositionFixStatusChange_Handler(@handle, @on_position_fix_status_change, pointer_for(obj)) end |
#position_fix_status ⇒ Boolean
Returns state of the digital input, or raises an error.
163 164 165 166 167 |
# File 'lib/phidgets-ffi/gps.rb', line 163 def position_fix_status ptr = ::FFI::MemoryPointer.new(:int) Klass.getPositionFixStatus(@handle, ptr) (ptr.get_int(0) == 0) ? false : true end |
#time ⇒ GPS_time
Returns the time in UTC, in or raises an error.
156 157 158 159 160 |
# File 'lib/phidgets-ffi/gps.rb', line 156 def time ptr = ::FFI::MemoryPointer.new 8 #2 bytes for each short Klass.getTime(@handle, ptr) obj = GPS_time.new(ptr) end |
#velocity ⇒ Float
Returns the velocity in km/h, in or raises an error.
142 143 144 145 146 |
# File 'lib/phidgets-ffi/gps.rb', line 142 def velocity ptr = ::FFI::MemoryPointer.new(:double) Klass.getVelocity(@handle, ptr) ptr.get_double(0) end |