summaryrefslogtreecommitdiff
path: root/metawatch
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
parentcf5d24b94d96b722c6d76c2225293a56a50d3c2b (diff)
downloadsowatch-0822b88738e00625efd27ccca9119885272924d2.tar.gz
sowatch-0822b88738e00625efd27ccca9119885272924d2.zip
fixing bugs found during use ;)
Diffstat (limited to 'metawatch')
-rw-r--r--metawatch/metawatch.cpp100
-rw-r--r--metawatch/metawatchpaintengine.cpp15
-rw-r--r--metawatch/metawatchpaintengine.h3
3 files changed, 65 insertions, 53 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)
diff --git a/metawatch/metawatchpaintengine.cpp b/metawatch/metawatchpaintengine.cpp
index 58a7b9d..1b449ab 100644
--- a/metawatch/metawatchpaintengine.cpp
+++ b/metawatch/metawatchpaintengine.cpp
@@ -3,24 +3,25 @@
using namespace sowatch;
+const QRect MetaWatchPaintEngine::totalAreaRect(0, 0, MetaWatch::screenWidth, MetaWatch::screenHeight);
+
MetaWatchPaintEngine::MetaWatchPaintEngine(MetaWatch* watch) :
- WatchPaintEngine(watch), _watch(watch),
- _imageRect(0, 0, MetaWatch::screenWidth, MetaWatch::screenHeight)
+ WatchPaintEngine(),
+ _watch(watch)
{
}
bool MetaWatchPaintEngine::begin(QPaintDevice *pdev)
{
- _damaged = QRegion();
_watch = static_cast<MetaWatch*>(pdev);
_mode = _watch->paintTargetMode();
- return _painter.begin(_watch->imageFor(_mode));
+ return WatchPaintEngine::begin(_watch->imageFor(_mode));
}
bool MetaWatchPaintEngine::end()
{
- bool ret = _painter.end();
+ bool ret = WatchPaintEngine::end();
if (ret) {
_watch->update(_mode, _damaged.rects().toList());
}
@@ -94,7 +95,7 @@ void MetaWatchPaintEngine::updateState(const QPaintEngineState &state)
bool MetaWatchPaintEngine::fillsEntireImage(const QRect& rect)
{
- return rect == _imageRect &&
+ return rect == totalAreaRect &&
(!_clipEnabled ||
- (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == _imageRect));
+ (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == totalAreaRect));
}
diff --git a/metawatch/metawatchpaintengine.h b/metawatch/metawatchpaintengine.h
index c3b7466..98e85bb 100644
--- a/metawatch/metawatchpaintengine.h
+++ b/metawatch/metawatchpaintengine.h
@@ -25,9 +25,10 @@ public:
protected:
bool fillsEntireImage(const QRect& rect);
+ static const QRect totalAreaRect;
+
MetaWatch* _watch;
MetaWatch::Mode _mode;
- QRect _imageRect;
bool _isBrushBlack;
bool _isBrushWhite;
};