From 3b61530507c9c24ba9ff50d4955ce56aa094ae7c Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Fri, 25 Jun 2021 22:09:42 -0400 Subject: [PATCH] Kobo Glo: methods to set brightness --- brightnessdialog.cpp | 18 ++++++++++++++++-- brightnessdialog.h | 1 + functions.h | 18 ++++++++++++++++++ mainwindow.cpp | 16 +++++++++++++++- mainwindow.h | 2 ++ reader.cpp | 18 ++++++++++++++++-- reader.h | 1 + 7 files changed, 69 insertions(+), 5 deletions(-) diff --git a/brightnessdialog.cpp b/brightnessdialog.cpp index 23f05f6..52f40d2 100644 --- a/brightnessdialog.cpp +++ b/brightnessdialog.cpp @@ -63,7 +63,7 @@ brightnessDialog::~brightnessDialog() void brightnessDialog::on_quitBtn_clicked() { // Reverting back to the old value - set_brightness(oldValue); + pre_set_brightness(oldValue); // Just in case ;) brightness_writeconfig(oldValue); @@ -74,7 +74,7 @@ void brightnessDialog::on_quitBtn_clicked() void brightnessDialog::on_horizontalSlider_valueChanged(int value) { - set_brightness(value); + pre_set_brightness(value); QString valueStr = QString::number(value); valueStr = valueStr.append("%"); ui->valueLabel->setText(valueStr); @@ -105,3 +105,17 @@ void brightnessDialog::on_okBtn_clicked() // Leaving brightnessDialog::close(); } + +void brightnessDialog::pre_set_brightness(int brightnessValue) { + if(deviceChecked == false) { + checkDevice(); + deviceChecked = true; + } + + if(device == "n705\n" or device == "n905\n") { + set_brightness(brightnessValue); + } + else { + set_brightness_ntxio(brightnessValue); + } +} diff --git a/brightnessdialog.h b/brightnessdialog.h index ba10238..ab339e9 100644 --- a/brightnessdialog.h +++ b/brightnessdialog.h @@ -16,6 +16,7 @@ class brightnessDialog : public QDialog public: QString checkconfig_str_val; int oldValue; + void pre_set_brightness(int brightnessValue); explicit brightnessDialog(QWidget *parent = nullptr); ~brightnessDialog(); diff --git a/functions.h b/functions.h index b5f5e59..a6e2a66 100644 --- a/functions.h +++ b/functions.h @@ -10,6 +10,10 @@ #include #include +#include +#include +#include + // WoW, global variables and namespaces are awesome namespace global { namespace battery { @@ -61,12 +65,14 @@ namespace global { namespace { QString checkconfig_str_val; QString deviceUID; + QString device; QString batt_level; QString kernelVersion; int batt_level_int; int defaultEpubPageWidth; int defaultEpubPageHeight; bool checked_box = false; + bool deviceChecked = false; bool checkconfig(QString file) { QFile config(file); config.open(QIODevice::ReadOnly); @@ -122,6 +128,14 @@ namespace { fhandler << value; fhandler.close(); } + void set_brightness_ntxio(int value) { + // Thanks to Kevin Short for this (GloLight) + int light; + if ((light = open("/dev/ntx_io", O_RDWR)) == -1) { + printf("Error opening ntx_io device"); + } + ioctl(light, 241, value); + } int int_checkconfig(QString file) { QFile int_config(file); int_config.open(QIODevice::ReadOnly); @@ -342,5 +356,9 @@ namespace { defaultEpubPageWidth = 425; } } + QString checkDevice() { + string_checkconfig_ro("/opt/inkbox_device"); + return checkconfig_str_val; + } } #endif // FUNCTIONS_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 1b0f51b..d7a6ba5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -321,7 +321,7 @@ MainWindow::MainWindow(QWidget *parent) // We set the brightness level saved in the config file int brightness_value = brightness_checkconfig(".config/03-brightness/config"); - set_brightness(brightness_value); + pre_set_brightness(brightness_value); // Display quote if requested; otherwise, display recent books string_checkconfig(".config/05-quote/config"); @@ -759,3 +759,17 @@ void MainWindow::setBatteryIcon() { } } } + +void MainWindow::pre_set_brightness(int brightnessValue) { + if(deviceChecked == false) { + checkDevice(); + deviceChecked = true; + } + + if(device == "n705\n" or device == "n905\n") { + set_brightness(brightnessValue); + } + else { + set_brightness_ntxio(brightnessValue); + } +} diff --git a/mainwindow.h b/mainwindow.h index b397add..13c3ef9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -49,6 +49,7 @@ public: void resetWindow(bool resetStackedWidget); void resetIcons(); void setBatteryIcon(); + void pre_set_brightness(); public slots: @@ -65,6 +66,7 @@ private slots: void on_brightnessBtn_clicked(); void openUpdateDialog(); void on_homeBtn_clicked(); + void pre_set_brightness(int brightnessValue); private: Ui::MainWindow *ui; diff --git a/reader.cpp b/reader.cpp index b314a11..7420b57 100644 --- a/reader.cpp +++ b/reader.cpp @@ -812,7 +812,7 @@ void reader::on_brightnessDecBtn_clicked() { int bval = get_brightness(); int set_bval = bval - 1; - set_brightness(set_bval); + pre_set_brightness(set_bval); brightness_writeconfig(set_bval); bval = get_brightness(); @@ -823,7 +823,7 @@ void reader::on_brightnessIncBtn_clicked() { int bval = get_brightness(); int set_bval = bval + 1; - set_brightness(set_bval); + pre_set_brightness(set_bval); brightness_writeconfig(set_bval); bval = get_brightness(); @@ -1353,3 +1353,17 @@ void reader::on_nightModeBtn_clicked() isNightModeActive = true; } } + +void reader::pre_set_brightness(int brightnessValue) { + if(deviceChecked == false) { + checkDevice(); + deviceChecked = true; + } + + if(device == "n705\n" or device == "n905\n") { + set_brightness(brightnessValue); + } + else { + set_brightness_ntxio(brightnessValue); + } +} diff --git a/reader.h b/reader.h index d13d073..9b2e6ac 100644 --- a/reader.h +++ b/reader.h @@ -91,6 +91,7 @@ public: void setPageStyle(); void alignText(int alignment); void delay(int seconds); + void pre_set_brightness(int brightnessValue); private slots: void on_nextBtn_clicked();