Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable realtime HRM from Device Settings Page #306

Merged
merged 6 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion daemon/src/devices/abstractdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class AbstractDevice : public QBLEDevice
SETTING_DEVICE_DATE,
SETTING_DEVICE_TIME,
SETTING_DEVICE_UNIT,
SETTING_DISCONNECT_NOTIFICATION
SETTING_DISCONNECT_NOTIFICATION,
SETTING_DEVICE_REALTIME_HRM_MEASUREMENT
};
Q_ENUM(Settings)

Expand Down
4 changes: 4 additions & 0 deletions daemon/src/devices/huamidevice.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "huamidevice.h"
#include "bipfirmwareinfo.h"
#include "updatefirmwareoperation.h"
#include "amazfishconfig.h"

#include <QtXml/QtXml>

Expand Down Expand Up @@ -305,6 +306,9 @@ void HuamiDevice::applyDeviceSetting(Settings s)
case SETTING_DISCONNECT_NOTIFICATION:
mi->setDisconnectNotification();
break;
case SETTING_DEVICE_REALTIME_HRM_MEASUREMENT:
hrm->enableRealtimeHRMeasurement(AmazfishConfig::instance()->deviceRealtimeHRMMeasurement());
break;
}
}

Expand Down
18 changes: 17 additions & 1 deletion daemon/src/devices/pinetimejfdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ void PinetimeJFDevice::initialise()

HRMService *hrm = qobject_cast<HRMService*>(service(HRMService::UUID_SERVICE_HRM));
if (hrm) {
hrm->enableRealtimeHRMeasurement(AmazfishConfig::instance()->deviceRealtimeHRMMeasurement());

connect(hrm, &HRMService::informationChanged, this, &AbstractDevice::informationChanged, Qt::UniqueConnection);
connect(hrm, &HRMService::informationChanged, &realtimeActivitySample, &RealtimeActivitySample::slot_informationChanged, Qt::UniqueConnection);
}
Expand Down Expand Up @@ -506,10 +508,24 @@ void PinetimeJFDevice::sendWeather(CurrentWeather *weather)
}
}

void PinetimeJFDevice::applyDeviceSetting(Settings s)
{

HRMService *hrm = qobject_cast<HRMService*>(service(HRMService::UUID_SERVICE_HRM));
switch(s) {
case SETTING_DEVICE_REALTIME_HRM_MEASUREMENT:
if (hrm) {
hrm->enableRealtimeHRMeasurement(AmazfishConfig::instance()->deviceRealtimeHRMMeasurement());
}
break;
}

}

void PinetimeJFDevice::immediateAlert(int level)
{
ImmediateAlertService *ias = qobject_cast<ImmediateAlertService*>(service(ImmediateAlertService::UUID_SERVICE_IMMEDIATE_ALERT));
if (ias) {
ias->sendAlert((ImmediateAlertService::Levels)level);
}
}
}
1 change: 1 addition & 0 deletions daemon/src/devices/pinetimejfdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PinetimeJFDevice : public AbstractDevice
//Weather
void sendWeather(CurrentWeather *weather) override;

virtual void applyDeviceSetting(Settings s);
virtual void immediateAlert(int level) override;

protected:
Expand Down
1 change: 0 additions & 1 deletion daemon/src/services/hrmservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ void HRMService::characteristicChanged(const QString &characteristic, const QByt
qDebug() << Q_FUNC_INFO << "Changed:" << characteristic << value;

if (characteristic == UUID_CHARACTERISTIC_HRM_MEASUREMENT) {
qDebug() << "..got HR measurement";
if (value.length() == 2 && value[0] == 0) {
m_heartRate = (value[1] & 0xff);
emit informationChanged(AbstractDevice::INFO_HEARTRATE, QString::number(m_heartRate));
Expand Down
1 change: 0 additions & 1 deletion daemon/src/services/infinitimemotionservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ void InfiniTimeMotionService::characteristicChanged(const QString &characteristi
qDebug() << Q_FUNC_INFO << characteristic << value.toHex();

if (characteristic == UUID_CHARACTERISTIC_MOTION_STEPS) {
qDebug() << "...Got realtime steps:" << value.length();
if (value.length() == 4) {
m_steps = TypeConversion::toUint32(value[0], value[1], value[2], value[3]);
emit informationChanged(AbstractDevice::INFO_STEPS, QString::number(m_steps));
Expand Down
3 changes: 2 additions & 1 deletion lib/src/amazfish.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class Amazfish : public QObject {
SETTING_DEVICE_DATE,
SETTING_DEVICE_TIME,
SETTING_DEVICE_UNIT,
SETTING_DISCONNECT_NOTIFICATION
SETTING_DISCONNECT_NOTIFICATION,
SETTING_DEVICE_REALTIME_HRM_MEASUREMENT
};
Q_ENUM(Settings)

Expand Down
1 change: 1 addition & 0 deletions lib/src/amazfishconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class AmazfishConfig : public QObject
INT_OPTION(QStringLiteral("app/refreshweather"), appRefreshWeather, setAppRefreshWeather, 80)
INT_OPTION(QStringLiteral("app/refreshcalendar"), appRefreshCalendar, setAppRefreshCalendar, 60)

BOOL_OPTION(QStringLiteral("device/realtimehrmmeasurement"), deviceRealtimeHRMMeasurement, setdeviceRealtimeHRMMeasurement, false)
BOOL_OPTION(QStringLiteral("device/disconnectnotification"), deviceDisconnectNotification, setDeviceDisconnectNotification, false)
BOOL_OPTION(QStringLiteral("device/displayweathershortcut"), deviceDisplayWeatherShortcut, setDeviceDisplayWeatherShortcut, true)
BOOL_OPTION(QStringLiteral("device/displayalipayshortcut"), deviceDisplayAliPayShortcut, setDeviceDisplayAliPayShortcut, true)
Expand Down
12 changes: 12 additions & 0 deletions ui/qml/pages/Settings-device.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ PagePL {
}
}

TextSwitchPL {
id: chkRealtimeHRMMeasuerement
width: parent.width
text: qsTr("Realtime HRM measurement")
Component.onCompleted: {
chkRealtimeHRMMeasuerement.checked = AmazfishConfig.deviceRealtimeHRMMeasurement
}
}

ButtonPL {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Huami Display Items")
Expand Down Expand Up @@ -121,6 +130,7 @@ PagePL {
DaemonInterfaceInstance.applyDeviceSetting(Amazfish.SETTING_DEVICE_TIME);
DaemonInterfaceInstance.applyDeviceSetting(Amazfish.SETTING_DEVICE_UNIT);
DaemonInterfaceInstance.applyDeviceSetting(Amazfish.SETTING_DISCONNECT_NOTIFICATION);
DaemonInterfaceInstance.applyDeviceSetting(Amazfish.SETTING_DEVICE_REALTIME_HRM_MEASUREMENT);
app.pages.pop();
}
}
Expand All @@ -132,6 +142,8 @@ PagePL {
AmazfishConfig.deviceTimeFormat = cboTimeFormat.currentIndex;
AmazfishConfig.deviceDistanceUnit = cboDistanceUnit.currentIndex;
AmazfishConfig.deviceDisconnectNotification = chkDisconnectNotification.checked;
AmazfishConfig.deviceRealtimeHRMMeasurement = chkRealtimeHRMMeasuerement.checked;

tmrSetDelay.start();
}
}
Loading