ui: add brightness controls (#974)

* brightness

* better brightness

* cleanup

---------

Co-authored-by: DevTekVE <devtekve@gmail.com>
This commit is contained in:
royjr
2025-06-06 15:51:05 -04:00
committed by GitHub
parent 539b5aab75
commit debba0c9f9
8 changed files with 98 additions and 3 deletions
+1
View File
@@ -133,6 +133,7 @@ inline static std::unordered_map<std::string, uint32_t> keys = {
{"CarPlatformBundle", PERSISTENT},
{"EnableGithubRunner", PERSISTENT | BACKUP},
{"MaxTimeOffroad", PERSISTENT | BACKUP},
{"Brightness", PERSISTENT | BACKUP},
{"ModelRunnerTypeCache", CLEAR_ON_ONROAD_TRANSITION},
{"OffroadMode", CLEAR_ON_MANAGER_START},
{"OffroadMode_Status", CLEAR_ON_MANAGER_START},
+1
View File
@@ -24,6 +24,7 @@ qt_src = [
"sunnypilot/qt/offroad/settings/lateral_panel.cc",
"sunnypilot/qt/offroad/settings/longitudinal_panel.cc",
"sunnypilot/qt/offroad/settings/max_time_offroad.cc",
"sunnypilot/qt/offroad/settings/brightness.cc",
"sunnypilot/qt/offroad/settings/models_panel.cc",
"sunnypilot/qt/offroad/settings/settings.cc",
"sunnypilot/qt/offroad/settings/software_panel.cc",
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
*
* This file is part of sunnypilot and is licensed under the MIT License.
* See the LICENSE.md file in the root directory for more details.
*/
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/brightness.h"
// Map of Brightness Options
const QMap<QString, QString> Brightness::brightness_options = {
{"0", "1"}, // Auto (Dark)
{"1", "0"}, // Auto
{"2", "10"},
{"3", "20"},
{"4", "30"},
{"5", "40"},
{"6", "50"},
{"7", "60"},
{"8", "70"},
{"9", "80"},
{"10", "90"},
{"11", "100"}
};
Brightness::Brightness() : OptionControlSP(
"Brightness",
tr("Brightness"),
tr("Overrides the brightness of the device."),
"../assets/offroad/icon_blank.png",
{0, 11}, 1, true, &brightness_options) {
refresh();
}
void Brightness::refresh() {
const int brightness = QString::fromStdString(params.get("Brightness")).toInt();
QString label;
if (brightness == 1) {
label = tr("Auto (Dark)");
} else if (brightness == 0) {
label = tr("Auto");
} else {
const int value = brightness;
label = QString("%1").arg(value);
}
setLabel(label);
}
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
*
* This file is part of sunnypilot and is licensed under the MIT License.
* See the LICENSE.md file in the root directory for more details.
*/
#pragma once
#include "selfdrive/ui/sunnypilot/ui.h"
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h"
class Brightness : public OptionControlSP {
Q_OBJECT
public:
static const QMap<QString, QString> brightness_options;
Brightness();
void refresh();
private:
Params params;
};
@@ -80,6 +80,11 @@ DevicePanelSP::DevicePanelSP(SettingsWindowSP *parent) : DevicePanel(parent) {
connect(maxTimeOffroad, &OptionControlSP::updateLabels, maxTimeOffroad, &MaxTimeOffroad::refresh);
addItem(maxTimeOffroad);
// Brightness
brightness = new Brightness();
connect(brightness, &OptionControlSP::updateLabels, brightness, &Brightness::refresh);
addItem(brightness);
addItem(device_grid_layout);
// offroad mode and power buttons
@@ -8,6 +8,7 @@
#pragma once
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/max_time_offroad.h"
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/brightness.h"
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h"
#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h"
@@ -25,6 +26,7 @@ private:
std::map<QString, PushButtonSP*> buttons;
PushButtonSP *offroadBtn;
MaxTimeOffroad *maxTimeOffroad;
Brightness *brightness;
const QString alwaysOffroadStyle = R"(
PushButtonSP {
+13 -3
View File
@@ -171,6 +171,8 @@ void Device::resetInteractiveTimeout(int timeout) {
}
void Device::updateBrightness(const UIState &s) {
int brightness;
int brightness_override = QString::fromStdString(Params().get("Brightness")).toInt();
float clipped_brightness = offroad_brightness;
if (s.scene.started && s.scene.light_sensor >= 0) {
clipped_brightness = s.scene.light_sensor;
@@ -182,11 +184,19 @@ void Device::updateBrightness(const UIState &s) {
clipped_brightness = std::pow((clipped_brightness + 16.0) / 116.0, 3.0);
}
// Scale back to 10% to 100%
clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f);
if (brightness_override == 1) {
clipped_brightness = std::clamp(100.0f * clipped_brightness, 1.0f, 100.0f); // Scale back to 1% to 100%
} else if (brightness_override == 0) {
clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f); // Scale back to 10% to 100%
}
}
if (brightness_override == 0 || brightness_override == 1) {
brightness = brightness_filter.update(clipped_brightness);
} else {
brightness = brightness_override;
}
int brightness = brightness_filter.update(clipped_brightness);
if (!awake) {
brightness = 0;
}
+1
View File
@@ -54,6 +54,7 @@ def manager_init() -> None:
("MadsSteeringMode", "0"),
("MadsUnifiedEngagementMode", "1"),
("MaxTimeOffroad", "1800"),
("Brightness", "0"),
("ModelManager_LastSyncTime", "0"),
("ModelManager_ModelsCache", ""),
("NeuralNetworkLateralControl", "0"),