tici: set brightness in std::async (#2347)

* set brightness in std::async

* CI
albatross
Willem Melching 2020-10-15 20:48:05 +02:00 committed by GitHub
parent 9e919fb5e0
commit 442f2543e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 13 deletions

View File

@ -3,6 +3,7 @@
#include <cmath>
#include <iostream>
#include <fstream>
#include <future>
#include <signal.h>
#include <QVBoxLayout>
@ -92,29 +93,31 @@ void GLWindow::timerUpdate(){
// Update brightness
float clipped_brightness = std::min(1023.0f, (ui_state->light_sensor*brightness_m) + brightness_b);
smooth_brightness = clipped_brightness * 0.01f + smooth_brightness * 0.99f;
int brightness = smooth_brightness;
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness");
if (brightness_control.is_open()){
brightness_control << int(smooth_brightness) << "\n";
brightness_control.close();
}
ui_update(ui_state);
#ifdef QCOM2
if (ui_state->started != onroad){
onroad = ui_state->started;
timer->setInterval(onroad ? 50 : 1000);
}
int brightness = onroad ? 1023 : 0;
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness");
if (brightness_control.is_open()){
brightness_control << int(brightness) << "\n";
brightness_control.close();
}
if (!ui_state->started){
brightness = 0;
}
#endif
std::async(std::launch::async,
[brightness]{
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness");
if (brightness_control.is_open()){
brightness_control << brightness << "\n";
brightness_control.close();
}
});
ui_update(ui_state);
update();
}