Compare commits
No commits in common. "keyboard-rewrite" and "master" have entirely different histories.
keyboard-r
...
master
1 changed files with 1 additions and 110 deletions
|
|
@ -38,10 +38,7 @@
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
use esp_idf_hal::{
|
use esp_idf_hal::{
|
||||||
gpio::{
|
gpio::{Gpio11, Gpio13, Gpio15, Gpio3, Gpio4, Gpio5, Gpio6, Gpio7, Gpio8, Gpio9, Input, InputOutput, Level, Output, PinDriver},
|
||||||
Gpio11, Gpio13, Gpio15, Gpio3, Gpio4, Gpio5, Gpio6, Gpio7, Gpio8, Gpio9, Input,
|
|
||||||
InputOutput, Level, Output, PinDriver,
|
|
||||||
},
|
|
||||||
peripheral::Peripheral,
|
peripheral::Peripheral,
|
||||||
};
|
};
|
||||||
use esp_idf_sys::EspError;
|
use esp_idf_sys::EspError;
|
||||||
|
|
@ -107,112 +104,6 @@ pub enum KeyImprint {
|
||||||
Space,
|
Space,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyImprint {
|
|
||||||
fn from_packed_address(i: usize, j: usize) -> Self {
|
|
||||||
match (i,j) {
|
|
||||||
(0, 0) => KeyImprint::Backquote,
|
|
||||||
(0, 1) => KeyImprint::Two,
|
|
||||||
(0, 2) => KeyImprint::Four,
|
|
||||||
(0, 3) => KeyImprint::Six,
|
|
||||||
(0, 4) => KeyImprint::Eight,
|
|
||||||
(0, 5) => KeyImprint::Zero,
|
|
||||||
(0, 6) => KeyImprint::Equal,
|
|
||||||
|
|
||||||
(1, 0) => KeyImprint::Tab,
|
|
||||||
(1, 1) => KeyImprint::W,
|
|
||||||
(1, 2) => KeyImprint::R,
|
|
||||||
(1, 3) => KeyImprint::Y,
|
|
||||||
(1, 4) => KeyImprint::I,
|
|
||||||
(1, 5) => KeyImprint::P,
|
|
||||||
(1, 6) => KeyImprint::CloseSquareBracket,
|
|
||||||
|
|
||||||
(2, 0) => KeyImprint::LeftFn,
|
|
||||||
(2, 1) => KeyImprint::A,
|
|
||||||
(2, 2) => KeyImprint::D,
|
|
||||||
(2, 3) => KeyImprint::G,
|
|
||||||
(2, 4) => KeyImprint::J,
|
|
||||||
(2, 5) => KeyImprint::L,
|
|
||||||
(2, 6) => KeyImprint::Quote,
|
|
||||||
|
|
||||||
(3, 0) => KeyImprint::LeftCtrl,
|
|
||||||
(3, 1) => KeyImprint::LeftAlt,
|
|
||||||
(3, 2) => KeyImprint::X,
|
|
||||||
(3, 3) => KeyImprint::V,
|
|
||||||
(3, 4) => KeyImprint::N,
|
|
||||||
(3, 5) => KeyImprint::Comma,
|
|
||||||
(3, 6) => KeyImprint::Slash,
|
|
||||||
|
|
||||||
(4, 0) => KeyImprint::One,
|
|
||||||
(4, 1) => KeyImprint::Three,
|
|
||||||
(4, 2) => KeyImprint::Five,
|
|
||||||
(4, 3) => KeyImprint::Seven,
|
|
||||||
(4, 4) => KeyImprint::Nine,
|
|
||||||
(4, 5) => KeyImprint::Minus,
|
|
||||||
(4, 6) => KeyImprint::Backspace,
|
|
||||||
|
|
||||||
(5, 0) => KeyImprint::Q,
|
|
||||||
(5, 1) => KeyImprint::E,
|
|
||||||
(5, 2) => KeyImprint::T,
|
|
||||||
(5, 3) => KeyImprint::U,
|
|
||||||
(5, 4) => KeyImprint::O,
|
|
||||||
(5, 5) => KeyImprint::OpenSquareBracket,
|
|
||||||
(5, 6) => KeyImprint::Backslash,
|
|
||||||
|
|
||||||
(6, 0) => KeyImprint::LeftShift,
|
|
||||||
(6, 1) => KeyImprint::S,
|
|
||||||
(6, 2) => KeyImprint::F,
|
|
||||||
(6, 3) => KeyImprint::H,
|
|
||||||
(6, 4) => KeyImprint::K,
|
|
||||||
(6, 5) => KeyImprint::SemiColon,
|
|
||||||
(6, 6) => KeyImprint::Enter,
|
|
||||||
|
|
||||||
(7, 0) => KeyImprint::LeftOpt,
|
|
||||||
(7, 1) => KeyImprint::Z,
|
|
||||||
(7, 2) => KeyImprint::C,
|
|
||||||
(7, 3) => KeyImprint::B,
|
|
||||||
(7, 4) => KeyImprint::M,
|
|
||||||
(7, 5) => KeyImprint::Period,
|
|
||||||
(7, 6) => KeyImprint::Space,
|
|
||||||
|
|
||||||
_ => unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FullKeyboardState {
|
|
||||||
packed_state: [u8; 7],
|
|
||||||
}
|
|
||||||
|
|
||||||
enum KeyAction {
|
|
||||||
Pressed,
|
|
||||||
Released,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FullKeyboardState {
|
|
||||||
fn changes<'a>(&'a self, old: &'a Self) -> impl Iterator<Item = (KeyImprint, KeyAction)> + 'a {
|
|
||||||
self.packed_state
|
|
||||||
.iter()
|
|
||||||
.zip(old.packed_state.iter())
|
|
||||||
.enumerate()
|
|
||||||
.flat_map(|(i, (new, old))| {
|
|
||||||
let diff = new ^ old; // XOR to find what changed
|
|
||||||
(0..8).filter_map(move |j| {
|
|
||||||
if (1 << j) & diff != 0 {
|
|
||||||
let key = KeyImprint::from_packed_address(i, j);
|
|
||||||
let action = if (1 << j) & new == 0 {
|
|
||||||
KeyAction::Released
|
|
||||||
} else {
|
|
||||||
KeyAction::Pressed
|
|
||||||
};
|
|
||||||
Some((key, action))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum Modified {
|
pub enum Modified {
|
||||||
Graph(char),
|
Graph(char),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue