Skip to content

Commit

Permalink
Improvements in t-watch 2020 v1
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlich committed Jan 25, 2025
1 parent d0508a6 commit 3470ada
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
52 changes: 42 additions & 10 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,33 @@ 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;
case AbstractDevice::INFO_STEPS:
qDebug() << AbstractDevice::INFO_STEPS << m_steps;
return QString("%1").arg(m_steps);
default:
break;
}

return QString();
Expand Down Expand Up @@ -384,14 +416,14 @@ void BangleJSDevice::handleRxJson(const QJsonObject &json)

long ts = json.value("ts").toInt(); // timestamp
int hrm = json.value("hrm").toInt(); // heart rate,
int stp = json.value("stp").toInt(); // steps
m_steps = json.value("stp").toInt(); // steps
int mov = json.value("mov").toInt(); // movement intensity
int rt = json.value("rt").toInt();

qDebug() << "parsed type = act " << ts << hrm << stp << mov << rt;
qDebug() << "parsed type = act " << ts << hrm << m_steps << mov << rt;

emit informationChanged(INFO_HEARTRATE, QString("%1").arg(hrm));
emit informationChanged(INFO_STEPS, QString("%1").arg(stp));
emit informationChanged(INFO_STEPS, QString("%1").arg(m_steps));

} else {
qDebug() << "Gadgetbridge type " << t;
Expand Down
1 change: 1 addition & 0 deletions daemon/src/devices/banglejsdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BangleJSDevice : public AbstractDevice

int m_infoBatteryLevel = 0;
QString m_firmwareVersion;
int m_steps = 0;
};

#endif // BANGLEJSDEVICE_H

0 comments on commit 3470ada

Please sign in to comment.