This commit is contained in:
Rafael Caricio 2020-06-17 01:06:02 +02:00 committed by Rafael Carício
parent 46562f23cf
commit 38d7a0e974
4 changed files with 10 additions and 47 deletions

View file

@ -12,43 +12,6 @@ use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex}; use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
//
// struct MyApp {
// time: Label,
// bt_label: Label,
// }
//
// impl MyApp {
// fn initialize(screen: &Obj) -> Result<Self, ()> {
// let mut screen_style = Style::default();
// screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
// screen_style.set_radius(State::DEFAULT, 0);
//
// let mut style_time = Style::default();
// style_time.set_text_color(State::DEFAULT, Color::from_rgb((255, 255, 255)));
//
// let time = screen.create_label()?;
// time.set_align(&screen, Align::Center, 0, 0)?;
// time.set_text(CString::new("20:46").unwrap().as_c_str())?;
// time.set_width(240)?;
// time.set_height(240)?;
//
// let bt = screen.create_label()?;
// bt.set_height(80)?;
// bt.set_recolor(true)?;
// bt.set_height(80)?;
// bt.set_recolor(true)?;
// bt.set_text(CString::new("#5794f2 \u{F293}#").unwrap().as_c_str())?;
// bt.set_label_align(LabelAlign::Left)?;
// bt.set_align(&screen, Align::InTopLeft, 0, 0)?;
//
// // attach styles
// screen.add_style(Part::Main, screen_style)?;
// time.add_style(Part::Main, style_time)?;
//
// Ok(MyApp { time, bt_label: bt })
// }
// }
fn main() -> Result<(), LvError> { fn main() -> Result<(), LvError> {
let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new( let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
@ -100,8 +63,9 @@ fn main() -> Result<(), LvError> {
let mut t: heapless::String<heapless::consts::U8> = heapless::String::from("test"); let mut t: heapless::String<heapless::consts::U8> = heapless::String::from("test");
t.push('\0').unwrap(); t.push('\0').unwrap();
CStr::from_bytes_with_nul_unchecked();
set_text(CStr::from_bytes_with_nul(t.as_bytes()).unwrap()).unwrap(); set_text(CStr::from_bytes_with_nul(t.as_bytes()).unwrap()).unwrap();
set_text(CStr::from_bytes_with_nul(("test\0").as_bytes()).unwrap()).unwrap(); set_text(cstr_core::CStr::from_bytes_with_nul("test\0".as_bytes()).unwrap()).unwrap();
set_text(cstr_core::CString::new("test").unwrap().as_c_str()).unwrap(); set_text(cstr_core::CString::new("test").unwrap().as_c_str()).unwrap();
let mut power = Label::new(&mut screen)?; let mut power = Label::new(&mut screen)?;

View file

@ -99,6 +99,7 @@ impl Rusty for LvFunc {
// generate constructor // generate constructor
if new_name.as_str().eq("create") { if new_name.as_str().eq("create") {
return Ok(quote! { return Ok(quote! {
pub fn new<C>(parent: &mut C) -> crate::LvResult<Self> pub fn new<C>(parent: &mut C) -> crate::LvResult<Self>
where where
C: crate::NativeObject, C: crate::NativeObject,
@ -113,6 +114,7 @@ impl Rusty for LvFunc {
} }
} }
} }
}); });
} }

View file

@ -15,7 +15,7 @@ build = "build.rs"
lvgl-sys = { version = "0.3.3", path = "../lvgl-sys" } lvgl-sys = { version = "0.3.3", path = "../lvgl-sys" }
cty = "0.2.1" cty = "0.2.1"
embedded-graphics = "0.6.2" embedded-graphics = "0.6.2"
cstr_core = { version = "0.2.0", default-features = false, features = ["alloc"] } cstr_core = { version = "0.2.0" }
bitflags = "1.2.1" bitflags = "1.2.1"
heapless = "0.5.5" heapless = "0.5.5"
typenum = "1.12.0" typenum = "1.12.0"

View file

@ -62,14 +62,13 @@ where
phantom: PhantomData, phantom: PhantomData,
}); });
let refresh_buffer1 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE];
let refresh_buffer2 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE];
let mut disp_buf = MaybeUninit::<lvgl_sys::lv_disp_buf_t>::uninit();
unsafe { unsafe {
// Create a display buffer for LittlevGL
// Initialize the display buffer // Initialize the display buffer
let refresh_buffer1 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE];
let refresh_buffer2 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE];
let mut disp_buf = MaybeUninit::<lvgl_sys::lv_disp_buf_t>::uninit();
lvgl_sys::lv_disp_buf_init( lvgl_sys::lv_disp_buf_init(
disp_buf.as_mut_ptr(), disp_buf.as_mut_ptr(),
Box::into_raw(Box::new(refresh_buffer1)?) as *mut cty::c_void, Box::into_raw(Box::new(refresh_buffer1)?) as *mut cty::c_void,
@ -87,8 +86,6 @@ where
disp_drv.buffer = Box::into_raw(disp_buf); disp_drv.buffer = Box::into_raw(disp_buf);
// Set your driver function // Set your driver function
disp_drv.flush_cb = Some(display_callback_wrapper::<T, C>); disp_drv.flush_cb = Some(display_callback_wrapper::<T, C>);
// TODO: DrawHandler type here
// Safety: `user_data` is set to NULL in C code.
disp_drv.user_data = &mut self.display_data as *mut _ as *mut cty::c_void; disp_drv.user_data = &mut self.display_data as *mut _ as *mut cty::c_void;
lvgl_sys::lv_disp_drv_register( lvgl_sys::lv_disp_drv_register(
&mut ManuallyDrop::take(&mut disp_drv) as *mut lvgl_sys::lv_disp_drv_t &mut ManuallyDrop::take(&mut disp_drv) as *mut lvgl_sys::lv_disp_drv_t