Skip to content

Commit

Permalink
use meter dimmer to control brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
cydia2020 committed Jan 27, 2024
1 parent f071c3d commit 325de7b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cereal
1 change: 1 addition & 0 deletions common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"VisionRadarToggle", PERSISTENT},
{"WheeledBody", PERSISTENT},
{"DisplayRadarInfo", PERSISTENT}, // display radar state on onroad UI
{"CarBrightnessControl", PERSISTENT}, // link display brightness with combination meter
};

} // namespace
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/assets/offroad/icon_brightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions selfdrive/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def update(self, cp, cp_cam):
# brake lights
ret.brakeLights = bool(cp.vl["ESP_CONTROL"]['BRAKE_LIGHTS_ACC'] or cp.vl["BRAKE_MODULE"]["BRAKE_PRESSED"] != 0)

# combination meter dimmer states
ret.meterDimmed = cp.vl["BODY_CONTROL_STATE"]['METER_DIMMED'] == 1
ret.meterLowBrightness = cp.vl["BODY_CONTROL_STATE_2"]["METER_SLIDER_LOW_BRIGHTNESS"] == 1

# Check EPS LKA/LTA fault status
ret.steerFaultTemporary = cp.vl["EPS_STATUS"]["LKA_STATE"] in TEMP_STEER_FAULTS
ret.steerFaultPermanent = cp.vl["EPS_STATUS"]["LKA_STATE"] in PERM_STEER_FAULTS
Expand Down
6 changes: 6 additions & 0 deletions selfdrive/ui/qt/offroad/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
tr("Display speed in km/h instead of mph."),
"../assets/offroad/icon_radar.png",
},
{
"CarBrightnessControl",
tr("Use Car For Backlight Control"),
tr("Use the car's meter dimmer state for brightness control."),
"../assets/offroad/icon_brightness.png",
},
#ifdef ENABLE_MAPS
{
"NavSettingTime24h",
Expand Down
23 changes: 10 additions & 13 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ static void update_sockets(UIState *s) {
static void update_state(UIState *s) {
SubMaster &sm = *(s->sm);
UIScene &scene = s->scene;
// meter dimmed and low brightness states
s->scene.meterDimmed = sm["carState"].getCarState().getMeterDimmed();
s->scene.meterLowBrightness = sm["carState"].getCarState().getMeterLowBrightness();

if (sm.updated("liveCalibration")) {
auto live_calib = sm["liveCalibration"].getLiveCalibration();
Expand Down Expand Up @@ -220,6 +223,7 @@ void ui_update_params(UIState *s) {
s->scene.is_metric = params.getBool("IsMetric");
s->scene.map_on_left = params.getBool("NavSettingLeftSide");
s->scene.radar_state = params.getBool("DisplayRadarInfo");
s->scene.car_brightness = Params().getBool("CarBrightnessControl");
}

void UIState::updateStatus() {
Expand Down Expand Up @@ -320,22 +324,15 @@ void Device::resetInteractiveTimeout(int timeout) {
}

void Device::updateBrightness(const UIState &s) {
float clipped_brightness = offroad_brightness;
if (s.scene.started) {
clipped_brightness = s.scene.light_sensor;
int brightness;

// CIE 1931 - https://www.photonstophotos.net/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm
if (clipped_brightness <= 8) {
clipped_brightness = (clipped_brightness / 903.3);
} else {
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 (s.scene.car_brightness) {
brightness = (s.scene.started) ? (s.scene.meterDimmed) ? 50.0 : (s.scene.meterLowBrightness ? 1.0 : 100.0) : offroad_brightness;
} else {
float clipped_brightness = (s.scene.started) ? std::clamp((s.scene.light_sensor <= 8) ? (s.scene.light_sensor / 903.3) : std::pow((s.scene.light_sensor + 16.0) / 116.0, 3.0) * 100.0f, 10.0f, 100.0f) : offroad_brightness;
brightness = brightness_filter.update(clipped_brightness);
}

int brightness = brightness_filter.update(clipped_brightness);
if (!awake) {
brightness = 0;
}
Expand Down

0 comments on commit 325de7b

Please sign in to comment.