summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-10-29 01:23:17 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-10-29 01:23:17 +0200
commitef80351e6fb029f3d22d62ef5a1873616884d882 (patch)
tree8a02989255fc79169de3b0fe3cbb14aa687071e8
parent00a8d95db62f5faada2bdb6798962aec8a2e1949 (diff)
downloadsowatch-ef80351e6fb029f3d22d62ef5a1873616884d882.tar.gz
sowatch-ef80351e6fb029f3d22d62ef5a1873616884d882.zip
completing nval support, but disabling for now
-rw-r--r--metawatch/metawatch.cpp71
-rw-r--r--metawatch/metawatch.h1
2 files changed, 65 insertions, 7 deletions
diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp
index b9adad1..e829c94 100644
--- a/metawatch/metawatch.cpp
+++ b/metawatch/metawatch.cpp
@@ -367,7 +367,7 @@ void MetaWatch::nvalWrite(NvalValue value, int data)
// Do a read operation first to get the current value
// If the current value matches what we want, avoid rewriting it to flash.
- Message msg(NvalOperation, QByteArray(3, 0), 2);
+ Message msg(NvalOperation, QByteArray(3, 0), 1);
msg.data[0] = id & 0xFF;
msg.data[1] = id >> 8;
@@ -566,22 +566,50 @@ void MetaWatch::handleNvalOperationMessage(const Message& msg)
switch (msg.options) {
case 0: // Success
- break;
+ {
+ int got_size = msg.data.size() - 2;
+ int size = nvalSize(value);
+ if (got_size != size) {
+ qWarning() << "Unexpected NVAL size" << got_size;
+ return;
+ }
+ // Read it
+ int data;
+ switch (size) {
+ case 1:
+ data = msg.data[2];
+ break;
+ default:
+ qWarning() << "Yet to implement this nval size";
+ return;
+ }
+
+ // Check if there's a pending write for this nval.
+ if (_nvals.contains(value)) {
+ int new_data = _nvals[value];
+ qDebug() << "nval" << value << "currently =" << data << "is pending write to =" << new_data;
+ if (new_data != data) {
+ realNvalWrite(value, _nvals[value]);
+ }
+ _nvals.remove(value);
+ }
+ }
+ break;
case 1: // Failure
qWarning() << "NVAL operation failed";
- return;
+ break;
case 0x9:
qWarning() << "NVAL operation failed: Identifier not found";
- return;
+ break;
case 0xA:
qWarning() << "NVAL operation failed: Operation failed";
- return;
+ break;
case 0xC:
qWarning() << "NVAL operation failed: Bad Item length";
- return;
+ break;
default:
qWarning() << "NVAL operation unknown response: " << msg.options;
- return;
+ break;
}
}
@@ -646,6 +674,11 @@ void MetaWatch::socketConnected()
_currentMode = IdleMode;
_paintMode = IdleMode;
+#if FIRMWARE_NOT_BUGGY
+ // Configure the watch according to user preferences
+ //nvalWrite(TimeFormat, _24hMode ? 1 : 0);
+#endif
+
// Sync watch date & time
setDateTime(QDateTime::currentDateTime());
@@ -743,6 +776,30 @@ void MetaWatch::timedRing()
setVibrateMode(true, 250, 250, 3);
}
+void MetaWatch::realNvalWrite(NvalValue value, int data)
+{
+ int size = nvalSize(value);
+ uint id = static_cast<uint>(value);
+ Message msg(NvalOperation, QByteArray(3 + size, 0), 2);
+
+ qDebug() << "nval" << value << "will be written with" << data;
+
+ msg.data[0] = id & 0xFF;
+ msg.data[1] = id >> 8;
+ msg.data[2] = size;
+
+ switch (size) {
+ case 1:
+ msg.data[3] = data & 0xFF;
+ break;
+ default:
+ qWarning() << "NVAL size not yet handled";
+ return;
+ }
+
+ send(msg);
+}
+
void MetaWatch::realSend(const Message &msg)
{
const int msgSize = msg.data.size();
diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h
index d468bc1..7ea835f 100644
--- a/metawatch/metawatch.h
+++ b/metawatch/metawatch.h
@@ -238,6 +238,7 @@ private slots:
void timedRing();
private:
+ void realNvalWrite(NvalValue value, int data);
void realSend(const Message& msg);
void realReceive(bool block);
};