Skip to content

Commit

Permalink
ui: display CPU temperature on sidebar (#118)
Browse files Browse the repository at this point in the history
* ui: display CPU temperature on sidebar

* ui: display CPU temperature on sidebar

* take it out for now

* Revert "take it out for now"

This reverts commit 3e7daa11f6a3e8ed6dec92df02bb4c390c99583c.

* small changes

* push this

* string

* flip???

* no setproperty

* check param every 1 second

* wrong param!

* do this

* flip them back

* don't need this
  • Loading branch information
sunnyhaibin authored Jun 9, 2023
1 parent 63fb07b commit b006e48
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
9 changes: 9 additions & 0 deletions selfdrive/ui/qt/offroad/sunnypilot_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,15 @@ SPVisualsPanel::SPVisualsPanel(QWidget *parent) : QWidget(parent) {
tr("Enable this will display an icon that appears when the End-to-end model decides to start or stop."),
"../assets/offroad/icon_road.png"
));

// Visuals: Display CPU Temperature
main_layout->addWidget(horizontal_line());
main_layout->addWidget(new ParamControl(
"SidebarCpuTemp",
tr("Display CPU Temperature"),
tr("Enable this will display the the CPU that has the highest temperature on the sidebar."),
"../assets/offroad/icon_calibration.png"
));
}

void SPVisualsPanel::showEvent(QShowEvent *event) {
Expand Down
24 changes: 21 additions & 3 deletions selfdrive/ui/qt/sidebar.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "selfdrive/ui/qt/sidebar.h"

#include <cmath>

#include <QMouseEvent>

#include "selfdrive/ui/qt/util.h"
Expand Down Expand Up @@ -96,12 +98,28 @@ void Sidebar::updateState(const UIState &s) {
}
setProperty("connectStatus", QVariant::fromValue(connectStatus));

ItemStatus tempStatus = {{tr("TEMP"), tr("HIGH")}, danger_color};
int max_cpu_temp_index = -1;
float max_cpu_temp = std::numeric_limits<float>::lowest();
const auto& cpu_temp_list = deviceState.getCpuTempC();

for (int i = 0; i < cpu_temp_list.size(); ++i) {
float temp = cpu_temp_list[i];
if (temp > max_cpu_temp) {
max_cpu_temp_index = i;
max_cpu_temp = temp;
}
}
QString max_cpu_temp_str = "0°C";
if (max_cpu_temp_index != -1) {
max_cpu_temp_str = QString::number(std::nearbyint(max_cpu_temp)) + "°C";
}

ItemStatus tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("HIGH")}, danger_color};
auto ts = deviceState.getThermalStatus();
if (ts == cereal::DeviceState::ThermalStatus::GREEN) {
tempStatus = {{tr("TEMP"), tr("GOOD")}, good_color};
tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("GOOD")}, good_color};
} else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) {
tempStatus = {{tr("TEMP"), tr("OK")}, warning_color};
tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("OK")}, warning_color};
}
setProperty("tempStatus", QVariant::fromValue(tempStatus));

Expand Down
10 changes: 8 additions & 2 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ void ui_update_params(UIState *s) {
}

void UIState::updateStatus() {
auto params = Params();
if (scene.started && sm->updated("controlsState")) {
auto controls_state = (*sm)["controlsState"].getControlsState();
auto car_control = (*sm)["carControl"].getCarControl();
Expand All @@ -293,8 +294,8 @@ void UIState::updateStatus() {
if (scene.started) {
status = STATUS_DISENGAGED;
scene.started_frame = sm->frame;
scene.live_torque_toggle = Params().getBool("LiveTorque");
scene.custom_torque_toggle = Params().getBool("CustomTorqueLateral");
scene.live_torque_toggle = params.getBool("LiveTorque");
scene.custom_torque_toggle = params.getBool("CustomTorqueLateral");
}
started_prev = scene.started;
emit offroadTransition(!scene.started);
Expand Down Expand Up @@ -342,6 +343,11 @@ void UIState::updateStatus() {
scene.sleep_time = scene.osoTimer;
}
}

if (millis_since_boot() - last_update_params_sidebar > 1000 * 1) {
last_update_params_sidebar = millis_since_boot();
scene.sidebar_cpu_temp = params.getBool("SidebarCpuTemp");
}
}

UIState::UIState(QObject *parent) : QObject(parent) {
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ typedef struct UIScene {

bool e2e_long_alert_light, e2e_long_alert_lead, e2e_long_alert_ui;
float e2eX[13] = {0};

bool sidebar_cpu_temp;
} UIScene;

class UIState : public QObject {
Expand Down Expand Up @@ -230,6 +232,7 @@ private slots:
QTimer *timer;
bool started_prev = false;
int prime_type = -1;
uint64_t last_update_params_sidebar;
};

UIState *uiState();
Expand Down

0 comments on commit b006e48

Please sign in to comment.