keyboard server basics seem working

This commit is contained in:
bunnie 2021-01-12 04:13:15 +08:00
parent 5cad631569
commit 426c747f8f
3 changed files with 90 additions and 63 deletions

View file

@ -255,7 +255,7 @@ fn xmain() -> ! {
info!("COM: starting main loop"); info!("COM: starting main loop");
loop { loop {
let envelope = xous::receive_message(com_sid).unwrap(); let envelope = xous::receive_message(com_sid).unwrap();
info!("COM: Message: {:?}", envelope); // info!("COM: Message: {:?}", envelope);
if let Ok(opcode) = Opcode::try_from(&envelope.body) { if let Ok(opcode) = Opcode::try_from(&envelope.body) {
// info!("COM: Opcode: {:?}", opcode); // info!("COM: Opcode: {:?}", opcode);
match opcode { match opcode {

View file

@ -74,7 +74,7 @@ fn map_dvorak(code: RowCol) -> ScanCode {
(3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3)
// the F4/ctrl key also doubles as a power key // the F4/ctrl key also doubles as a power key
(3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4)
(4, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')},
(3, 6) => ScanCode{key: Some('→'), shift: Some('→'), hold: None, alt: Some('→')}, (3, 6) => ScanCode{key: Some('→'), shift: Some('→'), hold: None, alt: Some('→')},
(6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')},
(8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')},
@ -147,7 +147,7 @@ fn map_qwerty(code: RowCol) -> ScanCode {
(3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3) (3, 8) => ScanCode{key: Some(0x13_u8.into()), shift: Some(0x13_u8.into()), hold: Some(0x13_u8.into()), alt: Some(0x13_u8.into())}, // DC3 (F3)
// the F4/ctrl key also doubles as a power key // the F4/ctrl key also doubles as a power key
(3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4) (3, 9) => ScanCode{key: Some(0x14_u8.into()), shift: Some(0x14_u8.into()), hold: Some(0x14_u8.into()), alt: Some(0x14_u8.into())}, // DC4 (F4)
(4, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')}, (8, 3) => ScanCode{key: Some('←'), shift: Some('←'), hold: None, alt: Some('←')},
(3, 6) => ScanCode{key: Some('→'), shift: Some('→'), hold: None, alt: Some('→')}, (3, 6) => ScanCode{key: Some('→'), shift: Some('→'), hold: None, alt: Some('→')},
(6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')}, (6, 4) => ScanCode{key: Some('↑'), shift: Some('↑'), hold: None, alt: Some('↑')},
(8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')}, (8, 2) => ScanCode{key: Some('↓'), shift: Some('↓'), hold: None, alt: Some('↓')},
@ -298,8 +298,6 @@ mod implementation {
} }
if keys.len() > 0 { if keys.len() > 0 {
for &rc in keys.iter() {
}
Some(keys) Some(keys)
} else { } else {
None None
@ -324,13 +322,21 @@ mod implementation {
if self.csr.rf(utra::keyboard::EV_PENDING_KEYPRESSED) != 0 { if self.csr.rf(utra::keyboard::EV_PENDING_KEYPRESSED) != 0 {
// only do the getcodes() call if we saw a change to key state // only do the getcodes() call if we saw a change to key state
self.lastcode = self.kbd_getcodes(); self.lastcode = self.kbd_getcodes();
/*
info!("KBD: pending detected");
if let Some(lc) = &self.lastcode {
for &code in lc.iter() {
info!("KBD: {:?}", code);
}
} else {
info!("KBD: lastcode is None");
}*/
// clear the pending bit // clear the pending bit
self.csr.wfo(utra::keyboard::EV_PENDING_KEYPRESSED, 1); self.csr.wfo(utra::keyboard::EV_PENDING_KEYPRESSED, 1);
}
let elapsed = ticktimer_server::elapsed_ms(self.ticktimer).unwrap() - self.timestamp; let elapsed = ticktimer_server::elapsed_ms(self.ticktimer).unwrap() - self.timestamp;
if (elapsed <= 1) || self.lastcode.is_none() { if elapsed <= 1 {
// skip debounce processing if time elapsed is too short or there's no key updates // skip debounce processing if time elapsed is too short
(None, None) (None, None)
} else { } else {
self.timestamp = elapsed; self.timestamp = elapsed;
@ -392,6 +398,9 @@ mod implementation {
(retdowns, retups) (retdowns, retups)
} }
} else {
(None, None)
}
} }
pub fn track_chord(&mut self, keyups: Option<Vec<RowCol, U16>>, keydowns: Option<Vec<RowCol, U16>>) -> Vec<char, U4> { pub fn track_chord(&mut self, keyups: Option<Vec<RowCol, U16>>, keydowns: Option<Vec<RowCol, U16>>) -> Vec<char, U4> {
@ -552,8 +561,10 @@ mod implementation {
if ((rc.r == 8) && (rc.c == 5)) || ((rc.r == 8) && (rc.c == 9)) { if ((rc.r == 8) && (rc.c == 5)) || ((rc.r == 8) && (rc.c == 9)) {
// if the shift key was tapped twice, remove the shift modifier // if the shift key was tapped twice, remove the shift modifier
if self.shift_up == false { if self.shift_up == false {
//info!("KBD: shift down true");
self.shift_down = true; self.shift_down = true;
} else { } else {
//info!("KBD: shift up false");
self.shift_up = false; self.shift_up = false;
} }
} }
@ -585,10 +596,13 @@ mod implementation {
if ((rc.r == 8) && (rc.c == 5)) || ((rc.r == 8) && (rc.c == 9)) { if ((rc.r == 8) && (rc.c == 5)) || ((rc.r == 8) && (rc.c == 9)) {
// only set the shift-up if we didn't previously clear it with a double-tap of shift // only set the shift-up if we didn't previously clear it with a double-tap of shift
if self.shift_down { if self.shift_down {
//info!("KBD: shift up true");
self.shift_up = true; self.shift_up = true;
} }
//info!("KBD: shift down false");
self.shift_down = false; self.shift_down = false;
} else { } else {
//info!("KBD: adding non-shift entry {:?}", rc);
ku_ns.push(RowCol{r: rc.r as _, c: rc.c as _}).unwrap(); ku_ns.push(RowCol{r: rc.r as _, c: rc.c as _}).unwrap();
} }
} }
@ -631,6 +645,7 @@ mod implementation {
if let Some(kus) = &keyups_noshift { if let Some(kus) = &keyups_noshift {
for &rc in kus.iter() { for &rc in kus.iter() {
// info!("KBD: interpreting keyups_noshift entry {:?}", rc);
let code = match self.map { let code = match self.map {
KeyMap::Qwerty => map_qwerty(rc), KeyMap::Qwerty => map_qwerty(rc),
KeyMap::Dvorak => map_dvorak(rc), KeyMap::Dvorak => map_dvorak(rc),
@ -694,6 +709,7 @@ mod implementation {
} }
} else { } else {
if let Some(keycode) = code.key { if let Some(keycode) = code.key {
// info!("KBD: appeding normal key '{}'", keycode);
ks.push(keycode).or_else(report_ok).ok(); ks.push(keycode).or_else(report_ok).ok();
} }
} }
@ -815,8 +831,19 @@ fn xmain() -> ! {
_ => xous::yield_slice(), _ => xous::yield_slice(),
} }
let (keyups, keydowns) = kbd.update(); let (keydowns, keyups) = kbd.update();
/*
if let Some(ku) = &keyups {
for &kus in ku.iter() {
info!("KBD: keyup r{} c{}", kus.r, kus.c);
}
}
if let Some(kd) = &keydowns {
for &kds in kd.iter() {
info!("KBD: keydown r{} c{}", kds.r, kds.c);
}
}
*/
if keyups.is_some() || keydowns.is_some() { if keyups.is_some() || keydowns.is_some() {
// send the raw codes // send the raw codes
for conn in raw_conns.iter() { for conn in raw_conns.iter() {
@ -852,9 +879,10 @@ fn xmain() -> ! {
if kc.len() > 0 { if kc.len() > 0 {
let mut keys: [char; 4] = ['\u{0000}', '\u{0000}', '\u{0000}', '\u{0000}']; let mut keys: [char; 4] = ['\u{0000}', '\u{0000}', '\u{0000}', '\u{0000}'];
for i in 0..kc.len() { for i in 0..kc.len() {
// info!("KBD: sending key '{}'", kc[i]);
keys[i] = kc[i]; keys[i] = kc[i];
} }
for conn in raw_conns.iter() { for conn in normal_conns.iter() {
xous::send_message(*conn, api::Opcode::KeyboardEvent(keys).into()).map(|_| ()).expect("KBD: Couldn't send event to listener"); xous::send_message(*conn, api::Opcode::KeyboardEvent(keys).into()).map(|_| ()).expect("KBD: Couldn't send event to listener");
} }
} }

View file

@ -115,7 +115,7 @@ fn event_thread(_arg: usize) {
info!("SHELL|event_thread: starting COM response handler thread"); info!("SHELL|event_thread: starting COM response handler thread");
loop { loop {
let envelope = xous::syscall::receive_message(shell_server).expect("couldn't get address"); let envelope = xous::syscall::receive_message(shell_server).expect("couldn't get address");
info!("SHELL|event_thread: got message {:?}", envelope); // info!("SHELL|event_thread: got message {:?}", envelope);
if let Ok(opcode) = com::api::Opcode::try_from(&envelope.body) { if let Ok(opcode) = com::api::Opcode::try_from(&envelope.body) {
match opcode { match opcode {
com::api::Opcode::BattStatsEvent(stats) => { com::api::Opcode::BattStatsEvent(stats) => {
@ -361,7 +361,6 @@ fn shell_main() -> ! {
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) { if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
if elapsed_time - last_time > 500 { if elapsed_time - last_time > 500 {
last_time = elapsed_time; last_time = elapsed_time;
info!("SHELL: Requesting batt stats from COM");
get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM"); get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
} }
} else { } else {