Skip to content

Commit b006e48

Browse files
authored
ui: display CPU temperature on sidebar (#118)
* 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
1 parent 63fb07b commit b006e48

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

selfdrive/ui/qt/offroad/sunnypilot_settings.cc

+9
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,15 @@ SPVisualsPanel::SPVisualsPanel(QWidget *parent) : QWidget(parent) {
690690
tr("Enable this will display an icon that appears when the End-to-end model decides to start or stop."),
691691
"../assets/offroad/icon_road.png"
692692
));
693+
694+
// Visuals: Display CPU Temperature
695+
main_layout->addWidget(horizontal_line());
696+
main_layout->addWidget(new ParamControl(
697+
"SidebarCpuTemp",
698+
tr("Display CPU Temperature"),
699+
tr("Enable this will display the the CPU that has the highest temperature on the sidebar."),
700+
"../assets/offroad/icon_calibration.png"
701+
));
693702
}
694703

695704
void SPVisualsPanel::showEvent(QShowEvent *event) {

selfdrive/ui/qt/sidebar.cc

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "selfdrive/ui/qt/sidebar.h"
22

3+
#include <cmath>
4+
35
#include <QMouseEvent>
46

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

99-
ItemStatus tempStatus = {{tr("TEMP"), tr("HIGH")}, danger_color};
101+
int max_cpu_temp_index = -1;
102+
float max_cpu_temp = std::numeric_limits<float>::lowest();
103+
const auto& cpu_temp_list = deviceState.getCpuTempC();
104+
105+
for (int i = 0; i < cpu_temp_list.size(); ++i) {
106+
float temp = cpu_temp_list[i];
107+
if (temp > max_cpu_temp) {
108+
max_cpu_temp_index = i;
109+
max_cpu_temp = temp;
110+
}
111+
}
112+
QString max_cpu_temp_str = "0°C";
113+
if (max_cpu_temp_index != -1) {
114+
max_cpu_temp_str = QString::number(std::nearbyint(max_cpu_temp)) + "°C";
115+
}
116+
117+
ItemStatus tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("HIGH")}, danger_color};
100118
auto ts = deviceState.getThermalStatus();
101119
if (ts == cereal::DeviceState::ThermalStatus::GREEN) {
102-
tempStatus = {{tr("TEMP"), tr("GOOD")}, good_color};
120+
tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("GOOD")}, good_color};
103121
} else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) {
104-
tempStatus = {{tr("TEMP"), tr("OK")}, warning_color};
122+
tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("OK")}, warning_color};
105123
}
106124
setProperty("tempStatus", QVariant::fromValue(tempStatus));
107125

selfdrive/ui/ui.cc

+8-2
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ void ui_update_params(UIState *s) {
271271
}
272272

273273
void UIState::updateStatus() {
274+
auto params = Params();
274275
if (scene.started && sm->updated("controlsState")) {
275276
auto controls_state = (*sm)["controlsState"].getControlsState();
276277
auto car_control = (*sm)["carControl"].getCarControl();
@@ -293,8 +294,8 @@ void UIState::updateStatus() {
293294
if (scene.started) {
294295
status = STATUS_DISENGAGED;
295296
scene.started_frame = sm->frame;
296-
scene.live_torque_toggle = Params().getBool("LiveTorque");
297-
scene.custom_torque_toggle = Params().getBool("CustomTorqueLateral");
297+
scene.live_torque_toggle = params.getBool("LiveTorque");
298+
scene.custom_torque_toggle = params.getBool("CustomTorqueLateral");
298299
}
299300
started_prev = scene.started;
300301
emit offroadTransition(!scene.started);
@@ -342,6 +343,11 @@ void UIState::updateStatus() {
342343
scene.sleep_time = scene.osoTimer;
343344
}
344345
}
346+
347+
if (millis_since_boot() - last_update_params_sidebar > 1000 * 1) {
348+
last_update_params_sidebar = millis_since_boot();
349+
scene.sidebar_cpu_temp = params.getBool("SidebarCpuTemp");
350+
}
345351
}
346352

347353
UIState::UIState(QObject *parent) : QObject(parent) {

selfdrive/ui/ui.h

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ typedef struct UIScene {
188188

189189
bool e2e_long_alert_light, e2e_long_alert_lead, e2e_long_alert_ui;
190190
float e2eX[13] = {0};
191+
192+
bool sidebar_cpu_temp;
191193
} UIScene;
192194

193195
class UIState : public QObject {
@@ -230,6 +232,7 @@ private slots:
230232
QTimer *timer;
231233
bool started_prev = false;
232234
int prime_type = -1;
235+
uint64_t last_update_params_sidebar;
233236
};
234237

235238
UIState *uiState();

0 commit comments

Comments
 (0)