From d3362890bebcfd9be7b9c7bbec29fdfe0c234953 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sun, 28 Mar 2021 22:18:48 -0400 Subject: [PATCH] First steps to control brightness from MainWindow and show battery level/status --- eink.qrc | 1 + mainwindow.cpp | 23 +++- mainwindow.h | 11 ++ mainwindow.ui | 273 +++++++++++++++++++++------------------ resources/frontlight.png | Bin 0 -> 5471 bytes 5 files changed, 179 insertions(+), 129 deletions(-) create mode 100644 resources/frontlight.png diff --git a/eink.qrc b/eink.qrc index 64c2b48..15c62d8 100644 --- a/eink.qrc +++ b/eink.qrc @@ -30,5 +30,6 @@ resources/battery_charging.png resources/alert.png resources/eink_dark.qss + resources/frontlight.png diff --git a/mainwindow.cpp b/mainwindow.cpp index d4a7b23..64a25b4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -30,12 +30,14 @@ MainWindow::MainWindow(QWidget *parent) ui->quitBtn->setProperty("type", "borderless"); ui->searchBtn->setProperty("type", "borderless"); ui->pushButton->setProperty("type", "borderless"); + ui->brightnessBtn->setProperty("type", "borderless"); ui->settingsBtn->setText(""); ui->appsBtn->setText(""); ui->pushButton->setText(""); ui->quitBtn->setText(""); ui->searchBtn->setText(""); + ui->brightnessBtn->setText(""); // Getting the screen's size float sW = QGuiApplication::screens()[0]->size().width(); @@ -44,15 +46,21 @@ MainWindow::MainWindow(QWidget *parent) float stdIconWidth; float stdIconHeight; + float brightnessIconWidth; + float brightnessIconHeight; string_checkconfig("/opt/inkbox_device"); if(checkconfig_str_val == "n705\n") { stdIconWidth = sW / 12; stdIconHeight = sH / 12; + brightnessIconWidth = sW / 30; + brightnessIconHeight = sH / 30; } else { stdIconWidth = sW / 14; stdIconHeight = sH / 14; + brightnessIconWidth = sW / 28; + brightnessIconHeight = sH / 28; } // Setting icons up @@ -67,11 +75,18 @@ MainWindow::MainWindow(QWidget *parent) ui->quitBtn->setIcon(QIcon(":/resources/power.png")); ui->quitBtn->setIconSize(QSize(stdIconWidth, stdIconHeight)); + ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png")); + ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight)); + ui->book1Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->book2Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->book3Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->book4Btn->setStyleSheet("font-size: 11pt; padding: 25px"); + ui->brightnessBtn->setStyleSheet("font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 10px; padding-right: 10px;"); + ui->batteryIcon->setStyleSheet("font-size: 5pt"); + ui->batteryIcon->setText(""); + ui->book1Btn->hide(); ui->book2Btn->hide(); ui->book3Btn->hide(); @@ -167,10 +182,10 @@ MainWindow::MainWindow(QWidget *parent) QTimer *t = new QTimer(this); t->setInterval(500); connect(t, &QTimer::timeout, [&]() { - QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd"); QString time = QTime::currentTime().toString("hh:mm:ss"); + get_battery_level(); ui->timeLabel->setText(time); - ui->dateLabel->setText(date); + ui->batteryLabel->setText(batt_level); } ); t->start(); } @@ -178,10 +193,10 @@ MainWindow::MainWindow(QWidget *parent) QTimer *t = new QTimer(this); t->setInterval(500); connect(t, &QTimer::timeout, [&]() { - QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd"); QString time = QTime::currentTime().toString("hh:mm"); + get_battery_level(); ui->timeLabel->setText(time); - ui->dateLabel->setText(date); + ui->batteryLabel->setText(batt_level); } ); t->start(); } diff --git a/mainwindow.h b/mainwindow.h index 74cf972..d3373c6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -26,8 +26,10 @@ public: bool checked_box = false; bool existing_recent_books = false; bool reboot_after_update = false; + int batt_level_int; QString checkconfig_str_val; QString relative_path; + QString batt_level; bool checkconfig(QString file) { QFile config(file); config.open(QIODevice::ReadOnly); @@ -48,6 +50,15 @@ public: fhandler << config << boolalpha << checked_box << endl; fhandler.close(); } + void get_battery_level() { + QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity"); + 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(); + } int brightness_checkconfig(QString file) { QFile config(file); config.open(QIODevice::ReadWrite); diff --git a/mainwindow.ui b/mainwindow.ui index 74badf8..937ea49 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -17,34 +17,50 @@ - - - - Qt::Horizontal + + + + Brightness - - - 40 - 20 - - - + - - - - Qt::Horizontal + + + + + 11 + - - - 40 - 20 - + + Welcome to InkBox - + + Qt::AlignCenter + + - - + + + + + 75 + true + + + + batteryLevel + + + + + + + batteryIcon + + + + + @@ -67,39 +83,46 @@ - - - - - 11 - + + + + Qt::Horizontal - - Welcome to InkBox + + + 40 + 20 + - - Qt::AlignCenter - - + - - + + - - - - - 11 - 75 - true - + + + + Qt::Horizontal - - date + + + 40 + 20 + + + + + + + + QFrame::Plain + + + Qt::Vertical @@ -140,22 +163,6 @@ - - - - - Chivo - true - - - - Recently read books will appear here. - - - Qt::AlignCenter - - - @@ -185,6 +192,84 @@ + + + + + Chivo + true + + + + Recently read books will appear here. + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 0 + + + + + 0 + + + + + Book 1 + + + + + + + Book 2 + + + + + + + + + 0 + + + + + Book 3 + + + + + + + Book 4 + + + + + + + @@ -277,68 +362,6 @@ - - - - 0 - - - - - 0 - - - - - Book 1 - - - - - - - Book 2 - - - - - - - - - 0 - - - - - Book 3 - - - - - - - Book 4 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/resources/frontlight.png b/resources/frontlight.png new file mode 100644 index 0000000000000000000000000000000000000000..5799f629af5684263123d5cceac9165a9b8027d5 GIT binary patch literal 5471 zcmbuDXH*kRm&cP32wj?jkkCvJ5D}y|2~7x6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