summaryrefslogtreecommitdiff
path: root/metawatch
diff options
context:
space:
mode:
Diffstat (limited to 'metawatch')
-rw-r--r--metawatch/metawatch.cpp39
-rw-r--r--metawatch/metawatch.h7
-rw-r--r--metawatch/metawatch.pro43
-rw-r--r--metawatch/metawatchanalog.cpp4
-rw-r--r--metawatch/metawatchanalog.h2
-rw-r--r--metawatch/metawatchdigital.cpp4
-rw-r--r--metawatch/metawatchdigital.h2
-rw-r--r--metawatch/metawatchplugin.cpp14
-rw-r--r--metawatch/metawatchplugin.h3
-rw-r--r--metawatch/metawatchscanner.cpp48
-rw-r--r--metawatch/metawatchscanner.h30
11 files changed, 146 insertions, 50 deletions
diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp
index a9718ec..fe080e4 100644
--- a/metawatch/metawatch.cpp
+++ b/metawatch/metawatch.cpp
@@ -78,8 +78,9 @@ const quint16 MetaWatch::crcTable[256] = {
}
#endif
-MetaWatch::MetaWatch(const QBluetoothAddress& address, QSettings* settings, QObject* parent) :
- Watch(parent),
+MetaWatch::MetaWatch(ConfigKey* settings, QObject* parent) :
+ Watch(parent),
+ _settings(settings->getSubkey(QString(), this)),
_idleTimer(new QTimer(this)), _ringTimer(new QTimer(this)),
_watchTime(), _watchBattery(0), _watchBatteryAverage(0), _watchCharging(false),
_currentMode(IdleMode), _paintMode(IdleMode),
@@ -87,14 +88,15 @@ MetaWatch::MetaWatch(const QBluetoothAddress& address, QSettings* settings, QObj
_connectRetries(0), _connected(false),
_connectTimer(new QTimer(this)),
_connectAlignedTimer(new QSystemAlignedTimer(this)),
- _address(address), _socket(0),
+ _socket(0),
_sendTimer(new QTimer(this))
{
- if (settings) {
- _notificationTimeout = settings->value("NotificationTimeout", 15).toInt();
- _24hMode = settings->value("24hMode", false).toBool();
- _dayMonthOrder = settings->value("DayMonthOrder", false).toBool();
- }
+ connect(_settings, SIGNAL(subkeyChanged(QString)), SLOT(settingChanged(QString)));
+
+ _address = QBluetoothAddress(settings->value("address").toString());
+ _notificationTimeout = settings->value("notification-timeout", 15).toInt();
+ _24hMode = settings->value("24h-mode", false).toBool();
+ _dayMonthOrder = settings->value("day-month-order", false).toBool();
_buttonNames << "A" << "B" << "C" << "D" << "E" << "F";
@@ -656,6 +658,27 @@ void MetaWatch::handleBatteryVoltageMessage(const Message &msg)
emit batteryLevelChanged();
}
+void MetaWatch::settingChanged(const QString &key)
+{
+ qDebug() << "Metawatch setting changed:" << key;
+
+ if (key == "address") {
+ _address = QBluetoothAddress(_settings->value(key).toString());
+ } else if (key == "notification-timeout") {
+ _notificationTimeout = _settings->value(key, 15).toInt();
+ } else if (key == "day-month-order") {
+ _dayMonthOrder = _settings->value(key, false).toBool();
+ if (isConnected()) {
+ nvalWrite(DateFormat, _dayMonthOrder ? 1 : 0);
+ }
+ } else if (key == "24h-mode") {
+ _24hMode = _settings->value(key, false).toBool();
+ if (isConnected()) {
+ nvalWrite(TimeFormat, _24hMode ? 1 : 0);
+ }
+ }
+}
+
void MetaWatch::socketConnected()
{
if (!_connected) {
diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h
index 5a42b8d..760752b 100644
--- a/metawatch/metawatch.h
+++ b/metawatch/metawatch.h
@@ -7,7 +7,7 @@
#include <QtConnectivity/QBluetoothAddress>
#include <QtConnectivity/QBluetoothSocket>
#include <QtSystemInfo/QSystemAlignedTimer>
-#include "watch.h"
+#include <sowatch.h>
using QTM_PREPEND_NAMESPACE(QBluetoothSocket);
using QTM_PREPEND_NAMESPACE(QBluetoothAddress);
@@ -23,7 +23,7 @@ class MetaWatch : public Watch
Q_OBJECT
public:
- explicit MetaWatch(const QBluetoothAddress& address, QSettings* settings = 0, QObject *parent = 0);
+ explicit MetaWatch(ConfigKey *settings, QObject *parent = 0);
~MetaWatch();
static const int DelayBetweenMessages = 10;
@@ -134,6 +134,8 @@ public:
void ungrabButton(Mode mode, Button button);
protected:
+ ConfigKey *_settings;
+
// Some configurable stuff.
short _notificationTimeout;
bool _24hMode : 1;
@@ -229,6 +231,7 @@ protected:
virtual void handleWatchConnected() = 0;
private slots:
+ void settingChanged(const QString& key);
void socketConnected();
void socketDisconnected();
void socketData();
diff --git a/metawatch/metawatch.pro b/metawatch/metawatch.pro
index 9e99da1..9331665 100644
--- a/metawatch/metawatch.pro
+++ b/metawatch/metawatch.pro
@@ -17,7 +17,8 @@ SOURCES += metawatchplugin.cpp \
metawatchpaintengine.cpp \
metawatch.cpp \
metawatchdigital.cpp \
- metawatchanalog.cpp
+ metawatchanalog.cpp \
+ metawatchscanner.cpp
HEADERS += metawatchplugin.h \
metawatchsimulatorform.h \
@@ -25,7 +26,8 @@ HEADERS += metawatchplugin.h \
metawatchpaintengine.h \
metawatch.h \
metawatchdigital.h \
- metawatchanalog.h
+ metawatchanalog.h \
+ metawatchscanner.h
FORMS += \
metawatchsimulatorform.ui
@@ -33,34 +35,19 @@ FORMS += \
res_files.files += res/graphics res/fonts
qml_files.files += qml/com
-win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/release/ -lsowatch
-else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/debug/ -lsowatch
-else:symbian: LIBS += -lsowatch
-else:unix: LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch
+LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch
INCLUDEPATH += $$PWD/../libsowatch
DEPENDPATH += $$PWD/../libsowatch
-symbian {
- MMP_RULES += EXPORTUNFROZEN
- TARGET.UID3 = 0xE4DC26B0
- TARGET.CAPABILITY =
- TARGET.EPOCALLOWDLLDATA = 1
- addFiles.sources = metawatchdriver.dll
- addFiles.path = !:/sys/bin
- DEPLOYMENT += addFiles
-}
-
-unix:!symbian {
- !isEmpty(MEEGO_VERSION_MAJOR)|maemo5 {
- QMAKE_RPATHDIR += /opt/sowatch/lib
- target.path = /opt/sowatch/lib/drivers
- res_files.path = /opt/sowatch/share/metawatch
- qml_files.path = /opt/sowatch/qml
- } else {
- target.path = /usr/lib/sowatch/drivers
- res_files.path = /usr/share/sowatch/metawatch
- qml_files.path = /usr/share/sowatch/qml
- }
- INSTALLS += target res_files qml_files
+!isEmpty(MEEGO_VERSION_MAJOR)|maemo5 {
+ QMAKE_RPATHDIR += /opt/sowatch/lib
+ target.path = /opt/sowatch/lib/drivers
+ res_files.path = /opt/sowatch/share/metawatch
+ qml_files.path = /opt/sowatch/qml
+} else {
+ target.path = /usr/lib/sowatch/drivers
+ res_files.path = /usr/share/sowatch/metawatch
+ qml_files.path = /usr/share/sowatch/qml
}
+INSTALLS += target res_files qml_files
diff --git a/metawatch/metawatchanalog.cpp b/metawatch/metawatchanalog.cpp
index 60993d4..5d35266 100644
--- a/metawatch/metawatchanalog.cpp
+++ b/metawatch/metawatchanalog.cpp
@@ -6,8 +6,8 @@ using namespace sowatch;
// TODO : Figure out how the OLED screen protocol works, including scrolling
// TODO : Idle and Notification screens for the Analog Metawatch
-MetaWatchAnalog::MetaWatchAnalog(const QBluetoothAddress& address, QSettings* settings, QObject *parent) :
- MetaWatch(address, settings, parent)
+MetaWatchAnalog::MetaWatchAnalog(ConfigKey* settings, QObject *parent) :
+ MetaWatch(settings, parent)
{
}
diff --git a/metawatch/metawatchanalog.h b/metawatch/metawatchanalog.h
index ff941c5..a0a4db2 100644
--- a/metawatch/metawatchanalog.h
+++ b/metawatch/metawatchanalog.h
@@ -10,7 +10,7 @@ class MetaWatchAnalog : public MetaWatch
{
Q_OBJECT
public:
- explicit MetaWatchAnalog(const QBluetoothAddress& address, QSettings* settings = 0, QObject *parent = 0);
+ explicit MetaWatchAnalog(ConfigKey *settings, QObject *parent = 0);
static const int screenWidth = 80;
static const int screenHeight = 16*2;
diff --git a/metawatch/metawatchdigital.cpp b/metawatch/metawatchdigital.cpp
index befdaea..3029613 100644
--- a/metawatch/metawatchdigital.cpp
+++ b/metawatch/metawatchdigital.cpp
@@ -2,8 +2,8 @@
using namespace sowatch;
-MetaWatchDigital::MetaWatchDigital(const QBluetoothAddress& address, QSettings* settings, QObject *parent) :
- MetaWatch(address, settings, parent),
+MetaWatchDigital::MetaWatchDigital(ConfigKey* settings, QObject *parent) :
+ MetaWatch(settings, parent),
_nMails(0), _nCalls(0), _nIms(0), _nSms(0), _nMms(0),
_wForecast(WeatherNotification::UnknownWeather)
{
diff --git a/metawatch/metawatchdigital.h b/metawatch/metawatchdigital.h
index 7ce195b..4fd6ae6 100644
--- a/metawatch/metawatchdigital.h
+++ b/metawatch/metawatchdigital.h
@@ -10,7 +10,7 @@ class MetaWatchDigital : public MetaWatch
{
Q_OBJECT
public:
- explicit MetaWatchDigital(const QBluetoothAddress& address, QSettings* settings = 0, QObject *parent = 0);
+ explicit MetaWatchDigital(ConfigKey *settings, QObject *parent = 0);
static const int screenWidth = 96;
static const int screenHeight = 96;
diff --git a/metawatch/metawatchplugin.cpp b/metawatch/metawatchplugin.cpp
index 523230b..72713ec 100644
--- a/metawatch/metawatchplugin.cpp
+++ b/metawatch/metawatchplugin.cpp
@@ -3,6 +3,7 @@
#include "metawatchdigital.h"
#include "metawatchanalog.h"
#include "metawatchsimulator.h"
+#include "metawatchscanner.h"
#include "metawatchplugin.h"
using namespace sowatch;
@@ -33,14 +34,17 @@ QStringList MetaWatchPlugin::drivers()
return d;
}
-Watch* MetaWatchPlugin::getWatch(const QString& driver, QSettings& settings, QObject *parent)
+WatchScanner* MetaWatchPlugin::getScanner(QObject *parent)
+{
+ return new MetaWatchScanner(parent);
+}
+
+Watch* MetaWatchPlugin::getWatch(const QString& driver, ConfigKey* settings, QObject *parent)
{
if (driver == "metawatch-digital") {
- QBluetoothAddress address(settings.value("address").toString());
- return new MetaWatchDigital(address, &settings, parent);
+ return new MetaWatchDigital(settings, parent);
} else if (driver == "metawatch-analog") {
- QBluetoothAddress address(settings.value("address").toString());
- return new MetaWatchAnalog(address, &settings, parent);
+ return new MetaWatchAnalog(settings, parent);
} else {
return 0;
}
diff --git a/metawatch/metawatchplugin.h b/metawatch/metawatchplugin.h
index 4ea0e5f..964aa04 100644
--- a/metawatch/metawatchplugin.h
+++ b/metawatch/metawatchplugin.h
@@ -15,7 +15,8 @@ public:
~MetaWatchPlugin();
virtual QStringList drivers();
- virtual Watch* getWatch(const QString& driver, QSettings& settings, QObject* parent = 0);
+ virtual WatchScanner* getScanner(QObject *parent);
+ virtual Watch* getWatch(const QString& driver, ConfigKey *settings, QObject *parent);
private:
static bool fontsLoaded;
diff --git a/metawatch/metawatchscanner.cpp b/metawatch/metawatchscanner.cpp
new file mode 100644
index 0000000..418500c
--- /dev/null
+++ b/metawatch/metawatchscanner.cpp
@@ -0,0 +1,48 @@
+#include <QtConnectivity/QBluetoothDeviceInfo>
+#include <QtConnectivity/QBluetoothAddress>
+
+#include "metawatchscanner.h"
+
+QTM_USE_NAMESPACE
+using namespace sowatch;
+
+MetaWatchScanner::MetaWatchScanner(QObject *parent) :
+ WatchScanner(parent),
+ _agent(new QBluetoothServiceDiscoveryAgent(this))
+{
+ _agent->setUuidFilter(QBluetoothUuid::SerialPort);
+ connect(_agent, SIGNAL(finished()), this, SIGNAL(finished()));
+ connect(_agent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
+ this, SLOT(handleDiscoveredService(QBluetoothServiceInfo)));
+}
+
+void MetaWatchScanner::start()
+{
+ if (_agent->isActive()) {
+ _agent->stop();
+ }
+ _agent->start();
+ qDebug() << "started metawatch bluetooth scan";
+ emit started();
+}
+
+void MetaWatchScanner::handleDiscoveredService(const QBluetoothServiceInfo &info)
+{
+ const QBluetoothDeviceInfo dev = info.device();
+ QString deviceName = dev.name();
+ if (deviceName.contains("MetaWatch", Qt::CaseInsensitive)) {
+ QVariantMap foundInfo;
+ foundInfo["address"] = dev.address().toString();
+ foundInfo["name"] = deviceName;
+ qDebug() << "metawatch bluetooth scan found" << deviceName;
+ if (deviceName.contains("Digital", Qt::CaseInsensitive)) {
+ foundInfo["driver"] = QString("metawatch-digital");
+ emit watchFound(foundInfo);
+ } else if (deviceName.contains("Analog", Qt::CaseInsensitive)) {
+ foundInfo["driver"] = QString("metawatch-analog");
+ emit watchFound(foundInfo);
+ } else {
+ qWarning() << "Unknown MetaWatch device found:" << deviceName;
+ }
+ }
+}
diff --git a/metawatch/metawatchscanner.h b/metawatch/metawatchscanner.h
new file mode 100644
index 0000000..c98bf1a
--- /dev/null
+++ b/metawatch/metawatchscanner.h
@@ -0,0 +1,30 @@
+#ifndef METAWATCHSCANNER_H
+#define METAWATCHSCANNER_H
+
+#include <sowatch.h>
+#include <QtConnectivity/QBluetoothServiceDiscoveryAgent>
+
+using QTM_PREPEND_NAMESPACE(QBluetoothServiceDiscoveryAgent);
+using QTM_PREPEND_NAMESPACE(QBluetoothServiceInfo);
+
+namespace sowatch
+{
+
+class MetaWatchScanner : public WatchScanner
+{
+ Q_OBJECT
+public:
+ explicit MetaWatchScanner(QObject *parent = 0);
+
+ void start();
+
+private:
+ QBluetoothServiceDiscoveryAgent *_agent;
+
+private slots:
+ void handleDiscoveredService(const QBluetoothServiceInfo& info);
+};
+
+}
+
+#endif // METAWATCHSCANNER_H