Skip to content

Commit

Permalink
Visuals - Screen Management - Standby Mode
Browse files Browse the repository at this point in the history
Turn the screen off after your screen times out when onroad, but wake it back up when engagement state changes or important alerts are triggered.
  • Loading branch information
FrogAi committed Jun 1, 2024
1 parent de232c4 commit c6319a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ void ui_update_frogpilot_params(UIState *s) {
scene.screen_recorder = screen_management && params.getBool("ScreenRecorder");
scene.screen_timeout = screen_management ? params.getInt("ScreenTimeout") : 30;
scene.screen_timeout_onroad = screen_management ? params.getInt("ScreenTimeoutOnroad") : 10;
scene.standby_mode = screen_management && params.getBool("StandbyMode");

scene.speed_limit_controller = scene.longitudinal_control && params.getBool("SpeedLimitController");
scene.show_slc_offset = scene.speed_limit_controller && params.getBool("ShowSLCOffset");
Expand All @@ -429,6 +430,7 @@ void UIState::updateStatus() {
if (scene.started && sm->updated("controlsState")) {
auto controls_state = (*sm)["controlsState"].getControlsState();
auto state = controls_state.getState();
auto previous_status = status;
if (state == cereal::ControlsState::OpenpilotState::PRE_ENABLED || state == cereal::ControlsState::OpenpilotState::OVERRIDING) {
status = STATUS_OVERRIDE;
} else if (scene.always_on_lateral_active) {
Expand All @@ -438,6 +440,8 @@ void UIState::updateStatus() {
} else {
status = controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED;
}

scene.wake_up_screen = controls_state.getAlertStatus() != cereal::ControlsState::AlertStatus::NORMAL || status != previous_status;
}

// Handle onroad/offroad transition
Expand Down Expand Up @@ -564,6 +568,8 @@ void Device::updateBrightness(const UIState &s) {
int brightness = brightness_filter.update(clipped_brightness);
if (!awake) {
brightness = 0;
} else if (s.scene.started && s.scene.standby_mode && !s.scene.wake_up_screen && interactive_timeout == 0) {
brightness = 0;
} else if (s.scene.started && s.scene.screen_brightness_onroad != 101) {
brightness = interactive_timeout > 0 ? fmax(5, s.scene.screen_brightness_onroad) : s.scene.screen_brightness_onroad;
} else if (s.scene.screen_brightness != 101) {
Expand All @@ -582,8 +588,18 @@ void Device::updateWakefulness(const UIState &s) {
bool ignition_state_changed = s.scene.ignition != ignition_on;
ignition_on = s.scene.ignition;

if (ignition_on && s.scene.standby_mode) {
if (s.scene.wake_up_screen) {
resetInteractiveTimeout(s.scene.screen_timeout, s.scene.screen_timeout_onroad);
}
}

if (ignition_state_changed) {
resetInteractiveTimeout(s.scene.screen_timeout, s.scene.screen_timeout_onroad);
if (ignition_on && s.scene.screen_brightness_onroad == 0 && !s.scene.standby_mode) {
resetInteractiveTimeout(0, 0);
} else {
resetInteractiveTimeout(s.scene.screen_timeout, s.scene.screen_timeout_onroad);
}
} else if (interactive_timeout > 0 && --interactive_timeout == 0) {
emit interactiveTimeout();
}
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ typedef struct UIScene {
bool speed_limit_changed;
bool speed_limit_controller;
bool speed_limit_overridden;
bool standby_mode;
bool standstill;
bool static_pedals_on_ui;
bool tethering_enabled;
Expand All @@ -264,6 +265,7 @@ typedef struct UIScene {
bool use_si;
bool use_vienna_slc_sign;
bool vtsc_controlling_curve;
bool wake_up_screen;
bool wheel_speed;

float acceleration;
Expand Down

0 comments on commit c6319a4

Please sign in to comment.