This commit is contained in:
Rafael Caricio 2020-06-20 12:58:26 +02:00
parent dc0e2f947a
commit 7781c12809
2 changed files with 19 additions and 8 deletions

View file

@ -123,7 +123,7 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::{Color, UI}; use crate::UI;
use core::marker::PhantomData; use core::marker::PhantomData;
use embedded_graphics::drawable::Pixel; use embedded_graphics::drawable::Pixel;
use embedded_graphics::geometry::Size; use embedded_graphics::geometry::Size;
@ -133,14 +133,14 @@ mod test {
struct FakeDisplay<C> struct FakeDisplay<C>
where where
C: PixelColor + From<Color>, C: PixelColor,
{ {
p: PhantomData<C>, p: PhantomData<C>,
} }
impl<C> DrawTarget<C> for FakeDisplay<C> impl<C> DrawTarget<C> for FakeDisplay<C>
where where
C: PixelColor + From<Color>, C: PixelColor,
{ {
type Error = (); type Error = ();
@ -161,14 +161,13 @@ mod test {
let disp: FakeDisplay<Rgb565> = FakeDisplay { p: PhantomData }; let disp: FakeDisplay<Rgb565> = FakeDisplay { p: PhantomData };
ui.disp_drv_register(disp); ui.disp_drv_register(disp)?;
fn read_touchpad_device() -> Point { fn read_touchpad_device() -> BufferStatus {
Point::new(120, 23) InputData::Touch(Point::new(120, 23)).pressed().once()
} }
let mut touch_screen = let mut touch_screen = Pointer::new(|| read_touchpad_device());
Pointer::new(|| InputData::Touch(read_touchpad_device()).pressed().once());
ui.indev_drv_register(&mut touch_screen)?; ui.indev_drv_register(&mut touch_screen)?;

View file

@ -58,6 +58,18 @@ where
} }
pub fn indev_drv_register(&mut self, input_device: &mut Pointer) -> LvResult<()> { pub fn indev_drv_register(&mut self, input_device: &mut Pointer) -> LvResult<()> {
if self.display_data.is_none() {
// TODO: Better yet would be to create a display struct that one register the
// input device in that instance. Represents better the LVGL correct usage. Also it's
// inline with unrepresentable invalid states using Rust type system.
// ```rust
// let disp = ui.disp_drv_register(embed_graph_disp)?;
// disp.indev_drv_register(disp);
// ...
// window.update(&disp)
// ```
return Err(LvError::Uninitialized);
}
unsafe { unsafe {
let descr = lvgl_sys::lv_indev_drv_register(&mut input_device.driver as *mut _); let descr = lvgl_sys::lv_indev_drv_register(&mut input_device.driver as *mut _);
input_device.set_descriptor(descr)?; input_device.set_descriptor(descr)?;