From ccd19d2b7ee4184503ea46b98333b27a5613190e Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Wed, 8 May 2013 18:04:31 +0200 Subject: big change: a new abstract BluetoothWatch class --- metawatch/metawatch.h | 47 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) (limited to 'metawatch/metawatch.h') diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h index a9cf58b..d671635 100644 --- a/metawatch/metawatch.h +++ b/metawatch/metawatch.h @@ -3,12 +3,12 @@ #include #include -#include #include #include #include #include #include +#include namespace sowatch { @@ -20,7 +20,7 @@ using QTM_PREPEND_NAMESPACE(QBluetoothLocalDevice); class MetaWatchPaintEngine; -class MetaWatch : public Watch +class MetaWatch : public BluetoothWatch { Q_OBJECT @@ -99,7 +99,7 @@ public: QString model() const; QStringList buttons() const; - bool isConnected() const; + bool busy() const; void setDateTime(const QDateTime& dateTime); @@ -177,40 +177,22 @@ protected: /** The framebuffers for each of the watch modes */ QImage _image[3]; - // Timers to retry the connection when the watch is not found. - static const int connectRetryTimesSize = 6; - static const int connectRetryTimes[connectRetryTimesSize]; - short _connectRetries; - bool _connected; - QTimer* _connectTimer; - QSystemAlignedTimer* _connectAlignedTimer; - - // Connection stuff - QBluetoothLocalDevice* _localDev; - QBluetoothAddress _address; - QBluetoothSocket* _socket; - /** The "packets to be sent" asynchronous queue **/ QQueue _toSend; QTimer* _sendTimer; Message _partialReceived; - /** Used to calculate CRC */ + // Watch connect/disconnect handling + void setupBluetoothWatch(); + void desetupBluetoothWatch(); + + // Message passing + /** Used to calculate CRC fields in message header */ static const quint8 bitRevTable[16]; static const quint16 crcTable[256]; static quint16 calcCrc(const QByteArray& data, int size); static quint16 calcCrc(const Message& msg); - /** 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 right now. */ - virtual void connectToWatch(); - /** Sends a message to the watch. Does not block. */ virtual void send(const Message& msg); /** Sends a message to the watch if a message of the same type is not @@ -239,18 +221,9 @@ protected: void handleButtonEventMessage(const Message& msg); void handleBatteryVoltageMessage(const Message& msg); - /** To be overriden; should configure a newly connected watch. */ - virtual void handleWatchConnected() = 0; - private slots: void settingChanged(const QString& key); - void localDevModeChanged(QBluetoothLocalDevice::HostMode state); - void socketConnected(); - void socketDisconnected(); - void socketData(); - void socketError(QBluetoothSocket::SocketError error); - void socketState(QBluetoothSocket::SocketState error); - void timedReconnect(); + void dataReceived(); void timedSend(); void timedRing(); -- cgit v1.2.3