pipe repair, minor improvments and fixes

This commit is contained in:
Szybet 2022-07-29 19:50:22 +02:00
parent 4463ced4c7
commit 4eaaeb33b8
6 changed files with 81 additions and 86 deletions

View file

@ -8,10 +8,11 @@ sleepThread::sleepThread() {}
void sleepThread::start() void sleepThread::start()
{ {
log("Sleep pipe thread active", className); log("Sleep pipe thread active", className);
QDir pipePath = QDir("/run/ipd"); QDir pipeDirPath = QDir("/dev/ipd");
QFile pipePath = QFile("/dev/ipd/fifo");
while(true) { while(true) {
QThread::sleep(1); QThread::sleep(1);
if(pipePath.exists() == true) { if(pipePath.exists() == true and pipeDirPath.exists() == true) {
log("Looking for messages in pipe", className); log("Looking for messages in pipe", className);
char * pipe = "/dev/ipd/fifo"; char * pipe = "/dev/ipd/fifo";
int fd = ::open(pipe, O_RDONLY); int fd = ::open(pipe, O_RDONLY);

View file

@ -91,45 +91,9 @@ void quit::on_pushButton_3_clicked()
{ {
log("Suspending", className); log("Suspending", className);
if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/9-deepSleep") == true) { if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/9-deepSleep") == true) {
writeFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/sleepCall", "deepsleep"); writeFile("/dev/ipd/sleepCall", "deepsleep");
} }
else { else {
emulatePowerButtonInputEvent(); writeFile("/dev/ipd/sleepCall", "sleep");
}
}
void quit::emulatePowerButtonInputEvent() {
log("Emulating power button input event", className);
// Input event
struct input_event inputEvent = {};
inputEvent.type = EV_KEY;
inputEvent.code = KEY_POWER;
// SYN report event
struct input_event synReportEvent = {};
synReportEvent.type = EV_SYN;
synReportEvent.code = SYN_REPORT;
synReportEvent.value = 0;
int fd = open("/dev/input/event0", O_WRONLY);
if(fd != -1) {
// Send press event
inputEvent.value = 1;
::write(fd, &inputEvent, sizeof(inputEvent));
// Send SYN report event
::write(fd, &synReportEvent, sizeof(synReportEvent));
// Some sleep
QThread::msleep(50);
// Send release event
inputEvent.value = 0;
::write(fd, &inputEvent, sizeof(inputEvent));
::write(fd, &synReportEvent, sizeof(synReportEvent));
::close(fd);
}
else {
QString function = __func__; log(function + ": Failed to open input device node at '/dev/input/event0'", className);
} }
} }

View file

@ -24,7 +24,6 @@ private slots:
void on_pushButton_4_clicked(); void on_pushButton_4_clicked();
void on_backBtn_clicked(); void on_backBtn_clicked();
void on_pushButton_3_clicked(); void on_pushButton_3_clicked();
void emulatePowerButtonInputEvent();
private: private:
Ui::quit *ui; Ui::quit *ui;

View file

@ -36,11 +36,32 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
// Experimental features label // Experimental features label
ui->label_2->setStyleSheet("font-weight: bold"); ui->label_2->setStyleSheet("font-weight: bold");
/*
if(global::deviceID == "n306")
{
ui->wifiReconnectBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->ledUsageBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->deepSleepBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->hWhenChargerSleepBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->hChargerWakeUpBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->hCustomCaseBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->wifiReconnectBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->wifiReconnectBtn->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
}
*/
// Icons // Icons
ui->CBSDecreaseBtn->setIcon(QIcon(":/resources/minus.png")); ui->CBSDecreaseBtn->setIcon(QIcon(":/resources/minus.png"));
ui->CBSDecreaseBtn->setFixedWidth(80);
ui->CBSIncreaseBtn->setIcon(QIcon(":/resources/plus.png")); ui->CBSIncreaseBtn->setIcon(QIcon(":/resources/plus.png"));
ui->CBSIncreaseBtn->setFixedWidth(80);
ui->idleSleepDecreaseBtn->setIcon(QIcon(":/resources/minus.png")); ui->idleSleepDecreaseBtn->setIcon(QIcon(":/resources/minus.png"));
ui->idleSleepDecreaseBtn->setFixedWidth(80);
ui->idleSleepIncreaseBtn->setIcon(QIcon(":/resources/plus.png")); ui->idleSleepIncreaseBtn->setIcon(QIcon(":/resources/plus.png"));
ui->idleSleepIncreaseBtn->setFixedWidth(80);
// Padding // Padding
ui->CBSDecreaseBtn->setStyleSheet("padding: 10px"); ui->CBSDecreaseBtn->setStyleSheet("padding: 10px");
ui->CBSIncreaseBtn->setStyleSheet("padding: 10px"); ui->CBSIncreaseBtn->setStyleSheet("padding: 10px");
@ -73,7 +94,8 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
// 1 - cinematicBrightnessDelayMs // 1 - cinematicBrightnessDelayMs
QString cinematicBrightnessMs = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/1-cinematicBrightnessDelayMs"); QString cinematicBrightnessMs = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/1-cinematicBrightnessDelayMs");
ui->CBSLabel->setText(cinematicBrightnessMs); cinematicBrightnessInt = cinematicBrightnessMs.toInt();
convertCinematicInt();
// 2- cpuGovernor // 2- cpuGovernor
QString cpuGovernor = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/2-cpuGovernor"); QString cpuGovernor = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/2-cpuGovernor");
@ -102,8 +124,7 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
ui->hCpuFreqComboBox->setCurrentIndex(0); ui->hCpuFreqComboBox->setCurrentIndex(0);
// 3 - whenChargerSleep // 3 - whenChargerSleep
QString whenChargerSleep = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/3-whenChargerSleep"); if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/3-whenChargerSleep") == true) {
if(whenChargerSleep == "true") {
whenChargerSleepBool = true; whenChargerSleepBool = true;
ui->hWhenChargerSleepBtn->click(); ui->hWhenChargerSleepBtn->click();
} }
@ -112,8 +133,7 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
} }
// 4 - chargerWakeUp // 4 - chargerWakeUp
QString chargerWakeUp = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/4-chargerWakeUp"); if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/4-chargerWakeUp") == true) {
if(chargerWakeUp == "true") {
chargerWakeUpBool = true; chargerWakeUpBool = true;
ui->hChargerWakeUpBtn->click(); ui->hChargerWakeUpBtn->click();
} }
@ -122,8 +142,7 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
} }
// 5 - wifiReconnect // 5 - wifiReconnect
QString wifiReconnect = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/5-wifiReconnect"); if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/5-wifiReconnect") == true) {
if(wifiReconnect == "true") {
ui->wifiReconnectBtn->click(); ui->wifiReconnectBtn->click();
wifiReconnectBool = true; wifiReconnectBool = true;
} }
@ -132,8 +151,7 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
} }
// 6 - ledUsage // 6 - ledUsage
QString ledUsagePath = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/6-ledUsage"); if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/6-ledUsage") == true) {
if(ledUsagePath == "true") {
ui->ledUsageBtn->click(); ui->ledUsageBtn->click();
ledUsageBool = true; ledUsageBool = true;
} }
@ -147,8 +165,7 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
convertIdleSleepInt(); convertIdleSleepInt();
// 8 - customCase // 8 - customCase
QString customCaseString = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/8-customCase"); if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/8-customCase") == true) {
if(customCaseString == "true") {
ui->hCustomCaseBtn->click(); ui->hCustomCaseBtn->click();
customCaseBool = true; customCaseBool = true;
} }
@ -157,8 +174,7 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
} }
// 9 - deepSleep // 9 - deepSleep
QString deepSleepString = readFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/9-deepSleep"); if(checkconfig("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/9-deepSleep") == true) {
if(deepSleepString == "true") {
ui->deepSleepBtn->click(); ui->deepSleepBtn->click();
deepSleepBool = true; deepSleepBool = true;
} }
@ -174,16 +190,19 @@ powerDaemonSettings::~powerDaemonSettings()
void powerDaemonSettings::on_CBSIncreaseBtn_clicked() void powerDaemonSettings::on_CBSIncreaseBtn_clicked()
{ {
int value = ui->CBSLabel->text().toInt() + 1; if(cinematicBrightnessInt < 500)
ui->CBSLabel->setText(QString::number(value)); {
cinematicBrightnessInt = cinematicBrightnessInt + 1;
convertCinematicInt();
}
} }
void powerDaemonSettings::on_CBSDecreaseBtn_clicked() void powerDaemonSettings::on_CBSDecreaseBtn_clicked()
{ {
int value = ui->CBSLabel->text().toInt(); if(cinematicBrightnessInt != 0)
if(value != 0) { {
value = value - 1; cinematicBrightnessInt = cinematicBrightnessInt - 1;
ui->CBSLabel->setText(QString::number(value)); convertCinematicInt();
} }
} }
@ -191,7 +210,7 @@ void powerDaemonSettings::on_exitBtn_clicked()
{ {
// Save all to files // Save all to files
// 1 - cinematicBrightnessdelayMs // 1 - cinematicBrightnessdelayMs
writeFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/1-cinematicBrightnessDelayMs", ui->CBSLabel->text()); writeFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/1-cinematicBrightnessDelayMs", QString::number(cinematicBrightnessInt));
// 2 - cpuGovernor // 2 - cpuGovernor
writeFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/2-cpuGovernor", ui->hCpuFreqComboBox->currentText()); writeFile("/mnt/onboard/.adds/inkbox/.config/20-sleep_daemon/2-cpuGovernor", ui->hCpuFreqComboBox->currentText());
// 3 - whenChargerSleep // 3 - whenChargerSleep
@ -322,12 +341,11 @@ void powerDaemonSettings::convertIdleSleepInt()
QString text; QString text;
if(minutes != 0) { if(minutes != 0) {
text.append(QString::number(minutes) + "m"); text.append(QString::number(minutes) + "m ");
} }
if(seconds != 0) { if(seconds != 0) {
text.append(QString::number(seconds) + "s"); text.append(QString::number(seconds) + "s");
} }
ui->idleSleepLabel->setText(text); ui->idleSleepLabel->setText(text);
} }
@ -356,3 +374,13 @@ void powerDaemonSettings::on_deepSleepBtn_clicked(bool checked)
deepSleepBool = false; deepSleepBool = false;
} }
} }
void powerDaemonSettings::convertCinematicInt()
{
QString text = QString::number(cinematicBrightnessInt);
// To avoid moving other widgets when the value changes
text.append("ms");
ui->CBSLabel->setText(text);
}

View file

@ -28,10 +28,12 @@ private slots:
void on_ledUsageBtn_clicked(bool checked); void on_ledUsageBtn_clicked(bool checked);
void on_idleSleepIncreaseBtn_clicked(); void on_idleSleepIncreaseBtn_clicked();
void on_idleSleepDecreaseBtn_clicked(); void on_idleSleepDecreaseBtn_clicked();
void convertIdleSleepInt();
void on_hCustomCaseBtn_clicked(bool checked); void on_hCustomCaseBtn_clicked(bool checked);
void on_deepSleepBtn_clicked(bool checked); void on_deepSleepBtn_clicked(bool checked);
void convertIdleSleepInt();
void convertCinematicInt();
private: private:
Ui::powerDaemonSettings * ui; Ui::powerDaemonSettings * ui;
bool whenChargerSleepBool; bool whenChargerSleepBool;
@ -41,6 +43,7 @@ private:
int idleSleepInt; int idleSleepInt;
bool customCaseBool; bool customCaseBool;
bool deepSleepBool; bool deepSleepBool;
int cinematicBrightnessInt;
}; };
#endif // POWERDAEMONSETTINGS_H #endif // POWERDAEMONSETTINGS_H

View file

@ -75,7 +75,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>680</width> <width>680</width>
<height>545</height> <height>553</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@ -114,15 +114,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="CBSLabel"> <widget class="QLabel" name="label">
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>50</weight>
<bold>true</bold> <bold>false</bold>
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>50</string> <string>Cinematic brightness speed</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -137,15 +137,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="CBSLabel">
<property name="font"> <property name="font">
<font> <font>
<weight>50</weight> <weight>75</weight>
<bold>false</bold> <bold>true</bold>
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>Cinematic brightness speed</string> <string>50</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -241,15 +241,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="idleSleepLabel"> <widget class="QLabel" name="label_5">
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>50</weight>
<bold>true</bold> <bold>false</bold>
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>Idle sleep number</string> <string>Sleep when idle</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -264,15 +264,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="idleSleepLabel">
<property name="font"> <property name="font">
<font> <font>
<weight>50</weight> <weight>75</weight>
<bold>false</bold> <bold>true</bold>
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>Sleep when idle</string> <string>60</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -494,7 +494,7 @@
<item> <item>
<widget class="QCheckBox" name="hCustomCaseBtn"> <widget class="QCheckBox" name="hCustomCaseBtn">
<property name="text"> <property name="text">
<string>Custom case</string> <string>Custom case support</string>
</property> </property>
</widget> </widget>
</item> </item>