Decode scancode into characters and write them to the screen

This commit is contained in:
pjht 2024-09-11 12:16:41 -05:00
parent 7b7f3e9a23
commit 1f30d20311
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -1,9 +1,9 @@
mod controller;
use std::{os::mikros::{ipc, syscalls}, sync::OnceLock};
use std::{fs::File, io::Write, os::mikros::{ipc, syscalls}, sync::OnceLock};
use controller::Ps2Controller;
use pc_keyboard::{ScancodeSet, ScancodeSet2};
use pc_keyboard::{layouts::Us104Key, EventDecoder, HandleControl, KeyState, Modifiers, ScancodeSet, ScancodeSet2};
static CONTROLLER: OnceLock<Ps2Controller> = OnceLock::new();
@ -110,12 +110,23 @@ fn main() {
syslog_client.send_text_message("ps2", "Set keyboard to scan code set 2").unwrap();
let mut scancode_decoder = ScancodeSet2::new();
let mut event_decoder = EventDecoder::new(Us104Key, HandleControl::Ignore);
let mut display = File::open("/dev/bga0").unwrap();
loop {
let byte = controller.read_port1();
let event = scancode_decoder.advance_state(byte).unwrap();
if let Some(event) = event {
dbg!(event);
let Some(event) = event else {
continue;
};
let key = event_decoder.process_keyevent(event);
let Some(key) = key else {
continue;
};
match key {
pc_keyboard::DecodedKey::RawKey(_) => (),
pc_keyboard::DecodedKey::Unicode(ch) => write!(display, "{}", ch).unwrap(),
}
}
}