1786003924

This commit is contained in:
2026-08-06 10:12:04 +02:00
parent 7088160a37
commit c26ac90dd2
5 changed files with 222 additions and 109 deletions

View File

@@ -1,76 +1,70 @@
mod rgba;
mod screen;
mod input;
mod trekstor;
use embedded_graphics::{prelude::*, primitives::{PrimitiveStyle, Rectangle}};
use evdev::{AbsoluteAxisCode, Device, EventSummary, KeyCode};
use screen::Screen;
use rgba::Rgba;
use evdev::KeyCode;
use crate::trekstor::Trekstor;
fn main() {
let mut screen = Screen::new();
let mut trekstor = Trekstor::new(30);
let red = (255, 0, 0, 255);
let green = (0, 255, 0, 255);
let blue = (0, 0, 255, 255);
trekstor.update(|screen, input| {
// retuyrningf false will exit loop
if input.is_just_pressed(KeyCode::BTN_TOUCH) {
println!("Touched {}x{}", input.x, input.y);
}
true
});
// /dev/input/event4: silead_ts
// let red = (255, 0, 0, 255);
// let green = (0, 255, 0, 255);
// let blue = (0, 0, 255, 255);
// // /dev/input/event4: silead_ts
Rectangle::new(Point::new(0, 0), Size::new(screen.width(), 1))
.into_styled(PrimitiveStyle::with_fill(Rgba::from(red)))
.draw(&mut screen)
.ok();
// Rectangle::new(Point::new(0, 0), Size::new(trekstor.screen.width(), 1))
// .into_styled(PrimitiveStyle::with_fill(Rgba::from(red)))
// .draw(&mut trekstor.screen)
// .ok();
Rectangle::new(Point::new(0, 1), Size::new(screen.width(), 1))
.into_styled(PrimitiveStyle::with_fill(Rgba::from(green)))
.draw(&mut screen)
.ok();
// Rectangle::new(Point::new(0, 1), Size::new(trekstor.screen.width(), 1))
// .into_styled(PrimitiveStyle::with_fill(Rgba::from(green)))
// .draw(&mut trekstor.screen)
// .ok();
Rectangle::new(Point::new(0, 2), Size::new(screen.width(), 1))
.into_styled(PrimitiveStyle::with_fill(Rgba::from(blue)))
.draw(&mut screen)
.ok();
let Ok(mut device) = Device::open("/dev/input/event4") else {
panic!("No TS");
};
// Rectangle::new(Point::new(0, 2), Size::new(trekstor.screen.width(), 1))
// .into_styled(PrimitiveStyle::with_fill(Rgba::from(blue)))
// .draw(&mut trekstor.screen)
// .ok();
// device.set_nonblocking(true).unwrap();
let mut x = -1;
let mut y = -1;
// loop {
// // println!("dont block");
loop {
// println!("dont block");
let Ok(events) = device.fetch_events() else {
continue;
};
// for event in events {
// match event.destructure() {
// EventSummary::AbsoluteAxis(_, AbsoluteAxisCode::ABS_X, value) => {
// x = (((value - 13) as f32 / 882.) * (trekstor.width() as f32)) as i32;
// }
// EventSummary::AbsoluteAxis(_, AbsoluteAxisCode::ABS_Y, value) => {
// y = (((value - 13) as f32 / 624.) * (trekstor.height() as f32)) as i32;
// }
// EventSummary::Key(_, KeyCode::BTN_TOUCH, value) => {
// // if value is 1, touch is started
// // if value is 0, touch ended
// println!("touch: {}", value)
// }
// _ => {}
// }
// }
for event in events {
match event.destructure(){
EventSummary::AbsoluteAxis(_, AbsoluteAxisCode::ABS_X, value) => {
x = (((value - 13) as f32 / 882.) * (screen.width() as f32)) as i32;
},
EventSummary::AbsoluteAxis(_, AbsoluteAxisCode::ABS_Y, value) => {
y = (((value - 13) as f32 / 624.) * (screen.height() as f32)) as i32;
},
EventSummary::Key(_, KeyCode::BTN_TOUCH, value) => {
// if value is 1, touch is started
// if value is 0, touch ended
println!("touch: {}", value)
},
_ => {}
}
}
// println!("{}x{}", x, y);
println!("{}x{}", x, y);
screen.clear(Rgba::from((0,0,0,255))).ok();
Rectangle::new(Point::new(x - 50, y - 50), Size::new(100, 100))
.into_styled(PrimitiveStyle::with_fill(Rgba::from(blue)))
.draw(&mut screen)
.ok();
}
// trekstor.clear(Rgba::from((0, 0, 0, 255))).ok();
// Rectangle::new(Point::new(x - 50, y - 50), Size::new(100, 100))
// .into_styled(PrimitiveStyle::with_fill(Rgba::from(blue)))
// .draw(&mut trekstor)
// .ok();
// }
}