Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tici: limit brightness with display uptime #22918

Merged
merged 8 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion selfdrive/hardware/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HardwareNone {

static void reboot() {}
static void poweroff() {}
static void set_brightness(int percent) {}
static void set_brightness(int percent, float ui_running_time) {}
static void set_display_power(bool on) {}

static bool get_ssh_enabled() { return false; }
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/hardware/eon/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HardwareEon : public HardwareNone {

static void reboot() { std::system("reboot"); };
static void poweroff() { std::system("LD_LIBRARY_PATH= svc power shutdown"); };
static void set_brightness(int percent) {
static void set_brightness(int percent, float ui_running_time) {
std::ofstream brightness_control("/sys/class/leds/lcd-backlight/brightness");
if (brightness_control.is_open()) {
brightness_control << (int)(percent * (255/100.)) << "\n";
Expand Down
13 changes: 12 additions & 1 deletion selfdrive/hardware/tici/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@ class HardwareTici : public HardwareNone {
public:
static constexpr float MAX_VOLUME = 1.0;
static constexpr float MIN_VOLUME = 0.4;
static constexpr float SECONDS_IN_HOUR = 60*60;
static constexpr float HOURLY_BRIGHTNESS_DECREASE = 5;
static constexpr float BRIGHTNESS_LIMIT_MIN = 30;
static constexpr float BRIGHTNESS_LIMIT_MAX = 100;
static constexpr float MAX_BRIGHTNESS_HOURS = 4;

static bool TICI() { return true; }
static std::string get_os_version() {
return "AGNOS " + util::read_file("/VERSION");
};

static void reboot() { std::system("sudo reboot"); };
static void poweroff() { std::system("sudo poweroff"); };
static void set_brightness(int percent) {
static void set_brightness(int percent, float ui_running_time) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just put this all in Device::updateBrightness until it gets moved to agnos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

float ui_running_hours = ui_running_time / SECONDS_IN_HOUR;
int anti_burnin_max_percent = std::clamp((int) (BRIGHTNESS_LIMIT_MAX - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS)),
BRIGHTNESS_LIMIT_MIN,
BRIGHTNESS_LIMIT_MIN);
percent = std::min(percent, anti_burnin_max_percent);
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness");
if (brightness_control.is_open()) {
brightness_control << (percent * (int)(1023/100.)) << "\n";
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/qt/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void setQtSurfaceFormat() {

void initApp() {
Hardware::set_display_power(true);
Hardware::set_brightness(65);
Hardware::set_brightness(65, 0);
setQtSurfaceFormat();
if (Hardware::EON()) {
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
Expand Down
3 changes: 2 additions & 1 deletion selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static void update_sockets(UIState *s) {
static void update_state(UIState *s) {
SubMaster &sm = *(s->sm);
UIScene &scene = s->scene;
s->running_time = 1e-9 * (sm["deviceState"].getLogMonoTime() - sm["deviceState"].getDeviceState().getStartedMonoTime());

// update engageability and DM icons at 2Hz
if (sm.frame % (UI_FREQ / 2) == 0) {
Expand Down Expand Up @@ -301,7 +302,7 @@ void Device::updateBrightness(const UIState &s) {
}

if (brightness != last_brightness) {
std::thread{Hardware::set_brightness, brightness}.detach();
std::thread{Hardware::set_brightness, brightness, s.running_time}.detach();
}
last_brightness = brightness;
}
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ typedef struct UIState {

float car_space_transform[6];
bool wide_camera;

float running_time;
} UIState;


Expand Down