tici: remove hardcoded max brightness (#26859)

* tici: remove hardcoded max brightness

* fix that one

* cleanup

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh
2023-01-01 19:47:02 -08:00
committed by GitHub
parent 3d44b6b3ac
commit 922bedaf47
2 changed files with 12 additions and 3 deletions
+3 -1
View File
@@ -25,9 +25,11 @@ public:
static void reboot() { std::system("sudo reboot"); };
static void poweroff() { std::system("sudo poweroff"); };
static void set_brightness(int percent) {
std::string max = util::read_file("/sys/class/backlight/panel0-backlight/max_brightness");
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness");
if (brightness_control.is_open()) {
brightness_control << (percent * (int)(1023/100.)) << "\n";
brightness_control << (int)(percent * (std::stof(max)/100.)) << "\n";
brightness_control.close();
}
};
+9 -2
View File
@@ -395,15 +395,22 @@ class Tici(HardwareBase):
def set_screen_brightness(self, percentage):
try:
with open("/sys/class/backlight/panel0-backlight/max_brightness") as f:
max_brightness = float(f.read().strip())
val = int(percentage * (max_brightness / 100.))
with open("/sys/class/backlight/panel0-backlight/brightness", "w") as f:
f.write(str(int(percentage * 10.23)))
f.write(str(val))
except Exception:
pass
def get_screen_brightness(self):
try:
with open("/sys/class/backlight/panel0-backlight/max_brightness") as f:
max_brightness = float(f.read().strip())
with open("/sys/class/backlight/panel0-backlight/brightness") as f:
return int(float(f.read()) / 10.23)
return int(float(f.read()) / (max_brightness / 100.))
except Exception:
return 0