summaryrefslogtreecommitdiff
path: root/metawatch
diff options
context:
space:
mode:
Diffstat (limited to 'metawatch')
-rw-r--r--metawatch/metawatch.cpp154
-rw-r--r--metawatch/metawatch.h36
2 files changed, 43 insertions, 147 deletions
diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp
index 3b30397..7c1fd8f 100644
--- a/metawatch/metawatch.cpp
+++ b/metawatch/metawatch.cpp
@@ -409,38 +409,24 @@ void MetaWatch::sendIfNotQueued(const Message& msg)
send(msg);
}
-uint MetaWatch::nvalSize(NvalValue value)
-{
- switch (value) {
- case ReservedNval:
- case LinkKey:
- return 0;
- case IdleBufferConfiguration:
- return 1;
- case TimeFormat:
- case DateFormat:
- case DisplaySeconds:
- return 1;
- }
- return 0;
-}
-
-void MetaWatch::nvalWrite(NvalValue value, int data)
+void MetaWatch::updateWatchProperties()
{
- uint id = static_cast<uint>(value);
- int size = nvalSize(value);
- Q_ASSERT(size > 0);
+ quint8 optBits = 0;
- // 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), 1);
+ if (_24hMode)
+ optBits |= 1 << 0;
+ if (_dayMonthOrder)
+ optBits |= 1 << 1;
+ if (_showSeconds)
+ optBits |= 1 << 2;
+ if (_separationLines)
+ optBits |= 1 << 3;
+ if (_autoBackligt)
+ optBits |= 1 << 4;
- msg.data[0] = id & 0xFF;
- msg.data[1] = id >> 8;
- msg.data[2] = size;
+ qDebug() << "Setting watch properties to" << optBits;
- _nvals[value] = data;
- send(msg);
+ send(Message(PropertyOperation, QByteArray(), optBits));
}
void MetaWatch::setVibrateMode(bool enable, uint on, uint off, uint cycles)
@@ -459,7 +445,7 @@ void MetaWatch::setVibrateMode(bool enable, uint on, uint off, uint cycles)
void MetaWatch::updateLcdLine(Mode mode, const QImage& image, int line)
{
- Message msg(WriteLcdBuffer, QByteArray(13, 0), (1 << 4) | (mode & 0xF));
+ Message msg(WriteLcdBuffer, QByteArray(13, 0), (1 << 4) | (mode & 0x3));
const char * scanLine = (const char *) image.constScanLine(line);
msg.data[0] = line;
@@ -470,7 +456,7 @@ void MetaWatch::updateLcdLine(Mode mode, const QImage& image, int line)
void MetaWatch::updateLcdLines(Mode mode, const QImage& image, int lineA, int lineB)
{
- Message msg(WriteLcdBuffer, QByteArray(26, 0), mode & 0xF);
+ Message msg(WriteLcdBuffer, QByteArray(26, 0), mode & 0x3);
const char * scanLine = (const char *) image.constScanLine(lineA);
msg.data[0] = lineA;
@@ -575,8 +561,8 @@ void MetaWatch::handleMessage(const Message &msg)
case GetRealTimeClockResponse:
handleRealTimeClockMessage(msg);
break;
- case NvalOperationResponse:
- handleNvalOperationMessage(msg);
+ case PropertyOperationResponse:
+ handlePropertyOperationMessage(msg);
break;
case StatusChangeEvent:
handleStatusChangeMessage(msg);
@@ -619,78 +605,21 @@ void MetaWatch::handleRealTimeClockMessage(const Message &msg)
emit dateTimeChanged();
}
-void MetaWatch::handleNvalOperationMessage(const Message& msg)
+void MetaWatch::handlePropertyOperationMessage(const Message& msg)
{
- Q_ASSERT(msg.type == NvalOperationResponse);
-
- // Nval operation response packet format is:
- // 2 bytes for id
- // Rest for contents
+ Q_ASSERT(msg.type == PropertyOperationResponse);
- if (msg.data.size() < 2) {
- qWarning() << "NVAL operation response too short";
- }
-
- uint id = ((msg.data[1] & 0xFF) << 8) | (msg.data[0] & 0xFF);
- NvalValue value = static_cast<NvalValue>(id);
-
- qDebug() << "nval operation response for value" << hex << value;
-
- switch (msg.options) {
- case 0: // Success
- {
- 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" << hex << value << "currently =" << dec << data
- << "is pending write to =" << new_data;
- if (new_data != data) {
- realNvalWrite(value, _nvals[value]);
- } else {
- qDebug() << " not rewriting it";
- }
- _nvals.remove(value);
- }
- }
- break;
- case 1: // Failure
- qWarning() << "NVAL operation failed";
- break;
- case 0x9:
- qWarning() << "NVAL operation failed: Identifier not found";
- break;
- case 0xA:
- qWarning() << "NVAL operation failed: Operation failed";
- break;
- case 0xC:
- qWarning() << "NVAL operation failed: Bad Item length";
- break;
- default:
- qWarning() << "NVAL operation unknown response: " << msg.options;
- break;
+ qDebug() << "got property operation result message";
+ if (msg.options != 0) {
+ qWarning() << "set property operation failed";
}
}
void MetaWatch::handleStatusChangeMessage(const Message &msg)
{
- Q_UNUSED(msg);
+ Q_ASSERT(msg.type == StatusChangeEvent);
+
+ // TODO: Maybe something could be done...
qDebug() << "got status change message";
}
@@ -756,12 +685,12 @@ void MetaWatch::settingChanged(const QString &key)
} else if (key == "day-month-order") {
_dayMonthOrder = _settings->value(key, false).toBool();
if (isConnected()) {
- nvalWrite(DateFormat, _dayMonthOrder ? 1 : 0);
+ updateWatchProperties();
}
} else if (key == "24h-mode") {
_24hMode = _settings->value(key, false).toBool();
if (isConnected()) {
- nvalWrite(TimeFormat, _24hMode ? 1 : 0);
+ updateWatchProperties();
}
}
}
@@ -796,8 +725,7 @@ void MetaWatch::socketConnected()
_paintMode = IdleMode;
// Configure the watch according to user preferences
- nvalWrite(TimeFormat, _24hMode ? 1 : 0);
- nvalWrite(DateFormat, _dayMonthOrder ? 1 : 0);
+ updateWatchProperties();
// Sync watch date & time
setDateTime(QDateTime::currentDateTime());
@@ -869,30 +797,6 @@ void MetaWatch::timedRing()
setVibrateMode(true, RingLength, RingLength, 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" << hex << value << "will be written with" << dec << 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 f411a7e..719ec94 100644
--- a/metawatch/metawatch.h
+++ b/metawatch/metawatch.h
@@ -49,8 +49,8 @@ public:
SetRealTimeClock = 0x26,
GetRealTimeClock = 0x27,
GetRealTimeClockResponse = 0x28,
- NvalOperation = 0x30,
- NvalOperationResponse = 0x31,
+ PropertyOperation = 0x30,
+ PropertyOperationResponse = 0x31,
StatusChangeEvent = 0x33,
ButtonEvent = 0x34,
GeneralPurposePhone = 0x35,
@@ -70,19 +70,11 @@ public:
ReadLightSensorResponse = 0x59
};
- enum NvalValue {
- ReservedNval = 0,
- LinkKey = 0x1,
- IdleBufferConfiguration = 0x2,
- TimeFormat = 0x2009,
- DateFormat = 0x200a,
- DisplaySeconds = 0x200b
- };
-
enum Mode {
IdleMode = 0,
ApplicationMode = 1,
- NotificationMode = 2
+ NotificationMode = 2,
+ MusicMode = 3 // Please note that the music mode is currently not used
};
enum Button {
@@ -157,6 +149,9 @@ protected:
short _notificationTimeout;
bool _24hMode : 1;
bool _dayMonthOrder : 1;
+ bool _showSeconds : 1;
+ bool _separationLines : 1;
+ bool _autoBackligt : 1;
// Notifications: timers
QTimer* _idleTimer;
@@ -202,20 +197,20 @@ protected:
QTimer* _sendTimer;
Message _partialReceived;
- /** Pending nvals to be written once the read operation is finished. */
- QMap<NvalValue, int> _nvals;
-
+ /** Used to calculate CRC */
static const quint8 bitRevTable[16];
static const quint16 crcTable[256];
static quint16 calcCrc(const QByteArray& data, int size);
static quint16 calcCrc(const Message& msg);
- /** Reprime the connection retry timers. */
+ /** Start the initial connection attempt, reset failed connection timers. */
void scheduleConnect();
+ /** Schedule an new connection attempt, consider the current one failed. */
void scheduleRetryConnect();
+ /** Cancel any pending connection attempts. */
void unscheduleConnect();
- /** Attempt a connection to the watch. */
+ /** Attempt a connection to the watch right now. */
virtual void connectToWatch();
/** Sends a message to the watch. Does not block. */
@@ -225,10 +220,8 @@ protected:
*/
void sendIfNotQueued(const Message& msg);
- static uint nvalSize(NvalValue value);
- void nvalWrite(NvalValue value, int data);
-
/* Some functions that wrap sending some watch messages. */
+ void updateWatchProperties();
void setVibrateMode(bool enable, uint on, uint off, uint cycles);
void updateLcdLine(Mode mode, const QImage& image, int line);
void updateLcdLines(Mode mode, const QImage& image, int lineA, int lineB);
@@ -242,7 +235,7 @@ protected:
void handleMessage(const Message& msg);
void handleDeviceTypeMessage(const Message& msg);
void handleRealTimeClockMessage(const Message& msg);
- void handleNvalOperationMessage(const Message& msg);
+ void handlePropertyOperationMessage(const Message& msg);
void handleStatusChangeMessage(const Message& msg);
void handleButtonEventMessage(const Message& msg);
void handleBatteryVoltageMessage(const Message& msg);
@@ -263,7 +256,6 @@ private slots:
void timedRing();
private:
- void realNvalWrite(NvalValue value, int data);
void realSend(const Message& msg);
void realReceive(bool block);
};