#![doc = include_str!("../README.md")]
#![forbid(missing_docs)]
#![forbid(unsafe_code)]
#![no_std]
#![allow(async_fn_in_trait)]
pub use embedded_fans::{Error, ErrorKind, ErrorType};
pub trait Fan: ErrorType {
fn max_rpm(&self) -> u16;
fn min_rpm(&self) -> u16;
fn min_start_rpm(&self) -> u16;
async fn set_speed_rpm(&mut self, rpm: u16) -> Result<u16, Self::Error>;
#[inline]
async fn set_speed_percent(&mut self, percent: u8) -> Result<u16, Self::Error> {
debug_assert!((0..=100).contains(&percent));
self.set_speed_rpm(((u32::from(self.max_rpm()) * u32::from(percent)) / 100) as u16)
.await
}
#[inline]
async fn set_speed_max(&mut self) -> Result<(), Self::Error> {
self.set_speed_rpm(self.max_rpm()).await?;
Ok(())
}
#[inline]
async fn stop(&mut self) -> Result<(), Self::Error> {
self.set_speed_rpm(0).await?;
Ok(())
}
}
impl<T: Fan + ?Sized> Fan for &mut T {
#[inline]
fn max_rpm(&self) -> u16 {
T::max_rpm(self)
}
#[inline]
fn min_rpm(&self) -> u16 {
T::min_rpm(self)
}
#[inline]
fn min_start_rpm(&self) -> u16 {
T::min_start_rpm(self)
}
#[inline]
async fn set_speed_rpm(&mut self, rpm: u16) -> Result<u16, Self::Error> {
T::set_speed_rpm(self, rpm).await
}
#[inline]
async fn set_speed_percent(&mut self, percent: u8) -> Result<u16, Self::Error> {
T::set_speed_percent(self, percent).await
}
#[inline]
async fn set_speed_max(&mut self) -> Result<(), Self::Error> {
T::set_speed_max(self).await
}
#[inline]
async fn stop(&mut self) -> Result<(), Self::Error> {
T::stop(self).await
}
}
pub trait RpmSense: ErrorType {
async fn rpm(&mut self) -> Result<u16, Self::Error>;
}
impl<T: RpmSense + ?Sized> RpmSense for &mut T {
#[inline]
async fn rpm(&mut self) -> Result<u16, Self::Error> {
T::rpm(self).await
}
}