Fix examples

This commit is contained in:
Rafael Caricio 2020-06-19 14:14:46 +02:00 committed by Rafael Carício
parent adee5994dc
commit 64527c3f2a
5 changed files with 60 additions and 41 deletions

View file

@ -11,7 +11,7 @@ use lvgl::{LvError, Widget};
use lvgl_sys;
use std::sync::{mpsc, Arc as StdArc, Mutex};
use std::thread::sleep;
use std::time::Duration;
use std::time::{Duration, Instant};
fn main() -> Result<(), LvError> {
let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
@ -55,14 +55,19 @@ fn main() -> Result<(), LvError> {
let (stop_ch, read_ch) = mpsc::channel();
let closure_ui = threaded_ui.clone();
let mut loop_started = Instant::now();
let tick_thr = std::thread::spawn(move || loop {
let period = Duration::from_millis(10);
closure_ui.lock().unwrap().tick_inc(period);
// Needs to be called periodically for LittlevGL internal timing calculations.
{
let mut ui = closure_ui.lock().unwrap();
ui.tick_inc(loop_started.elapsed());
}
sleep(period);
sleep(Duration::from_millis(5));
if read_ch.try_recv().is_ok() {
break;
}
loop_started = Instant::now();
});
let mut angle = 0;
@ -80,9 +85,8 @@ fn main() -> Result<(), LvError> {
sleep(Duration::from_millis(50));
let mut ui = threaded_ui.lock().unwrap();
ui.task_handler();
if let Some(disp) = ui.get_display_ref() {
threaded_ui.lock().unwrap().task_handler();
if let Some(disp) = threaded_ui.lock().unwrap().get_display_ref() {
window.update(disp);
}

View file

@ -10,7 +10,7 @@ use lvgl::{self, Align, Animation, Color, Event, LvError, Part, State, Widget, U
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
use std::time::{Duration, Instant};
fn main() -> Result<(), LvError> {
let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
@ -40,7 +40,7 @@ fn main() -> Result<(), LvError> {
bar.set_align(&mut screen, Align::Center, 0, 10)?;
bar.set_range(0, 100)?;
bar.on_event(|_b, _e| {
println!("received");
println!("Completed!");
})?;
// // Set the indicator style for the bar object
@ -61,14 +61,19 @@ fn main() -> Result<(), LvError> {
let (stop_ch, read_ch) = mpsc::channel();
let closure_ui = threaded_ui.clone();
let mut loop_started = Instant::now();
let tick_thr = std::thread::spawn(move || loop {
let period = Duration::from_millis(5);
closure_ui.lock().unwrap().tick_inc(period);
// Needs to be called periodically for LittlevGL internal timing calculations.
{
let mut ui = closure_ui.lock().unwrap();
ui.tick_inc(loop_started.elapsed());
}
sleep(period);
sleep(Duration::from_millis(5));
if read_ch.try_recv().is_ok() {
break;
}
loop_started = Instant::now();
});
let mut i = 0;
@ -80,14 +85,13 @@ fn main() -> Result<(), LvError> {
.unwrap()
.event_send(&mut bar, Event::Clicked)?
}
bar.set_value(i, Animation::OFF)?;
bar.set_value(i, Animation::ON)?;
i += 1;
sleep(Duration::from_millis(50));
let mut ui = threaded_ui.lock().unwrap();
ui.task_handler();
if let Some(disp) = ui.get_display_ref() {
threaded_ui.lock().unwrap().task_handler();
if let Some(disp) = threaded_ui.lock().unwrap().get_display_ref() {
window.update(disp);
}

View file

@ -10,7 +10,7 @@ use lvgl::{self, Align, Color, Event, LvError, Part, State, Widget, UI};
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
use std::time::{Duration, Instant};
fn main() -> Result<(), LvError> {
let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
@ -60,22 +60,24 @@ fn main() -> Result<(), LvError> {
let (stop_ch, read_ch) = mpsc::channel();
let closure_ui = threaded_ui.clone();
let mut loop_started = Instant::now();
let tick_thr = std::thread::spawn(move || loop {
let period = Duration::from_millis(5);
// Needs to be called periodically for LittlevGL internal timing calculations.
closure_ui.lock().unwrap().tick_inc(period);
{
let mut ui = closure_ui.lock().unwrap();
ui.tick_inc(loop_started.elapsed());
}
sleep(period);
sleep(Duration::from_millis(5));
if read_ch.try_recv().is_ok() {
break;
}
loop_started = Instant::now();
});
'running: loop {
let mut ui = threaded_ui.lock().unwrap();
ui.task_handler();
if let Some(disp) = ui.get_display_ref() {
threaded_ui.lock().unwrap().task_handler();
if let Some(disp) = threaded_ui.lock().unwrap().get_display_ref() {
window.update(disp);
}
for event in window.events() {
@ -86,7 +88,10 @@ fn main() -> Result<(), LvError> {
} => {
println!("Clicked on: {:?}", point);
// Send a event to the button directly
ui.event_send(&mut button, Event::Clicked)?;
threaded_ui
.lock()
.unwrap()
.event_send(&mut button, Event::Clicked)?;
}
SimulatorEvent::Quit => break 'running,
_ => {}

View file

@ -11,7 +11,7 @@ use lvgl::{Align, Color, LvError, Part, State, Widget, UI};
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
use std::time::{Duration, Instant};
fn main() -> Result<(), LvError> {
let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
@ -79,14 +79,19 @@ fn main() -> Result<(), LvError> {
let (stop_ch, read_ch) = mpsc::channel();
let closure_ui = threaded_ui.clone();
let mut loop_started = Instant::now();
let tick_thr = std::thread::spawn(move || loop {
let period = Duration::from_millis(250);
closure_ui.lock().unwrap().tick_inc(period);
// Needs to be called periodically for LittlevGL internal timing calculations.
{
let mut ui = closure_ui.lock().unwrap();
ui.tick_inc(loop_started.elapsed());
}
sleep(period);
sleep(Duration::from_millis(5));
if read_ch.try_recv().is_ok() {
break;
}
loop_started = Instant::now();
});
let mut i = 0;
@ -100,9 +105,8 @@ fn main() -> Result<(), LvError> {
sleep(Duration::from_secs(1));
let mut ui = threaded_ui.lock().unwrap();
ui.task_handler();
if let Some(disp) = ui.get_display_ref() {
threaded_ui.lock().unwrap().task_handler();
if let Some(disp) = threaded_ui.lock().unwrap().get_display_ref() {
window.update(disp);
}

View file

@ -9,7 +9,7 @@ use lvgl::{self, Align, Color, LvError, Part, State, Widget, UI};
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
use std::time::{Duration, Instant};
fn main() -> Result<(), LvError> {
let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
@ -60,25 +60,27 @@ fn main() -> Result<(), LvError> {
let (stop_ch, read_ch) = mpsc::channel();
let closure_ui = threaded_ui.clone();
let mut loop_started = Instant::now();
let tick_thr = std::thread::spawn(move || loop {
let period = Duration::from_millis(5);
// Needs to be called periodically for LittlevGL internal timing calculations.
closure_ui.lock().unwrap().tick_inc(period);
{
let mut ui = closure_ui.lock().unwrap();
ui.tick_inc(loop_started.elapsed());
}
sleep(period);
sleep(Duration::from_millis(5));
if read_ch.try_recv().is_ok() {
break;
}
loop_started = Instant::now();
});
let mut i = 0;
'running: loop {
gauge.set_value(0, i)?;
let mut ui = threaded_ui.lock().unwrap();
ui.task_handler();
if let Some(disp) = ui.get_display_ref() {
threaded_ui.lock().unwrap().task_handler();
if let Some(disp) = threaded_ui.lock().unwrap().get_display_ref() {
window.update(disp);
}
@ -95,7 +97,7 @@ fn main() -> Result<(), LvError> {
}
}
sleep(Duration::from_millis(50));
sleep(Duration::from_millis(15));
if i > 99 {
i = 0;