summaryrefslogtreecommitdiff
path: root/metawatch/metawatch.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-26 02:36:09 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-09-26 02:36:09 +0200
commit0822b88738e00625efd27ccca9119885272924d2 (patch)
treef379817602cc23dd829c0aa4751b6b5edc348923 /metawatch/metawatch.cpp
parentcf5d24b94d96b722c6d76c2225293a56a50d3c2b (diff)
downloadsowatch-0822b88738e00625efd27ccca9119885272924d2.tar.gz
sowatch-0822b88738e00625efd27ccca9119885272924d2.zip
fixing bugs found during use ;)
Diffstat (limited to 'metawatch/metawatch.cpp')
-rw-r--r--metawatch/metawatch.cpp100
1 files changed, 55 insertions, 45 deletions
diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp
index 1ad7159..e1d9780 100644
--- a/metawatch/metawatch.cpp
+++ b/metawatch/metawatch.cpp
@@ -238,6 +238,11 @@ void MetaWatch::displayNotification(Notification *n)
QFont lf("MetaWatch Large 16pt");
QFont mf("MetaWatch Large 16pt");
QImage icon = iconForNotification(n);
+
+ sf.setPixelSize(8);
+ mf.setPixelSize(14);
+ lf.setPixelSize(16);
+
const int iconW = icon.width(), iconH = icon.height();
const int margin = 4;
const int x = margin;
@@ -247,10 +252,6 @@ void MetaWatch::displayNotification(Notification *n)
int textFlags;
QString text;
- sf.setPixelSize(8);
- mf.setPixelSize(16);
- lf.setPixelSize(18);
-
qDebug() << "displayNotification" << n->title() << n->body();
p.begin(this);
@@ -267,7 +268,7 @@ void MetaWatch::displayNotification(Notification *n)
p.drawText(dateRect, textFlags, text);
p.setFont(lf);
- textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere;
+ textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap;
text = n->title();
QRect titleMaxRect(x, titleY, screenWidth - x*2, screenHeight - titleY);
@@ -607,6 +608,8 @@ void MetaWatch::updateLines(Mode mode, const QImage& image, const QVector<bool>&
if (lineCount == 0) return;
+ qDebug() << "sending" << lineCount << "rows to watch";
+
for (int line = 0; line < lines.size(); line++) {
if (lines[line]) {
lineCount--;
@@ -690,6 +693,7 @@ void MetaWatch::disableButton(Mode mode, Button button, ButtonPress press)
void MetaWatch::handleStatusChange(const Message &msg)
{
Q_UNUSED(msg);
+ qDebug() << "got status change message";
}
void MetaWatch::handleButtonEvent(const Message &msg)
@@ -700,7 +704,7 @@ void MetaWatch::handleButtonEvent(const Message &msg)
}
quint8 watchBtn = msg.options & 0xF;
- ButtonPress press = (ButtonPress) ((msg.options & 0x30) >> 4);
+ ButtonPress press = static_cast<ButtonPress>((msg.options & 0x30) >> 4);
int button = -1;
if (watchBtn < 8) {
@@ -785,52 +789,58 @@ void MetaWatch::socketDisconnected()
void MetaWatch::socketData()
{
- qint64 dataRead;
+ do {
+ qint64 dataRead;
- 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];
+ qDebug() << "received" << _socket->bytesAvailable() << "bytes";
- dataRead = _socket->read(header, 4);
- if (dataRead < 4 || header[0] != 0x01) {
- qWarning() << "TODO: Resync / Handle Garbage";
- return;
- }
+ 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];
- _partialReceived.type = static_cast<MessageType>(header[2]);
- _partialReceived.data.resize(header[1] - 6);
- _partialReceived.options = header[3];
- }
+ dataRead = _socket->read(header, 4);
+ if (dataRead < 4 || header[0] != 0x01) {
+ qWarning() << "TODO: Resync to start of frame";
+ return;
+ }
- /* Got 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;
- }
+ _partialReceived.type = static_cast<MessageType>(header[2]);
+ _partialReceived.data.resize(header[1] - 6);
+ _partialReceived.options = header[3];
+ qDebug() << "got header";
+ }
- char tail[2];
- dataRead = _socket->read(tail, 2);
- if (dataRead < 2) {
- qWarning() << "Short read";
- return;
- }
+ /* 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;
+ }
- quint16 realCrc = calcCrc(_partialReceived);
- quint16 expectedCrc = tail[1] << 8 | (tail[0] & 0xFFU);
- if (realCrc == expectedCrc) {
- handleMessage(_partialReceived);
- } else {
- qWarning() << "CRC error?";
- }
+ char tail[2];
+ dataRead = _socket->read(tail, 2);
+ if (dataRead < 2) {
+ qWarning() << "Short read";
+ return;
+ }
- _partialReceived.data.clear();
- _partialReceived.type = NoMessage;
+ 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);
}
void MetaWatch::socketError(QBluetoothSocket::SocketError error)