mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
basic chording is working
This commit is contained in:
parent
d807098ed1
commit
0ef50b178f
1 changed files with 111 additions and 104 deletions
|
|
@ -209,8 +209,10 @@ mod implementation {
|
|||
chord_interval: u32,
|
||||
/// chord state array
|
||||
chord: [[bool; KBD_COLS]; KBD_ROWS],
|
||||
/// memoize when chord is all false
|
||||
chord_active: bool,
|
||||
/// memoize number of keys that have been pressed
|
||||
chord_active: u32,
|
||||
/// indicate if the chord has been captured. Once captured, further presses are ignored, until all keys are let up.
|
||||
chord_captured: bool,
|
||||
}
|
||||
|
||||
fn handle_kbd(_irq_no: usize, arg: *mut usize) {
|
||||
|
|
@ -260,9 +262,10 @@ mod implementation {
|
|||
repeating_key: None,
|
||||
rate_timestamp: timestamp,
|
||||
chord_timestamp: timestamp,
|
||||
chord_interval: 100,
|
||||
chord_interval: 50,
|
||||
chord: [[false; KBD_COLS]; KBD_ROWS],
|
||||
chord_active: false,
|
||||
chord_active: 0,
|
||||
chord_captured: false,
|
||||
};
|
||||
|
||||
xous::claim_interrupt(
|
||||
|
|
@ -395,22 +398,24 @@ mod implementation {
|
|||
5. Extract chord state and turn into scancode using lookup table
|
||||
6. Return scancodes
|
||||
*/
|
||||
let was_idle = self.chord_active == 0;
|
||||
if let Some(kds) = &keydowns {
|
||||
for &rc in kds.iter() {
|
||||
self.chord[rc.r as usize][rc.c as usize] = true;
|
||||
self.chord_active += 1;
|
||||
}
|
||||
}
|
||||
log::trace!("self.chord: {:?}", self.chord);
|
||||
let mut keystates: Vec<char, U4> = Vec::new();
|
||||
|
||||
if self.chord_active || keydowns.is_some() {
|
||||
let now = self.ticktimer.elapsed_ms();
|
||||
if was_idle && self.chord_active != 0 {
|
||||
// "rising edge" of chord_active
|
||||
self.chord_timestamp = now; // record the beginning of the chord active interval
|
||||
}
|
||||
|
||||
if !self.chord_active && keydowns.is_some() {
|
||||
log::trace!("chord_active set");
|
||||
self.chord_active = true;
|
||||
self.chord_timestamp = now;
|
||||
} else if self.chord_active && ((now - self.chord_timestamp) >= self.chord_interval as u64) {
|
||||
if self.chord_active != 0 && ((now - self.chord_timestamp) >= self.chord_interval as u64) && !self.chord_captured {
|
||||
self.chord_captured = true;
|
||||
log::trace!("interpreting chords");
|
||||
// extract chord state
|
||||
/*
|
||||
|
|
@ -501,16 +506,18 @@ mod implementation {
|
|||
log::trace!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}",
|
||||
up, left, right, down, center, space, esc, func);
|
||||
}
|
||||
}
|
||||
if let Some(kus) = &keyups {
|
||||
for &rc in kus.iter() {
|
||||
self.chord[rc.r as usize][rc.c as usize] = false;
|
||||
if self.chord_active > 0 {
|
||||
self.chord_active -= 1;
|
||||
} else {
|
||||
log::error!("received more keyups than we had keydowns!")
|
||||
}
|
||||
}
|
||||
// not sure if this is the right way to handle keyups, but let's try it.
|
||||
if keyups.is_some() {
|
||||
self.chord_active = false;
|
||||
log::trace!("chord_active going false");
|
||||
}
|
||||
if self.chord_active == 0 {
|
||||
self.chord_captured = false;
|
||||
}
|
||||
|
||||
keystates
|
||||
|
|
@ -797,7 +804,7 @@ fn send_rawstates(cb_conns: &mut [Option<CID>; 16], krs: &KeyRawStates) {
|
|||
fn xmain() -> ! {
|
||||
use crate::implementation::Keyboard;
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue