basic i/o
This commit is contained in:
78
src/main.rs
Normal file
78
src/main.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
mod rgba;
|
||||
mod screen;
|
||||
|
||||
use embedded_graphics::{prelude::*, primitives::{PrimitiveStyle, Rectangle}};
|
||||
use evdev::{AbsoluteAxisCode, Device, EventSummary, KeyCode};
|
||||
use screen::Screen;
|
||||
use rgba::Rgba;
|
||||
|
||||
|
||||
fn main() {
|
||||
let mut screen = Screen::new();
|
||||
|
||||
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, 1), Size::new(screen.width(), 1))
|
||||
.into_styled(PrimitiveStyle::with_fill(Rgba::from(green)))
|
||||
.draw(&mut 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");
|
||||
};
|
||||
|
||||
// device.set_nonblocking(true).unwrap();
|
||||
|
||||
let mut x = -1;
|
||||
let mut y = -1;
|
||||
|
||||
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.) * (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);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user