Touch input device #27

Open
rafaelcaricio wants to merge 15 commits from indev into master
3 changed files with 7 additions and 11 deletions
Showing only changes of commit c8c63456bc - Show all commits

View file

@ -1,3 +1,4 @@
use core::cell::Cell;
use cstr_core::CString; use cstr_core::CString;
use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*; use embedded_graphics::prelude::*;
@ -8,8 +9,6 @@ use lvgl::input_device::{BufferStatus, InputData, Pointer};
use lvgl::style::Style; use lvgl::style::Style;
use lvgl::widgets::{Btn, Label}; use lvgl::widgets::{Btn, Label};
use lvgl::{self, Align, Color, LvError, Part, State, Widget, UI}; use lvgl::{self, Align, Color, LvError, Part, State, Widget, UI};
use std::cell::RefCell;
use std::rc::Rc;
use std::thread::sleep; use std::thread::sleep;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -26,13 +25,11 @@ fn main() -> Result<(), LvError> {
ui.disp_drv_register(display)?; ui.disp_drv_register(display)?;
// Initial state of input // Initial state of input
let latest_touch_status: Rc<RefCell<BufferStatus>> = Rc::new(RefCell::new( let latest_touch_status: Cell<BufferStatus> =
InputData::Touch(Point::new(0, 0)).released().once(), Cell::new(InputData::Touch(Point::new(0, 0)).released().once());
));
// Register the input mode // Register the input mode
let internal = Rc::clone(&latest_touch_status); let mut touch_screen = Pointer::new(|| latest_touch_status.get());
let mut touch_screen = Pointer::new(move || internal.borrow().clone());
ui.indev_drv_register(&mut touch_screen)?; ui.indev_drv_register(&mut touch_screen)?;
@ -52,7 +49,7 @@ fn main() -> Result<(), LvError> {
let mut btn_state = false; let mut btn_state = false;
button.on_event(|mut btn, event| { button.on_event(|mut btn, event| {
println!("Some event! {:?}", event); println!("Button received event: {:?}", event);
if let lvgl::Event::Clicked = event { if let lvgl::Event::Clicked = event {
if btn_state { if btn_state {
let nt = CString::new("Click me!").unwrap(); let nt = CString::new("Click me!").unwrap();
@ -62,7 +59,6 @@ fn main() -> Result<(), LvError> {
btn_lbl.set_text(nt.as_c_str()).unwrap(); btn_lbl.set_text(nt.as_c_str()).unwrap();
} }
btn_state = !btn_state; btn_state = !btn_state;
println!("Clicked! Inner..");
btn.toggle().unwrap(); btn.toggle().unwrap();
} }
})?; })?;

View file

@ -47,7 +47,7 @@ pub struct Pointer {
} }
impl Pointer { impl Pointer {
pub fn new<F>(mut handler: F) -> Self pub fn new<F>(handler: F) -> Self
where where
F: Fn() -> BufferStatus, F: Fn() -> BufferStatus,
{ {

View file

@ -1,4 +1,4 @@
use crate::input_device::{BufferStatus, Pointer}; use crate::input_device::Pointer;
use crate::mem::Box; use crate::mem::Box;
use crate::{Color, Event, LvError, LvResult, Obj, Widget}; use crate::{Color, Event, LvError, LvResult, Obj, Widget};
use core::marker::PhantomData; use core::marker::PhantomData;