Skip to content

Commit

Permalink
Implementing udev monitoring for rM1 (#314)
Browse files Browse the repository at this point in the history
* Fix #280

* Update to python 3.12

* install the sentry cli manually
  • Loading branch information
Eeems authored Oct 4, 2024
1 parent d5b14bd commit 67cd2ce
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
- name: Install toltecmk
run: pip install toltecmk requests==2.26.0
- name: Build packages
Expand Down
46 changes: 34 additions & 12 deletions applications/system-service/powerapi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "powerapi.h"

#include <liboxide/udev.h>

PowerAPI* PowerAPI::singleton(PowerAPI* self){
static PowerAPI* instance;
if(self != nullptr){
Expand All @@ -9,7 +11,7 @@ PowerAPI* PowerAPI::singleton(PowerAPI* self){
}

PowerAPI::PowerAPI(QObject* parent)
: APIBase(parent), m_chargerState(ChargerUnknown){
: APIBase(parent), m_chargerState(ChargerUnknown){
Oxide::Sentry::sentry_transaction("Power API Init", "init", [this](Oxide::Sentry::Transaction* t){
Oxide::Sentry::sentry_span(t, "singleton", "Setup singleton", [this]{
singleton(this);
Expand All @@ -21,24 +23,44 @@ PowerAPI::PowerAPI(QObject* parent)
Oxide::Sentry::sentry_span(t, "update", "Update current state", [this]{
update();
});
Oxide::Sentry::sentry_span(t, "timer", "Setup timer", [this]{
timer = new QTimer(this);
timer->setSingleShot(false);
timer->setInterval(3 * 1000); // 3 seconds
timer->moveToThread(qApp->thread());
connect(timer, &QTimer::timeout, this, QOverload<>::of(&PowerAPI::update));
timer->start();
Oxide::Sentry::sentry_span(t, "monitor", "Setup monitor", [this]{
if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::RM1){
Oxide::UDev::singleton()->addMonitor("platform", NULL);
Oxide::UDev::singleton()->subsystem("power_supply", [this]{
QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection);
});
}else{
timer = new QTimer(this);
timer->setSingleShot(false);
timer->setInterval(3 * 1000); // 3 seconds
timer->moveToThread(qApp->thread());
connect(timer, &QTimer::timeout, this, QOverload<>::of(&PowerAPI::update));
timer->start();
}
});
});
}

PowerAPI::~PowerAPI(){
O_DEBUG("Killing timer");
timer->stop();
delete timer;
if(timer != nullptr){
qDebug() << "Killing timer";
timer->stop();
delete timer;
}else{
qDebug() << "Killing UDev monitor";
Oxide::UDev::singleton()->stop();
}
}

void PowerAPI::setEnabled(bool enabled) {
void PowerAPI::setEnabled(bool enabled){
if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::RM1){
if(enabled){
Oxide::UDev::singleton()->start();
}else{
Oxide::UDev::singleton()->stop();
}
return;
}
if(enabled){
timer->start();
}else{
Expand Down
2 changes: 1 addition & 1 deletion applications/system-service/powerapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PowerAPI : public APIBase {
void chargerWarning();

private:
QTimer* timer;
QTimer* timer = nullptr;
int m_state = Normal;
int m_batteryState = BatteryUnknown;
int m_batteryLevel = 0;
Expand Down
4 changes: 3 additions & 1 deletion shared/liboxide/liboxide.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SOURCES += \
slothandler.cpp \
sysobject.cpp \
signalhandler.cpp \
udev.cpp \
xochitlsettings.cpp

HEADERS += \
Expand All @@ -56,6 +57,7 @@ HEADERS += \
slothandler.h \
sysobject.h \
signalhandler.h \
udev.h \
xochitlsettings.h

PRECOMPILED_HEADER = \
Expand All @@ -75,7 +77,7 @@ DBUS_INTERFACES += \
../../interfaces/notificationapi.xml \
../../interfaces/notification.xml

LIBS += -lsystemd
LIBS += -lsystemd -ludev

include(../../qmake/common.pri)

Expand Down
Loading

0 comments on commit 67cd2ce

Please sign in to comment.