mirror of
https://github.com/FliegendeWurst/raspi-oled.git
synced 2024-11-22 10:24:58 +00:00
Update PC debug code
This commit is contained in:
parent
4e737ca007
commit
c5a930bed1
@ -28,7 +28,6 @@ pub type Oled = Ssd1351<SPIInterfaceNoCS<Spi, OutputPin>>;
|
|||||||
pub type Rng = Xoroshiro128StarStar;
|
pub type Rng = Xoroshiro128StarStar;
|
||||||
|
|
||||||
static BLACK: Rgb565 = Rgb565::new(0, 0, 0);
|
static BLACK: Rgb565 = Rgb565::new(0, 0, 0);
|
||||||
static TIME_COLOR: Rgb565 = Rgb565::new(0b01_111, 0b011_111, 0b01_111);
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if rppal::system::DeviceInfo::new().is_ok() {
|
if rppal::system::DeviceInfo::new().is_ok() {
|
||||||
@ -42,13 +41,13 @@ pub trait Context {
|
|||||||
fn do_action(&self, action: Action);
|
fn do_action(&self, action: Action);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContextDefault {
|
struct ContextDefault<D: DrawTarget<Color = Rgb565>> {
|
||||||
screensavers: Vec<Box<dyn Screensaver<Oled>>>,
|
screensavers: Vec<Box<dyn Screensaver<D>>>,
|
||||||
scheduled: Vec<Box<dyn Schedule>>,
|
scheduled: Vec<Box<dyn Schedule>>,
|
||||||
active: RefCell<Vec<Box<dyn Draw<Oled>>>>,
|
active: RefCell<Vec<Box<dyn Draw<D>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextDefault {
|
impl<D: DrawTarget<Color = Rgb565>> ContextDefault<D> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
ContextDefault {
|
ContextDefault {
|
||||||
screensavers: screensaver::screensavers(),
|
screensavers: screensaver::screensavers(),
|
||||||
@ -57,7 +56,7 @@ impl ContextDefault {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn loop_iter(&mut self, disp: &mut Oled, rng: &mut Rng) -> bool {
|
fn loop_iter(&mut self, disp: &mut D, rng: &mut Rng) -> bool {
|
||||||
let time = OffsetDateTime::now_utc().to_timezone(BERLIN);
|
let time = OffsetDateTime::now_utc().to_timezone(BERLIN);
|
||||||
// check schedules
|
// check schedules
|
||||||
for s in &self.scheduled {
|
for s in &self.scheduled {
|
||||||
@ -72,7 +71,7 @@ impl ContextDefault {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context for ContextDefault {
|
impl<D: DrawTarget<Color = Rgb565>> Context for ContextDefault<D> {
|
||||||
fn do_action(&self, action: Action) {
|
fn do_action(&self, action: Action) {
|
||||||
match action {
|
match action {
|
||||||
Action::Screensaver(id) => {
|
Action::Screensaver(id) => {
|
||||||
@ -93,7 +92,6 @@ fn pc_main() {}
|
|||||||
fn pc_main() {
|
fn pc_main() {
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
use rand_xoshiro::{rand_core::SeedableRng, Xoroshiro128StarStar};
|
|
||||||
use winit::{
|
use winit::{
|
||||||
dpi::LogicalSize,
|
dpi::LogicalSize,
|
||||||
event::{Event, WindowEvent},
|
event::{Event, WindowEvent},
|
||||||
@ -114,10 +112,11 @@ fn pc_main() {
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut iters = 0;
|
let mut iters = 0;
|
||||||
let mut disp = FrameOutput::new(128, 128);
|
let mut disp = FrameOutput::new(128, 128);
|
||||||
//disp.buffer.save("/tmp/x.png").unwrap();
|
|
||||||
let mut rng = Xoroshiro128StarStar::seed_from_u64(0);
|
|
||||||
let mut buffer_dirty = true;
|
let mut buffer_dirty = true;
|
||||||
|
|
||||||
|
let mut ctx = ContextDefault::new();
|
||||||
|
let mut rng = Xoroshiro128StarStar::seed_from_u64(17381);
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
// ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
|
// ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
|
||||||
// dispatched any events. This is ideal for games and similar applications.
|
// dispatched any events. This is ideal for games and similar applications.
|
||||||
@ -158,6 +157,7 @@ fn pc_main() {
|
|||||||
// redraw
|
// redraw
|
||||||
if Instant::now().duration_since(start) > Duration::from_millis(iters * 1000) {
|
if Instant::now().duration_since(start) > Duration::from_millis(iters * 1000) {
|
||||||
iters += 1;
|
iters += 1;
|
||||||
|
buffer_dirty = ctx.loop_iter(&mut disp, &mut rng);
|
||||||
//loop_iter(&mut disp).unwrap();
|
//loop_iter(&mut disp).unwrap();
|
||||||
/*
|
/*
|
||||||
let mut time = OffsetDateTime::now_utc().to_timezone(BERLIN);
|
let mut time = OffsetDateTime::now_utc().to_timezone(BERLIN);
|
||||||
@ -165,7 +165,7 @@ fn pc_main() {
|
|||||||
disp.clear(Rgb565::new(0, 0, 0)).unwrap();
|
disp.clear(Rgb565::new(0, 0, 0)).unwrap();
|
||||||
display_clock(&mut disp, &time).unwrap();
|
display_clock(&mut disp, &time).unwrap();
|
||||||
*/
|
*/
|
||||||
DUOLINGO.draw(&mut disp, &mut rng).unwrap();
|
//DUOLINGO.draw(&mut disp, &mut rng).unwrap();
|
||||||
/*
|
/*
|
||||||
let iters = iters % 300;
|
let iters = iters % 300;
|
||||||
let (s, c) = (iters as f32 * 0.1).sin_cos();
|
let (s, c) = (iters as f32 * 0.1).sin_cos();
|
||||||
@ -230,7 +230,6 @@ fn pc_main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
buffer_dirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buffer = surface.buffer_mut().unwrap();
|
let mut buffer = surface.buffer_mut().unwrap();
|
||||||
@ -332,7 +331,7 @@ fn main_loop(mut disp: Oled) {
|
|||||||
if !menu.is_empty() && Instant::now().duration_since(last_button).as_secs() >= 10 {
|
if !menu.is_empty() && Instant::now().duration_since(last_button).as_secs() >= 10 {
|
||||||
menu.clear();
|
menu.clear();
|
||||||
}
|
}
|
||||||
// check schedules
|
// run context loop
|
||||||
let dirty = ctx.loop_iter(&mut disp, &mut rng);
|
let dirty = ctx.loop_iter(&mut disp, &mut rng);
|
||||||
if dirty {
|
if dirty {
|
||||||
let _ = disp.flush(); // ignore bus write errors, they are harmless
|
let _ = disp.flush(); // ignore bus write errors, they are harmless
|
||||||
|
@ -82,7 +82,12 @@ pub struct TimeDisplay {
|
|||||||
impl TimeDisplay {
|
impl TimeDisplay {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
TimeDisplay {
|
TimeDisplay {
|
||||||
last_min: RefCell::new(OffsetDateTime::now_utc().checked_sub(Duration::minutes(2)).unwrap()),
|
last_min: RefCell::new(
|
||||||
|
OffsetDateTime::now_utc()
|
||||||
|
.to_timezone(BERLIN)
|
||||||
|
.checked_sub(Duration::minutes(2))
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user