diff --git a/src/bin/main.rs b/src/bin/main.rs index 7806ee7..b19a00a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,9 +1,54 @@ use fpt::lr35902::LR35902; fn main() { - let mut lr = LR35902::new(); + let lr: Box = Box::from(LR35902::new()); - loop { - lr.step(); - } + let the_thing = thread::spawn(move || { + let mut loop_cycle: u64 = 0; + loop { + loop_cycle += 1; + println!("---[Loop cycle: {:#04}]---", loop_cycle); + lr.step(); + println!(); + } + }); + + the_loop(&lr); + the_thing.join().unwrap(); +} + +fn the_loop<'a>(lr: &'a LR35902) { + let event_loop: EventLoop<()> = EventLoop::new(); + let window = WindowBuilder::new().build(&event_loop).unwrap(); + + event_loop.run(move |event, _, control_flow| { + match event { + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => { + println!("The close button was pressed; stopping"); + control_flow.set_exit(); + } + Event::MainEventsCleared => { + // Application update code. + // lr35902.step(); + + // Queue a RedrawRequested event. + // + // You only need to call this if you've determined that you need to redraw, in + // applications which do not always need to. Applications that redraw continuously + // can just render here instead. + window.request_redraw(); + } + Event::RedrawRequested(_) => { + // Redraw the application. + // + // It's preferable for applications that do not render continuously to render in + // this event rather than in MainEventsCleared, since rendering in here allows + // the program to gracefully handle redraws requested by the OS. + } + _ => (), + } + }); }