Skip to content

Commit

Permalink
Merge branch 'master' into immediatealertservice
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlich committed Dec 28, 2023
2 parents 650d614 + 8315131 commit 42ce869
Show file tree
Hide file tree
Showing 61 changed files with 1,415 additions and 90 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/sailfishos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: SailfishOS Build

on: [push, pull_request]

env:
OS_VERSION: 4.5.0.16

jobs:
build:
runs-on: ubuntu-latest
name: Build App
strategy:
matrix:
arch: ['armv7hl', 'aarch64', 'i486']

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Prepare
run: docker pull coderus/sailfishos-platform-sdk:$OS_VERSION && mkdir output

- name: Build ${{ matrix.arch }}
run: docker run --rm --privileged -v $PWD:/share coderus/sailfishos-platform-sdk:$OS_VERSION /bin/bash -c "
mkdir -p build ;
cd build ;
cp -r /share/* . ;
sb2 -t SailfishOS-$OS_VERSION-${{ matrix.arch }} -R zypper --non-interactive ar --no-gpgcheck http://repo.merproject.org/obs/home:/piggz:/kf5/sailfish_latest_${{ matrix.arch }}/ piggz ;
sb2 -t SailfishOS-$OS_VERSION-${{ matrix.arch }} -R zypper --non-interactive refresh ;
sb2 -t SailfishOS-$OS_VERSION-${{ matrix.arch }} -R zypper --non-interactive in -y mpris-qt5-devel libkf5archive-devel kcoreaddons-devel kdb-devel libKDb3-3 mkcal-qt5-devel libicu-devel;
mb2 -t SailfishOS-$OS_VERSION-${{ matrix.arch }} build ;
sudo cp -r RPMS/*.rpm /share/output"

- name: Upload RPM (${{ matrix.arch }})
uses: actions/upload-artifact@v3
with:
name: rpm-${{ matrix.arch }}
path: output
1 change: 1 addition & 0 deletions clickable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies_target:
- libkf5archive-dev
- libkf5coreaddons-dev
- libdbus-1-dev
- libtelepathy-qt5-dev

libraries:
qtmpris:
Expand Down
10 changes: 10 additions & 0 deletions daemon/daemon.pro
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ flavor_silica {
voicecall \
notificationmonitor \
calendar
} else:flavor_uuitk {
DEFINES += UUITK_EDITION
WATCHFISH_FEATURES += music \
voicecall \
notificationmonitor \
calendar
} else {
WATCHFISH_FEATURES += music \
notificationmonitor \
Expand Down Expand Up @@ -125,11 +131,13 @@ SOURCES += \
src/services/infinitimemotionservice.cpp \
src/services/infinitimenavservice.cpp \
src/services/infinitimeweatherservice.cpp \
src/services/pinetimesimpleweatherservice.cpp \
src/services/pinetimemusicservice.cpp \
src/services/uartservice.cpp \
src/typeconversion.cpp \
src/bipbatteryinfo.cpp \
src/devicefactory.cpp \
src/realtimeactivitysample.cpp \
src/services/mibandservice.cpp \
src/services/miband2service.cpp \
src/services/alertnotificationservice.cpp \
Expand Down Expand Up @@ -198,6 +206,7 @@ HEADERS += \
src/services/infinitimemotionservice.h \
src/services/infinitimenavservice.h \
src/services/infinitimeweatherservice.h \
src/services/pinetimesimpleweatherservice.h \
src/services/pinetimemusicservice.h \
src/services/uartservice.h \
src/services/immediatealertservice.h \
Expand All @@ -210,6 +219,7 @@ HEADERS += \
src/activitysummary.h \
src/activitysample.h \
src/devicefactory.h \
src/realtimeactivitysample.h \
src/services/mibandservice.h \
src/services/miband2service.h \
src/services/alertnotificationservice.h \
Expand Down
97 changes: 91 additions & 6 deletions daemon/src/deviceinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QProcess>

#include <KDb3/KDbDriverManager>
#include <KDb3/KDbTransactionGuard>

static const char *SERVICE = SERVICE_NAME_AMAZFISH;
static const char *PATH = "/application";
Expand Down Expand Up @@ -47,7 +48,7 @@ DeviceInterface::DeviceInterface()
connect(&m_notificationMonitor, &watchfish::NotificationMonitor::notification, this, &DeviceInterface::onNotification);

// Calls
#ifdef MER_EDITION_SAILFISH
#if defined(MER_EDITION_SAILFISH) || defined(UUITK_EDITION)
connect(&m_voiceCallController, &watchfish::VoiceCallController::ringingChanged, this, &DeviceInterface::onRingingChanged);
#endif
//Weather
Expand Down Expand Up @@ -178,7 +179,7 @@ void DeviceInterface::onNotification(watchfish::Notification *notification)

void DeviceInterface::onRingingChanged()
{
#ifdef MER_EDITION_SAILFISH
#if defined(MER_EDITION_SAILFISH) || defined(UUITK_EDITION)
qDebug() << Q_FUNC_INFO << m_voiceCallController.ringing();

if (!m_device) {
Expand Down Expand Up @@ -245,6 +246,39 @@ void DeviceInterface::createTables()
}


if (!m_conn->containsTable("info_log")) {
KDbTableSchema *t_info = new KDbTableSchema("info_log");
t_info->setCaption("Info log");
t_info->addField(f = new KDbField("id", KDbField::Integer, KDbField::PrimaryKey | KDbField::AutoInc, KDbField::Unsigned));
f->setCaption("ID");
t_info->addField(f = new KDbField("timestamp", KDbField::Integer, nullptr));
f->setCaption("Timestamp");
t_info->addField(f = new KDbField("timestamp_dt", KDbField::DateTime));
f->setCaption("Timestamp in Date/Time format");
t_info->addField(f = new KDbField("key", KDbField::Integer, nullptr, KDbField::Unsigned));
f->setCaption("Key based on AbstractDevice::Info");
t_info->addField(f = new KDbField("value", KDbField::Integer, nullptr, KDbField::Unsigned));
f->setCaption("Value");

if (!m_conn->createTable(t_info)) {
qDebug() << m_conn->result();
return;
}
qDebug() << "-- info_log created --";
qDebug() << *t_info;
}

int batteryLevel = 0;

if (m_conn->querySingleNumber(
KDbEscapedString("SELECT value FROM info_log WHERE key = %1 ORDER BY id DESC").arg(AbstractDevice::INFO_BATTERY), // automatically adds LIMIT 1 into query
&batteryLevel) == true) { // comparision of tristate type (true, false, canceled)
m_lastBatteryLevel = batteryLevel;
qDebug() << "Last Battery Level: " << m_lastBatteryLevel;
} else {
qWarning() << "Cannot get battery level";
}

if (!m_conn->containsTable("sports_data")) {
KDbTableSchema *t_summary = new KDbTableSchema("sports_data");
t_summary->setCaption("Sports Data");
Expand Down Expand Up @@ -395,6 +429,7 @@ void DeviceInterface::onConnectionStateChanged()
qDebug() << "DeviceInterface::onConnectionStateChanged" << connectionState();

if (connectionState() == "authenticated") {
m_device->setDatabase(dbConnection());
if (miBandService()) {
miBandService()->setDatabase(dbConnection());
m_dbusHRM->setMiBandService(miBandService());
Expand All @@ -415,6 +450,42 @@ void DeviceInterface::onConnectionStateChanged()
emit connectionStateChanged();
}

void DeviceInterface::log_battery_level(int level) {

if (!m_conn || !(m_conn->isDatabaseUsed())) {
qDebug() << "Database not connected";
return;
}

QDateTime m_sampleTime = QDateTime::currentDateTime();
qDebug() << "Start time" << m_sampleTime;

KDbTransaction transaction = m_conn->beginTransaction();
KDbTransactionGuard tg(transaction);

KDbFieldList fields;
auto s_battery = m_conn->tableSchema("info_log");

fields.addField(s_battery->field("timestamp"));
fields.addField(s_battery->field("timestamp_dt"));
fields.addField(s_battery->field("key"));
fields.addField(s_battery->field("value"));

QList<QVariant> values;

values << m_sampleTime.toMSecsSinceEpoch() / 1000;
values << m_sampleTime;
values << AbstractDevice::INFO_BATTERY;
values << level;

if (!m_conn->insertRecord(&fields, values)) {
qDebug() << "error inserting record";
return;
}
tg.commit();

}

void DeviceInterface::slot_informationChanged(AbstractDevice::Info key, const QString &val)
{
qDebug() << Q_FUNC_INFO << key << val;
Expand All @@ -426,11 +497,15 @@ void DeviceInterface::slot_informationChanged(AbstractDevice::Info key, const QS

//Handle notification of low battery
if (key == AbstractDevice::INFO_BATTERY) {
if (val.toInt() != m_lastBatteryLevel) {
if (val.toInt() <= 10 && val.toInt() < m_lastBatteryLevel && AmazfishConfig::instance()->appNotifyLowBattery()) {
int battery_level = val.toInt();
if (battery_level != m_lastBatteryLevel) {

log_battery_level(battery_level);

if (battery_level <= 10 && battery_level < m_lastBatteryLevel && AmazfishConfig::instance()->appNotifyLowBattery()) {
sendAlert("Amazfish", tr("Low Battery"), tr("Battery level now ") + QString::number(m_lastBatteryLevel) + "%");
}
m_lastBatteryLevel = val.toInt();
m_lastBatteryLevel = battery_level;
}
}

Expand Down Expand Up @@ -474,13 +549,16 @@ void DeviceInterface::deviceEvent(AbstractDevice::Events event)
case AbstractDevice::EVENT_APP_MUSIC:
musicChanged();
break;
#ifdef MER_EDITION_SAILFISH
#if defined(MER_EDITION_SAILFISH) || defined(UUITK_EDITION)
case AbstractDevice::EVENT_IGNORE_CALL:
m_voiceCallController.silence();
break;
case AbstractDevice::EVENT_DECLINE_CALL:
m_voiceCallController.hangup();
break;
case AbstractDevice::EVENT_ANSWER_CALL:
m_voiceCallController.answer();
break;
#endif
}
}
Expand Down Expand Up @@ -858,6 +936,13 @@ void DeviceInterface::enableFeature(int feature)
}
}

void DeviceInterface::fetchLogs()
{
if (miBandService()) {
miBandService()->fetchLogs();
}
}

QStringList DeviceInterface::supportedDisplayItems()
{
qDebug() << Q_FUNC_INFO;
Expand Down
5 changes: 4 additions & 1 deletion daemon/src/deviceinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DeviceInterface : public QObject
Q_INVOKABLE void updateCalendar();
Q_INVOKABLE void reloadCities();
Q_INVOKABLE void enableFeature(int feature);
Q_INVOKABLE void fetchLogs();
Q_INVOKABLE QStringList supportedDisplayItems();
Q_INVOKABLE void immediateAlert(int level);

Expand Down Expand Up @@ -105,6 +106,8 @@ class DeviceInterface : public QObject
void createSettings();
void updateServiceController();

void log_battery_level(int level);

//TODO Minimise use of these funcitons
MiBandService *miBandService() const;
HRMService *hrmService() const;
Expand All @@ -124,7 +127,7 @@ class DeviceInterface : public QObject

//Watchfish
watchfish::MusicController m_musicController;
#ifdef MER_EDITION_SAILFISH
#if defined(MER_EDITION_SAILFISH) || defined(UUITK_EDITION)
watchfish::VoiceCallController m_voiceCallController;
#endif
watchfish::NotificationMonitor m_notificationMonitor;
Expand Down
5 changes: 5 additions & 0 deletions daemon/src/devices/abstractdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ bool AbstractDevice::supportsFeature(AbstractDevice::Feature f) const
return (supportedFeatures() & f) == f;
}

void AbstractDevice::setDatabase(KDbConnection *conn)
{
m_conn = conn;
}

QString AbstractDevice::deviceName() const
{
return m_pairedName;
Expand Down
9 changes: 9 additions & 0 deletions daemon/src/devices/abstractdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "weather/currentweather.h"
#include "abstractfirmwareinfo.h"

#include <KDb3/KDbDriver>
#include <KDb3/KDbConnection>
#include <KDb3/KDbConnectionData>
#include <KDb3/KDbTransactionGuard>

class AbstractDevice : public QBLEDevice
{
Q_OBJECT
Expand Down Expand Up @@ -84,6 +89,8 @@ class AbstractDevice : public QBLEDevice
bool supportsFeature(Feature f) const;
virtual int supportedFeatures() const = 0;

void setDatabase(KDbConnection *conn);

virtual QString deviceType() const = 0;
QString deviceName() const;
virtual void abortOperations();
Expand Down Expand Up @@ -127,11 +134,13 @@ class AbstractDevice : public QBLEDevice
QTimer *m_reconnectTimer;

void setConnectionState(const QString &state);
KDbConnection *m_conn = nullptr;

private:
void reconnectionTimer();
void devicePairFinished(const QString& status);
QString m_pairedName;

};

#endif
6 changes: 3 additions & 3 deletions daemon/src/devices/banglejsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ void BangleJSDevice::sendWeather(CurrentWeather *weather)
QJsonObject o;
o.insert("t", "weather");
o.insert("temp", weather->temperature());
o.insert("hum", 0); //TODO we dont have this
o.insert("hum", weather->humidity());
o.insert("txt", weather->description());
o.insert("wind", 0); //TODO we dont have this
o.insert("wdir", ""); // TODO we dont have this
o.insert("wind", weather->windSpeed());
o.insert("wdir", weather->windDeg());
o.insert("loc", weather->city()->name());

uart->txJson(o);
Expand Down
22 changes: 21 additions & 1 deletion daemon/src/devices/infinitimefirmwareinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,27 @@ void InfinitimeFirmwareInfo::determineFirmwareVersion()
{
switch (m_type) {
case Firmware:
m_version = "FW ()";
{
m_version = "FW ()";

QRegularExpression binNameVersionPattern(".*-((\\d+\\.){2}\\d+)\\.bin$");
if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(ZIP_HEADER))) {
QDataStream in(&m_bytes, QIODevice::ReadOnly);
KCompressionDevice dev(in.device(), false, KCompressionDevice::CompressionType::None);
KZip zip(&dev);

if(zip.open(QIODevice::ReadOnly)) {
auto* root = zip.directory();
foreach (const QString &entryName, root->entries()) {
QRegularExpressionMatch match = binNameVersionPattern.match(entryName);
if (match.hasMatch()) {
m_version = QString("FW (%1)").arg(match.captured(1));
break;
}
}
}
}
}
break;
case Res_Compressed:
m_version = "Ressource ()";
Expand Down
Loading

0 comments on commit 42ce869

Please sign in to comment.