summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--liveview/liveview.cpp116
-rw-r--r--liveview/liveview.h23
-rw-r--r--liveview/liveview.pro4
-rw-r--r--liveview/res/graphics/menu_messages.pngbin0 -> 1377 bytes
-rw-r--r--liveview/res/graphics/menu_missed_calls.pngbin0 -> 1116 bytes
-rw-r--r--liveview/res/graphics/menu_notifications.pngbin0 -> 908 bytes
6 files changed, 126 insertions, 17 deletions
diff --git a/liveview/liveview.cpp b/liveview/liveview.cpp
index 80f0aa9..4e5d6fc 100644
--- a/liveview/liveview.cpp
+++ b/liveview/liveview.cpp
@@ -16,6 +16,7 @@ LiveView::LiveView(ConfigKey* settings, QObject* parent) :
connect(_sendTimer, SIGNAL(timeout()), SLOT(handleSendTimerTick()));
_24hMode = settings->value("24h-mode", false).toBool();
+ _buttons << "Select" << "Up" << "Down" << "Left" << "Right";
}
LiveView::~LiveView()
@@ -40,12 +41,14 @@ QString LiveView::model() const
QStringList LiveView::buttons() const
{
- return QStringList();
+ return _buttons;
}
bool LiveView::busy() const
{
- return false; // TODO
+ return !_connected ||
+ _socket->state() != QBluetoothSocket::ConnectedState ||
+ _sendingMsgs.size() > 20;
}
void LiveView::setDateTime(const QDateTime& dateTime)
@@ -68,21 +71,22 @@ QDateTime LiveView::dateTime() const
void LiveView::queryBatteryLevel()
{
-
+ // LiveView does not seem to support this.
}
+
int LiveView::batteryLevel() const
{
- return 0; // TODO
+ return 100;
}
void LiveView::queryCharging()
{
-
+ // LiveView does not seem to support this.
}
bool LiveView::charging() const
{
- return false; // TODO
+ return false;
}
void LiveView::displayIdleScreen()
@@ -109,6 +113,7 @@ void LiveView::setupBluetoothWatch()
{
connect(_socket, SIGNAL(readyRead()), SLOT(handleDataReceived()));
updateDisplayProperties();
+ refreshMenu();
}
void LiveView::desetupBluetoothWatch()
@@ -116,6 +121,11 @@ void LiveView::desetupBluetoothWatch()
}
+void LiveView::refreshMenu()
+{
+ setMenuSize(2);
+}
+
void LiveView::send(const Message &msg)
{
_sendingMsgs.enqueue(msg);
@@ -142,7 +152,33 @@ void LiveView::updateSoftwareVersion()
send(Message(GetSoftwareVersion, QByteArray(1, 0)));
}
-void LiveView::enableLed(const QColor& color, int delay, int time)
+void LiveView::setMenuSize(unsigned char size)
+{
+ send(Message(SetMenuSize, QByteArray(1, size)));
+}
+
+void LiveView::sendMenuItem(unsigned char id, bool alert, unsigned short unread, const QString& text, const QByteArray& image)
+{
+ QByteArray data(1 + 2 * 3 + 2 + 2 * 3, 0);
+ data[0] = alert ? 1 : 0;
+ //data[1,2] // Unknown
+ data[3] = (unread & 0xFF00U) >> 8;
+ data[4] = (unread & 0x00FFU);
+ //data[5,6] // Unknown
+ data[7] = id + 3;
+ //data[8] // Unknown
+ //data[9,10] // Unknown
+ //data[11,12] // Unknown
+ quint16 text_length = text.length();
+ data[13] = (text_length & 0xFF00U) >> 8;
+ data[14] = (text_length & 0x00FFU);
+ data.append(text.toLatin1());
+ data.append(image);
+
+ send(Message(MenuItemResponse, data));
+}
+
+void LiveView::enableLed(const QColor& color, unsigned short delay, unsigned short time)
{
QByteArray data;
@@ -168,6 +204,18 @@ void LiveView::handleMessage(const Message &msg)
case DeviceStatusChange:
handleDeviceStatusChange(msg);
break;
+ case MenuItemRequest:
+ handleMenuItemRequest(msg);
+ break;
+ case NotificationRequest:
+ handleNotificationRequest(msg);
+ break;
+ case Navigation:
+ handleNavigation(msg);
+ break;
+ case MenuItemsRequest:
+ handleMenuItemsRequest(msg);
+ break;
case DateTimeRequest:
handleDateTimeRequest(msg);
break;
@@ -190,14 +238,57 @@ void LiveView::handleDeviceStatusChange(const Message &msg)
if (msg.data.size() == 1) {
DeviceStatus status = static_cast<DeviceStatus>(msg.data.at(0));
qDebug() << "liveview device status change" << status;
+ switch (status) {
+ case DeviceOn:
+ refreshMenu();
+ break;
+ default:
+ break;
+ }
}
sendResponse(DeviceStatusChangeResponse, ResponseOk);
}
+void LiveView::handleMenuItemRequest(const Message &msg)
+{
+ Q_UNUSED(msg);
+ // TODO
+ qWarning() << "TODO" << Q_FUNC_INFO;
+}
+
+void LiveView::handleNotificationRequest(const Message &msg)
+{
+ // TODO
+ sendResponse(NotificationResponse, ResponseError); // TODO Crashes the watch
+}
+
+void LiveView::handleNavigation(const Message &msg)
+{
+ // TODO
+ sendResponse(NavigationResponse, ResponseOk);
+}
+
+void LiveView::handleMenuItemsRequest(const Message &msg)
+{
+ qDebug() << "Sending menu items";
+ QFile icon_file;
+
+ icon_file.setFileName(SOWATCH_RESOURCES_DIR "/liveview/graphics/menu_notifications.png");
+ icon_file.open(QIODevice::ReadOnly);
+ sendMenuItem(0, false, 4, tr("Notifications"), icon_file.readAll());
+ icon_file.close();
+
+ icon_file.setFileName(SOWATCH_RESOURCES_DIR "/liveview/graphics/menu_missed_calls.png");
+ icon_file.open(QIODevice::ReadOnly);
+ sendMenuItem(1, false, 1, tr("Missed calls"), icon_file.readAll());
+ icon_file.close();
+}
+
void LiveView::handleDateTimeRequest(const Message &msg)
{
- QByteArray data;
- data.resize(5);
+ QByteArray data(5, 0);
+
+ Q_UNUSED(msg);
QDateTime time = QDateTime::currentDateTime();
time.setTimeSpec(Qt::UTC);
@@ -217,6 +308,7 @@ void LiveView::handleDisplayProperties(const Message &msg)
// after display properties
// Otherwise the watch hangs up the connection
updateSoftwareVersion();
+ Q_UNUSED(msg);
}
void LiveView::handleSoftwareVersion(const Message &msg)
@@ -256,9 +348,6 @@ void LiveView::handleDataReceived()
}
dataRead = _socket->read(header.c, HEADER_SIZE);
-#if PROTOCOL_DEBUG
- qDebug() << "received header" << QByteArray(header.c, HEADER_SIZE).toHex();
-#endif
if (dataRead < HEADER_SIZE) {
qWarning() << "Short read";
return;
@@ -283,9 +372,6 @@ void LiveView::handleDataReceived()
/* We have the header; now, try to get the complete packet. */
if (_socket->bytesAvailable() < _receivingMsg.data.size()) {
-#if PROTOCOL_DEBUG
- qDebug() << "Waiting for more data" << _socket->bytesAvailable() << "/" << _receivingMsg.data.size();
-#endif
return; /* Wait for more. */
}
diff --git a/liveview/liveview.h b/liveview/liveview.h
index b993ee2..17819bc 100644
--- a/liveview/liveview.h
+++ b/liveview/liveview.h
@@ -48,6 +48,15 @@ protected:
GetDisplayPropertiesResponse = 2,
DeviceStatusChange = 7,
DeviceStatusChangeResponse = 8,
+ SetMenuSize = 23,
+ SetMenuSizeResponse = 24,
+ MenuItemRequest = 25,
+ MenuItemResponse = 26,
+ NotificationRequest = 27,
+ NotificationResponse = 28,
+ Navigation = 29,
+ NavigationResponse = 30,
+ MenuItemsRequest = 35,
DateTimeRequest = 38,
DateTimeResponse = 39,
EnableLed = 40,
@@ -82,15 +91,25 @@ protected:
void setupBluetoothWatch();
void desetupBluetoothWatch();
+ /** Update the device menu (after a power on, etc.) */
+ void refreshMenu();
+
+protected:
void send(const Message& msg);
void sendResponse(MessageType type, ResponseType response);
void updateDisplayProperties();
void updateSoftwareVersion();
- void enableLed(const QColor& color, int delay, int time);
+ void setMenuSize(unsigned char size);
+ void sendMenuItem(unsigned char id, bool alert, unsigned short unread, const QString& text, const QByteArray& image);
+ void enableLed(const QColor& color, unsigned short delay, unsigned short time);
void handleMessage(const Message& msg);
void handleDeviceStatusChange(const Message& msg);
+ void handleMenuItemRequest(const Message& msg);
+ void handleNotificationRequest(const Message& msg);
+ void handleNavigation(const Message& msg);
+ void handleMenuItemsRequest(const Message& msg);
void handleDateTimeRequest(const Message& msg);
void handleDisplayProperties(const Message& msg);
void handleSoftwareVersion(const Message& msg);
@@ -104,6 +123,8 @@ private:
bool _24hMode : 1;
+ QStringList _buttons;
+
/** Message outbox queue. */
QQueue<Message> _sendingMsgs;
QTimer* _sendTimer;
diff --git a/liveview/liveview.pro b/liveview/liveview.pro
index 9b949d7..045c0eb 100644
--- a/liveview/liveview.pro
+++ b/liveview/liveview.pro
@@ -18,6 +18,8 @@ HEADERS += liveviewplugin.h \
liveviewscanner.h \
liveview.h
+res_files.files += res/graphics res/fonts
+
LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch
INCLUDEPATH += $$PWD/../libsowatch
DEPENDPATH += $$PWD/../libsowatch
@@ -36,4 +38,4 @@ DEPENDPATH += $$PWD/../libsowatchbt
res_files.path = /usr/share/sowatch/metawatch
qml_files.path = /usr/share/sowatch/qml
}
-INSTALLS += target
+INSTALLS += target res_files
diff --git a/liveview/res/graphics/menu_messages.png b/liveview/res/graphics/menu_messages.png
new file mode 100644
index 0000000..203ef30
--- /dev/null
+++ b/liveview/res/graphics/menu_messages.png
Binary files differ
diff --git a/liveview/res/graphics/menu_missed_calls.png b/liveview/res/graphics/menu_missed_calls.png
new file mode 100644
index 0000000..023b391
--- /dev/null
+++ b/liveview/res/graphics/menu_missed_calls.png
Binary files differ
diff --git a/liveview/res/graphics/menu_notifications.png b/liveview/res/graphics/menu_notifications.png
new file mode 100644
index 0000000..0b6c9b9
--- /dev/null
+++ b/liveview/res/graphics/menu_notifications.png
Binary files differ