diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-03-28 16:14:58 +0100 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-03-28 16:14:58 +0100 |
commit | a5573bbdae4a0ca4161418e6063762e5d5c74ab6 (patch) | |
tree | a95d3ce45b5807d83451f311c07688921734ec22 /metawatch | |
parent | f723ba995f698543fe019c8adac74439b90994f5 (diff) | |
download | sowatch-a5573bbdae4a0ca4161418e6063762e5d5c74ab6.tar.gz sowatch-a5573bbdae4a0ca4161418e6063762e5d5c74ab6.zip |
update battery message to gen2 version
Diffstat (limited to 'metawatch')
-rw-r--r-- | metawatch/metawatch.cpp | 31 | ||||
-rw-r--r-- | metawatch/metawatch.h | 5 |
2 files changed, 21 insertions, 15 deletions
diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index f05e362..3b30397 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -81,7 +81,7 @@ MetaWatch::MetaWatch(ConfigKey* settings, QObject* parent) : Watch(parent), _settings(settings->getSubkey(QString(), this)), _idleTimer(new QTimer(this)), _ringTimer(new QTimer(this)), - _watchTime(), _watchBattery(0), _watchBatteryAverage(0), _watchCharging(false), + _watchTime(), _watchBattery(0), _watchCharging(false), _currentMode(IdleMode), _paintMode(IdleMode), _paintEngine(0), _connectRetries(0), _connected(false), @@ -210,12 +210,7 @@ void MetaWatch::queryBatteryLevel() int MetaWatch::batteryLevel() const { - // TODO This "estimation" is quite awful, could be way more accurate. - int level = (_watchBatteryAverage - 3500) / (4100-3500); - if (level < 0) level = 0; - if (level > 100) level = 100; - - return level; + return _watchBattery; } void MetaWatch::queryCharging() @@ -730,16 +725,24 @@ void MetaWatch::handleBatteryVoltageMessage(const Message &msg) qWarning() << "Short battery voltage response:" << msg.data.size(); return; } - _watchCharging = msg.data[1]; - _watchBattery = ((msg.data[3] & 0xFF) << 8) | (msg.data[2] & 0xFF); - _watchBatteryAverage = ((msg.data[5] & 0xFF) << 8) | (msg.data[4] & 0xFF); + bool charging = msg.data[1]; + unsigned char level = msg.data[2]; - qDebug() << "got battery voltage" << _watchBattery << "mV " - << "average" << _watchBatteryAverage << "mV " + qDebug() << "got battery level" << level << "% " << (_watchCharging ? "charging" : "discharging"); - emit chargingChanged(); - emit batteryLevelChanged(); + // Just in case + if (level > 100) level = 100; + + // Emit changed() signals as necessary + if (charging != _watchCharging) { + _watchCharging = charging; + emit chargingChanged(); + } + if (level != _watchBattery) { + _watchBattery = level; + emit batteryLevelChanged(); + } } void MetaWatch::settingChanged(const QString &key) diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h index 5d7534a..f411a7e 100644 --- a/metawatch/metawatch.h +++ b/metawatch/metawatch.h @@ -167,10 +167,13 @@ protected: QStringList _buttonNames; // Current watch state + /** The watch's currently displayed date & time. */ QDateTime _watchTime; + /** The current watch battery level (from 0 to 100). */ short _watchBattery; - short _watchBatteryAverage; + /** Whether the watch is currently charging. */ bool _watchCharging; + /** The watch's current display mode. */ Mode _currentMode; /** The mode where paint operations done using QPaintDevice go into */ Mode _paintMode; |