Implement cinematic brightness between book and Home if local settings enabled

This commit is contained in:
Nicolas Mailloux 2022-04-15 22:28:25 -04:00
parent 239ac55bd7
commit 105b13cb86
3 changed files with 36 additions and 7 deletions

View file

@ -614,10 +614,12 @@ namespace {
} }
} }
void cinematicBrightness(int value, int mode) { void cinematicBrightness(int value, int mode) {
/* mode can be 0 or 1, respectively /* mode can be 0, 1, or 2, respectively:
* 0: Bring UP brightness * 0: Bring UP brightness
* 1: Bring DOWN brightness * 1: Bring DOWN brightness
* 2: Auto; smooth brightness transition between two brightness levels
*/ */
QString function = __func__; log(function + ": Setting brightness to " + QString::number(value), "functions");
if(mode == 0) { if(mode == 0) {
int brightness = 0; int brightness = 0;
while(brightness != value) { while(brightness != value) {
@ -626,7 +628,7 @@ namespace {
QThread::msleep(30); QThread::msleep(30);
} }
} }
else { else if(mode == 1) {
int brightness = get_brightness(); int brightness = get_brightness();
while(brightness != 0) { while(brightness != 0) {
brightness = brightness - 1; brightness = brightness - 1;
@ -634,6 +636,23 @@ namespace {
QThread::msleep(30); QThread::msleep(30);
} }
} }
else if(mode == 2) {
int brightness = get_brightness();
if(brightness <= value) {
while(brightness != value) {
brightness = brightness + 1;
pre_set_brightness(brightness);
QThread::msleep(30);
}
}
else if(brightness >= value) {
while(brightness != value) {
brightness = brightness - 1;
pre_set_brightness(brightness);
QThread::msleep(30);
}
}
}
} }
bool connectToNetwork(QString essid, QString passphrase) { bool connectToNetwork(QString essid, QString passphrase) {
log("Connecting to network " + essid, "functions"); log("Connecting to network " + essid, "functions");

View file

@ -879,17 +879,25 @@ void MainWindow::setInitialBrightness() {
if(global::deviceID != "n705\n" and global::deviceID != "n905\n") { if(global::deviceID != "n705\n" and global::deviceID != "n905\n") {
log("Setting initial brightness to " + QString::number(brightness_value), className); log("Setting initial brightness to " + QString::number(brightness_value), className);
} }
if(checkconfig("/tmp/oobe-inkbox_completed") == true or checkconfig("/tmp/inkbox-cinematicBrightness_ran") == true) { if(checkconfig("/tmp/oobe-inkbox_completed") == true) {
// Coming from OOBE setup; not doing that fancy stuff again ;p // Coming from OOBE setup; not doing that fancy stuff again ;p
QFile::remove("/tmp/oobe-inkbox_completed"); QFile::remove("/tmp/oobe-inkbox_completed");
pre_set_brightness(brightness_value); pre_set_brightness(brightness_value);
} }
else { else {
// Fancy brightness fade-in // Fancy brightness fade-in
if(checkconfig("/tmp/inkbox-cinematic_brightness_auto") == true) {
QFile::remove("/tmp/inkbox-cinematic_brightness_auto");
cinematicBrightness(brightness_value, 2);
}
else {
if(checkconfig("/tmp/inkbox-cinematicBrightness_ran") == false) {
string_writeconfig("/tmp/inkbox-cinematicBrightness_ran", "true"); string_writeconfig("/tmp/inkbox-cinematicBrightness_ran", "true");
cinematicBrightness(brightness_value, 0); cinematicBrightness(brightness_value, 0);
} }
} }
}
}
void MainWindow::refreshScreen() { void MainWindow::refreshScreen() {
this->repaint(); this->repaint();

View file

@ -249,8 +249,8 @@ reader::reader(QWidget *parent) :
if(global::reader::globalReadingSettings == false) { if(global::reader::globalReadingSettings == false) {
if(global::deviceID != "n705\n" and global::deviceID != "n905\n") { if(global::deviceID != "n705\n" and global::deviceID != "n905\n") {
int brightness_value = brightness_checkconfig(".config/03-brightness/config"); int brightness_value = brightness_checkconfig(".config/03-brightness/config");
log("Local Reading Settings: setting brightness to " + QString::number(brightness_value), className); log("Local Reading Settings: Setting brightness to " + QString::number(brightness_value), className);
pre_set_brightness(brightness_value); cinematicBrightness(brightness_value, 2);
} }
} }
// Font // Font
@ -1229,6 +1229,8 @@ void reader::on_homeBtn_clicked()
string_writeconfig("/tmp/inkboxReading", "false"); string_writeconfig("/tmp/inkboxReading", "false");
// Remount tmpfs // Remount tmpfs
string_writeconfig("/inkbox/remount", "true"); string_writeconfig("/inkbox/remount", "true");
// Specify cinematic brightness mode
string_writeconfig("/tmp/inkbox-cinematic_brightness_auto", "true");
// Relaunching process // Relaunching process
quit_restart(); quit_restart();