...
[jspeed] / src / location.cpp
index f22c7c8..56071f5 100644 (file)
 
 namespace
 {
-    static const double KM_MULTIPLIER = 1.0;
-    static const double MILE_MULTIPLIER = 0.621371192;
+    static double const KM_MULTIPLIER = 1.0;
+    static double const MILE_MULTIPLIER = 0.621371192;
+    static double const METER_MULTIPLIER = 1.0;
+    static double const FEET_MULTIPLIER = 3.2808399;
 }
 
 Location::Unit Location::unit_ = Location::KM;
@@ -73,6 +75,38 @@ void Location::end()
     started_ = false;
 }
 
+bool Location::hasFix() const
+{
+    if(!started_)
+    {
+        return false;
+    }
+
+    return (device_->status == LOCATION_GPS_DEVICE_STATUS_FIX);
+}
+
+double Location::getSignalStrength() const
+{
+    if(!hasFix())
+    {
+        return 0.0;
+    }
+
+    if(device_->satellites_in_view == 0)
+    {
+        return 0.0;
+    }
+
+    double val = (device_->satellites_in_use / static_cast<double>(device_->satellites_in_view)) * 100.0;
+
+    if(val > 100.0)
+    {
+        val = 100.0;
+    }
+
+    return val;
+}
+
 void Location::setUnit(Location::Unit unit)
 {
     unit_ = unit;
@@ -93,6 +127,16 @@ double Location::getUnitMultiplier()
     return KM_MULTIPLIER;
 }
 
+double Location::getMeterMultiplier()
+{
+    if(unit_ == MILE)
+    {
+        return FEET_MULTIPLIER;
+    }
+
+    return METER_MULTIPLIER;
+}
+
 void Location::onChanged(LocationGPSDevice *device, gpointer data)
 {
     if(device && device->fix &&
@@ -113,7 +157,7 @@ void Location::onChanged(LocationGPSDevice *device, gpointer data)
 
         if(device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET)
         {
-            fix.altitude = device->fix->altitude;
+            fix.altitude = device->fix->altitude * getMeterMultiplier();
             fix.epv = device->fix->epv;
         }