Skip to content

Commit

Permalink
Add thermometer progression
Browse files Browse the repository at this point in the history
  • Loading branch information
bim9262 committed Mar 21, 2023
1 parent fa6ef33 commit b36ba34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ impl CommonApi {
.or_error(|| format!("Icon '{icon}' not found"))
}

pub fn get_icon_in_progression_bound(
&self,
icon: &str,
value: f64,
low: f64,
high: f64,
) -> Result<String> {
self.get_icon_in_progression(icon, (value.clamp(low, high) - low) / (high - low))
}

/// Repeatedly call provided async function until it succeeds.
///
/// This function will call `f` in a loop. If it succeeds, the result will be returned.
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub async fn run(config: Config, mut api: CommonApi) -> Result<()> {

'outer: loop {
widget.set_values(map! {
"icon" => Value::icon(api.get_icon("thermometer")?),
"icon" => Value::icon(api.get_icon_in_progression_bound("thermometer", max_temp, good, warn)?),
"average" => Value::degrees(avg_temp),
"min" => Value::degrees(min_temp),
"max" => Value::degrees(max_temp),
Expand Down

0 comments on commit b36ba34

Please sign in to comment.