Class: Phidgets::GPS

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/phidgets-ffi/gps.rb

Overview

This class represents a PhidgetGPS.

Defined Under Namespace

Classes: GPS_date, GPS_time

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetGPS

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

The attributes of a PhidgetGPS



71
72
73
# File 'lib/phidgets-ffi/gps.rb', line 71

def attributes
  @attributes
end

Instance Method Details

#altitudeFloat

Returns the altitude in meters, or raises an error.

Returns:

  • (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

#dateGPS_date

Returns the date in UTC, in or raises an error.

Returns:

  • (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

#headingFloat

Returns the heading in degrees or raises an error.

Returns:

  • (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

#latitudeFloat

Returns the latitude in degrees, or raises an error.

Returns:

  • (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

#longitudeFloat

Returns the longitude in degrees or raises an error.

Returns:

  • (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.

Examples:

gps.on_position_change do |device, lat, long, alt, obj|
  puts "Latitude: #{lat} degrees, longitude: #{long} degrees, altitude: #{alt} m"
end

Parameters:

  • obj (String) (defaults to: nil)

    Object to pass to the callback function. This is optional.

  • Block (Proc)

    When the callback is executed, the device and object are yielded to this block.

Returns:

  • (Boolean)

    returns true or raises an error



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.

Examples:

gps.on_position_fix_status_change do |device, fix_status, obj|
  puts "Position fix status changed to: #{fix_status}"
end

Parameters:

  • obj (String) (defaults to: nil)

    Object to pass to the callback function. This is optional.

  • Block (Proc)

    When the callback is executed, the device and object are yielded to this block.

Returns:

  • (Boolean)

    returns true or raises an error



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_statusBoolean

Returns state of the digital input, or raises an error.

Returns:

  • (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

#timeGPS_time

Returns the time in UTC, in or raises an error.

Returns:

  • (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

#velocityFloat

Returns the velocity in km/h, in or raises an error.

Returns:

  • (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