hardware/tici: simplify use of std::ofstream (#34420)

Simplify Use of std::ofstream
pull/34425/head
Dean Lee 3 months ago committed by GitHub
parent ba6afb19ed
commit 31ae8958ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 29
      system/hardware/tici/hardware.h

@ -61,20 +61,11 @@ public:
static void reboot() { std::system("sudo reboot"); } static void reboot() { std::system("sudo reboot"); }
static void poweroff() { std::system("sudo poweroff"); } static void poweroff() { std::system("sudo poweroff"); }
static void set_brightness(int percent) { static void set_brightness(int percent) {
std::string max = util::read_file("/sys/class/backlight/panel0-backlight/max_brightness"); float max = std::stof(util::read_file("/sys/class/backlight/panel0-backlight/max_brightness"));
std::ofstream("/sys/class/backlight/panel0-backlight/brightness") << int(percent * (max / 100.0f)) << "\n";
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness");
if (brightness_control.is_open()) {
brightness_control << (int)(percent * (std::stof(max)/100.)) << "\n";
brightness_control.close();
}
} }
static void set_display_power(bool on) { static void set_display_power(bool on) {
std::ofstream bl_power_control("/sys/class/backlight/panel0-backlight/bl_power"); std::ofstream("/sys/class/backlight/panel0-backlight/bl_power") << (on ? "0" : "4") << "\n";
if (bl_power_control.is_open()) {
bl_power_control << (on ? "0" : "4") << "\n";
bl_power_control.close();
}
} }
static void set_ir_power(int percent) { static void set_ir_power(int percent) {
@ -85,18 +76,8 @@ public:
} }
int value = util::map_val(std::clamp(percent, 0, 100), 0, 100, 0, 255); int value = util::map_val(std::clamp(percent, 0, 100), 0, 100, 0, 255);
std::ofstream("/sys/class/leds/led:torch_2/brightness") << value << "\n";
std::ofstream torch_brightness("/sys/class/leds/led:torch_2/brightness"); std::ofstream("/sys/class/leds/led:switch_2/brightness") << value << "\n";
if (torch_brightness.is_open()) {
torch_brightness << value << "\n";
torch_brightness.close();
}
std::ofstream switch_brightness("/sys/class/leds/led:switch_2/brightness");
if (switch_brightness.is_open()) {
switch_brightness << value << "\n";
switch_brightness.close();
}
} }
static std::map<std::string, std::string> get_init_logs() { static std::map<std::string, std::string> get_init_logs() {

Loading…
Cancel
Save