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

Implementing udev monitoring for rM1 #314

Merged
merged 25 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 23 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
22 changes: 12 additions & 10 deletions .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 Expand Up @@ -129,20 +129,22 @@ jobs:
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_URL: https://sentry.eeems.codes
- name: Setup Sentry CLI
uses: mathieu-bour/setup-sentry-cli@v2
with:
version: latest
url: https://sentry.eeems.codes
token: ${{ secrets.SENTRY_AUTH_TOKEN }}
organization: ${{ secrets.SENTRY_ORG }}
project: ${{ secrets.SENTRY_PROJECT }}
- name: Upload debug artifacts (debug)
run: curl -sL https://sentry.io/get-cli/ | bash
- name: Upload debug artifacts
if: ${{ !runner.debug }}
run: sentry-cli debug-files upload --include-sources .
env:
SENTRY_LOG_LEVEL: info
- name: Upload debug artifacts
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_URL: https://sentry.eeems.codes
- name: Upload debug artifacts (debug)
if: ${{ runner.debug }}
run: sentry-cli debug-files upload --include-sources .
env:
SENTRY_LOG_LEVEL: debug
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_URL: https://sentry.eeems.codes
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(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 @@
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]{
update();
});
}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));
Eeems marked this conversation as resolved.
Show resolved Hide resolved
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 Expand Up @@ -113,60 +135,60 @@
void PowerAPI::setChargerState(int chargerState){
m_chargerState = chargerState;
emit chargerStateChanged(chargerState);
}

void PowerAPI::updateBattery(){
if(!Oxide::Power::batteries()->length()){
if(m_batteryState != BatteryUnknown){
setBatteryState(BatteryUnknown);
}
if(!m_batteryWarning){
O_WARNING("Can't find battery information");
m_batteryWarning = true;
emit batteryWarning();
}
return;
}
if(!Oxide::Power::batteryPresent()){
if(m_batteryState != BatteryNotPresent){
O_WARNING("Battery is somehow not in the device?");
setBatteryState(BatteryNotPresent);
}
if(!m_batteryWarning){
O_WARNING("Battery is somehow not in the device?");
m_batteryWarning = true;
emit batteryWarning();
}
return;
}
int battery_level = Oxide::Power::batteryLevel();
if(m_batteryLevel != battery_level){
setBatteryLevel(battery_level);
}
bool charging = Oxide::Power::batteryCharging();
if(charging && m_batteryState != BatteryCharging){
setBatteryState(BatteryCharging);
}else if(!charging && m_batteryState != BatteryDischarging){
setBatteryState(BatteryDischarging);
}
bool alert = Oxide::Power::batteryHasAlert();
if(m_batteryAlert != alert){
m_batteryAlert = alert;
if(alert){
emit batteryAlert();
}
}
bool warning = Oxide::Power::batteryHasWarning();
if(m_batteryWarning != warning){
if(warning){
emit batteryWarning();
}
m_batteryWarning = warning;
}
int temperature = Oxide::Power::batteryTemperature();
if(m_batteryTemperature != temperature){
setBatteryTemperature(temperature);
}

Check notice on line 191 in applications/system-service/powerapi.cpp

View check run for this annotation

codefactor.io / CodeFactor

applications/system-service/powerapi.cpp#L138-L191

Complex Method
}

void PowerAPI::updateCharger(){
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
Loading