From ed8ba182b1ac6cf812ef59c73958d67dc192fcc9 Mon Sep 17 00:00:00 2001 From: eshe Date: Thu, 15 Jul 2010 10:34:30 +0100 Subject: [PATCH] Added signal strength indicator to detail screen. Changed speed treshold to change dynamically according to speed accuracy. --- src/detailscreen.cpp | 53 +++++++++++++++++++++++++++++++++----------- src/detailscreen.h | 4 ++++ src/graphicsscreen.cpp | 15 ++++++++----- src/graphicsscreen.h | 1 + src/location.cpp | 33 +++++++++++++++++++++++++++ src/location.h | 2 ++ src/odometer.cpp | 33 ++++++++++++++++++++++----- src/odometer.h | 1 + src/resources.qrc | 5 +++++ src/resources/signal_0.png | Bin 0 -> 655 bytes src/resources/signal_1.png | Bin 0 -> 913 bytes src/resources/signal_2.png | Bin 0 -> 1062 bytes src/resources/signal_3.png | Bin 0 -> 1066 bytes src/resources/signal_4.png | Bin 0 -> 927 bytes 14 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 src/resources/signal_0.png create mode 100644 src/resources/signal_1.png create mode 100644 src/resources/signal_2.png create mode 100644 src/resources/signal_3.png create mode 100644 src/resources/signal_4.png 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 0000000000000000000000000000000000000000..ec7c5418a94b2fb3ee1172f8af2712117f024094 GIT binary patch literal 655 zcmV;A0&x9_P)R4I}Zx>u)~l(1RZI>e&~nLIf5#gRI0GCAc2ah-C6 zj`8Dz9zpIT{QLr$gUm3F#~n!4o@^e6i`#y`|I}``rKY3FWWr7zkCL0r!TH8qpPK4g zbsURWMAI+~le-ttp`bcR=ca-f*Aai{qlj@G#L&HZ^dJ?)vRKZv5tng14sjjEP&Y8L zR6iR_`9V}-^e?EcgIFf0j!kYVRe`K?Q=xhs;#5>mCB{uro$}z=g+`pBb5m_OsX8~M zto~a$Gfh==ubzbl#-!t1}$Kop*2lC)aNvLG!8 zErMS73iVzPyt2LU5oBLL@Cm#Sda3pS+86M$g%sKfg81yaUwMzceBNN1v1}9bh7cY?@ zjXFMC4kfq=8=fiRl6^eai0dFXMSunQky{@R8a?-UYX)!713Di{O?tI0gITeJWH>nupO>Wg0Hp ze{<2VseVoM6t;yh_(Z1R*q%yM52mAjzc0Kk?DcwtXLyu}XI8mYDwRLiv)L@twh&Hb z8Nn&@THT*W(x{vZ#Ce9NIq{?mw>OAK4NeDxc${>U)W`i#8Lz!9Uzl8gyxeBEh-^bk zw7);*rfe25VX}$%<1gPPCvV@q4_&bvhJN(w*^?8vd=dN%B!V~&jQX;vE+vm!%ps<2 zgVLH78dXU_*ND1>Vm?h7W8u{c=*XbD^vcb&8Tq+1$nOnKAu)q;BHGT@IUl#TmTacM|!(urVcJZZD`ks&6!*lh)bn91~XSMPCqq;1rXXfKNL~or^H<%&fs-w7zfcFN72G2Ck zUpG;xE_32ZkH3b4ahR`7TlZ+WrUj-m1KKgT@p5?_A5U6xN<|!vLc`IgDbSjE1q?Ew zXz1>{KMVb zx5)FS4?~qbAAb{QK5sUgm$h2$bLe22yUu3;92UJcm#4! n@GI#@PJ7aSJ5%rfTYv!o4$2PQJX3-P00000NkvXXu0mjfpvI*( literal 0 HcmV?d00001 diff --git a/src/resources/signal_2.png b/src/resources/signal_2.png new file mode 100644 index 0000000000000000000000000000000000000000..476a79dbb762d9cf8ae6d96bdf33f6dd3178ccd3 GIT binary patch literal 1062 zcmV+>1ljwEP)ptbTH30#-6WIv zzDcsX#_Z#eeX?D&GS4~w_|&IyU_TVnHi?DlX09UX{G2VNxqP5 zodmQdCthht8ht`gs-+;jZf@&Wk={M{ZfkDcW8Oa+{u>?w;@L z>|}P;D7oRfcH|Z+QpE7INUM>3zH-%pZ7k{4wfj`k{8{o1GYx92a{ z-z0Wy7&?1!=Q@isJd5JvQn^hXSvK4Jy5}oL54UW|q(@59pDs8vb)oK^GEtzhD|uag zP`O%pt?m#ahsPG{kl`VMIvL$GbvDs3hZ<5x#Jk5)$7Y8l9ou1!lxh-F3R2i(LgOLg zBS~kKRc@9emBGhWXt=M4RKHr+-Qx_;N={>iI1IJPc#Dh<4fp3Dv?z`y`L!9x4e92;v+I09SV$oKqWJtNYR&s1VRhBmIljkA7IhBuPKw zw?2H{nt%3cJ#ob-MyH!VNEefMjJuj*`cOvU>ZRmyn^3VFM=7s5keed^ z@&PW^o7{JaJe6BkS1-MC13?{jC>>c2;ap8Wn^@THOG#lKZcxo( z35VKs#n|J3c&V=5Wn|B1WLL4Wk9c@**uy#3lxILOoD-p|T3wx^o%z>A5Fbh9=0A`r z)nI_fwcl8mb1e}$^btyWUpjCO0ZGO^qw*LxNHIeQMP@)8`4?SqjdD|`dpaNdsV(pL zGF&~+(KDQsL%y~gqg!KR61A7(02#7kSH?H^yIIJa?8o zyn7?Da}cA8k>*0s=E=H`C1TCMkq%IfeaZ8OrGYrGb$;uOiH6bprao_QPh-mT#H gqF+lhkN+jW04yyW8|cZrO8@`>07*qoM6N<$f^KR1M*si- literal 0 HcmV?d00001 diff --git a/src/resources/signal_3.png b/src/resources/signal_3.png new file mode 100644 index 0000000000000000000000000000000000000000..02b7e7571d9f5792d835bd56589e17f7ae4c343b GIT binary patch literal 1066 zcmV+_1l9YAP)Vyk0iY^E|b+wZ#@zaK~}-Kiz|a1JUdCx@CO6?SU35qh9h{_UzI9^&-Kw)}<3+Ok;!FNf@ypQcPiy^d|&ozAKq4_()AIbZ|QkB6fHZ z7~z$+i-f>RY1Uox&J1q&y|8cw(}uu@Cm~%!BPhZRNyDL1W&^^+$IW7~NTFCn&!XgBlT7^~(Rzh(z^oTU zuZtF?$*+|my9o$xoIB=sL>r?MzaJLd^3Fc01CCz3*?Ctw5YhSZgFCE9a0sOnlSSVs z&`JBT(Y*cNoXiag2>bT^R~Dp#kW4kUa3m=>dE}=l4pY0?x?CMTcz6srQkm&V61w9_ z*7d#i=ITcTMHY@C6O1s4r-U(A;qX-BQxSY_nOl&+(Q%LpZWp4=)yd4gbsC4DfT6%( zu@&6T5u3C#h$M?*&8F4H_3<JYva0rf65|yz5FmulptSMjF&THz0WvQu*a*&kbuunNhAR@Xiv+Af-rk+LQ*hXY+ zqO#R^`fSw8QAP0tUeKq2o>f=r+1cO;+WGlw&D<;|GV^LIAm+{hW^(S7nh?eaL#O9s z=z|a>N4;Yl{#tz;XIriiCYV9vz~A%)1nH)vXOf?N;5Tpnaoefj^m5>J5V={7jomS2 zCEZ7G8-?Yw{&qD~q|BS&?f3h4cXxL?r2$P!wzjtRfx4fZ#6%|jS~+ii kM8peKavh@I==>F60K<_8q^7ntgA6 zJ;kx(XgU%(NSr@y8rJ0HwQ zg|~0rd_mo3>vJf?;LA}giIiSsPI9D=(kI}^!{W_{;4T$L|WMTS~l#Wn|8RvQjyfZD_ zmX0h-*aQT(ER!KW)5bX0FO6S_7M}BQ7xHY}0Jdrw`<^xLMZbVwh!!Sw0@H;SCI!3; zEldV@S6Y}1@UFD*x?3!OU)3pdmrO~X??VeY?;7-J%$%o%ebD%W&tHEWt+S&|jePWQ zJ3Hz|3wvkksGzhlO|hVAc9cok`l7D1uvfqlpqL$@Rt6ugfx}-X<5Hy58sMI3VV#cX z8fs<9Bmvq4QRrJPz7pWoS~{|IRK^Ct%*!GdK1Gc)Gg?YXF%OTZ=FqvJadoBas5iiy zi0nf|b{v(1#^YSumsPMRSO%&!^eLb>>?)p}t)8G=@A?KfPfEd4c!AI4(s+15TZ_-+ zEQ|9o^dSh6ZSVNk>l@%W+bZ&$gBdiA{2Na|P;M%kQ`zOr( zt)y`Tx3*k9wDk>e3}PXCI_Fc5#VO~QSQX}4Yu|ybU%3Ns#-;>wSv}WoGqWMCSDTK9 zAe+8q?9+y_UQ&v>?6<2yu9tOgzU