Add uptime timer module (#15)

This commit is contained in:
Stuart Irwin
2024-03-11 00:51:43 -07:00
committed by GitHub
parent 8ba5d68e5a
commit 4434d82981

View File

@@ -29,6 +29,9 @@ pub enum LabelContent {
format: Arc<str>, format: Arc<str>,
timezone: Option<Arc<str>>, timezone: Option<Arc<str>>,
}, },
Timer {
format: Arc<str>,
},
Battery { Battery {
device: usize, device: usize,
low_threshold: f32, low_threshold: f32,
@@ -49,6 +52,10 @@ pub enum LabelData {
format: Arc<str>, format: Arc<str>,
timezone: Option<Tz>, timezone: Option<Tz>,
}, },
Timer {
format: Arc<str>,
start: Instant,
},
Exec { Exec {
last_exec: Instant, last_exec: Instant,
interval: f32, interval: f32,
@@ -85,6 +92,10 @@ pub fn modular_label_init(label: &mut ModularControl, content: &LabelContent) {
timezone: tz, timezone: tz,
}) })
} }
LabelContent::Timer { format } => Some(LabelData::Timer {
format: format.clone(),
start: Instant::now(),
}),
LabelContent::Exec { command, interval } => Some(LabelData::Exec { LabelContent::Exec { command, interval } => Some(LabelData::Exec {
last_exec: Instant::now(), last_exec: Instant::now(),
interval: *interval, interval: *interval,
@@ -155,6 +166,14 @@ pub(super) fn label_update(control: &mut ModularControl, _: &mut (), app: &mut A
control.set_text(&format!("{}", &date.format(&format))); control.set_text(&format!("{}", &date.format(&format)));
} }
} }
LabelData::Timer { format, start } => {
let mut format = format.clone().to_lowercase();
let duration = start.elapsed().as_secs();
format = format.replace("%s", &format!("{:02}", (duration % 60)));
format = format.replace("%m", &format!("{:02}", ((duration / 60) % 60)));
format = format.replace("%h", &format!("{:02}", ((duration / 60) / 60)));
control.set_text(&format);
}
LabelData::Exec { LabelData::Exec {
last_exec, last_exec,
interval, interval,