return rad * 180 / PI;
}
+inline static double absValue(double value)
+{
+ if(value < 0.0)
+ {
+ return -value;
+ }
+
+ return value;
+}
+
PoiAlerts::PoiAlerts(): QObject(0), enabled_(false), currentPoi_(0), loaded_(false)
{
}
return true;
}
- distance_ = Settings::instance().value("alert_distance", 300).toBool();
+ distance_ = Settings::instance().value("alert_distance", 300).toDouble();
onlyOnRoute_ = Settings::instance().value("alert_only_on_route", true).toBool();
if(distance_ < 0)
void PoiAlerts::onDataUpdated()
{
- qDebug() << "Data update";
-
- static int i = 0;
- i++;
-
- double travelled = Odometer::instance().getTotal();
const Location::Fix* fix = &(Odometer::instance().getLatestFix());
- if(fix->latitude < 0.01 || fix->longitude < 0.01 || fix->kmSpeed < 0.01)
+ if(fix->latitude < 0.01 || fix->longitude < 0.01 ||
+ fix->kmSpeed < 0.01 || isnan(fix->eph))
{
return;
}
- else
- {
- /*if(i < 5)
- {
- pois_[0].latitude = fix->latitude;
- pois_[0].longitude = fix->longitude;
- }*/
- }
-
- double distance;
- double inRouteMargin = IN_ROUTE_MARGIN + (fix->eph / 1000.0);
- qDebug() << "Eph: " << fix->eph;
- qDebug() << "In route margin: " << inRouteMargin;
+ double travelled = Odometer::instance().getTotal();
- if(1 == 1 || abs(travelled - travelled_) > 0.03)
+ if(absValue(travelled - travelled_) > 0.02)
{
+ double distance;
+ double inRouteMargin = IN_ROUTE_MARGIN + (fix->eph / 1000.0);
+
+ bool found = false;
+
travelled_ = travelled;
for(int i = 0; i < pois_.size(); i++)
if(onlyOnRoute_)
{
- double track = abs(calculateTrack(fix->latitude, fix->longitude,
- pois_.at(i).latitude, pois_.at(i).longitude) - fix->track);
+ double track = absValue(calculateTrack(fix->latitude, fix->longitude,
+ pois_.at(i).latitude, pois_.at(i).longitude) - fix->track);
if(track > 180)
{
}
qDebug() << "Real track: " << track;
- qDebug() << "Epd: " << fix->epd;
double trackLimit;
}
else
{
- trackLimit = 90.0 - radToDeg(acos((inRouteMargin + (distance * 0.15)) / distance));
+ trackLimit = 90.0 - radToDeg(acos((inRouteMargin + (distance * 0.16)) / distance));
}
qDebug() << "Tracklimit: " << trackLimit;
if(track < trackLimit)
{
+ found = true;
currentPoi_ = &pois_[i];
currentDistance_ = distance;
+ emit visibilityChanged(true);
playSound(i);
}
else
{
currentPoi_ = 0;
+ emit visibilityChanged(false);
}
}
else
{
+ found = true;
currentPoi_ = &pois_[i];
currentDistance_ = distance;
+ emit visibilityChanged(true);
playSound(i);
}
break;
}
- else
- {
- currentPoi_ = 0;
- qDebug() << "Distance: " << distance;
- }
}
- }
- qDebug() << '\n';
-}
-
-void PoiAlerts::startTest()
-{
- Odometer::instance().start();
- enabled_ = true;
- distance_ = 100;
- PoiReader::Poi poi;
- poi.latitude = 0.0;
- poi.longitude = 0.0;
- poi.name = "Mokki";
- pois_.push_back(poi);
- onlyOnRoute_ = true;
- start();
+ if(!found && currentPoi_)
+ {
+ currentPoi_ = 0;
+ emit visibilityChanged(false);
+ }
+ }
}
double PoiAlerts::calculateDistance(double latitude1, double longitude1,
{
return Settings::getDir() + "pois" + QDir::separator();
}
-