Class: Tinkerforge::BrickletGPSV3
- Inherits:
-
Object
- Object
- Tinkerforge::BrickletGPSV3
- Defined in:
- lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb
Instance Method Summary collapse
-
#coordinates ⇒ Object
Returns latitude and longitude as reported by the GPS Bricklet.
-
#fix? ⇒ Boolean
Returns true if a fix is available.
-
#openstreetmap_marker_url(zoom = 12) ⇒ Object
Returns a URL for viewing the current coordinates on OpenStreetMap.
-
#state ⇒ Object
Returns the device’s state.
-
#time ⇒ Object
Returns a Time object representing the time as reported by the GPS Bricklet.
Instance Method Details
#coordinates ⇒ Object
Returns latitude and longitude as reported by the GPS Bricklet.
Nil when there is no fix (position not determined).
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb', line 21 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.
14 15 16 |
# File 'lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb', line 14 def fix? get_status[0] end |
#openstreetmap_marker_url(zoom = 12) ⇒ Object
Returns a URL for viewing the current coordinates on OpenStreetMap.
43 44 45 46 47 |
# File 'lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb', line 43 def openstreetmap_marker_url(zoom=12) if c = coordinates "https://www.openstreetmap.org/?mlat=%f&mlon=%f&zoom=%d" % [c, zoom].flatten end end |
#state ⇒ Object
Returns the device’s state.
6 7 8 9 10 11 |
# File 'lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb', line 6 def state super.merge( 'fix_led_config' => get_fix_led_config, 'fix' => fix?, ) end |
#time ⇒ Object
Returns a Time object representing the time as reported by the GPS Bricklet.
34 35 36 37 38 39 40 |
# File 'lib/tinderfridge/devices/bricklet_gps_v3/bricklet_gps_v3.rb', line 34 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 |