Glo: cinematicBrightness for a nice brightness fade-in

This commit is contained in:
Nicolas Mailloux 2021-06-28 15:26:04 -04:00
parent 01ee2eaf87
commit ae0284bed2
6 changed files with 69 additions and 43 deletions

View file

@ -83,7 +83,7 @@ brightnessDialog::~brightnessDialog()
void brightnessDialog::on_quitBtn_clicked()
{
// Reverting back to the old value
pre_set_brightness(oldValue);
brightnessDialog::pre_set_brightness(oldValue);
// Just in case ;)
brightness_writeconfig(oldValue);
@ -94,7 +94,7 @@ void brightnessDialog::on_quitBtn_clicked()
void brightnessDialog::on_horizontalSlider_valueChanged(int value)
{
pre_set_brightness(value);
brightnessDialog::pre_set_brightness(value);
QString valueStr = QString::number(value);
valueStr = valueStr.append("%");
ui->valueLabel->setText(valueStr);

View file

@ -117,15 +117,6 @@ namespace {
return content_int;
config.close();
return 0;
};
int get_brightness() {
QFile brightness("/var/run/brightness");
brightness.open(QIODevice::ReadOnly);
QString valuestr = brightness.readAll();
int value = valuestr.toInt();
brightness.close();
return value;
return 0;
}
void set_brightness(int value) {
std::ofstream fhandler;
@ -192,6 +183,29 @@ namespace {
fhandler << value;
fhandler.close();
}
int get_brightness() {
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n613") {
string_checkconfig_ro(".config/03-brightness/config");
int brightness;
if(checkconfig_str_val == "") {
brightness = 0;
}
else {
brightness = checkconfig_str_val.toInt();
}
return brightness;
}
else {
QFile brightness("/var/run/brightness");
brightness.open(QIODevice::ReadOnly);
QString valuestr = brightness.readAll();
int value = valuestr.toInt();
brightness.close();
return value;
}
return 0;
}
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);
@ -379,5 +393,40 @@ namespace {
defaultEpubPageWidth = 450;
}
}
void pre_set_brightness(int brightnessValue) {
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
set_brightness(brightnessValue);
}
else if(checkconfig_str_val == "n613\n") {
set_brightness_ntxio(brightnessValue);
}
else {
set_brightness(brightnessValue);
}
}
void cinematicBrightness(int value, int mode) {
/* mode can be 0 or 1, respectively
* 0: Bring UP brightness
* 1: Bring DOWN brightness
*/
if(mode == 0) {
int brightness = 0;
while(brightness != value) {
brightness = brightness + 1;
pre_set_brightness(brightness);
QThread::msleep(33);
}
}
else {
int brightness = get_brightness();
while(brightness != 0) {
brightness = brightness - 1;
pre_set_brightness(brightness);
QThread::msleep(33);
}
}
}
}
#endif // FUNCTIONS_H

View file

@ -345,7 +345,15 @@ MainWindow::MainWindow(QWidget *parent)
// We set the brightness level saved in the config file
int brightness_value = brightness_checkconfig(".config/03-brightness/config");
pre_set_brightness(brightness_value);
if(checkconfig("/tmp/oobe-inkbox_completed") == true) {
// Coming from OOBE setup; not doing that fancy stuff again ;p
QFile::remove("/tmp/oobe-inkbox_completed");
pre_set_brightness(brightness_value);
}
else {
// Fancy brightness fade-in
cinematicBrightness(brightness_value, 0);
}
// Display quote if requested; otherwise, display recent books
string_checkconfig(".config/05-quote/config");
@ -786,17 +794,3 @@ void MainWindow::setBatteryIcon() {
}
}
}
void MainWindow::pre_set_brightness(int brightnessValue) {
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
set_brightness(brightnessValue);
}
else if(checkconfig_str_val == "n613\n") {
set_brightness_ntxio(brightnessValue);
}
else {
set_brightness(brightnessValue);
}
}

View file

@ -49,7 +49,6 @@ public:
void resetWindow(bool resetStackedWidget);
void resetIcons();
void setBatteryIcon();
void pre_set_brightness();
public slots:
@ -66,7 +65,6 @@ private slots:
void on_brightnessBtn_clicked();
void openUpdateDialog();
void on_homeBtn_clicked();
void pre_set_brightness(int brightnessValue);
private:
Ui::MainWindow *ui;

View file

@ -1400,17 +1400,3 @@ void reader::on_nightModeBtn_clicked()
isNightModeActive = true;
}
}
void reader::pre_set_brightness(int brightnessValue) {
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
set_brightness(brightnessValue);
}
else if(checkconfig_str_val == "n613\n") {
set_brightness_ntxio(brightnessValue);
}
else {
set_brightness(brightnessValue);
}
}

View file

@ -91,7 +91,6 @@ public:
void setPageStyle();
void alignText(int alignment);
void delay(int seconds);
void pre_set_brightness(int brightnessValue);
private slots:
void on_nextBtn_clicked();