USB charging fixes

This commit is contained in:
Nicolas Mailloux 2022-02-15 22:47:10 -05:00
parent 89dda0247b
commit 2853ad70c3
3 changed files with 45 additions and 52 deletions

View file

@ -459,6 +459,8 @@ namespace {
kernelVersion = proc->readAllStandardOutput();
kernelVersion = kernelVersion.trimmed();
proc->deleteLater();
setDefaultWorkDir();
QString fifo_prog("sh");
QStringList fifo_args;

View file

@ -307,8 +307,7 @@ MainWindow::MainWindow(QWidget *parent)
}
else {
if(isBatteryCritical() == true) {
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
if(isUsbPluggedIn() == true) {
;
}
else {
@ -328,12 +327,11 @@ MainWindow::MainWindow(QWidget *parent)
;
}
else {
qDebug() << "Warning! Battery is low!";
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
if(isUsbPluggedIn() == true) {
;
}
else {
qDebug() << "Warning! Battery is low!";
openLowBatteryDialog();
}
}
@ -342,36 +340,6 @@ MainWindow::MainWindow(QWidget *parent)
} );
batteryWatchdog->start();
// USB mass storage prompt
QTimer *usbmsPrompt = new QTimer(this);
usbmsPrompt->setInterval(500);
connect(usbmsPrompt, &QTimer::timeout, [&]() {
if(checkconfig("/opt/inkbox_genuine") == true) {
if(global::usbms::showUsbmsDialog != true) {
if(isUsbPluggedIn() != usbmsStatus) {
global::usbms::showUsbmsDialog = true;
}
}
else {
usbmsStatus = isUsbPluggedIn();
if(usbmsStatus == false) {
// Loop again...
;
}
else {
// An USB cable is connected!
setBatteryIcon();
openUsbmsDialog();
}
}
}
else {
// Do nothing, we're running along with Nickel & friends...
;
}
} );
usbmsPrompt->start();
// We set the brightness level saved in the config file
QTimer::singleShot(2000, this, SLOT(setInitialBrightness()));
@ -522,9 +490,6 @@ MainWindow::MainWindow(QWidget *parent)
}
}
// Check for an update and ask if the user wants to install it
checkForUpdate();
// Check if it's the first boot since an update and confirm that it installed successfully
if(checkconfig("/opt/inkbox_genuine") == true) {
if(checkconfig("/external_root/opt/update/inkbox_updated") == true) {
@ -540,6 +505,38 @@ MainWindow::MainWindow(QWidget *parent)
}
}
// Check for an update and ask if the user wants to install it
checkForUpdate();
// USB mass storage prompt
QTimer *usbmsPrompt = new QTimer(this);
usbmsPrompt->setInterval(500);
connect(usbmsPrompt, &QTimer::timeout, [&]() {
if(checkconfig("/opt/inkbox_genuine") == true) {
if(global::usbms::showUsbmsDialog != true) {
if(isUsbPluggedIn() != usbmsStatus) {
global::usbms::showUsbmsDialog = true;
}
}
else {
usbmsStatus = isUsbPluggedIn();
if(usbmsStatus == false) {
// Loop again...
;
}
else {
// An USB cable is connected!
setBatteryIcon();
openUsbmsDialog();
}
}
}
else {
// Do nothing, we're running along with Nickel & friends...
;
}
} );
usbmsPrompt->start();
// If the DEVKEY file is present, install a developer key
if(QFile::exists("/mnt/onboard/onboard/.inkbox/DEVKEY") == true && QFile::exists("/mnt/onboard/onboard/.inkbox/DEVKEY.dgst") == true) {
string_checkconfig_ro("/mnt/onboard/onboard/.inkbox/DEVKEY");
@ -790,8 +787,7 @@ void MainWindow::setBatteryIcon() {
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
// Checking battery level and status, then displaying the relevant icon on batteryIconLabel
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
if(isUsbPluggedIn() == true) {
ui->batteryIcon->setPixmap(scaledChargingPixmap);
}
else {
@ -821,8 +817,7 @@ void MainWindow::setBatteryIcon() {
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
// Checking battery level and status, then displaying the relevant icon on batteryIconLabel
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
if(isUsbPluggedIn() == true) {
ui->batteryIcon->setPixmap(scaledChargingPixmap);
}
else {

View file

@ -616,15 +616,13 @@ reader::reader(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...
;
}
@ -668,12 +666,11 @@ reader::reader(QWidget *parent) :
;
}
else {
qDebug() << "Warning! Battery is low!";
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
if(isUsbPluggedIn()) {
;
}
else {
qDebug() << "Warning! Battery is low!";
openLowBatteryDialog();
}
}
@ -1341,8 +1338,7 @@ void reader::alignText(int alignment) {
void reader::menubar_show() {
// Checking battery level and status, then displaying the relevant icon on batteryIconLabel
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
if(isUsbPluggedIn() == true) {
ui->batteryIconLabel->setPixmap(scaledChargingPixmap);
}
else {