diff --git a/alert.cpp b/alert.cpp
index 8d2353b..74cb095 100644
--- a/alert.cpp
+++ b/alert.cpp
@@ -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}");
diff --git a/eink.qrc b/eink.qrc
index 7057e82..f0d8a85 100644
--- a/eink.qrc
+++ b/eink.qrc
@@ -71,5 +71,7 @@
resources/online-library.png
resources/online-library-inverted.png
resources/cover_unavailable.png
+ resources/clock-inverted.png
+ resources/clock.png
diff --git a/functions.h b/functions.h
index 2ecb4ae..beebe68 100644
--- a/functions.h
+++ b/functions.h
@@ -15,6 +15,7 @@
#include
#include
#include
+#include
// 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
diff --git a/mainwindow.cpp b/mainwindow.cpp
index a2e68f3..e50d17f 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -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...
;
}
diff --git a/resources/clock-inverted.png b/resources/clock-inverted.png
new file mode 100644
index 0000000..ce29789
Binary files /dev/null and b/resources/clock-inverted.png differ
diff --git a/resources/clock.png b/resources/clock.png
new file mode 100644
index 0000000..a592245
Binary files /dev/null and b/resources/clock.png differ
diff --git a/usbms_splash.cpp b/usbms_splash.cpp
index 865bfeb..8c2fa36 100644
--- a/usbms_splash.cpp
+++ b/usbms_splash.cpp
@@ -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();
+}
diff --git a/usbms_splash.h b/usbms_splash.h
index 75fd48d..67e744a 100644
--- a/usbms_splash.h
+++ b/usbms_splash.h
@@ -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;