Skip to content

Commit 05837ea

Browse files
committed
screens: overtemperature: add over temperature warning screen
Notify the user if the TAC is running hot. Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
1 parent 2b79116 commit 05837ea

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

src/ui/screens.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod help;
3131
mod iobus;
3232
mod iobus_health;
3333
mod locator;
34+
mod overtemperature;
3435
mod power;
3536
mod reboot;
3637
mod screensaver;
@@ -46,6 +47,7 @@ use help::HelpScreen;
4647
use iobus::IoBusScreen;
4748
use iobus_health::IoBusHealthScreen;
4849
use locator::LocatorScreen;
50+
use overtemperature::OverTemperatureScreen;
4951
use power::PowerScreen;
5052
use reboot::RebootConfirmScreen;
5153
use screensaver::ScreenSaverScreen;
@@ -84,6 +86,7 @@ pub enum AlertScreen {
8486
UpdateInstallation,
8587
Help,
8688
Setup,
89+
OverTemperature,
8790
}
8891

8992
#[derive(Serialize, Deserialize, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug)]
@@ -199,6 +202,10 @@ pub(super) fn init(
199202
Box::new(RebootConfirmScreen::new(alerts, reboot_message)),
200203
Box::new(ScreenSaverScreen::new(buttons, alerts)),
201204
Box::new(SetupScreen::new(alerts, &res.setup_mode.setup_mode)),
205+
Box::new(OverTemperatureScreen::new(
206+
alerts,
207+
&res.temperatures.warning,
208+
)),
202209
Box::new(LocatorScreen::new(alerts, locator)),
203210
]
204211
}

src/ui/screens/overtemperature.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// This file is part of tacd, the LXA TAC system daemon
2+
// Copyright (C) 2023 Pengutronix e.K.
3+
//
4+
// This program is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation; either version 2 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License along
15+
// with this program; if not, write to the Free Software Foundation, Inc.,
16+
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
18+
use async_std::prelude::*;
19+
use async_std::sync::Arc;
20+
use async_std::task::spawn;
21+
use async_trait::async_trait;
22+
use embedded_graphics::{
23+
mono_font::MonoTextStyle, pixelcolor::BinaryColor, prelude::*, text::Text,
24+
};
25+
26+
use super::widgets::*;
27+
use super::{
28+
row_anchor, ActivatableScreen, ActiveScreen, AlertList, AlertScreen, Alerter, Display,
29+
InputEvent, Screen, Ui,
30+
};
31+
use crate::broker::Topic;
32+
use crate::measurement::Measurement;
33+
use crate::temperatures::Warning;
34+
35+
const SCREEN_TYPE: AlertScreen = AlertScreen::OverTemperature;
36+
37+
pub struct OverTemperatureScreen;
38+
39+
struct Active {
40+
widgets: WidgetContainer,
41+
}
42+
43+
impl OverTemperatureScreen {
44+
pub fn new(alerts: &Arc<Topic<AlertList>>, warning: &Arc<Topic<Warning>>) -> Self {
45+
let (mut warning_events, _) = warning.clone().subscribe_unbounded();
46+
let alerts = alerts.clone();
47+
48+
spawn(async move {
49+
while let Some(warning) = warning_events.next().await {
50+
match warning {
51+
Warning::Okay => alerts.deassert(SCREEN_TYPE),
52+
Warning::SocHigh | Warning::SocCritical => alerts.assert(SCREEN_TYPE),
53+
}
54+
}
55+
});
56+
57+
Self
58+
}
59+
}
60+
61+
impl ActivatableScreen for OverTemperatureScreen {
62+
fn my_type(&self) -> Screen {
63+
Screen::Alert(SCREEN_TYPE)
64+
}
65+
66+
fn activate(&mut self, ui: &Ui, display: Display) -> Box<dyn ActiveScreen> {
67+
let ui_text_style: MonoTextStyle<BinaryColor> =
68+
MonoTextStyle::new(&UI_TEXT_FONT, BinaryColor::On);
69+
70+
display.with_lock(|target| {
71+
Text::new("Temperature alert!", row_anchor(0), ui_text_style)
72+
.draw(target)
73+
.unwrap();
74+
75+
Text::new(
76+
"TAC is overheating.\nProvide more airflow\nand check loads.",
77+
row_anchor(2),
78+
ui_text_style,
79+
)
80+
.draw(target)
81+
.unwrap();
82+
83+
Text::new("SoC Temperature:", row_anchor(6), ui_text_style)
84+
.draw(target)
85+
.unwrap();
86+
});
87+
88+
let mut widgets = WidgetContainer::new(display);
89+
90+
widgets.push(|display| {
91+
DynamicWidget::text_center(
92+
ui.res.temperatures.soc_temperature.clone(),
93+
display,
94+
Point::new(120, 210),
95+
Box::new(|meas: &Measurement| format!("{:-4.0} C", meas.value)),
96+
)
97+
});
98+
99+
Box::new(Active { widgets })
100+
}
101+
}
102+
103+
#[async_trait]
104+
impl ActiveScreen for Active {
105+
fn my_type(&self) -> Screen {
106+
Screen::Alert(SCREEN_TYPE)
107+
}
108+
109+
async fn deactivate(mut self: Box<Self>) -> Display {
110+
self.widgets.destroy().await
111+
}
112+
113+
fn input(&mut self, _ev: InputEvent) {}
114+
}

0 commit comments

Comments
 (0)