summaryrefslogtreecommitdiff
path: root/metawatch.h
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-16 17:47:24 +0200
committerJavier <javier@pcjavier.(none)>2011-09-16 17:47:24 +0200
commitaa1c0fd3146b4ed055d181c99d52463afa6bedbb (patch)
treef6fb8d9693ad8c545ddabf76312f8f33b5b9878f /metawatch.h
downloadsowatch-aa1c0fd3146b4ed055d181c99d52463afa6bedbb.tar.gz
sowatch-aa1c0fd3146b4ed055d181c99d52463afa6bedbb.zip
Initial import
Diffstat (limited to 'metawatch.h')
-rw-r--r--metawatch.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/metawatch.h b/metawatch.h
new file mode 100644
index 0000000..2ec56f9
--- /dev/null
+++ b/metawatch.h
@@ -0,0 +1,117 @@
+#ifndef METAWATCH_H
+#define METAWATCH_H
+
+#include <QtConnectivity/QBluetoothAddress>
+#include <QtConnectivity/QBluetoothSocket>
+#include <QtCore/QQueue>
+#include <QtCore/QTimer>
+#include "watch.h"
+
+using QTM_PREPEND_NAMESPACE(QBluetoothSocket);
+using QTM_PREPEND_NAMESPACE(QBluetoothAddress);
+
+namespace sowatch
+{
+
+class MetaWatch : public Watch
+{
+ Q_OBJECT
+ Q_ENUMS(MessageType)
+
+public:
+ explicit MetaWatch(const QBluetoothAddress& address, QObject *parent = 0);
+
+ QPaintEngine* paintEngine() const;
+
+ QString model() const;
+ bool isConnected() const;
+ bool busy() const;
+ void update(const QList<QRect>& rects);
+ void clear(bool white = false);
+ void vibrate(bool on);
+
+ void setDateTime(const QDateTime& dateTime);
+
+ enum MessageType {
+ NoMessage = 0,
+ GetDeviceType = 0x01,
+ GetDeviceTypeResponse = 0x02,
+ GetInformationString = 0x03,
+ GetInformationStringResponse = 0x04,
+ AdvanceWatchHands = 0x20,
+ SetVibrateMode = 0x23,
+ SetRealTimeClock = 0x26,
+ GetRealTimeClock = 0x27,
+ GetRealTimeClockResponse = 0x28,
+ StatusChangeEvent = 0x33,
+ ButtonEvent = 0x34,
+ WriteBuffer = 0x40,
+ ConfigureMode = 0x41,
+ ConfigureIdleBufferSize = 0x42,
+ UpdateDisplay = 0x43,
+ LoadTemplate = 0x44,
+ EnableButton = 0x46,
+ DisableButton = 0x47,
+ ReadButtonConfiguration = 0x48,
+ ReadButtonConfigurationResponse = 0x49,
+ BatteryConfiguration = 0x53,
+ LowBatteryWarning = 0x54,
+ LowBatteryBluetoothOff = 0x55,
+ ReadBatteryVoltage = 0x56,
+ ReadBatteryVoltageResponse = 0x57,
+ Accelerometer = 0xea
+ };
+
+protected:
+ QBluetoothSocket* _socket;
+
+ struct Message {
+ MessageType type;
+ quint8 options;
+ QByteArray data;
+ Message(MessageType ntype = NoMessage, QByteArray ndata = QByteArray(), quint8 noptions = 0) :
+ type(ntype), options(noptions), data(ndata)
+ {
+
+ }
+ };
+
+ QQueue<Message> _toSend;
+ QTimer* _sendTimer;
+ Message _partialReceived;
+
+ quint8 _buttonState;
+
+ static const quint8 bitRevTable[16];
+ static const quint16 crcTable[256];
+ quint16 calcCrc(const QByteArray& data, int size);
+ quint16 calcCrc(const Message& msg);
+
+ void send(const Message& msg);
+ void handleMessage(const Message& msg);
+
+ void updateLine(int mode, const QImage& image, int line);
+ void updateLines(int mode, const QImage& image, int lineA, int lineB);
+ void updateLines(int mode, const QImage& image, const QVector<bool>& lines);
+ void configureWatchMode(int mode, int timeout = 10, bool invert = false);
+ void updateDisplay(int mode, bool copy = true);
+ void loadTemplate(int mode, int templ);
+
+ void handleStatusChange(const Message& msg);
+ void handleButtonEvent(const Message& msg);
+
+protected slots:
+ void socketConnected();
+ void socketDisconnected();
+ void socketData();
+ void socketError(QBluetoothSocket::SocketError error);
+ void socketState(QBluetoothSocket::SocketState error);
+ void timedSend();
+
+private:
+ void realSend(const Message& msg);
+};
+
+}
+
+#endif // METAWATCH_H