From 9fce504d6450a18d205e5122a0ac17b106c78ce6 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Thu, 20 Jul 2023 20:58:26 -0400 Subject: [PATCH] N249: Make battery level display work --- src/functions.h | 48 ++++++++++++--------------- src/homeWidget/mainwindow.cpp | 16 ++++----- src/reader/reader.cpp | 10 +++--- src/reader/reader.h | 1 - src/splash/usbmsSplash.cpp | 2 +- src/widgets/dialogs/generaldialog.cpp | 2 +- 6 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/functions.h b/src/functions.h index f325e3b..42b371f 100644 --- a/src/functions.h +++ b/src/functions.h @@ -215,9 +215,9 @@ namespace global { namespace { QString deviceUID; QString device; - QString batt_level; + QString batteryLevel; QString kernelVersion; - int batt_level_int; + int batteryLevelInt; int defaultEpubPageWidth; int defaultEpubPageHeight; int defaultPdfPageWidth; @@ -388,31 +388,27 @@ namespace { return 0; } void getBatteryLevel() { - QString batteryLevelFileQstr; + batteryLevelInt = 100; + batteryLevel = "100%"; if(global::deviceID == "kt\n") { - QFile batt_level_file("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity"); - if(batt_level_file.exists()) { - batt_level_file.open(QIODevice::ReadOnly); - batt_level = batt_level_file.readAll(); - batt_level = batt_level.trimmed(); - batt_level_int = batt_level.toInt(); - batt_level = batt_level.append("%"); - batt_level_file.close(); + if(QFile::exists("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity")) { + batteryLevel = readFile("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity").trimmed(); + batteryLevelInt = batteryLevel.toInt(); + batteryLevel.append("%"); + } + } + else if(global::deviceID == "n249\n") { + if(QFile::exists("/sys/class/power_supply/rn5t618-battery/capacity")) { + batteryLevel = readFile("/sys/class/power_supply/rn5t618-battery/capacity").trimmed(); + batteryLevelInt = batteryLevel.toInt(); + batteryLevel.append("%"); } } else { - QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity"); - if(batt_level_file.exists()) { - batt_level_file.open(QIODevice::ReadOnly); - batt_level = batt_level_file.readAll(); - batt_level = batt_level.trimmed(); - batt_level_int = batt_level.toInt(); - batt_level = batt_level.append("%"); - batt_level_file.close(); - } - else { - batt_level_int = 100; - batt_level = "100%"; + if(QFile::exists("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity")) { + batteryLevel = readFile("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity").trimmed(); + batteryLevelInt = batteryLevel.toInt(); + batteryLevel.append("%"); } } } @@ -445,7 +441,7 @@ namespace { bool isBatteryLow() { // Checks if battery level is under 15% of total capacity. getBatteryLevel(); - if(batt_level_int <= 15) { + if(batteryLevelInt <= 15) { return true; } else { @@ -456,7 +452,7 @@ namespace { bool isBatteryCritical() { // Checks if the battery level is critical (i.e. <= 5%) getBatteryLevel(); - if(batt_level_int <= 5) { + if(batteryLevelInt <= 5) { QString function = __func__; log(function + ": Battery is at a critical charge level!", "functions"); return true; } @@ -815,7 +811,7 @@ namespace { } } else if(global::deviceID == "n249\n") { - if(readFile("/sys/class/udc/ci_hdrc.0/state") != "not attached\n") { + if(readFile("/sys/class/power_supply/rn5t618-battery/status") != "Not charging\n") { return 1; } else { diff --git a/src/homeWidget/mainwindow.cpp b/src/homeWidget/mainwindow.cpp index cdd1eb3..96001b3 100644 --- a/src/homeWidget/mainwindow.cpp +++ b/src/homeWidget/mainwindow.cpp @@ -201,7 +201,7 @@ MainWindow::MainWindow(QWidget *parent) QString time = QTime::currentTime().toString("hh:mm:ss"); getBatteryLevel(); ui->timeLabel->setText(time); - ui->batteryLabel->setText(batt_level); + ui->batteryLabel->setText(batteryLevel); } ); t->start(); } @@ -212,7 +212,7 @@ MainWindow::MainWindow(QWidget *parent) QString time = QTime::currentTime().toString("hh:mm"); getBatteryLevel(); ui->timeLabel->setText(time); - ui->batteryLabel->setText(batt_level); + ui->batteryLabel->setText(batteryLevel); } ); t->start(); } @@ -666,13 +666,13 @@ void MainWindow::setBatteryIcon() { } else { getBatteryLevel(); - if(batt_level_int >= 75 && batt_level_int <= 100) { + if(batteryLevelInt >= 75 && batteryLevelInt <= 100) { ui->batteryIcon->setPixmap(scaledFullPixmap); } - else if(batt_level_int >= 25 && batt_level_int <= 74) { + else if(batteryLevelInt >= 25 && batteryLevelInt <= 74) { ui->batteryIcon->setPixmap(scaledHalfPixmap); } - else if(batt_level_int >= 0 && batt_level_int <= 24) { + else if(batteryLevelInt >= 0 && batteryLevelInt <= 24) { ui->batteryIcon->setPixmap(scaledEmptyPixmap); } } @@ -696,13 +696,13 @@ void MainWindow::setBatteryIcon() { } else { getBatteryLevel(); - if(batt_level_int >= 75 && batt_level_int <= 100) { + if(batteryLevelInt >= 75 && batteryLevelInt <= 100) { ui->batteryIcon->setPixmap(scaledFullPixmap); } - else if(batt_level_int >= 25 && batt_level_int <= 74) { + else if(batteryLevelInt >= 25 && batteryLevelInt <= 74) { ui->batteryIcon->setPixmap(scaledHalfPixmap); } - else if(batt_level_int >= 0 && batt_level_int <= 24) { + else if(batteryLevelInt >= 0 && batteryLevelInt <= 24) { ui->batteryIcon->setPixmap(scaledEmptyPixmap); } } diff --git a/src/reader/reader.cpp b/src/reader/reader.cpp index 73f4d7e..13533ed 100644 --- a/src/reader/reader.cpp +++ b/src/reader/reader.cpp @@ -397,7 +397,7 @@ reader::reader(QWidget *parent) : connect(t, &QTimer::timeout, [&]() { QString time = QTime::currentTime().toString("hh:mm:ss"); getBatteryLevel(); - ui->batteryLabel->setText(batt_level); + ui->batteryLabel->setText(batteryLevel); ui->timeLabel->setText(time); } ); t->start(); @@ -408,7 +408,7 @@ reader::reader(QWidget *parent) : connect(t, &QTimer::timeout, [&]() { QString time = QTime::currentTime().toString("hh:mm"); getBatteryLevel(); - ui->batteryLabel->setText(batt_level); + ui->batteryLabel->setText(batteryLevel); ui->timeLabel->setText(time); } ); t->start(); @@ -1360,13 +1360,13 @@ void reader::menubar_show() { } else { getBatteryLevel(); - if(batt_level_int >= 75 && batt_level_int <= 100) { + if(batteryLevelInt >= 75 && batteryLevelInt <= 100) { ui->batteryIconLabel->setPixmap(scaledFullPixmap); } - if(batt_level_int >= 25 && batt_level_int <= 74) { + if(batteryLevelInt >= 25 && batteryLevelInt <= 74) { ui->batteryIconLabel->setPixmap(scaledHalfPixmap); } - if(batt_level_int >= 0 && batt_level_int <= 24) { + if(batteryLevelInt >= 0 && batteryLevelInt <= 24) { ui->batteryIconLabel->setPixmap(scaledEmptyPixmap); } } diff --git a/src/reader/reader.h b/src/reader/reader.h index 0aab69b..d8d5a7b 100644 --- a/src/reader/reader.h +++ b/src/reader/reader.h @@ -80,7 +80,6 @@ public: bool goToSavedPageDone; QString ittext; QString book_file; - bool batt_status; QString selected_text; QString word; QString words; // Saved words diff --git a/src/splash/usbmsSplash.cpp b/src/splash/usbmsSplash.cpp index 02826e1..0ea1369 100644 --- a/src/splash/usbmsSplash.cpp +++ b/src/splash/usbmsSplash.cpp @@ -88,7 +88,7 @@ void usbmsSplash::usbmsLaunch() writeFile("/opt/ibxd", "gui_apps_stop\n"); QThread::msleep(1000); - if(global::deviceID == "n306\n" or global::deviceID == "n873\n") { + if(global::deviceID == "n306\n" or global::deviceID == "n249\n" or global::deviceID == "n873\n") { QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/fs/configfs/configfs.ko"); QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/libcomposite.ko"); QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/function/usb_f_mass_storage.ko"); diff --git a/src/widgets/dialogs/generaldialog.cpp b/src/widgets/dialogs/generaldialog.cpp index c4c8961..47b7fc4 100644 --- a/src/widgets/dialogs/generaldialog.cpp +++ b/src/widgets/dialogs/generaldialog.cpp @@ -124,7 +124,7 @@ generalDialog::generalDialog(QWidget *parent) : ui->stackedWidget->setCurrentIndex(1); getBatteryLevel(); QString message = "The battery's level is low.\nPlease charge your eReader.\nCurrent level: "; - message.append(batt_level); + message.append(batteryLevel); ui->bodyLabel->setText(message); ui->headerLabel->setText("Low battery"); QTimer::singleShot(50, this, SLOT(adjust_size()));