From: eshe Date: Thu, 15 Jul 2010 09:34:30 +0000 (+0100) Subject: Added signal strength indicator to detail screen. Changed speed treshold to change... X-Git-Url: http://git.maemo.org/git/?p=jspeed;a=commitdiff_plain;h=ed8ba182b1ac6cf812ef59c73958d67dc192fcc9 Added signal strength indicator to detail screen. Changed speed treshold to change dynamically according to speed accuracy. --- diff --git a/src/detailscreen.cpp b/src/detailscreen.cpp index ba54052..660ba27 100644 --- a/src/detailscreen.cpp +++ b/src/detailscreen.cpp @@ -18,8 +18,11 @@ #include #include +#include +#include #include #include +#include #include "detailscreen.h" #include "odometer.h" #include "graphicsscene.h" @@ -29,7 +32,6 @@ namespace QString const FONT = "Tahoma"; QString const BACKGROUND = ":/resources/themes/default/background.png"; int const FONT_SIZE = 20; - int const PADDING_LEFT = 40; int const START_HEIGHT = 80; int const ITEM_WIDTH = 130; } @@ -71,6 +73,11 @@ DetailScreen::DetailScreen(QWidget* parent): GraphicsScreen(parent) line1_ = createLine(); line2_ = createLine(); + strength_ = new QGraphicsPixmapItem; + currentStrength_ = getStrength(); + strength_->setPixmap(QPixmap(":/resources/signal_" + QString::number(currentStrength_) + ".png")); + getScene()->addItem(strength_); + connect(&(Odometer::instance()), SIGNAL(timeUpdated()), this, SLOT(updateTime())); connect(&(Odometer::instance()), SIGNAL(unitChanged()), this, SLOT(updateUnits())); @@ -84,6 +91,14 @@ void DetailScreen::update() total_->setPlainText(roundDouble(Odometer::instance().getTotal())); avgSpeed_->setPlainText(roundDouble(Odometer::instance().getAverageSpeed())); maxSpeed_->setPlainText(roundDouble(Odometer::instance().getMaxSpeed())); + + int strength = getStrength(); + + if(strength != currentStrength_) + { + currentStrength_ = strength; + strength_->setPixmap(QPixmap(":/resources/signal_" + QString::number(strength) + ".png")); + } } void DetailScreen::updateTime() @@ -110,42 +125,48 @@ void DetailScreen::reArrange() { GraphicsScreen::reArrange(); - int lineHeight = getScene()->height() / 9; + int width = getScene()->width(); + int height = getScene()->height(); + + int lineHeight = height / 9; - int area1 = (getScene()->width() / 3) + ITEM_WIDTH / 2 + 20; + int padding = width / 22; + int area1 = (width / 3) + ITEM_WIDTH / 2 + 20; int area2 = area1 + ITEM_WIDTH; - tripLabel_->setPos(PADDING_LEFT, START_HEIGHT); + tripLabel_->setPos(padding, START_HEIGHT); trip_->setPos(area1, START_HEIGHT); tripUnit_->setPos(area2, START_HEIGHT); - totalLabel_->setPos(PADDING_LEFT, START_HEIGHT + lineHeight); + totalLabel_->setPos(padding, START_HEIGHT + lineHeight); total_->setPos(area1, START_HEIGHT + lineHeight); totalUnit_->setPos(area2, START_HEIGHT + lineHeight); - speedLabel_->setPos(PADDING_LEFT, START_HEIGHT + 2 * lineHeight); + speedLabel_->setPos(padding, START_HEIGHT + 2 * lineHeight); speed_->setPos(area1, START_HEIGHT + 2 * lineHeight); speedUnit_->setPos(area2, START_HEIGHT + 2 * lineHeight); - avgSpeedLabel_->setPos(PADDING_LEFT, START_HEIGHT + 3 * lineHeight); + avgSpeedLabel_->setPos(padding, START_HEIGHT + 3 * lineHeight); avgSpeed_->setPos(area1, START_HEIGHT + 3 * lineHeight); avgSpeedUnit_->setPos(area2, START_HEIGHT + 3 * lineHeight); - maxSpeedLabel_->setPos(PADDING_LEFT, START_HEIGHT + 4 * lineHeight); + maxSpeedLabel_->setPos(padding, START_HEIGHT + 4 * lineHeight); maxSpeed_->setPos(area1, START_HEIGHT + 4 * lineHeight); maxSpeedUnit_->setPos(area2, START_HEIGHT + 4 * lineHeight); - tripTimeLabel_->setPos(PADDING_LEFT, START_HEIGHT + 5 * lineHeight); + tripTimeLabel_->setPos(padding, START_HEIGHT + 5 * lineHeight); tripTime_->setPos(area1, START_HEIGHT + 5 * lineHeight); - totalTimeLabel_->setPos(PADDING_LEFT, START_HEIGHT + 6 * lineHeight); + totalTimeLabel_->setPos(padding, START_HEIGHT + 6 * lineHeight); totalTime_->setPos(area1, START_HEIGHT + 6 * lineHeight); int y1 = START_HEIGHT + 2 * lineHeight - lineHeight / 2 + FONT_SIZE + 2; int y2 = START_HEIGHT + 5 * lineHeight - lineHeight / 2 + FONT_SIZE + 2; - int x = getScene()->width() - PADDING_LEFT; - line1_->setLine(PADDING_LEFT + 2, y1, x, y1); - line2_->setLine(PADDING_LEFT + 2, y2, x, y2); + int x = width - padding; + line1_->setLine(padding + 2, y1, x, y1); + line2_->setLine(padding + 2, y2, x, y2); + + strength_->setPos(width - padding - 64, height - padding - 41); } QGraphicsTextItem* DetailScreen::createItem(QString const& text) @@ -189,3 +210,9 @@ QString DetailScreen::formatTime(qulonglong time) QString().sprintf(format, mins) + ":" + QString().sprintf(format, secs); } + +int DetailScreen::getStrength() +{ + double strength = round(Odometer::instance().getSignalStrength() / 25.0); + return static_cast(strength); +} diff --git a/src/detailscreen.h b/src/detailscreen.h index 75eee3f..5e94ff5 100644 --- a/src/detailscreen.h +++ b/src/detailscreen.h @@ -24,6 +24,7 @@ class QString; class QGraphicsTextItem; class QGraphicsLineItem; +class QGraphicsPixmapItem; class DetailScreen : public GraphicsScreen { @@ -45,6 +46,7 @@ private: QGraphicsTextItem* createItem(QString const& text); QGraphicsLineItem* createLine(); QString roundDouble(double number); + int getStrength(); QGraphicsTextItem* tripLabel_; QGraphicsTextItem* trip_; QGraphicsTextItem* tripUnit_; @@ -66,6 +68,8 @@ private: QGraphicsTextItem* totalTime_; QGraphicsLineItem* line1_; QGraphicsLineItem* line2_; + QGraphicsPixmapItem* strength_; + int currentStrength_; }; #endif diff --git a/src/graphicsscreen.cpp b/src/graphicsscreen.cpp index 322dae9..42c67f8 100644 --- a/src/graphicsscreen.cpp +++ b/src/graphicsscreen.cpp @@ -29,7 +29,7 @@ namespace } GraphicsScreen::GraphicsScreen(QWidget* parent): QGraphicsView(parent), -AbstractScreen(), scene_(0) +AbstractScreen(), scene_(0), isFlipped_(false) { QRect rect = QApplication::desktop()->availableGeometry(); @@ -71,18 +71,21 @@ void GraphicsScreen::reArrange() scene_->setSceneRect(rect); minimizeButton_->setPos(PADDING, PADDING); closeButton_->setPos(rect.width() - imageWidth_ - PADDING, PADDING); - settingsButton_->setPos((rect.width() / 2) - (imageWidth_ / 2) - (PADDING / 2), PADDING); + settingsButton_->setPos((rect.width() / 2) - (imageWidth_ / 2), PADDING); } void GraphicsScreen::flip() { - if(isTransformed()) + if(isFlipped_) { resetMatrix(); - return; + isFlipped_ = false; + } + else + { + setTransform(QTransform(1, 0, 0, 0, -1, 0, 0, 0, 1)); + isFlipped_ = true; } - - setTransform(QTransform(1, 0, 0, 0, -1, 0, 0, 0, 1)); } GraphicsScene* GraphicsScreen::getScene() const diff --git a/src/graphicsscreen.h b/src/graphicsscreen.h index afa7097..7bc8ed8 100644 --- a/src/graphicsscreen.h +++ b/src/graphicsscreen.h @@ -54,6 +54,7 @@ private: ToolbarItem* settingsButton_; ToolbarItem* closeButton_; int imageWidth_; + bool isFlipped_; }; #endif diff --git a/src/location.cpp b/src/location.cpp index f22c7c8..3b5ee32 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -73,6 +73,39 @@ 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()) + { + qDebug() << "No fix"; + return 0.0; + } + + if(device_->satellites_in_view == 0) + { + return 0.0; + } + + double val = (device_->satellites_in_use / static_cast(device_->satellites_in_view)) * 100.0; + + if(val > 100.0) + { + val = 100.0; + } + + return val; +} + void Location::setUnit(Location::Unit unit) { unit_ = unit; diff --git a/src/location.h b/src/location.h index 656be1c..a431cf8 100644 --- a/src/location.h +++ b/src/location.h @@ -61,6 +61,8 @@ public: ~Location(); void start(); void end(); + bool hasFix() const; + double getSignalStrength() const; static void setUnit(Unit unit); static Unit getUnit(); static double getUnitMultiplier(); diff --git a/src/odometer.cpp b/src/odometer.cpp index 041ee33..e4da0a9 100644 --- a/src/odometer.cpp +++ b/src/odometer.cpp @@ -33,8 +33,9 @@ namespace QString const MILE_UNIT = "mi"; QString const KM_SPEEDUNIT = "km/h"; QString const MILE_SPEEDUNIT = "mph"; - double const SPEED_TRESHOLD = 0.9; - double const SPEED_IGNORE_LEVEL = 0.2; + double const DEFAULT_SPEED_TRESHOLD = 8.0; + double const MIN_SPEED_TRESHOLD = 0.9; + double const SPEED_IGNORE_LEVEL = 0.01; } Odometer::Odometer(): QObject(0), trip_(0), total_(0), @@ -98,9 +99,21 @@ void Odometer::update(Location::Fix const& fix) fixTimer_->restart(); - if(elapsed > 200 && fix.kmSpeed > SPEED_IGNORE_LEVEL && elapsed < 10000) + if(fix.kmSpeed > SPEED_IGNORE_LEVEL) { - if(fix.kmSpeed > SPEED_TRESHOLD) + double treshold = DEFAULT_SPEED_TRESHOLD; + + if(fix.eps > 0.01) + { + treshold = fix.eps * 0.23822 + 0.471204; + + if(treshold < MIN_SPEED_TRESHOLD) + { + treshold = MIN_SPEED_TRESHOLD; + } + } + + if(fix.kmSpeed > treshold && elapsed > 200 && elapsed < 8000) { double km = fix.kmSpeed * (static_cast(elapsed) / (1000 * 3600)); trip_ += km; @@ -121,7 +134,7 @@ void Odometer::update(Location::Fix const& fix) } else { - if(latestFix_.kmSpeed > 0.49) + if(latestFix_.kmSpeed > SPEED_IGNORE_LEVEL) { latestFix_ = fix; latestFix_.speed = 0.0; @@ -222,6 +235,16 @@ Location::Fix const& Odometer::getLatestFix() const return latestFix_; } +double Odometer::getSignalStrength() const +{ + if(!location_) + { + return 0.0; + } + + return location_->getSignalStrength(); +} + QString const& Odometer::getUnit() { if(Location::getUnit() == Location::KM) diff --git a/src/odometer.h b/src/odometer.h index 93b91d8..0bbee30 100644 --- a/src/odometer.h +++ b/src/odometer.h @@ -41,6 +41,7 @@ public: qulonglong getTotalTime() const; qulonglong getTripTime() const; Location::Fix const& getLatestFix() const; + double getSignalStrength() const; static QString const& getUnit(); static QString const& getSpeedUnit(); diff --git a/src/resources.qrc b/src/resources.qrc index 72fcf5d..24f58d4 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -7,6 +7,11 @@ resources/close_active.png resources/settings_active.png resources/appicon.png + resources/signal_0.png + resources/signal_1.png + resources/signal_2.png + resources/signal_3.png + resources/signal_4.png resources/themes/default/theme.xml resources/themes/default/digital7.ttf resources/themes/default/background.png diff --git a/src/resources/signal_0.png b/src/resources/signal_0.png new file mode 100644 index 0000000..ec7c541 Binary files /dev/null and b/src/resources/signal_0.png differ diff --git a/src/resources/signal_1.png b/src/resources/signal_1.png new file mode 100644 index 0000000..5876020 Binary files /dev/null and b/src/resources/signal_1.png differ diff --git a/src/resources/signal_2.png b/src/resources/signal_2.png new file mode 100644 index 0000000..476a79d Binary files /dev/null and b/src/resources/signal_2.png differ diff --git a/src/resources/signal_3.png b/src/resources/signal_3.png new file mode 100644 index 0000000..02b7e75 Binary files /dev/null and b/src/resources/signal_3.png differ diff --git a/src/resources/signal_4.png b/src/resources/signal_4.png new file mode 100644 index 0000000..68f9a22 Binary files /dev/null and b/src/resources/signal_4.png differ