Skip to content

Commit

Permalink
Bangle.js should have also device info service and battery service
Browse files Browse the repository at this point in the history
tested on Lilygo T-Watch 2020v1
  • Loading branch information
jmlich committed Jan 26, 2025
1 parent d0508a6 commit dc02f3b
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions daemon/src/devices/banglejsdevice.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "banglejsdevice.h"
#include "batteryservice.h"
#include "uartservice.h"
#include "deviceinfoservice.h"

#include <QtXml/QtXml>

Expand All @@ -25,10 +27,11 @@ void BangleJSDevice::pair()

int BangleJSDevice::supportedFeatures() const
{
return FEATURE_HRM |
FEATURE_ALERT |
FEATURE_MUSIC_CONTROL |
FEATURE_WEATHER;
return FEATURE_STEPS |
FEATURE_HRM |
FEATURE_ALERT |
FEATURE_MUSIC_CONTROL |
FEATURE_WEATHER;
}

QString BangleJSDevice::deviceType() const
Expand Down Expand Up @@ -152,6 +155,10 @@ void BangleJSDevice::parseServices()

if (uuid == UARTService::UUID_SERVICE_UART && !service(UARTService::UUID_SERVICE_UART)) {
addService(UARTService::UUID_SERVICE_UART, new UARTService(path, this));
} else if (uuid == BatteryService::UUID_SERVICE_BATTERY && !service(BatteryService::UUID_SERVICE_BATTERY)) {
addService(BatteryService::UUID_SERVICE_BATTERY, new BatteryService(path, this));
} else if (uuid == DeviceInfoService::UUID_SERVICE_DEVICEINFO && !service(DeviceInfoService::UUID_SERVICE_DEVICEINFO)) {
addService(DeviceInfoService::UUID_SERVICE_DEVICEINFO, new DeviceInfoService(path, this));
} else if ( !service(uuid)) {
addService(uuid, new QBLEService(uuid, path, this));
}
Expand All @@ -174,6 +181,16 @@ void BangleJSDevice::initialise()
uart->tx(QByteArray(1, 0x03)); //Clear line)
}

BatteryService *battery = qobject_cast<BatteryService*>(service(BatteryService::UUID_SERVICE_BATTERY));
if (battery) {
connect(battery, &BatteryService::informationChanged, this, &BangleJSDevice::informationChanged, Qt::UniqueConnection);
}

DeviceInfoService *info = qobject_cast<DeviceInfoService*>(service(DeviceInfoService::UUID_SERVICE_DEVICEINFO));
if (info) {
connect(info, &DeviceInfoService::informationChanged, this, &BangleJSDevice::informationChanged, Qt::UniqueConnection);
}

setConnectionState("authenticated");

setTime();
Expand Down Expand Up @@ -304,18 +321,30 @@ void BangleJSDevice::startDownload()
void BangleJSDevice::refreshInformation()
{
qDebug() << Q_FUNC_INFO;
DeviceInfoService *info = qobject_cast<DeviceInfoService*>(service(DeviceInfoService::UUID_SERVICE_DEVICEINFO));
if (info) {
info->refreshInformation();
}

BatteryService *bat = qobject_cast<BatteryService*>(service(BatteryService::UUID_SERVICE_BATTERY));
if (bat) {
bat->refreshInformation();
}


}

QString BangleJSDevice::information(Info i) const
{
qDebug() << Q_FUNC_INFO << i;

if (i == INFO_BATTERY) {
switch (i) {
case AbstractDevice::INFO_BATTERY:
return QString::number(m_infoBatteryLevel);
}
if (i == INFO_SWVER) {
case AbstractDevice::INFO_SWVER:
return m_firmwareVersion;
default:
break;
}

return QString();
Expand Down

0 comments on commit dc02f3b

Please sign in to comment.