From 7b22a2b4ad537458e42ae68372a192e072edb421 Mon Sep 17 00:00:00 2001 From: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> Date: Sun, 5 Feb 2023 23:55:14 -0500 Subject: [PATCH] Onroad Screen Off Brightness + Timer + Global Brightness (#19) * Onroad Screen Off Brightness + Timer + Global Brightness * need to add the object * missed this --- selfdrive/ui/qt/home.cc | 5 +++++ selfdrive/ui/ui.cc | 26 ++++++++++++++++++++++++++ selfdrive/ui/ui.h | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index 3f3c9a5885..41a97f805f 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -83,6 +83,11 @@ void HomeWindow::mousePressEvent(QMouseEvent* e) { if ((onroad->isVisible() || body->isVisible()) && (!sidebar->isVisible() || e->x() > sidebar->width())) { sidebar->setVisible(!sidebar->isVisible() && !onroad->isMapVisible()); } + + if (uiState()->scene.started && uiState()->scene.onroadScreenOff != -2) { + uiState()->scene.touched2 = true; + QTimer::singleShot(500, []() { uiState()->scene.touched2 = false; }); + } } void HomeWindow::mouseDoubleClickEvent(QMouseEvent* e) { diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 834c001750..a40c9052c0 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -179,6 +179,19 @@ void ui_update_params(UIState *s) { s->scene.map_on_left = params.getBool("NavSettingLeftSide"); s->scene.dynamic_lane_profile_toggle = params.getBool("DynamicLaneProfileToggle"); s->scene.visual_brake_lights = params.getBool("BrakeLights"); + s->scene.onroadScreenOff = std::atoi(params.get("OnroadScreenOff").c_str()); + s->scene.onroadScreenOffBrightness = std::atoi(params.get("OnroadScreenOffBrightness").c_str()); + s->scene.brightness = std::atoi(params.get("BrightnessControl").c_str()); + + if (s->scene.onroadScreenOff > 0) { + s->scene.osoTimer = s->scene.onroadScreenOff * 60 * UI_FREQ; + } else if (s->scene.onroadScreenOff == 0) { + s->scene.osoTimer = 30 * UI_FREQ; + } else if (s->scene.onroadScreenOff == -1) { + s->scene.osoTimer = 15 * UI_FREQ; + } else { + s->scene.osoTimer = -1; + } } void UIState::updateStatus() { @@ -290,11 +303,24 @@ void Device::updateBrightness(const UIState &s) { // Scale back to 10% to 100% clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f); + if (s.scene.onroadScreenOff != -2 && s.scene.touched2) { + sleep_time = s.scene.osoTimer; + } else if (s.scene.controlsState.getAlertSize() != cereal::ControlsState::AlertSize::NONE && s.scene.onroadScreenOff != -2) { + sleep_time = s.scene.osoTimer; + } else if (sleep_time > 0 && s.scene.onroadScreenOff != -2) { + sleep_time--; + } else if (s.scene.started && sleep_time == -1 && s.scene.onroadScreenOff != -2) { + sleep_time = s.scene.osoTimer; + } } int brightness = brightness_filter.update(clipped_brightness); if (!awake) { brightness = 0; + } else if (s.scene.started && sleep_time == 0 && s.scene.onroadScreenOff != -2) { + brightness = s.scene.onroadScreenOffBrightness * 0.01 * brightness; + } else if (s.scene.brightness) { + brightness = s.scene.brightness * 0.99; } if (brightness != last_brightness) { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 838d09434f..872ad12a13 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -94,6 +94,7 @@ typedef struct UIScene { mat3 view_from_calib = DEFAULT_CALIBRATION; mat3 view_from_wide_calib = DEFAULT_CALIBRATION; cereal::PandaState::PandaType pandaType; + cereal::ControlsState::Reader controlsState; // modelV2 float lane_line_probs[4]; @@ -113,6 +114,9 @@ typedef struct UIScene { bool dynamic_lane_profile_status, dynamic_lane_profile_toggle; bool visual_brake_lights; + + int onroadScreenOff, osoTimer, brightness, onroadScreenOffBrightness, awake; + bool touched2 = false; } UIScene; class UIState : public QObject { @@ -178,6 +182,8 @@ private: bool motionTriggered(const UIState &s); void setAwake(bool on); + int sleep_time = -1; + signals: void displayPowerChanged(bool on); void interactiveTimout();