mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +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_interval: u32,
|
||||||
/// chord state array
|
/// chord state array
|
||||||
chord: [[bool; KBD_COLS]; KBD_ROWS],
|
chord: [[bool; KBD_COLS]; KBD_ROWS],
|
||||||
/// memoize when chord is all false
|
/// memoize number of keys that have been pressed
|
||||||
chord_active: bool,
|
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) {
|
fn handle_kbd(_irq_no: usize, arg: *mut usize) {
|
||||||
|
|
@ -260,9 +262,10 @@ mod implementation {
|
||||||
repeating_key: None,
|
repeating_key: None,
|
||||||
rate_timestamp: timestamp,
|
rate_timestamp: timestamp,
|
||||||
chord_timestamp: timestamp,
|
chord_timestamp: timestamp,
|
||||||
chord_interval: 100,
|
chord_interval: 50,
|
||||||
chord: [[false; KBD_COLS]; KBD_ROWS],
|
chord: [[false; KBD_COLS]; KBD_ROWS],
|
||||||
chord_active: false,
|
chord_active: 0,
|
||||||
|
chord_captured: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
xous::claim_interrupt(
|
xous::claim_interrupt(
|
||||||
|
|
@ -395,22 +398,24 @@ mod implementation {
|
||||||
5. Extract chord state and turn into scancode using lookup table
|
5. Extract chord state and turn into scancode using lookup table
|
||||||
6. Return scancodes
|
6. Return scancodes
|
||||||
*/
|
*/
|
||||||
|
let was_idle = self.chord_active == 0;
|
||||||
if let Some(kds) = &keydowns {
|
if let Some(kds) = &keydowns {
|
||||||
for &rc in kds.iter() {
|
for &rc in kds.iter() {
|
||||||
self.chord[rc.r as usize][rc.c as usize] = true;
|
self.chord[rc.r as usize][rc.c as usize] = true;
|
||||||
|
self.chord_active += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::trace!("self.chord: {:?}", self.chord);
|
log::trace!("self.chord: {:?}", self.chord);
|
||||||
let mut keystates: Vec<char, U4> = Vec::new();
|
let mut keystates: Vec<char, U4> = Vec::new();
|
||||||
|
|
||||||
if self.chord_active || keydowns.is_some() {
|
|
||||||
let now = self.ticktimer.elapsed_ms();
|
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() {
|
if self.chord_active != 0 && ((now - self.chord_timestamp) >= self.chord_interval as u64) && !self.chord_captured {
|
||||||
log::trace!("chord_active set");
|
self.chord_captured = true;
|
||||||
self.chord_active = true;
|
|
||||||
self.chord_timestamp = now;
|
|
||||||
} else if self.chord_active && ((now - self.chord_timestamp) >= self.chord_interval as u64) {
|
|
||||||
log::trace!("interpreting chords");
|
log::trace!("interpreting chords");
|
||||||
// extract chord state
|
// extract chord state
|
||||||
/*
|
/*
|
||||||
|
|
@ -501,16 +506,18 @@ mod implementation {
|
||||||
log::trace!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}",
|
log::trace!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}",
|
||||||
up, left, right, down, center, space, esc, func);
|
up, left, right, down, center, space, esc, func);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let Some(kus) = &keyups {
|
if let Some(kus) = &keyups {
|
||||||
for &rc in kus.iter() {
|
for &rc in kus.iter() {
|
||||||
self.chord[rc.r as usize][rc.c as usize] = false;
|
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() {
|
if self.chord_active == 0 {
|
||||||
self.chord_active = false;
|
self.chord_captured = false;
|
||||||
log::trace!("chord_active going false");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keystates
|
keystates
|
||||||
|
|
@ -797,7 +804,7 @@ fn send_rawstates(cb_conns: &mut [Option<CID>; 16], krs: &KeyRawStates) {
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
use crate::implementation::Keyboard;
|
use crate::implementation::Keyboard;
|
||||||
log_server::init_wait().unwrap();
|
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());
|
info!("my PID is {}", xous::process::id());
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue