Skip to main content

lcd_async/dcs/
set_invert_mode.rs

1use crate::options::ColorInversion;
2
3use super::DcsCommand;
4
5/// Set Invert Mode
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8pub struct SetInvertMode(ColorInversion);
9
10impl SetInvertMode {
11    /// Construct a new SetInvertMode DCS with the given value
12    pub fn new(color_inversion: ColorInversion) -> Self {
13        SetInvertMode(color_inversion)
14    }
15}
16
17impl DcsCommand for SetInvertMode {
18    fn instruction(&self) -> u8 {
19        match self.0 {
20            ColorInversion::Normal => 0x20,
21            ColorInversion::Inverted => 0x21,
22        }
23    }
24
25    fn fill_params_buf(&self, _buffer: &mut [u8]) -> usize {
26        0
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn set_invert_mode_chooses_correct_instruction() {
36        let ste = SetInvertMode(ColorInversion::Inverted);
37
38        let mut buffer = [0u8; 0];
39        assert_eq!(ste.instruction(), 0x21);
40        assert_eq!(ste.fill_params_buf(&mut buffer), 0);
41    }
42}