1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#[derive(thiserror::Error, Debug)]
#[error("mock Ws2812Esp32RmtDriverError")]
pub struct Ws2812Esp32RmtDriverError;
pub struct Ws2812Esp32RmtDriver {
pub pixel_data: Option<Vec<u8>>,
}
impl Ws2812Esp32RmtDriver {
pub fn new(_channel_num: u8, _gpio_num: u32) -> Result<Self, Ws2812Esp32RmtDriverError> {
Ok(Self { pixel_data: None })
}
pub fn write(&mut self, pixel_data: &[u8]) -> Result<(), Ws2812Esp32RmtDriverError> {
self.pixel_data = Some(pixel_data.to_vec());
Ok(())
}
}
#[test]
fn test_ws2812_esp32_rmt_driver_mock() {
let sample_data: [u8; 6] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05];
let mut driver = Ws2812Esp32RmtDriver::new(0, 27).unwrap();
assert_eq!(driver.pixel_data, None);
driver.write(&sample_data).unwrap();
assert_eq!(driver.pixel_data.unwrap(), &sample_data);
}