hd44780_controller/command/
set_backlight.rs

1use crate::device::*;
2
3use super::*;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
6pub struct SetBacklight(pub bool);
7
8impl SyncCommand for SetBacklight {
9    type Ret = ();
10
11    type Err = super::Error;
12
13    fn execute<D: SyncDevice + ?Sized>(&self, dev: &mut D) -> Result<Self::Ret, Self::Err> {
14        dev.set_backlight(self.0);
15        dev.flush().map_err(|_| super::Error::DeviceError)?;
16        dev.delay_us(50);
17
18        Ok(())
19    }
20}
21
22#[cfg(feature = "async")]
23#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
24impl AsyncCommand for SetBacklight {
25    type Ret = ();
26
27    type Err = super::Error;
28
29    async fn execute_async<D: AsyncDevice + ?Sized>(
30        &self,
31        dev: &mut D,
32    ) -> Result<Self::Ret, Self::Err> {
33        dev.set_backlight(self.0);
34        dev.flush_async()
35            .await
36            .map_err(|_| super::Error::DeviceError)?;
37        dev.delay_us_async(50).await;
38
39        Ok(())
40    }
41}