tici: remove hardcoded max brightness (#26859)

* tici: remove hardcoded max brightness

* fix that one

* cleanup

Co-authored-by: Comma Device <device@comma.ai>
pull/26863/head
Adeeb Shihadeh 2 years ago committed by GitHub
parent 3d44b6b3ac
commit 922bedaf47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      system/hardware/tici/hardware.h
  2. 11
      system/hardware/tici/hardware.py

@ -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();
}
};

@ -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

Loading…
Cancel
Save