From: Toni Jussila Date: Wed, 31 Mar 2010 07:44:08 +0000 (+0300) Subject: Route save dialog development. Added: gps,icon... X-Git-Tag: v0.2-RC1~11^2~6^2 X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=2902e3c96a34377d252d222ff60ce11f46556882 Route save dialog development. Added: gps,icon... --- diff --git a/Client/Graphics/Speedometer.png b/Client/Graphics/Speedometer.png new file mode 100644 index 0000000..aa706cd Binary files /dev/null and b/Client/Graphics/Speedometer.png differ diff --git a/Client/Graphics/Speedometer2.png b/Client/Graphics/Speedometer2.png new file mode 100644 index 0000000..ff02874 Binary files /dev/null and b/Client/Graphics/Speedometer2.png differ diff --git a/Client/Graphics/applications_internet.png b/Client/Graphics/applications_internet.png new file mode 100755 index 0000000..d3f8382 Binary files /dev/null and b/Client/Graphics/applications_internet.png differ diff --git a/Client/Graphics/route_play.png b/Client/Graphics/route_play.png new file mode 100755 index 0000000..2689e38 Binary files /dev/null and b/Client/Graphics/route_play.png differ diff --git a/Client/Graphics/route_stop.png b/Client/Graphics/route_stop.png new file mode 100755 index 0000000..d017a95 Binary files /dev/null and b/Client/Graphics/route_stop.png differ diff --git a/Client/Graphics/satellite_vista.png b/Client/Graphics/satellite_vista.png new file mode 100755 index 0000000..6d7601f Binary files /dev/null and b/Client/Graphics/satellite_vista.png differ diff --git a/Client/Graphics/settings.png b/Client/Graphics/settings.png new file mode 100755 index 0000000..5ef3171 Binary files /dev/null and b/Client/Graphics/settings.png differ diff --git a/Client/Graphics/trophy_gold.png b/Client/Graphics/trophy_gold.png new file mode 100755 index 0000000..3ee0701 Binary files /dev/null and b/Client/Graphics/trophy_gold.png differ diff --git a/Client/Graphics/www.png b/Client/Graphics/www.png new file mode 100755 index 0000000..4db37a8 Binary files /dev/null and b/Client/Graphics/www.png differ diff --git a/Client/gpsdata.cpp b/Client/gpsdata.cpp new file mode 100644 index 0000000..db0a6bc --- /dev/null +++ b/Client/gpsdata.cpp @@ -0,0 +1,268 @@ +/* + * GPS data + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#include "gpsdata.h" + +/** + *Default constructor of this class. + */ +GPSData::GPSData(Maemo5Location *maemo5location) +{ + location = maemo5location; + + connect(location,SIGNAL(agnss()),this,SLOT(agnss())); + connect(location,SIGNAL(awcp()),this,SLOT(awcp())); + connect(location,SIGNAL(locationUpdated()),this,SLOT(locationUpdated())); + connect(location,SIGNAL(gps_connected()),this,SLOT(gpsConnected())); + connect(location,SIGNAL(gps_disconnected()),this,SLOT(gpsDisconnected())); + connect(location,SIGNAL(gps_error(int)),this,SLOT(gpsError())); + connect(location,SIGNAL(gpsd_running()),this,SLOT(gpsdRunning())); + connect(location,SIGNAL(gpsd_stopped()),this,SLOT(gpsdStopped())); + + gpsDateTime = new QDateTime(); + resetAll(); +} + +/** + *Destructor of this class. Deletes all dynamic objects and sets them to NULL. + */ +GPSData::~GPSData() +{ + delete location; + delete gpsDateTime; +} + +void GPSData::resetAll() +{ + satellitesInUse = 0; + satellitesInView = 0; + signalStrength = 0; + latitude = 0; + longitude = 0; + time = 0; + ept = 0; + eph = 0; + altitude = 0; + epv = 0; + track = 0; + epd = 0; + speed = 0; + eps = 0; + climb = 0; + epc = 0; + latitudePrevious = 0; + longitudePrevious = 0; + sLatitudeNow = ""; + sLongitudeNow = ""; + sLatitudePrevious = ""; + sLongitudePrevious = ""; + routeStartTime = ""; + routeStopTime = ""; + recordingStatus = false; + roundCounter = 0; +} + +/** + *This slot function is called when GPS update location. + */ +void GPSData::agnss() +{ + //satellitesInUse = location->getSatellitesInUse()); //Returns number of satellites in use. + //satellitesInView = location->getSatellitesInView(); //Returns number of satellites in view. + //signalStrength = location->getSignalStrength(); //Returns average signal strength of satellites which are in use. + //gpsOnline = location->getGpsOnline(); //Returns gsp online + //ept = location->getEpt(); //Returns time accuracy in seconds. + //eph = location->getEph(); //Returns horizontal position accuracy in cm. + //track = location->getTrack(); //Returns direction of motion in degrees(0-359). + //epd = location->getEpd(); //Returns track accuracy in degrees. + //climb = location->getClimb(); //Returns current rate of climb in m/s. + //epc = location->getEpc(); //Returns climb accuracy in m/s. + //time = location->getTime(); //Returns timestamp of the update in seconds. + //epv = location->getEpv(); //Returns altitude accuracy in meters. + //eps = location->getEps(); //Returns speed accuracy in km/h. + //distance = location->distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f); + + //If route recording true + if ( recordingStatus == true ) + { + latitudePrevious = latitude; + longitudePrevious = longitude; + latitude = location->getLatitude(); //Returns latitude. + longitude = location->getLongitude(); //Returns longitude. + altitude = location->getAltitude(); //Returns fix altitude in meters. + speed = location->getSpeed(); //Returns current speed in km/h. + + QFile routeTempFile("routetemp.xml");//Temp xml. + + //If first round + if (roundCounter == 0) + { + if (!routeTempFile.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + writeRouteXml(&routeTempFile, 0); + routeTempFile.close(); + roundCounter ++; + } + + //Points writing round. + else + { + sLatitudeNow.sprintf("%.4f", latitude); //Latitude now to string + sLongitudeNow.sprintf("%.4f", longitude);//Longitude now to string + sLatitudePrevious.sprintf("%.4f", latitudePrevious); //Previous latitude to string + sLongitudePrevious.sprintf("%.4f", longitudePrevious); //Previous longitude to string + + //If latitude or longitude change + if ( sLatitudeNow != sLatitudePrevious || sLongitudeNow != sLongitudePrevious ) + { + if (!routeTempFile.open(QIODevice::Append | QIODevice::Text)) + return; + + writeRouteXml(&routeTempFile, 0); + roundCounter ++; + routeTempFile.close(); + } + } + } +} + +/** + *This slot function is called when gprs update location. + */ +void GPSData::awcp() +{ + +} + +/** + *This slot function is called when . + */ +void GPSData::locationUpdated() +{ + +} + +/** + *This slot function is called when . + */ +void GPSData::gpsConnected() +{ + +} + +/** + *This slot function is called when . + */ +void GPSData::gpsDisconnected() +{ + +} + +/** + *This slot function is called when . + */ +void GPSData::gpsError() +{ + +} + +/** + *This slot function is called when . + */ +void GPSData::gpsdRunning() +{ + +} + +/** + *This slot function is called when . + */ +void GPSData::gpsdStopped() +{ + +} + +/** + *This function start route recording. + *@param QString time recording start time. + */ +void GPSData::startRouteRecording() +{ + if (recordingStatus == false) + { + //Get start time and start recording. + gpsDateTime->setTime_t(location->getTime()); + routeStartTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss"); + recordingStatus = true; + roundCounter = 0; + } +} + +/** + *This function stop route recording. + *@param QString time recording stop time. + */ +void GPSData::stopRouteRecording() +{ + if (recordingStatus == true) + { + //Get stop time and stop recording. + gpsDateTime->setTime_t(location->getTime()); + routeStopTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss"); + recordingStatus = false; + + //Write final xml. + QFile file("route.xml"); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + writeRouteXml(&file, 1); + file.close(); + roundCounter = 0; + } +} + +/** + *This function write route to .xml file. + */ +void GPSData::writeRouteXml(QIODevice *device, int round) +{ + xmlwriter.setDevice(device); + + //Write temp xml (routetemp.xml). + if ( round == 0 ) + { + xmlwriter.writeStartElement("Point"); + xmlwriter.writeAttribute("Latitude", QString::number(latitude)); + xmlwriter.writeAttribute("Longitude", QString::number(longitude)); + xmlwriter.writeAttribute("Altitude", QString::number(altitude)); + xmlwriter.writeAttribute("Speed", QString::number(speed)); + xmlwriter.writeEndElement();//Point + } + + //Write final xml (route.xml). + else if ( round == 1 ) + { + xmlwriter.writeStartDocument(); + xmlwriter.writeStartElement("Route"); + xmlwriter.writeAttribute("Start-time", routeStartTime); + xmlwriter.writeAttribute("Stop-time", routeStopTime); + xmlwriter.writeAttribute("Points", QString::number(roundCounter)); + + //Open temp xml and read points + QFile tempFile("routetemp.xml"); + if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + QTextStream readRoute(&tempFile); + QTextStream writeRoute(device); + writeRoute << readRoute.readLine(); + tempFile.close();//Close temp xml + + xmlwriter.writeEndElement();//Route + xmlwriter.writeEndDocument(); + } +} diff --git a/Client/gpsdata.h b/Client/gpsdata.h new file mode 100644 index 0000000..f7b40e8 --- /dev/null +++ b/Client/gpsdata.h @@ -0,0 +1,75 @@ +/* + * GPS data + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#ifndef GPSDATA_H +#define GPSDATA_H + +#include +#include +#include +#include +#include +#include + +class GPSData : public QObject +{ + Q_OBJECT +public: + GPSData( Maemo5Location *maemo5location ); + ~GPSData(); + void startRouteRecording(); + void stopRouteRecording(); + int roundCounter; //testing, move private!!! + +private: + Maemo5Location *location; + void resetAll(); + QXmlStreamWriter xmlwriter; + void writeRouteXml(QIODevice *device, int round); + + int satellitesInUse; //Number of satellites in use. + int satellitesInView;//Number of satellites in view. + int signalStrength; //Average signal strength of satellites which are in use. + double latitude; //Latitude. + double longitude; //Longitude. + double time; //Timestamp of the update in seconds. + double ept; //Time accuracy in seconds. + double eph; //Horizontal position accuracy in cm. + double altitude; //Fix altitude in meters. + double epv; //Altitude accuracy in meters. + double track; //Direction of motion in degrees(0-359). + double epd; //Track accuracy in degrees. + double speed; //Current speed in km/h. + double eps; //Speed accuracy in km/h. + double climb; //Current rate of climb in m/s. + double epc; //Climb accuracy in m/s. + double latitudePrevious; + double longitudePrevious; + QString routeStartTime; + QString routeStopTime; + QString sLatitudeNow; + QString sLongitudeNow; + QString sLatitudePrevious; + QString sLongitudePrevious; + QDateTime *gpsDateTime; + bool recordingStatus; + //int roundCounter; + +private slots: + void agnss(); + void awcp(); + void locationUpdated(); + void gpsConnected(); + void gpsDisconnected(); + void gpsError(); + void gpsdRunning(); + void gpsdStopped(); + +}; + +#endif // GPSDATA_H diff --git a/Client/graphics.qrc b/Client/graphics.qrc index 36b139d..69f30cb 100644 --- a/Client/graphics.qrc +++ b/Client/graphics.qrc @@ -2,6 +2,13 @@ Graphics/meter.png Graphics/route.png - Graphics/Speedometer .png + Graphics/satellite_vista.png + Graphics/route_play.png + Graphics/route_stop.png + Graphics/settings.png + Graphics/trophy_gold.png + Graphics/applications_internet.png + Graphics/Speedometer.png + Graphics/Speedometer2.png diff --git a/Client/maemo5location.cpp b/Client/maemo5location.cpp new file mode 100755 index 0000000..a8065fd --- /dev/null +++ b/Client/maemo5location.cpp @@ -0,0 +1,201 @@ +/* + * Maemo5Location + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +//#ifdef Q_WS_MAEMO_5 +#include "maemo5locationprivate.h" +#include "maemo5location.h" + +/** + *Default constructor of this class. + *@param QObject pointer to parent object. By default the value is NULL. + */ +Maemo5Location::Maemo5Location(QObject* parent):QObject(parent) +{ + ptr = new Maemo5LocationPrivate(this); + + connect(ptr, SIGNAL(agnss()), this, SIGNAL(agnss())); + connect(ptr, SIGNAL(awcp()), this, SIGNAL(awcp())); + connect(ptr, SIGNAL(locationUpdated()), this, SIGNAL(locationUpdated())); + connect(ptr, SIGNAL(gps_connected()), this, SIGNAL(gps_connected())); + connect(ptr, SIGNAL(gps_disconnected()), this, SIGNAL(gps_disconnected())); + connect(ptr, SIGNAL(gps_error(int)), this, SIGNAL(gps_error(int))); + connect(ptr, SIGNAL(gpsd_running()), this, SIGNAL(gpsd_running())); + connect(ptr, SIGNAL(gpsd_stopped()), this, SIGNAL(gpsd_stopped())); +} + +/** + *Destructor of this class. Should be used to release all allocated resources. + */ +Maemo5Location::~Maemo5Location() +{ + delete ptr; +} + +/** + *Start polling gps. + */ +void Maemo5Location::startPollingGPS() +{ + ptr->get_agnss(); +} + +/** + *Stop polling gps. + */ +void Maemo5Location::stopPollingGPS() +{ + ptr->stop(); +} + +/** + *Returns number of satellites in use. + */ +int Maemo5Location::getSatellitesInUse() +{ + return ptr->get_satellites_in_use(); +} + +/** + *Returns number of satellites in view. + */ +int Maemo5Location::getSatellitesInView() +{ + return ptr->get_satellites_in_view(); +} + +/** + *Returns average signal strength of satellites which are in use. + */ +int Maemo5Location::getSignalStrength() +{ + return ptr->get_signal_strength(); +} + +/** + *Returns gps online. + */ +bool Maemo5Location::getGpsOnline() +{ + return ptr->get_gps_online(); +} + +/** + *Returns latitude. + */ +double Maemo5Location::getLatitude() +{ + return ptr->get_lat(); +} + +/** + *Returns longitude. + */ +double Maemo5Location::getLongitude() +{ + return ptr->get_lon(); +} + +/** + *Returns timestamp of the update in seconds. + */ +double Maemo5Location::getTime() +{ + return ptr->get_time(); +} + +/** + *Returns time accuracy in seconds. + */ +double Maemo5Location::getEpt() +{ + return ptr->get_ept(); +} + +/** + *Returns horizontal position accuracy in cm. + */ +double Maemo5Location::getEph() +{ + return ptr->get_eph(); +} + +/** + *Returns fix altitude in meters. + */ +double Maemo5Location::getAltitude() +{ + return ptr->get_altitude(); +} + +/** + *Returns altitude accuracy in meters. + */ +double Maemo5Location::getEpv() +{ + return ptr->get_epv(); +} + +/** + *Returns direction of motion in degrees(0-359). + */ +double Maemo5Location::getTrack() +{ + return ptr->get_track(); +} + +/** + *Returns track accuracy in degrees. + */ +double Maemo5Location::getEpd() +{ + return ptr->get_epd(); +} + +/** + *Returns current speed in km/h. + */ +double Maemo5Location::getSpeed() +{ + return ptr->get_speed(); +} + +/** + *Returns speed accuracy in km/h. + */ +double Maemo5Location::getEps() +{ + return ptr->get_eps(); +} + +/** + *Returns current rate of climb in m/s. + */ +double Maemo5Location::getClimb() +{ + return ptr->get_climb(); +} + +/** + *Returns climb accuracy in m/s. + */ +double Maemo5Location::getEpc() +{ + return ptr->get_epc(); +} + +/** + *Returns distance between two points in kilometers. + *@param latitude of first point + *@param longitude of first point + *@param latitude of second point + *@param longitude of second point + */ +double Maemo5Location::distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f) +{ + return ptr->distance_between_two_points(latitude_s, longitude_s, latitude_f, longitude_f); +} diff --git a/Client/maemo5location.h b/Client/maemo5location.h new file mode 100755 index 0000000..7f376f0 --- /dev/null +++ b/Client/maemo5location.h @@ -0,0 +1,58 @@ +/* + * Maemo5Location + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#ifndef MAEMO5LOCATION_H +#define MAEMO5LOCATION_H + +#include + +class Maemo5LocationPrivate; + +class Maemo5Location : public QObject +{ + Q_OBJECT +public: + Maemo5Location(QObject* parent = 0); + ~Maemo5Location(); + + void startPollingGPS(); + void stopPollingGPS(); + int getSatellitesInUse(); + int getSatellitesInView(); + int getSignalStrength(); + bool getGpsOnline(); + double getLatitude(); + double getLongitude(); + double getTime(); + double getEpt(); + double getEph(); + double getAltitude(); + double getEpv(); + double getTrack(); + double getEpd(); + double getSpeed(); + double getEps(); + double getClimb(); + double getEpc(); + double distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f); + +signals: + void awcp(); + void agnss(); + void locationUpdated(); + void gps_connected(); + void gps_disconnected(); + void gps_error(int); + void gpsd_running(); + void gpsd_stopped(); + +private: + Maemo5LocationPrivate* ptr; +}; + +#endif // MAEMO5LOCATION_H diff --git a/Client/maemo5locationprivate.cpp b/Client/maemo5locationprivate.cpp new file mode 100755 index 0000000..d8b3b5d --- /dev/null +++ b/Client/maemo5locationprivate.cpp @@ -0,0 +1,277 @@ +/* + * Maemo5LocationPrivate + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#include "maemo5locationprivate.h" + +/** + *Default constructor of this class. + *@param Maemo5Location pointer to public interface. + */ +Maemo5LocationPrivate::Maemo5LocationPrivate(Maemo5Location* location):QObject(location) +{ + //Initialize variables + gps_online = false; + usegps = -1; + resetAll(); + //Get gps control object + control = location_gpsd_control_get_default(); + //create gps device + device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL); + + g_signal_connect(device, "changed", G_CALLBACK(gps_data_changed), this); + g_signal_connect(device, "connected", G_CALLBACK(gps_connected_func), this); + g_signal_connect(device, "disconnected", G_CALLBACK(gps_disconnected_func), this); + + g_signal_connect(control, "error-verbose", G_CALLBACK(gps_error_func), this); + g_signal_connect(control, "gpsd_running", G_CALLBACK(gpsd_running_func), this); + g_signal_connect(control, "gpsd_stopped", G_CALLBACK(gpsd_running_func), this); + +} +/** + *Destructor of this class. Should be used to release all allocated resources. + */ +Maemo5LocationPrivate::~Maemo5LocationPrivate() +{ + delete device; + delete control; +} + +/** + *This function is used to start to poll with gprs + */ +void Maemo5LocationPrivate::get_acwp() +{ + g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL); + usegps = 0; + restart(); +} + +/** + *This function starts to poll via gps interface + */ +void Maemo5LocationPrivate::get_agnss() +{ + g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL); + usegps = 1; + restart(); +} + +/** + *Stop polling gps + */ +void Maemo5LocationPrivate::stop() +{ + location_gpsd_control_stop(control); +} + +/** + *Stop and restart polling + */ +void Maemo5LocationPrivate::restart() +{ + location_gpsd_control_stop(control); + location_gpsd_control_start(control); +} + +/** + *This function is called when device managed to connect to the lcoation server. + *Function emits gps_connected signal. + *@param Pointer to LocationGPSDevice class + *@param Pointer to Maemo5LocationPrivate class + */ +void gps_connected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps) +{ + emit gps->gps_connected(); +} + +/** + *This function is called when device is disconnected from the location server. + *Function emits gps_disconnected signal. + *Also this function resets all arguments of Maemo5LcoationPrivate class. + *@param Pointer to LocationGPSDevice class + *@param Pointer to Maemo5LocationPrivate class + */ +void gps_disconnected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps) +{ + gps->resetAll(); + emit gps->gps_disconnected(); +} + +/** + *This function is called after the location_gpsd_control_stop has been called. + *@param Pointer to LocationGPSDControl class + *@param Pointer to Maemo5LocationPrivate class + */ +void gpsd_stopped_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps) +{ + emit gps->gpsd_stopped(); +} + +/** + *This function is called when an error has occurred. + *@param Pointer to LocationGPSDControl class + *@param error code + *@param Pointer to Maemo5LocationPrivate class + */ +void gps_error_func(LocationGPSDControl *control, gint error, Maemo5LocationPrivate *gps) +{ + + switch (error) { + case LOCATION_ERROR_USER_REJECTED_DIALOG: + emit gps->gps_error(0); + g_debug("User didn't enable requested methods"); + break; + case LOCATION_ERROR_USER_REJECTED_SETTINGS: + emit gps->gps_error(1); + g_debug("User changed settings, which disabled location"); + break; + case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE: + emit gps->gps_error(2); + g_debug("Problems with BT GPS"); + break; + case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE: + emit gps->gps_error(3); + g_debug("Requested method is not allowed in offline mode"); + break; + case LOCATION_ERROR_SYSTEM: + emit gps->gps_error(4); + g_debug("System error"); + break; + } +} + +/** + *This function is called after the location_gpsd_control_start has been called. + *@param Pointer to LocationGPSDControl class + *@param Pointer to Maemo5LocationPrivate class + */ +void gpsd_running_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps) +{ + emit gps->gpsd_running(); +} + +/** + *Callback function to catch gps signals. + *@param Pointer to LocationGPSDControl class + *@param Pointer to Maemo5LocationPrivate class + */ +void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps) +{ + //First check that LocationGpsDeviceFix can be found...this data structure contains the location info. + if(gps->device->fix) + { + //Check that there are fields + if(gps->device->fix->fields) + { + //Store values and emit signal + if(gps->device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) + { + gps->latitude = gps->device->fix->latitude; + gps->longitude = gps->device->fix->longitude; + gps->eph = gps->device->fix->eph; + } + + + gps->satellites_in_use = gps->device->satellites_in_use; + gps->satellites_in_view = gps->device->satellites_in_view; + + if(gps->device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) + { + gps->time = gps->device->fix->time; + gps->ept = gps->device->fix->ept; + } + + if(gps->device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) + { + gps->altitude = gps->device->fix->altitude; + gps->epv = gps->device->fix->epv; + } + + if(gps->device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) + { + gps->track = gps->device->fix->track; + gps->epd = gps->device->fix->epd; + } + + if(gps->device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) + { + gps->speed = gps->device->fix->speed; + gps->eps = gps->device->fix->eps; + } + + if(gps->device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) + { + gps->climb = gps->device->fix->climb; + gps->epc = gps->device->fix->epc; + } + + + // Calculate average signal strength of satellites in use + int temp = 0; + if(gps->satellites_in_use != 0) + { + for(int i=0 ; i < gps->satellites_in_use ; i++) + { + LocationGPSDeviceSatellite *view = (LocationGPSDeviceSatellite*) g_ptr_array_index (gps->device->satellites, i); + temp = temp + view->signal_strength; + } + gps->signal_strength = (temp / gps->satellites_in_use); + } + + + if(gps->usegps == 0) + { + emit gps->awcp(); + } + else if(gps->usegps == 1) + { + emit gps->agnss(); + } + else + { + emit gps->locationUpdated(); + } + } + } + +} + +/** + *Resets all arguments of Maemo5LocationPrivate class. + */ +void Maemo5LocationPrivate::resetAll() +{ + time = 0; + latitude = 0; + longitude = 0; + satellites_in_view = 0; + satellites_in_use = 0; + ept = 0; + eph = 0; + altitude = 0; + epv = 0; + track = 0; + epd = 0; + speed = 0; + eps = 0; + climb = 0; + epc = 0; +} + +/** + *Returns distance between two points in kilometers. + *@param latitude of first point + *@param longitude of first point + *@param latitude of second point + *@param longitude of second point + */ +double Maemo5LocationPrivate::distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f) +{ + double distance = 0; + return distance = location_distance_between(latitude_s, longitude_s, latitude_f, longitude_f); +} diff --git a/Client/maemo5locationprivate.h b/Client/maemo5locationprivate.h new file mode 100755 index 0000000..c61d041 --- /dev/null +++ b/Client/maemo5locationprivate.h @@ -0,0 +1,109 @@ +/* + * Maemo5LocationPrivate + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#ifndef MAEMO5LOCATIONPRIVATE_H +#define MAEMO5LOCATIONPRIVATE_H + +//We have to declare these header file inside extern, since these modules are actually c modules not c++ +extern "C" +{ +#include +#include +#include +} + +#include +#include "maemo5location.h" + +class Maemo5LocationPrivate : public QObject +{ + Q_OBJECT + +public: + Maemo5LocationPrivate(Maemo5Location* location); + ~Maemo5LocationPrivate(); + + void get_acwp(); + void get_agnss(); + + friend void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps); + friend void gps_connected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps); + friend void gps_disconnected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps); + friend void gps_error_func(LocationGPSDControl *control, gint error, Maemo5LocationPrivate *gps); + friend void gpsd_running_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps); + friend void gpsd_stopped_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps); + + static void handleStatus( LocationGPSDeviceStatus status ); + + int get_satellites_in_view() { return satellites_in_view; } + int get_satellites_in_use() { return satellites_in_use; } + int get_signal_strength() { return signal_strength; } + gboolean get_gps_online() { return gps_online; } + double get_lat() { return latitude; } + double get_lon() { return longitude; } + double get_time() { return time; } + double get_ept() { return ept; } + double get_eph() { return eph; } + double get_altitude() { return altitude; } + double get_epv() { return epv; } + double get_track() { return track; } + double get_epd() { return epd; } + double get_speed() { return speed; } + double get_eps() { return eps; } + double get_climb() { return climb; } + double get_epc() { return epc; } + double distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f); + void stop(); + +signals: + void awcp(); + void agnss(); + void locationUpdated(); + void gps_connected(); + void gps_disconnected(); + void gps_error(int); + void gpsd_running(); + void gpsd_stopped(); + +private: + void resetAll(); + //void stop(); + void restart(); + + int satellites_in_view; + int satellites_in_use; + int signal_strength; + gboolean gps_online; + double latitude; + double longitude; + double time; + double ept; + double eph; + double altitude; + double epv; + double track; + double epd; + double speed; + double eps; + double climb; + double epc; + + Maemo5Location* d_ptr; + int usegps; + LocationGPSDControl *control; + LocationGPSDevice *device; +}; + +void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps); +void gps_connected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps); +void gps_disconnected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps); +void gps_error_func(LocationGPSDControl *control, gint error, Maemo5LocationPrivate *gps); +void gpsd_running_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps); +void gpsd_stopped_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps); + +#endif // MAEMO5LOCATIONPRIVATE_H diff --git a/Client/mainwindow.cpp b/Client/mainwindow.cpp index 91ca8a4..6e5ea66 100644 --- a/Client/mainwindow.cpp +++ b/Client/mainwindow.cpp @@ -20,12 +20,23 @@ MainWindow::MainWindow(QWidget *parent) : creditsDialog = new CreditsDialog; routeSaveDialog = new RouteSaveDialog; + + //Button settings + ui->pushButtonAccelerate->setAutoFillBackground(true); + ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + ui->pushButtonRoute->setAutoFillBackground(true); + ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + ui->pushButtonResults->setAutoFillBackground(true); + ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + ui->pushButtonSettings->setAutoFillBackground(true); + ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + ui->pushButtonWWW->setAutoFillBackground(true); + ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); } MainWindow::~MainWindow() { delete ui; - delete routeSaveDialog; } diff --git a/Client/mainwindow.ui b/Client/mainwindow.ui index 0f5cbe2..5ad3ad8 100644 --- a/Client/mainwindow.ui +++ b/Client/mainwindow.ui @@ -28,7 +28,11 @@ - :/new/prefix1/Graphics/Speedometer .png:/new/prefix1/Graphics/Speedometer .png + :/new/prefix1/Graphics/Speedometer.png + :/new/prefix1/Graphics/Speedometer2.png + :/new/prefix1/Graphics/Speedometer2.png + :/new/prefix1/Graphics/Speedometer2.png + :/new/prefix1/Graphics/Speedometer2.png:/new/prefix1/Graphics/Speedometer.png @@ -70,7 +74,17 @@ - Results + + + + + :/new/prefix1/Graphics/trophy_gold.png:/new/prefix1/Graphics/trophy_gold.png + + + + 125 + 125 + @@ -83,7 +97,17 @@ - Settings + + + + + :/new/prefix1/Graphics/settings.png:/new/prefix1/Graphics/settings.png + + + + 125 + 125 + @@ -95,8 +119,21 @@ 130 + + true + - WWW + + + + + :/new/prefix1/Graphics/applications_internet.png:/new/prefix1/Graphics/applications_internet.png + + + + 125 + 125 + @@ -119,7 +156,7 @@ 0 0 800 - 25 + 27 diff --git a/Client/routesavedialog.cpp b/Client/routesavedialog.cpp index 9cbcb45..befe678 100644 --- a/Client/routesavedialog.cpp +++ b/Client/routesavedialog.cpp @@ -19,12 +19,42 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : { ui->setupUi(this); + routeDialog = new RouteDialog; + + //Button settings + buttonStatus = true; + pixmapRouteStop = new QPixmap("Graphics/route_stop.png"); + pixmapRoutePlay = new QPixmap("Graphics/route_play.png"); + iconRouteStop = new QIcon(*pixmapRouteStop); + iconRoutePlay = new QIcon(*pixmapRoutePlay); + QSize iconSize(125, 125); + ui->buttonRouteStartStop->setIconSize(iconSize); + ui->buttonRouteStartStop->setIcon(*iconRoutePlay); + ui->buttonRouteStartStop->setAutoFillBackground(true); + ui->buttonRouteStartStop->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + + //Satellite picture and label ui->labelRouteSatelliteStatus->setVisible(0); ui->labelRouteSatellitePicture->setVisible(0); - ui->labelRouteSatellitePicture->setPixmap(QPixmap("satellite_vista.png")); + //ui->labelRouteSatellitePicture->setPixmap(QPixmap("Graphics/satellite_vista.png")); timerSatellitePicture = new QTimer(); timerSatellitePicture->setInterval(400); connect(timerSatellitePicture, SIGNAL(timeout()),this, SLOT(timerSatellitePictureTimeout())); + + //Route picture and label + ui->labelRouteStatus->setVisible(0); + ui->labelRoutePicture->setVisible(0); + timerRoutePicture = new QTimer(); + timerRoutePicture->setInterval(400); + connect(timerRoutePicture, SIGNAL(timeout()),this, SLOT(timerRoutePictureTimeout())); + + //GPS speed label + ui->labelGpsSpeed->setVisible(0); + + //GPS + location = new Maemo5Location(this); + gpsData = new GPSData(location); + connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus())); } /** @@ -33,6 +63,15 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : RouteSaveDialog::~RouteSaveDialog() { delete ui; + delete timerSatellitePicture; + delete timerRoutePicture; + delete location; + delete gpsData; + delete routeDialog; + delete pixmapRouteStop; + delete pixmapRoutePlay; + delete iconRouteStop; + delete iconRoutePlay; } void RouteSaveDialog::changeEvent(QEvent *e) @@ -52,20 +91,37 @@ void RouteSaveDialog::changeEvent(QEvent *e) */ void RouteSaveDialog::on_buttonRouteStartStop_clicked() { - if ( ui->buttonRouteStartStop->text() == "Start" ) + //If start button clicked + if ( buttonStatus == true ) { - ui->buttonRouteStartStop->setText("Stop"); - ui->labelRouteSatelliteStatus->setText("Searching satellite"); - ui->labelRouteSatelliteStatus->setVisible(1); - ui->labelRouteSatellitePicture->setVisible(1); - timerSatellitePicture->start(); + buttonStatus = false; + ui->buttonRouteStartStop->setIcon(*iconRouteStop); + location->startPollingGPS(); + gpsStatus(); } else { - ui->buttonRouteStartStop->setText("Start"); + buttonStatus = true; + ui->buttonRouteStartStop->setIcon(*iconRoutePlay); + + //Satellite picture and label + ui->labelRouteSatelliteStatus->setText("Searching satellite"); ui->labelRouteSatelliteStatus->setVisible(0); ui->labelRouteSatellitePicture->setVisible(0); timerSatellitePicture->stop(); + + //Route picture and label + ui->labelRouteStatus->setVisible(0); + ui->labelRoutePicture->setVisible(0); + timerRoutePicture->stop(); + location->stopPollingGPS(); + routeDialog->show(); + + //GPS speed label + ui->labelGpsSpeed->setVisible(0); + + //Stop route recording + gpsData->stopRouteRecording(); } } @@ -87,3 +143,87 @@ void RouteSaveDialog::timerSatellitePictureTimeout() } timerSatellitePicture->start(); } + +/** + *This slot function is called when route picture timer timeout(400ms). + */ +void RouteSaveDialog::timerRoutePictureTimeout() +{ + //If route picture visible. + if (ui->labelRoutePicture->isVisible() == 1) + { + ui->labelRouteStatus->setVisible(0); + ui->labelRoutePicture->setVisible(0); + } + else + { + ui->labelRouteStatus->setVisible(1); + ui->labelRoutePicture->setVisible(1); + } + timerRoutePicture->start(); +} + +void RouteSaveDialog::gpsStatus() +{ + //IF GPS start button clicked + if (buttonStatus == false) + { + //If GPS find 4 satellite. + if (location->getSatellitesInUse() >= 4) + { + //Satellite picture and label + ui->labelRouteSatelliteStatus->setText("GPS Ready"); + ui->labelRouteSatelliteStatus->setVisible(1); + ui->labelRouteSatellitePicture->setVisible(1); + timerSatellitePicture->stop(); + + //Route picture and label + ui->labelRouteStatus->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point"); + ui->labelRouteStatus->setVisible(1); + ui->labelRoutePicture->setVisible(1); + timerRoutePicture->start(); + + //Set GPS speed. + gpsSpeed.sprintf("%.0f",location->getSpeed()); + ui->labelGpsSpeed->setText(gpsSpeed + " km/h"); + ui->labelGpsSpeed->setVisible(1); + + //Start route recording + gpsData->startRouteRecording(); + } + + //If GPS find less than 4 satellite. + else + { + //Satellite picture and label + ui->labelRouteSatelliteStatus->setText("Searching satellite"); + ui->labelRouteSatelliteStatus->setVisible(1); + ui->labelRouteSatellitePicture->setVisible(1); + timerSatellitePicture->start(); + + //Route picture and label + ui->labelRouteStatus->setVisible(0); + ui->labelRoutePicture->setVisible(0); + timerRoutePicture->stop(); + + //GPS speed label + ui->labelGpsSpeed->setVisible(0); + } + } + else + { + //Satellite picture and label + ui->labelRouteSatelliteStatus->setText("Searching satellite"); + ui->labelRouteSatelliteStatus->setVisible(0); + ui->labelRouteSatellitePicture->setVisible(0); + timerSatellitePicture->stop(); + + //Route picture and label + ui->labelRouteStatus->setVisible(0); + ui->labelRoutePicture->setVisible(0); + timerRoutePicture->stop(); + + //GPS speed label + ui->labelGpsSpeed->setVisible(0); + } +} diff --git a/Client/routesavedialog.h b/Client/routesavedialog.h index b4a38f1..5112c4b 100644 --- a/Client/routesavedialog.h +++ b/Client/routesavedialog.h @@ -11,7 +11,12 @@ #include #include +#include +#include #include +#include +#include "gpsdata.h" +#include "routedialog.h" namespace Ui { class RouteSaveDialog; @@ -29,10 +34,22 @@ protected: private: Ui::RouteSaveDialog *ui; QTimer *timerSatellitePicture; + QTimer *timerRoutePicture; + GPSData *gpsData; + Maemo5Location *location; + RouteDialog *routeDialog; + QString gpsSpeed; + QPixmap *pixmapRouteStop; + QPixmap *pixmapRoutePlay; + QIcon *iconRouteStop; + QIcon *iconRoutePlay; + bool buttonStatus; private slots: void on_buttonRouteStartStop_clicked(); void timerSatellitePictureTimeout(); + void timerRoutePictureTimeout(); + void gpsStatus(); }; #endif // ROUTESAVEDIALOG_H diff --git a/Client/routesavedialog.ui b/Client/routesavedialog.ui index d935540..f141299 100644 --- a/Client/routesavedialog.ui +++ b/Client/routesavedialog.ui @@ -7,11 +7,22 @@ 0 0 800 - 480 + 360 + + + Bitstream Charter + 75 + true + + - Dialog + Route + + + + :/new/prefix1/Graphics/route.png:/new/prefix1/Graphics/route.png @@ -23,20 +34,42 @@ - Start + + + + + :/new/prefix1/Graphics/route_play.png:/new/prefix1/Graphics/route_play.png + + + + 125 + 125 + + + + false - 190 - 150 - 100 - 100 + 200 + 60 + 80 + 80 + + true + - Satellite + + + + :/new/prefix1/Graphics/satellite_vista.png + + + true Qt::AlignCenter @@ -45,12 +78,17 @@ - 110 - 280 - 251 + 90 + 80 + 301 51 + + + 12 + + Satellite status @@ -58,7 +96,79 @@ Qt::AlignCenter + + + + 200 + 170 + 80 + 80 + + + + true + + + + + + :/new/prefix1/Graphics/route.png + + + true + + + Qt::AlignCenter + + + + + + 90 + 190 + 301 + 51 + + + + + 12 + + + + false + + + Route status + + + Qt::AlignCenter + + + + + + 540 + 40 + 241 + 91 + + + + + 36 + + + + GPS speed + + + Qt::AlignCenter + + - + + + diff --git a/Client/speedfreak.pro b/Client/speedfreak.pro index 3d53060..3b190f2 100644 --- a/Client/speedfreak.pro +++ b/Client/speedfreak.pro @@ -1,5 +1,8 @@ # ------------------------------------------------- # Project created by QtCreator 2010-03-29T09:21:42 +# @author Speed Freak team +# @copyright (c) 2010 Speed Freak team +# @license http://opensource.org/licenses/gpl-license.php GNU Public License # ------------------------------------------------- TARGET = speedfreak TEMPLATE = app @@ -7,13 +10,36 @@ SOURCES += main.cpp \ mainwindow.cpp \ creditsdialog.cpp \ routedialog.cpp \ - routesavedialog.cpp + routesavedialog.cpp \ + gpsdata.cpp \ + maemo5locationprivate.cpp \ + maemo5location.cpp HEADERS += mainwindow.h \ creditsdialog.h \ routedialog.h \ - routesavedialog.h + routesavedialog.h \ + gpsdata.h \ + maemo5locationprivate.h \ + maemo5location.h FORMS += mainwindow.ui \ creditsdialog.ui \ routedialog.ui \ routesavedialog.ui RESOURCES += graphics.qrc + +contains(QT_CONFIG, hildon):CONFIG += hildon +CONFIG += link_pkgconfig + +# Enable this to disable debugging +DEFINES += QT_NO_DEBUG_OUTPUT +target.path += /usr/lib +devincludes.files = $$HEADERS +devincludes.path += /usr/include/$$TEMPLATE$$TARGET +INSTALLS += target \ + devincludes +PKGCONFIG += glib-2.0 \ + liblocation +exists(/usr/lib/liblocation.so) { + DEFINES += LIBLOCATION + message(liblocation found) +}