mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
N249: Make battery level display work
This commit is contained in:
parent
09872f052c
commit
9fce504d64
6 changed files with 37 additions and 42 deletions
|
@ -215,9 +215,9 @@ namespace global {
|
||||||
namespace {
|
namespace {
|
||||||
QString deviceUID;
|
QString deviceUID;
|
||||||
QString device;
|
QString device;
|
||||||
QString batt_level;
|
QString batteryLevel;
|
||||||
QString kernelVersion;
|
QString kernelVersion;
|
||||||
int batt_level_int;
|
int batteryLevelInt;
|
||||||
int defaultEpubPageWidth;
|
int defaultEpubPageWidth;
|
||||||
int defaultEpubPageHeight;
|
int defaultEpubPageHeight;
|
||||||
int defaultPdfPageWidth;
|
int defaultPdfPageWidth;
|
||||||
|
@ -388,31 +388,27 @@ namespace {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void getBatteryLevel() {
|
void getBatteryLevel() {
|
||||||
QString batteryLevelFileQstr;
|
batteryLevelInt = 100;
|
||||||
|
batteryLevel = "100%";
|
||||||
if(global::deviceID == "kt\n") {
|
if(global::deviceID == "kt\n") {
|
||||||
QFile batt_level_file("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity");
|
if(QFile::exists("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity")) {
|
||||||
if(batt_level_file.exists()) {
|
batteryLevel = readFile("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity").trimmed();
|
||||||
batt_level_file.open(QIODevice::ReadOnly);
|
batteryLevelInt = batteryLevel.toInt();
|
||||||
batt_level = batt_level_file.readAll();
|
batteryLevel.append("%");
|
||||||
batt_level = batt_level.trimmed();
|
}
|
||||||
batt_level_int = batt_level.toInt();
|
}
|
||||||
batt_level = batt_level.append("%");
|
else if(global::deviceID == "n249\n") {
|
||||||
batt_level_file.close();
|
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 {
|
else {
|
||||||
QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity");
|
if(QFile::exists("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity")) {
|
||||||
if(batt_level_file.exists()) {
|
batteryLevel = readFile("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity").trimmed();
|
||||||
batt_level_file.open(QIODevice::ReadOnly);
|
batteryLevelInt = batteryLevel.toInt();
|
||||||
batt_level = batt_level_file.readAll();
|
batteryLevel.append("%");
|
||||||
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%";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -445,7 +441,7 @@ namespace {
|
||||||
bool isBatteryLow() {
|
bool isBatteryLow() {
|
||||||
// Checks if battery level is under 15% of total capacity.
|
// Checks if battery level is under 15% of total capacity.
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
if(batt_level_int <= 15) {
|
if(batteryLevelInt <= 15) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -456,7 +452,7 @@ namespace {
|
||||||
bool isBatteryCritical() {
|
bool isBatteryCritical() {
|
||||||
// Checks if the battery level is critical (i.e. <= 5%)
|
// Checks if the battery level is critical (i.e. <= 5%)
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
if(batt_level_int <= 5) {
|
if(batteryLevelInt <= 5) {
|
||||||
QString function = __func__; log(function + ": Battery is at a critical charge level!", "functions");
|
QString function = __func__; log(function + ": Battery is at a critical charge level!", "functions");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -815,7 +811,7 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(global::deviceID == "n249\n") {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -201,7 +201,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
QString time = QTime::currentTime().toString("hh:mm:ss");
|
QString time = QTime::currentTime().toString("hh:mm:ss");
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
ui->timeLabel->setText(time);
|
ui->timeLabel->setText(time);
|
||||||
ui->batteryLabel->setText(batt_level);
|
ui->batteryLabel->setText(batteryLevel);
|
||||||
} );
|
} );
|
||||||
t->start();
|
t->start();
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
QString time = QTime::currentTime().toString("hh:mm");
|
QString time = QTime::currentTime().toString("hh:mm");
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
ui->timeLabel->setText(time);
|
ui->timeLabel->setText(time);
|
||||||
ui->batteryLabel->setText(batt_level);
|
ui->batteryLabel->setText(batteryLevel);
|
||||||
} );
|
} );
|
||||||
t->start();
|
t->start();
|
||||||
}
|
}
|
||||||
|
@ -666,13 +666,13 @@ void MainWindow::setBatteryIcon() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
if(batt_level_int >= 75 && batt_level_int <= 100) {
|
if(batteryLevelInt >= 75 && batteryLevelInt <= 100) {
|
||||||
ui->batteryIcon->setPixmap(scaledFullPixmap);
|
ui->batteryIcon->setPixmap(scaledFullPixmap);
|
||||||
}
|
}
|
||||||
else if(batt_level_int >= 25 && batt_level_int <= 74) {
|
else if(batteryLevelInt >= 25 && batteryLevelInt <= 74) {
|
||||||
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
||||||
}
|
}
|
||||||
else if(batt_level_int >= 0 && batt_level_int <= 24) {
|
else if(batteryLevelInt >= 0 && batteryLevelInt <= 24) {
|
||||||
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -696,13 +696,13 @@ void MainWindow::setBatteryIcon() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
if(batt_level_int >= 75 && batt_level_int <= 100) {
|
if(batteryLevelInt >= 75 && batteryLevelInt <= 100) {
|
||||||
ui->batteryIcon->setPixmap(scaledFullPixmap);
|
ui->batteryIcon->setPixmap(scaledFullPixmap);
|
||||||
}
|
}
|
||||||
else if(batt_level_int >= 25 && batt_level_int <= 74) {
|
else if(batteryLevelInt >= 25 && batteryLevelInt <= 74) {
|
||||||
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
||||||
}
|
}
|
||||||
else if(batt_level_int >= 0 && batt_level_int <= 24) {
|
else if(batteryLevelInt >= 0 && batteryLevelInt <= 24) {
|
||||||
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,7 +397,7 @@ reader::reader(QWidget *parent) :
|
||||||
connect(t, &QTimer::timeout, [&]() {
|
connect(t, &QTimer::timeout, [&]() {
|
||||||
QString time = QTime::currentTime().toString("hh:mm:ss");
|
QString time = QTime::currentTime().toString("hh:mm:ss");
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
ui->batteryLabel->setText(batt_level);
|
ui->batteryLabel->setText(batteryLevel);
|
||||||
ui->timeLabel->setText(time);
|
ui->timeLabel->setText(time);
|
||||||
} );
|
} );
|
||||||
t->start();
|
t->start();
|
||||||
|
@ -408,7 +408,7 @@ reader::reader(QWidget *parent) :
|
||||||
connect(t, &QTimer::timeout, [&]() {
|
connect(t, &QTimer::timeout, [&]() {
|
||||||
QString time = QTime::currentTime().toString("hh:mm");
|
QString time = QTime::currentTime().toString("hh:mm");
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
ui->batteryLabel->setText(batt_level);
|
ui->batteryLabel->setText(batteryLevel);
|
||||||
ui->timeLabel->setText(time);
|
ui->timeLabel->setText(time);
|
||||||
} );
|
} );
|
||||||
t->start();
|
t->start();
|
||||||
|
@ -1360,13 +1360,13 @@ void reader::menubar_show() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
if(batt_level_int >= 75 && batt_level_int <= 100) {
|
if(batteryLevelInt >= 75 && batteryLevelInt <= 100) {
|
||||||
ui->batteryIconLabel->setPixmap(scaledFullPixmap);
|
ui->batteryIconLabel->setPixmap(scaledFullPixmap);
|
||||||
}
|
}
|
||||||
if(batt_level_int >= 25 && batt_level_int <= 74) {
|
if(batteryLevelInt >= 25 && batteryLevelInt <= 74) {
|
||||||
ui->batteryIconLabel->setPixmap(scaledHalfPixmap);
|
ui->batteryIconLabel->setPixmap(scaledHalfPixmap);
|
||||||
}
|
}
|
||||||
if(batt_level_int >= 0 && batt_level_int <= 24) {
|
if(batteryLevelInt >= 0 && batteryLevelInt <= 24) {
|
||||||
ui->batteryIconLabel->setPixmap(scaledEmptyPixmap);
|
ui->batteryIconLabel->setPixmap(scaledEmptyPixmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,6 @@ public:
|
||||||
bool goToSavedPageDone;
|
bool goToSavedPageDone;
|
||||||
QString ittext;
|
QString ittext;
|
||||||
QString book_file;
|
QString book_file;
|
||||||
bool batt_status;
|
|
||||||
QString selected_text;
|
QString selected_text;
|
||||||
QString word;
|
QString word;
|
||||||
QString words; // Saved words
|
QString words; // Saved words
|
||||||
|
|
|
@ -88,7 +88,7 @@ void usbmsSplash::usbmsLaunch()
|
||||||
writeFile("/opt/ibxd", "gui_apps_stop\n");
|
writeFile("/opt/ibxd", "gui_apps_stop\n");
|
||||||
QThread::msleep(1000);
|
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/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/libcomposite.ko");
|
||||||
QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/function/usb_f_mass_storage.ko");
|
QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/function/usb_f_mass_storage.ko");
|
||||||
|
|
|
@ -124,7 +124,7 @@ generalDialog::generalDialog(QWidget *parent) :
|
||||||
ui->stackedWidget->setCurrentIndex(1);
|
ui->stackedWidget->setCurrentIndex(1);
|
||||||
getBatteryLevel();
|
getBatteryLevel();
|
||||||
QString message = "The battery's level is low.\nPlease charge your eReader.\nCurrent level: ";
|
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->bodyLabel->setText(message);
|
||||||
ui->headerLabel->setText("Low battery");
|
ui->headerLabel->setText("Low battery");
|
||||||
QTimer::singleShot(50, this, SLOT(adjust_size()));
|
QTimer::singleShot(50, this, SLOT(adjust_size()));
|
||||||
|
|
Loading…
Reference in a new issue