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

WIP: Immediatealertservice part2 #369

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions daemon/src/deviceinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ void DeviceInterface::slot_informationChanged(AbstractDevice::Info key, const QS
{
qDebug() << Q_FUNC_INFO << key << val;


if (key == AbstractDevice::INFO_IMMEDIATE_ALERT) {
message(QString("Immediate Alert Service: %1").arg(val)); // FIXME should trigger phone ringing
}

//Handle notification of low battery
if (key == AbstractDevice::INFO_BATTERY) {
int battery_level = val.toInt();
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/devices/abstractdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ QStringList AbstractDevice::supportedDisplayItems() const

void AbstractDevice::immediateAlert(int level) {
qDebug() << Q_FUNC_INFO << level;
}
}
6 changes: 6 additions & 0 deletions daemon/src/devices/pinetimejfdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ void PinetimeJFDevice::initialise()
connect(battery, &BatteryService::informationChanged, this, &PinetimeJFDevice::informationChanged, Qt::UniqueConnection);
}

ImmediateAlertService *immediateAlerts = qobject_cast<ImmediateAlertService*>(service(ImmediateAlertService::UUID_SERVICE_IMMEDIATE_ALERT));
if (immediateAlerts) {
immediateAlerts->enableNotification(ImmediateAlertService::UUID_CHARACTERISTIC_IMMEDIATE_ALERT_LEVEL);
connect(immediateAlerts, &ImmediateAlertService::informationChanged, this, &PinetimeJFDevice::informationChanged, Qt::UniqueConnection);
}

CurrentTimeService *cts = qobject_cast<CurrentTimeService*>(service(CurrentTimeService::UUID_SERVICE_CURRENT_TIME));
if (cts) {
cts->currentTime();
Expand Down
14 changes: 14 additions & 0 deletions daemon/src/services/immediatealertservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const char* ImmediateAlertService::UUID_CHARACTERISTIC_IMMEDIATE_ALERT_LEVEL = "
ImmediateAlertService::ImmediateAlertService(const QString &path, QObject *parent) : QBLEService(UUID_SERVICE_IMMEDIATE_ALERT, path, parent)
{
qDebug() << Q_FUNC_INFO;

connect(this, &QBLEService::characteristicChanged, this, &ImmediateAlertService::characteristicChanged);
enableNotification(UUID_CHARACTERISTIC_IMMEDIATE_ALERT_LEVEL);
}

QString ImmediateAlertService::levelToString(const ImmediateAlertService::Levels level)
Expand All @@ -22,6 +25,17 @@ QString ImmediateAlertService::levelToString(const ImmediateAlertService::Levels
}
}

void ImmediateAlertService::characteristicChanged(const QString &characteristic, const QByteArray &value)
{
qDebug() << Q_FUNC_INFO << "Read:" << characteristic << value;
if (characteristic == UUID_CHARACTERISTIC_IMMEDIATE_ALERT_LEVEL) {
m_alertLevel = (ImmediateAlertService::Levels)value[0];
emit informationChanged(AbstractDevice::INFO_IMMEDIATE_ALERT, QString::number(static_cast<int>(m_alertLevel)));
} else {
qWarning() << Q_FUNC_INFO << "Unknown value";
}
}

ImmediateAlertService::Levels ImmediateAlertService::alertLevel()
{
qDebug() << Q_FUNC_INFO << levelToString(m_alertLevel);
Expand Down
3 changes: 3 additions & 0 deletions daemon/src/services/immediatealertservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class ImmediateAlertService : public QBLEService
void sendAlert(ImmediateAlertService::Levels level);
QString levelToString(const ImmediateAlertService::Levels level);

Q_SIGNAL void informationChanged(AbstractDevice::Info key, const QString &val);

private:
Levels m_alertLevel;
Q_SLOT void characteristicChanged(const QString &c, const QByteArray &value);
};

#endif // IMMEDIATE_ALERT_SERVICE_H
Loading