Module: Tinkerforge::Shared::GPS

Included in:
BrickletGPSV2, BrickletGPSV3
Defined in:
lib/tinderfridge/shared/gps.rb

Overview

Mixin for GPS Bricklet versions 2 & 3.

Instance Method Summary collapse

Instance Method Details

#coordinatesObject

Returns latitude and longitude as reported by the GPS Bricklet.

Nil when there is no fix (position not determined).



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tinderfridge/shared/gps.rb', line 23

def coordinates
  if fix?
    c = get_coordinates
    [
      c[0] / (c[1] == 'N' ? 1000000.0 : -1000000.0),
      c[2] / (c[3] == 'E' ? 1000000.0 : -1000000.0)
    ]
  else
    nil
  end
end

#fix?Boolean

Returns true if a fix is available.

Returns:

  • (Boolean)


16
17
18
# File 'lib/tinderfridge/shared/gps.rb', line 16

def fix?
  get_status[0]
end

#openstreetmap_marker_url(zoom = 12) ⇒ Object

Returns a URL for viewing the current coordinates on OpenStreetMap.



45
46
47
48
49
# File 'lib/tinderfridge/shared/gps.rb', line 45

def openstreetmap_marker_url(zoom=12)
  if c = coordinates
    "https://www.openstreetmap.org/?mlat=%f&mlon=%f&zoom=%d" % [c, zoom].flatten
  end
end

#stateObject

Returns the device's state.



8
9
10
11
12
13
# File 'lib/tinderfridge/shared/gps.rb', line 8

def state
  super.merge(
    'fix_led_config' => get_fix_led_config,
    'fix'            => fix?,
  )
end

#timeObject

Returns a Time object representing the time as reported by the GPS Bricklet.



36
37
38
39
40
41
42
# File 'lib/tinderfridge/shared/gps.rb', line 36

def time
  # FIXME: This will not work after 31-Dec-2099.
  dt = get_date_time.map &:to_s
  dt = dt[0].rjust(6,'0').unpack('a2a2a2').reverse + dt[1].rjust(9,'0').concat('000').unpack('a2a2a2a6')
  dt[0].prepend '20'
  Time.gm *dt.map(&:to_i)
end