N249: Make battery level display work

This commit is contained in:
Nicolas Mailloux 2023-07-20 20:58:26 -04:00
parent 09872f052c
commit 9fce504d64
6 changed files with 37 additions and 42 deletions

View file

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

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -80,7 +80,6 @@ public:
bool goToSavedPageDone;
QString ittext;
QString book_file;
bool batt_status;
QString selected_text;
QString word;
QString words; // Saved words

View file

@ -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");

View file

@ -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()));