Skip to content

Commit 0535389

Browse files
authored
ui: Sidebar Temperature selector (commaai#183)
* ui: Sidebar Temperature selector * don't update * should be numerical * update it! * fix index * fix * correct wording * use ListWidget-like method * No lines, can shrink * update description * fix * not needed * Update CHANGELOGS.md * cleanup
1 parent 6027b8a commit 0535389

File tree

7 files changed

+125
-29
lines changed

7 files changed

+125
-29
lines changed

CHANGELOGS.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ sunnypilot - 0.9.3.1 (2023-XX-XX)
55
* NEW❗: HKG CAN: Smoother Stopping Performance (Beta) toggle
66
* Smoother stopping behind a stopped car or desired stopping event.
77
* This is only applicable to HKG CAN platforms using openpilot longitudinal control
8+
* NEW❗: Display Temperature on Sidebar toggle
9+
* Display Ambient temperature, memory temperature, CPU core with the highest temperature, GPU temperature, or max of Memory/CPU/GPU on the sidebar
10+
* Replace "Display CPU Temperature on Sidebar" toggle
811
* DISABLED: Screen Recorder
912
* UI sometimes crashes on startup along with screen recorder, will reimplement in future updates
13+
* REMOVED: Display CPU Temperature on Sidebar
1014

1115
sunnypilot - 0.9.2.3 (2023-06-18)
1216
========================

selfdrive/ui/qt/offroad/sunnypilot_settings.cc

+41-6
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,6 @@ SPVisualsPanel::SPVisualsPanel(QWidget *parent) : ListWidget(parent) {
636636
tr("Enable this will display an icon that appears when the End-to-end model decides to start or stop."),
637637
"../assets/offroad/icon_road.png",
638638
},
639-
{
640-
"SidebarCpuTemp",
641-
tr("Display CPU Temperature on Sidebar"),
642-
tr("Enable this will display the CPU core with the highest temperature on the sidebar."),
643-
"../assets/offroad/icon_calibration.png",
644-
},
645639
};
646640

647641
// Developer UI Info (Dev UI)
@@ -664,6 +658,9 @@ SPVisualsPanel::SPVisualsPanel(QWidget *parent) : ListWidget(parent) {
664658
}
665659
}
666660

661+
auto sidebar_temp = new SidebarTemp(this);
662+
addItem(sidebar_temp);
663+
667664
// trigger updateToggles() when toggleFlipped
668665
connect(toggles["DevUI"], &ToggleControl::toggleFlipped, [=](bool state) {
669666
updateToggles();
@@ -1779,3 +1776,41 @@ void ChevronInfo::refresh() {
17791776
btnminus.setText("-");
17801777
btnplus.setText("+");
17811778
}
1779+
1780+
SidebarTemp::SidebarTemp(QWidget *parent) : QWidget(parent), outer_layout(this) {
1781+
outer_layout.setMargin(0);
1782+
outer_layout.setSpacing(0);
1783+
outer_layout.addLayout(&inner_layout);
1784+
inner_layout.setMargin(0);
1785+
//inner_layout.setSpacing(25); // default spacing is 25
1786+
outer_layout.addStretch();
1787+
1788+
sidebarTemperature = new ParamControl(
1789+
"SidebarTemperature",
1790+
tr("Display Temperature on Sidebar"),
1791+
tr("Display Ambient temperature, memory temperature, CPU core with the highest temperature, GPU temperature, or max of Memory/CPU/GPU on the sidebar."),
1792+
"../assets/offroad/icon_calibration.png"
1793+
);
1794+
1795+
std::vector<QString> sidebar_temp_texts{tr("Ambient"), tr("Memory"), tr("CPU"), tr("GPU"), tr("Max")};
1796+
sidebar_temp_setting = new ButtonParamControl(
1797+
"SidebarTemperatureOptions", "", "",
1798+
"../assets/offroad/icon_blank.png",
1799+
sidebar_temp_texts
1800+
);
1801+
1802+
connect(sidebarTemperature, &ToggleControl::toggleFlipped, [=](bool state) {
1803+
updateToggles();
1804+
});
1805+
1806+
addItem(sidebarTemperature);
1807+
addItem(sidebar_temp_setting);
1808+
}
1809+
1810+
void SidebarTemp::showEvent(QShowEvent *event) {
1811+
updateToggles();
1812+
}
1813+
1814+
void SidebarTemp::updateToggles() {
1815+
sidebar_temp_setting->setVisible(params.getBool("SidebarTemperature"));
1816+
}

selfdrive/ui/qt/offroad/sunnypilot_settings.h

+22
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,28 @@ class ChevronInfo : public AbstractControl {
242242
void refresh();
243243
};
244244

245+
class SidebarTemp : public QWidget {
246+
Q_OBJECT
247+
248+
public:
249+
explicit SidebarTemp(QWidget *parent = nullptr);
250+
void showEvent(QShowEvent *event) override;
251+
252+
public slots:
253+
void updateToggles();
254+
255+
private:
256+
inline void addItem(QWidget *w) { inner_layout.addWidget(w); }
257+
inline void addItem(QLayout *layout) { inner_layout.addLayout(layout); }
258+
inline void setSpacing(int spacing) { inner_layout.setSpacing(spacing); }
259+
QVBoxLayout outer_layout;
260+
QVBoxLayout inner_layout;
261+
Params params;
262+
263+
ParamControl *sidebarTemperature;
264+
ButtonParamControl *sidebar_temp_setting;
265+
};
266+
245267
class SPGeneralPanel : public ListWidget {
246268
Q_OBJECT
247269

selfdrive/ui/qt/sidebar.cc

+50-20
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,60 @@ void Sidebar::updateState(const UIState &s) {
9898
}
9999
setProperty("connectStatus", QVariant::fromValue(connectStatus));
100100

101-
if (millis_since_boot() - last_max_cpu_temp_count > 1000 * 1) {
102-
last_max_cpu_temp_count = millis_since_boot();
103-
104-
QString max_cpu_temp_str = "0°C";
105-
const auto& cpu_temp_list = deviceState.getCpuTempC();
106-
float max_cpu_temp = std::numeric_limits<float>::lowest();
107-
108-
for (const float& temp : cpu_temp_list) {
109-
max_cpu_temp = std::max(max_cpu_temp, temp);
101+
if (millis_since_boot() - last_temp_count > 1000 * 1) {
102+
last_temp_count = millis_since_boot();
103+
104+
switch (s.scene.sidebar_temp_options) {
105+
case 0:
106+
sidebar_temp = QString::number((int)deviceState.getAmbientTempC());
107+
break;
108+
case 1:
109+
sidebar_temp = QString::number((int)deviceState.getMemoryTempC());
110+
break;
111+
case 2: {
112+
const auto& cpu_temp_list = deviceState.getCpuTempC();
113+
float max_cpu_temp = std::numeric_limits<float>::lowest();
114+
115+
for (const float& temp : cpu_temp_list) {
116+
max_cpu_temp = std::max(max_cpu_temp, temp);
117+
}
118+
119+
if (max_cpu_temp >= 0) {
120+
sidebar_temp = QString::number(std::nearbyint(max_cpu_temp));
121+
}
122+
break;
123+
}
124+
case 3: {
125+
const auto& gpu_temp_list = deviceState.getGpuTempC();
126+
float max_gpu_temp = std::numeric_limits<float>::lowest();
127+
128+
for (const float& temp : gpu_temp_list) {
129+
max_gpu_temp = std::max(max_gpu_temp, temp);
130+
}
131+
132+
if (max_gpu_temp >= 0) {
133+
sidebar_temp = QString::number(std::nearbyint(max_gpu_temp));
134+
}
135+
break;
136+
}
137+
case 4:
138+
sidebar_temp = QString::number((int)deviceState.getMaxTempC());
139+
break;
140+
default:
141+
break;
110142
}
111143

112-
if (max_cpu_temp >= 0) {
113-
max_cpu_temp_str = QString::number(std::nearbyint(max_cpu_temp)) + "°C";
114-
}
144+
setProperty("sidebarTemp", sidebar_temp + "°C");
145+
}
115146

116-
ItemStatus tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("HIGH")}, danger_color};
117-
auto ts = deviceState.getThermalStatus();
118-
if (ts == cereal::DeviceState::ThermalStatus::GREEN) {
119-
tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("GOOD")}, good_color};
120-
} else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) {
121-
tempStatus = {{tr("TEMP"), s.scene.sidebar_cpu_temp ? max_cpu_temp_str : tr("OK")}, warning_color};
122-
}
123-
setProperty("tempStatus", QVariant::fromValue(tempStatus));
147+
ItemStatus tempStatus = {{tr("TEMP"), s.scene.sidebar_temp ? sidebar_temp_str : tr("HIGH")}, danger_color};
148+
auto ts = deviceState.getThermalStatus();
149+
if (ts == cereal::DeviceState::ThermalStatus::GREEN) {
150+
tempStatus = {{tr("TEMP"), s.scene.sidebar_temp ? sidebar_temp_str : tr("GOOD")}, good_color};
151+
} else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) {
152+
tempStatus = {{tr("TEMP"), s.scene.sidebar_temp ? sidebar_temp_str : tr("OK")}, warning_color};
124153
}
154+
setProperty("tempStatus", QVariant::fromValue(tempStatus));
125155

126156
ItemStatus pandaStatus = {{tr("VEHICLE"), tr("ONLINE")}, good_color};
127157
if (s.scene.pandaType == cereal::PandaState::PandaType::UNKNOWN) {

selfdrive/ui/qt/sidebar.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Sidebar : public QFrame {
1515
Q_PROPERTY(ItemStatus tempStatus MEMBER temp_status NOTIFY valueChanged);
1616
Q_PROPERTY(QString netType MEMBER net_type NOTIFY valueChanged);
1717
Q_PROPERTY(int netStrength MEMBER net_strength NOTIFY valueChanged);
18+
Q_PROPERTY(QString sidebarTemp MEMBER sidebar_temp_str NOTIFY valueChanged);
1819

1920
public:
2021
explicit Sidebar(QWidget* parent = 0);
@@ -58,5 +59,7 @@ public slots:
5859
private:
5960
std::unique_ptr<PubMaster> pm;
6061

61-
uint64_t last_max_cpu_temp_count;
62+
uint64_t last_temp_count;
63+
QString sidebar_temp = "0";
64+
QString sidebar_temp_str = "0";
6265
};

selfdrive/ui/ui.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ void UIState::updateStatus() {
350350

351351
if (millis_since_boot() - last_update_params_sidebar > 1000 * 1) {
352352
last_update_params_sidebar = millis_since_boot();
353-
scene.sidebar_cpu_temp = params.getBool("SidebarCpuTemp");
353+
scene.sidebar_temp = params.getBool("SidebarTemperature");
354+
scene.sidebar_temp_options = std::atoi(params.get("SidebarTemperatureOptions").c_str());
354355
}
355356
}
356357

selfdrive/ui/ui.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ typedef struct UIScene {
190190
bool e2e_long_alert_light, e2e_long_alert_lead, e2e_long_alert_ui;
191191
float e2eX[13] = {0};
192192

193-
bool sidebar_cpu_temp;
193+
bool sidebar_temp;
194+
int sidebar_temp_options;
194195
} UIScene;
195196

196197
class UIState : public QObject {

0 commit comments

Comments
 (0)