mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
Improve USBMS handling
Finally applying @NiLuJe's suggestion!
This commit is contained in:
parent
30c71a954a
commit
76327f4958
8 changed files with 71 additions and 46 deletions
|
@ -77,7 +77,6 @@ alert::alert(QWidget *parent) :
|
|||
ui->warningLabel->setText("Please charge your eReader.");
|
||||
ui->securityLabel->setText("The battery's charge level is critical.");
|
||||
ui->messageLabel->setText("To prevent damage, your device has been turned off.\nPlease consider charging it.");
|
||||
poweroff(false);
|
||||
}
|
||||
|
||||
ui->warningLabel->setStyleSheet("QLabel { background-color : black; color : white; font-size: 16pt}");
|
||||
|
|
2
eink.qrc
2
eink.qrc
|
@ -71,5 +71,7 @@
|
|||
<file>resources/online-library.png</file>
|
||||
<file>resources/online-library-inverted.png</file>
|
||||
<file>resources/cover_unavailable.png</file>
|
||||
<file>resources/clock-inverted.png</file>
|
||||
<file>resources/clock.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
13
functions.h
13
functions.h
|
@ -15,6 +15,7 @@
|
|||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// WoW, global variables and namespaces are awesome
|
||||
namespace global {
|
||||
|
@ -206,6 +207,7 @@ namespace {
|
|||
fprintf(stderr, "Error opening ntx_io device\n");
|
||||
}
|
||||
ioctl(light, 241, value);
|
||||
close(light);
|
||||
}
|
||||
int int_checkconfig(QString file) {
|
||||
if(QFile::exists(file)) {
|
||||
|
@ -666,6 +668,17 @@ namespace {
|
|||
bool getEncFSStatus() {
|
||||
return checkconfig("/external_root/run/encfs_mounted");
|
||||
}
|
||||
bool isUsbPluggedIn() {
|
||||
// Thanks to https://github.com/koreader/KoboUSBMS/blob/2efdf9d920c68752b2933f21c664dc1afb28fc2e/usbms.c#L148-L158
|
||||
int ntxfd;
|
||||
if((ntxfd = open("/dev/ntx_io", O_RDWR)) == -1) {
|
||||
fprintf(stderr, "Error opening ntx_io device\n");
|
||||
}
|
||||
unsigned long ptr = 0U;
|
||||
ioctl(ntxfd, 108, &ptr);
|
||||
close(ntxfd);
|
||||
return !!ptr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // FUNCTIONS_H
|
||||
|
|
|
@ -348,15 +348,13 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(usbmsPrompt, &QTimer::timeout, [&]() {
|
||||
if(checkconfig("/opt/inkbox_genuine") == true) {
|
||||
if(global::usbms::showUsbmsDialog != true) {
|
||||
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
|
||||
if(usbmsStatus != checkconfig_str_val) {
|
||||
if(isUsbPluggedIn() != usbmsStatus) {
|
||||
global::usbms::showUsbmsDialog = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
|
||||
usbmsStatus = checkconfig_str_val;
|
||||
if(usbmsStatus != "Charging\n") {
|
||||
usbmsStatus = isUsbPluggedIn();
|
||||
if(usbmsStatus == false) {
|
||||
// Loop again...
|
||||
;
|
||||
}
|
||||
|
|
BIN
resources/clock-inverted.png
Normal file
BIN
resources/clock-inverted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
BIN
resources/clock.png
Normal file
BIN
resources/clock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
|
@ -14,8 +14,8 @@ usbms_splash::usbms_splash(QWidget *parent) :
|
|||
ui->setupUi(this);
|
||||
|
||||
// Getting the screen's size
|
||||
float sW = QGuiApplication::screens()[0]->size().width();
|
||||
float sH = QGuiApplication::screens()[0]->size().height();
|
||||
sW = QGuiApplication::screens()[0]->size().width();
|
||||
sH = QGuiApplication::screens()[0]->size().height();
|
||||
|
||||
// Defining what the default icon size will be
|
||||
if(global::kobox::showKoboxSplash == true) {
|
||||
|
@ -97,52 +97,47 @@ void usbms_splash::usbms_launch()
|
|||
proc_1->waitForFinished();
|
||||
proc_1->deleteLater();
|
||||
|
||||
bool exitUsbMsDone = false;
|
||||
QTimer *usbms_t = new QTimer(this);
|
||||
usbms_t->setInterval(1000);
|
||||
connect(usbms_t, &QTimer::timeout, [&]() {
|
||||
QString prog ("mass_storage.sh");
|
||||
QStringList args;
|
||||
QProcess *proc = new QProcess();
|
||||
proc->start(prog, args);
|
||||
proc->waitForFinished();
|
||||
proc->deleteLater();
|
||||
if(exitUsbMsDone == false) {
|
||||
if(isUsbPluggedIn() == false) {
|
||||
if(global::usbms::koboxExportExtensions == true) {
|
||||
reboot(false);
|
||||
}
|
||||
else {
|
||||
qDebug() << "Exiting USBMS session...";
|
||||
ui->label->setText("Processing content");
|
||||
ui->label_3->setText("Please wait");
|
||||
ui->label->setStyleSheet("QLabel { background-color : black; color : white; font-size: 15pt }");
|
||||
ui->label_3->setStyleSheet("QLabel { background-color : black; color : white; font-size: 11pt }");
|
||||
|
||||
QFile modules("/tmp/usbevent");
|
||||
modules.open(QIODevice::ReadWrite);
|
||||
QTextStream in (&modules);
|
||||
const QString content = in.readAll();
|
||||
std::string contentstr = content.toStdString();
|
||||
modules.close();
|
||||
if(contentstr.find("1") != std::string::npos) {
|
||||
if(global::usbms::koboxExportExtensions == true) {
|
||||
reboot(false);
|
||||
float stdIconWidth = sW / 1.5;
|
||||
float stdIconHeight = sH / 1.5;
|
||||
|
||||
QPixmap pixmap(":/resources/clock-inverted.png");
|
||||
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
||||
ui->label_2->setPixmap(scaledPixmap);
|
||||
|
||||
this->repaint();
|
||||
|
||||
QString prog("rmmod");
|
||||
QStringList args;
|
||||
args << "g_mass_storage";
|
||||
QProcess * proc = new QProcess();
|
||||
proc->start(prog, args);
|
||||
proc->waitForFinished();
|
||||
proc->deleteLater();
|
||||
|
||||
QTimer::singleShot(500, this, SLOT(restartServices()));
|
||||
}
|
||||
exitUsbMsDone = true;
|
||||
}
|
||||
else {
|
||||
QString prog("rmmod");
|
||||
QStringList args;
|
||||
args << "g_mass_storage";
|
||||
QProcess * proc = new QProcess();
|
||||
proc->start(prog, args);
|
||||
proc->waitForFinished();
|
||||
proc->deleteLater();
|
||||
|
||||
// Restarting USBNet
|
||||
// NOTE: USBNet is only started if required conditions are met (see https://github.com/Kobo-InkBox/rootfs/blob/master/etc/init.d/usbnet)
|
||||
string_writeconfig("/opt/ibxd", "usbnet_start\n");
|
||||
QThread::msleep(1000);
|
||||
// Mounting onboard storage
|
||||
string_writeconfig("/opt/ibxd", "onboard_mount\n");
|
||||
QThread::msleep(1000);
|
||||
// Checking for updates
|
||||
string_writeconfig("/opt/ibxd", "update_inkbox_restart\n");
|
||||
QThread::msleep(2500);
|
||||
|
||||
quit_restart();
|
||||
;
|
||||
}
|
||||
}
|
||||
else {
|
||||
;
|
||||
}
|
||||
} );
|
||||
usbms_t->start();
|
||||
}
|
||||
|
@ -165,3 +160,18 @@ void usbms_splash::quit_restart() {
|
|||
process.startDetached("inkbox", QStringList());
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void usbms_splash::restartServices() {
|
||||
// Restarting USBNet
|
||||
// NOTE: USBNet is only started if required conditions are met (see https://github.com/Kobo-InkBox/rootfs/blob/master/etc/init.d/usbnet)
|
||||
string_writeconfig("/opt/ibxd", "usbnet_start\n");
|
||||
QThread::msleep(1000);
|
||||
// Mounting onboard storage
|
||||
string_writeconfig("/opt/ibxd", "onboard_mount\n");
|
||||
QThread::msleep(1000);
|
||||
// Checking for updates
|
||||
string_writeconfig("/opt/ibxd", "update_inkbox_restart\n");
|
||||
QThread::msleep(2500);
|
||||
|
||||
quit_restart();
|
||||
}
|
||||
|
|
|
@ -14,12 +14,15 @@ class usbms_splash : public QWidget
|
|||
public:
|
||||
explicit usbms_splash(QWidget *parent = nullptr);
|
||||
~usbms_splash();
|
||||
float sW;
|
||||
float sH;
|
||||
|
||||
void usbms_launch();
|
||||
|
||||
private slots:
|
||||
void brightnessDown();
|
||||
void quit_restart();
|
||||
void restartServices();
|
||||
|
||||
private:
|
||||
Ui::usbms_splash *ui;
|
||||
|
|
Loading…
Reference in a new issue