Decode input events in inputdev_event.rs
This commit is contained in:
parent
4430e86d5a
commit
f0cecc4940
9 changed files with 67 additions and 67 deletions
|
@ -12,5 +12,7 @@ bitflags = "1.2.1"
|
|||
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
|
||||
embedded-graphics = "0.7.1"
|
||||
oorandom ="11"
|
||||
virtio-input-decoder = "0.1.4"
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
|
@ -48,7 +48,6 @@ impl DrawingBoard {
|
|||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
// let fb_ptr = framebuffer() as *mut u8;
|
||||
let mut board = DrawingBoard::new();
|
||||
let _ = board.disp.clear(Rgb888::BLACK).unwrap();
|
||||
for i in 0..20 {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::{VIRTGPU_XRES, VIRTGPU_YRES, Display};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
extern crate alloc;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use user_lib::{event_get};
|
||||
use user_lib::{event_get, DecodeType, Key, KeyType};
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
@ -9,13 +9,17 @@ extern crate user_lib;
|
|||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
println!("Input device event test");
|
||||
let mut event=0;
|
||||
for _ in 0..3 {
|
||||
while event==0 {
|
||||
event = event_get();
|
||||
}
|
||||
println!("event: {:?}", event);
|
||||
loop {
|
||||
if let Some(event) = event_get() {
|
||||
if let Some(decoder_type) = event.decode() {
|
||||
println!("{:?}", decoder_type);
|
||||
if let DecodeType::Key(key, keytype) = decoder_type {
|
||||
if key == Key::Enter && keytype == KeyType::Press {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
}
|
|
@ -2,6 +2,8 @@ use super::*;
|
|||
use embedded_graphics::prelude::{RgbColor, Size};
|
||||
use embedded_graphics::{draw_target::DrawTarget, prelude::OriginDimensions};
|
||||
use embedded_graphics::pixelcolor::Rgb888;
|
||||
use virtio_input_decoder::Decoder;
|
||||
pub use virtio_input_decoder::{DecodeType, Key, KeyType, Mouse};
|
||||
|
||||
pub const VIRTGPU_XRES: u32 = 1280;
|
||||
pub const VIRTGPU_YRES: u32 = 800;
|
||||
|
@ -14,17 +16,6 @@ pub fn framebuffer_flush() -> isize {
|
|||
sys_framebuffer_flush()
|
||||
}
|
||||
|
||||
pub fn event_get() -> isize {
|
||||
sys_event_get()
|
||||
}
|
||||
|
||||
pub fn key_pressed() -> bool {
|
||||
if sys_key_pressed() == 1 {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
pub struct Display {
|
||||
pub size: Size,
|
||||
pub fb: &'static mut [u8],
|
||||
|
@ -76,3 +67,52 @@ impl DrawTarget for Display {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn event_get() -> Option<InputEvent> {
|
||||
let raw_value = sys_event_get();
|
||||
if raw_value == 0 {
|
||||
None
|
||||
} else {
|
||||
Some((raw_value as u64).into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn key_pressed() -> bool {
|
||||
if sys_key_pressed() == 1 {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct InputEvent {
|
||||
pub event_type: u16,
|
||||
pub code: u16,
|
||||
pub value: u32,
|
||||
}
|
||||
|
||||
impl From<u64> for InputEvent {
|
||||
fn from(mut v: u64) -> Self {
|
||||
let value = v as u32;
|
||||
v >>= 32;
|
||||
let code = v as u16;
|
||||
v >>= 16;
|
||||
let event_type = v as u16;
|
||||
Self {
|
||||
event_type,
|
||||
code,
|
||||
value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InputEvent {
|
||||
pub fn decode(&self) -> Option<DecodeType> {
|
||||
Decoder::decode(
|
||||
self.event_type as usize,
|
||||
self.code as usize,
|
||||
self.value as usize,
|
||||
).ok()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue