From a644a7cc6749f8dd5ca20589ee6e59acc2892b3e Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 27 Sep 2011 04:51:30 +0200 Subject: new qmafw watchlet --- metawatch/metawatch.cpp | 219 ++++++++++++++++++++++++-------------------- metawatch/metawatch.h | 17 ++-- metawatch/metawatchplugin.h | 2 +- 3 files changed, 130 insertions(+), 108 deletions(-) (limited to 'metawatch') diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index e1d9780..e9a8af1 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -9,9 +9,6 @@ QTM_USE_NAMESPACE #define SINGLE_LINE_UPDATE 0 -const char MetaWatch::watchToBtn[8] = { - 0, 1, 2, 3, -1, 4, 5, -1 -}; const char MetaWatch::btnToWatch[8] = { 0, 1, 2, 3, 5, 6, -1, -1 }; @@ -106,6 +103,9 @@ MetaWatch::MetaWatch(const QBluetoothAddress& address, QSettings* settings, QObj _24hMode = settings->value("24hMode", false).toBool(); _dayMonthOrder = settings->value("DayMonthOrder", false).toBool(); _notificationTimeout = settings->value("NotificationTimeout", 10).toInt(); + _invertedIdle = settings->value("InvertedIdleScreen", false).toBool(); + _invertedNotifications = settings->value("InvertedNotifications", false).toBool(); + _invertedApplications = settings->value("InvertedApplications", false).toBool(); } _idleTimer->setInterval(_notificationTimeout * 1000); @@ -215,6 +215,45 @@ void MetaWatch::setDateTime(const QDateTime &dateTime) send(msg); } +void MetaWatch::grabButton(int button) +{ + grabButton(_currentMode, (Button) button); +} + +void MetaWatch::ungrabButton(int button) +{ + ungrabButton(_currentMode, (Button) button); +} + +void MetaWatch::updateNotificationCount(Notification::Type type, int count) +{ + switch (type) { + case Notification::MissedCallNotification: + _nCalls = count; + break; + case Notification::EmailNotification: + _nMails = count; + break; + case Notification::ImNotification: + _nIms = count; + break; + case Notification::SmsNotification: + _nSms = count; + break; + case Notification::MmsNotification: + _nMms = count; + break; + default: + // Ignore + return; + break; + } + + if (isConnected()) { + renderIdleCounts(); + } +} + void MetaWatch::displayIdleScreen() { _currentMode = IdleMode; @@ -231,7 +270,7 @@ void MetaWatch::displayNotification(Notification *n) const bool shouldRing = n->type() == Notification::CallNotification; _currentMode = NotificationMode; _paintMode = NotificationMode; - configureWatchMode(NotificationMode, shouldRing ? 60 : 10); + configureWatchMode(NotificationMode, shouldRing ? 120 : 10, _invertedNotifications); QPainter p; QFont sf("MetaWatch Small caps 8pt"); @@ -314,47 +353,13 @@ void MetaWatch::displayApplication() _paintMode = ApplicationMode; _ringTimer->stop(); _idleTimer->stop(); - configureWatchMode(ApplicationMode, 250); + configureWatchMode(ApplicationMode, 250, _invertedApplications); qDebug() << "displayApplication"; } -void MetaWatch::grabButton(int button) -{ - grabButton(_currentMode, (Button) button); -} - -void MetaWatch::ungrabButton(int button) +void MetaWatch::vibrate(int msecs) { - ungrabButton(_currentMode, (Button) button); -} - -void MetaWatch::updateNotificationCount(Notification::Type type, int count) -{ - switch (type) { - case Notification::MissedCallNotification: - _nCalls = count; - break; - case Notification::EmailNotification: - _nMails = count; - break; - case Notification::ImNotification: - _nIms = count; - break; - case Notification::SmsNotification: - _nSms = count; - break; - case Notification::MmsNotification: - _nMms = count; - break; - default: - // Ignore - return; - break; - } - - if (isConnected()) { - renderIdleCounts(); - } + setVibrateMode(true, msecs, 0, 1); } MetaWatch::Mode MetaWatch::currentMode() const @@ -703,19 +708,15 @@ void MetaWatch::handleButtonEvent(const Message &msg) return; } - quint8 watchBtn = msg.options & 0xF; ButtonPress press = static_cast((msg.options & 0x30) >> 4); - int button = -1; + int button = msg.options & 0xF; - if (watchBtn < 8) { - button = watchToBtn[watchBtn]; - } - if (button == -1) { - qWarning() << "Unknown watch button" << watchBtn; + if (button >= 6) { + qWarning() << "Unknown watch button" << button; return; } - qDebug() << "button event" << button << press; + qDebug() << "button event" << button << " (" << press << ")"; if (press == PressOnly) { emit buttonPressed(button); @@ -736,9 +737,14 @@ void MetaWatch::socketConnected() _currentMode = IdleMode; _paintMode = IdleMode; + // Sync watch date & time setDateTime(QDateTime::currentDateTime()); + // Configure to show watch-rendered clock in idle screen configureIdleSystemArea(false); + // Follow inverted screen user preference + configureWatchMode(IdleMode, 0, _invertedIdle); + // Grab all buttons in both notification and application modes grabButton(ApplicationMode, BtnA); grabButton(ApplicationMode, BtnB); grabButton(ApplicationMode, BtnC); @@ -752,6 +758,7 @@ void MetaWatch::socketConnected() grabButton(NotificationMode, BtnE); grabButton(NotificationMode, BtnF); + // Render the idle screen from zero renderIdleScreen(); renderNotificationScreen(); @@ -789,58 +796,7 @@ void MetaWatch::socketDisconnected() void MetaWatch::socketData() { - do { - qint64 dataRead; - - qDebug() << "received" << _socket->bytesAvailable() << "bytes"; - - if (_partialReceived.type == 0) { - /* Still not received even the packet type */ - /* Receive the full header, 4 bytes. */ - if (_socket->bytesAvailable() < 4) return; /* Wait for more. */ - char header[4]; - - dataRead = _socket->read(header, 4); - if (dataRead < 4 || header[0] != 0x01) { - qWarning() << "TODO: Resync to start of frame"; - return; - } - - _partialReceived.type = static_cast(header[2]); - _partialReceived.data.resize(header[1] - 6); - _partialReceived.options = header[3]; - qDebug() << "got header"; - } - - /* We have the header; now, try to get the complete packet. */ - if (_socket->bytesAvailable() < _partialReceived.data.size() + 2) { - return; /* Wait for more. */ - } - dataRead = _socket->read(_partialReceived.data.data(), _partialReceived.data.size()); - if (dataRead < _partialReceived.data.size()) { - qWarning() << "Short read"; - return; - } - - char tail[2]; - dataRead = _socket->read(tail, 2); - if (dataRead < 2) { - qWarning() << "Short read"; - return; - } - - quint16 realCrc = calcCrc(_partialReceived); - quint16 expectedCrc = tail[1] << 8 | (tail[0] & 0xFFU); - if (realCrc == expectedCrc) { - handleMessage(_partialReceived); - } else { - qWarning() << "CRC error?"; - } - - // Prepare for the next packet - _partialReceived.data.clear(); - _partialReceived.type = NoMessage; - } while (_socket->bytesAvailable() > 0); + realReceive(false); } void MetaWatch::socketError(QBluetoothSocket::SocketError error) @@ -906,3 +862,64 @@ void MetaWatch::realSend(const Message &msg) _socket->write(data); } + +void MetaWatch::realReceive(bool block) +{ + do { + qint64 dataRead; + + qDebug() << "received" << _socket->bytesAvailable() << "bytes"; + + if (_partialReceived.type == 0) { + /* Still not received even the packet type */ + /* Receive the full header, 4 bytes. */ + if (_socket->bytesAvailable() < 4 && !block) { + /* Still not enough data available. */ + return; /* Wait for more, if non blocking. */ + } + char header[4]; + + dataRead = _socket->read(header, 4); + if (dataRead < 4 || header[0] != 0x01) { + qWarning() << "TODO: Resync to start of frame"; + return; + } + + _partialReceived.type = static_cast(header[2]); + _partialReceived.data.resize(header[1] - 6); + _partialReceived.options = header[3]; + qDebug() << "got header"; + } + + /* We have the header; now, try to get the complete packet. */ + if (_socket->bytesAvailable() < (_partialReceived.data.size() + 2) && + !block) { + return; /* Wait for more. */ + } + dataRead = _socket->read(_partialReceived.data.data(), _partialReceived.data.size()); + if (dataRead < _partialReceived.data.size()) { + qWarning() << "Short read"; + return; + } + + char tail[2]; + dataRead = _socket->read(tail, 2); + if (dataRead < 2) { + qWarning() << "Short read"; + return; + } + + quint16 realCrc = calcCrc(_partialReceived); + quint16 expectedCrc = tail[1] << 8 | (tail[0] & 0xFFU); + if (realCrc == expectedCrc) { + handleMessage(_partialReceived); + } else { + qWarning() << "CRC error?"; + } + + // Prepare for the next packet + _partialReceived.data.clear(); + _partialReceived.type = NoMessage; + } while (_socket->bytesAvailable() > 0 && !block); + // Loop until there are no more messages, or we are blocking and have received one. +} diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h index 0a9123a..9a25134 100644 --- a/metawatch/metawatch.h +++ b/metawatch/metawatch.h @@ -93,15 +93,17 @@ public: QDateTime dateTime(); void setDateTime(const QDateTime& dateTime); - void displayIdleScreen(); - void displayNotification(Notification *n); - void displayApplication(); - void grabButton(int button); void ungrabButton(int button); void updateNotificationCount(Notification::Type type, int count); + void displayIdleScreen(); + void displayNotification(Notification *notification); + void displayApplication(); + + void vibrate(int msecs); + Mode currentMode() const; Mode paintTargetMode() const; QImage* imageFor(Mode mode); @@ -121,6 +123,9 @@ protected: // Some configurable stuff. bool _24hMode : 1; bool _dayMonthOrder : 1; + bool _invertedIdle : 1; + bool _invertedNotifications : 1; + bool _invertedApplications : 1; short _notificationTimeout; // Notifications: Unread count @@ -131,7 +136,6 @@ protected: QTimer* _ringTimer; // Buttons - static const char watchToBtn[8]; static const char btnToWatch[8]; QStringList _buttonNames; @@ -181,7 +185,7 @@ protected: void updateLine(Mode mode, const QImage& image, int line); void updateLines(Mode mode, const QImage& image, int lineA, int lineB); void updateLines(Mode mode, const QImage& image, const QVector& lines); - void configureWatchMode(Mode mode, int timeout, bool invert = false); + void configureWatchMode(Mode mode, int timeout, bool invert); void configureIdleSystemArea(bool entireScreen); void updateDisplay(Mode mode, bool copy = true); void loadTemplate(Mode mode, int templ); @@ -203,6 +207,7 @@ protected slots: private: void realSend(const Message& msg); + void realReceive(bool block); }; } diff --git a/metawatch/metawatchplugin.h b/metawatch/metawatchplugin.h index 6834247..4ea0e5f 100644 --- a/metawatch/metawatchplugin.h +++ b/metawatch/metawatchplugin.h @@ -17,7 +17,7 @@ public: virtual QStringList drivers(); virtual Watch* getWatch(const QString& driver, QSettings& settings, QObject* parent = 0); -protected: +private: static bool fontsLoaded; }; -- cgit v1.2.3