Merge pull request #31 from Szybet/master

Named pipe repair, minor improvements and other fixes
This commit is contained in:
Nicolas Mailloux 2022-08-01 18:30:22 -04:00 committed by GitHub
commit e92bd36a34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 72 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

@ -38,9 +38,15 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
// 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");
@ -54,10 +60,25 @@ powerDaemonSettings::powerDaemonSettings(QWidget *parent) :
stylesheetFile.close(); stylesheetFile.close();
// Button tweaks // Button tweaks
int autoRepeatDelay = 1250;
int autoRepeatInterval = 20;
ui->CBSDecreaseBtn->setAutoRepeat(true); ui->CBSDecreaseBtn->setAutoRepeat(true);
ui->CBSDecreaseBtn->setAutoRepeatDelay(autoRepeatDelay);
ui->CBSDecreaseBtn->setAutoRepeatInterval(autoRepeatInterval);
ui->CBSIncreaseBtn->setAutoRepeat(true); ui->CBSIncreaseBtn->setAutoRepeat(true);
ui->CBSIncreaseBtn->setAutoRepeatDelay(autoRepeatDelay);
ui->CBSIncreaseBtn->setAutoRepeatInterval(autoRepeatInterval);
ui->idleSleepDecreaseBtn->setAutoRepeat(true); ui->idleSleepDecreaseBtn->setAutoRepeat(true);
ui->idleSleepDecreaseBtn->setAutoRepeatDelay(autoRepeatDelay);
ui->idleSleepDecreaseBtn->setAutoRepeatInterval(autoRepeatInterval);
ui->idleSleepIncreaseBtn->setAutoRepeat(true); ui->idleSleepIncreaseBtn->setAutoRepeat(true);
ui->idleSleepIncreaseBtn->setAutoRepeatDelay(autoRepeatDelay);
ui->idleSleepIncreaseBtn->setAutoRepeatInterval(autoRepeatInterval);
// Hide items // Hide items
ui->hLabel_3->hide(); ui->hLabel_3->hide();
@ -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,17 @@ 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) { cinematicBrightnessInt = cinematicBrightnessInt - 1;
value = value - 1; convertCinematicInt();
ui->CBSLabel->setText(QString::number(value));
} }
} }
@ -191,7 +208,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
@ -327,7 +344,6 @@ void powerDaemonSettings::convertIdleSleepInt()
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 +372,10 @@ 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,19 +28,21 @@ 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;
bool chargerWakeUpBool; bool chargerWakeUpBool;
bool wifiReconnectBool; bool wifiReconnectBool;
bool ledUsageBool; bool ledUsageBool;
int idleSleepInt;
bool customCaseBool; bool customCaseBool;
bool deepSleepBool; bool deepSleepBool;
int idleSleepInt;
int cinematicBrightnessInt;
}; };
#endif // POWERDAEMONSETTINGS_H #endif // POWERDAEMONSETTINGS_H

View file

@ -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>