Skip to content

Commit

Permalink
Merge pull request #33 from rust-embedded-community/moredocs
Browse files Browse the repository at this point in the history
Add more docs
  • Loading branch information
thejpster authored Feb 12, 2023
2 parents 93820bb + e0afc98 commit c28896e
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 52 deletions.
238 changes: 238 additions & 0 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/layouts/azerty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ mod test {
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Down)),
None
Some(DecodedKey::RawKey(KeyCode::NumpadLock))
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Up)),
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/colemak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};

/// A Colemak 101-key (or 104-key including Windows keys) keyboard.
///
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
pub struct Colemak;

impl KeyboardLayout for Colemak {
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/dvorak104.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};

/// A Dvorak 101-key (or 104-key including Windows keys) keyboard.
///
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
pub struct Dvorak104Key;

impl KeyboardLayout for Dvorak104Key {
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/dvorak_programmer104.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};

/// A Dvorak Programmer 101-key (or 104-key including Windows keys) keyboard.
///
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
pub struct DVP104Key;

impl KeyboardLayout for DVP104Key {
Expand Down
59 changes: 43 additions & 16 deletions src/layouts/jis109.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};
/// A standard Japan 106-key (or 109-key including Windows keys) keyboard.
///
/// Has a small space bar, to fit in extra keys.
///
/// We used <https://www.win.tue.nl/~aeb/linux/kbd/scancodes-8.html> as a
/// reference.
pub struct Jis109Key;

impl KeyboardLayout for Jis109Key {
Expand All @@ -16,11 +19,8 @@ impl KeyboardLayout for Jis109Key {
) -> DecodedKey {
match keycode {
KeyCode::Oem8 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('`')
} else {
DecodedKey::Unicode('@')
}
// hankaku/zenkaku/kanji
DecodedKey::RawKey(KeyCode::Oem8)
}
KeyCode::Escape => DecodedKey::Unicode(0x1B.into()),
KeyCode::Key1 => {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl KeyboardLayout for Jis109Key {
}
KeyCode::Key0 => {
if modifiers.is_shifted() {
DecodedKey::Unicode(' ')
DecodedKey::Unicode('~')
} else {
DecodedKey::Unicode('0')
}
Expand All @@ -102,46 +102,73 @@ impl KeyboardLayout for Jis109Key {
}
KeyCode::OemPlus => {
if modifiers.is_shifted() {
DecodedKey::Unicode('+')
DecodedKey::Unicode('¯')
} else {
DecodedKey::Unicode(';')
DecodedKey::Unicode('^')
}
}
KeyCode::Oem4 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('`')
} else {
DecodedKey::Unicode('@')
}
}
KeyCode::Oem6 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('{')
} else {
DecodedKey::Unicode('[')
}
}
KeyCode::Oem6 => {
KeyCode::Oem7 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('}')
} else {
DecodedKey::Unicode(']')
}
}
KeyCode::Oem7 => {
KeyCode::Oem1 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('|')
DecodedKey::Unicode('+')
} else {
DecodedKey::Unicode('\\')
DecodedKey::Unicode(';')
}
}
KeyCode::Oem1 => {
KeyCode::Oem3 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('*')
} else {
DecodedKey::Unicode(':')
}
}
KeyCode::Oem3 => {
KeyCode::Oem9 => {
// Muhenkan
DecodedKey::RawKey(keycode)
}
KeyCode::Oem10 => {
// Henkan/Zenkouho
DecodedKey::RawKey(keycode)
}
KeyCode::Oem11 => {
// Hiragana/Katakana
DecodedKey::RawKey(keycode)
}
KeyCode::Oem12 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('~')
DecodedKey::Unicode('_')
} else {
DecodedKey::Unicode('^')
DecodedKey::Unicode('\\')
}
}
KeyCode::Oem13 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('|')
} else {
DecodedKey::Unicode('¥')
}
}

e => {
let us = super::Us104Key;
us.map_keycode(e, modifiers, handle_ctrl)
Expand Down
65 changes: 64 additions & 1 deletion src/layouts/uk105.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,70 @@ impl KeyboardLayout for Uk105Key {
#[cfg(test)]
mod test {
use super::*;
use crate::{HandleControl, Keyboard, ScancodeSet2};
use crate::{EventDecoder, HandleControl, Keyboard, ScancodeSet, ScancodeSet1, ScancodeSet2};

#[test]
fn layout() {
// Codes taken from https://kbdlayout.info/kbduk/overview+scancodes?arrangement=ISO105
let mut s = ScancodeSet1::new();
let mut dec = EventDecoder::new(Uk105Key, HandleControl::Ignore);
let data = [
(0x29, '`'),
(0x02, '1'),
(0x03, '2'),
(0x04, '3'),
(0x05, '4'),
(0x06, '5'),
(0x07, '6'),
(0x08, '7'),
(0x09, '8'),
(0x0a, '9'),
(0x0b, '0'),
(0x0c, '-'),
(0x0d, '='),
(0x0f, '\t'),
(0x10, 'q'),
(0x11, 'w'),
(0x12, 'e'),
(0x13, 'r'),
(0x14, 't'),
(0x15, 'y'),
(0x16, 'u'),
(0x17, 'i'),
(0x18, 'o'),
(0x19, 'p'),
(0x1a, '['),
(0x1b, ']'),
(0x1e, 'a'),
(0x1f, 's'),
(0x20, 'd'),
(0x21, 'f'),
(0x22, 'g'),
(0x23, 'h'),
(0x24, 'j'),
(0x25, 'k'),
(0x26, 'l'),
(0x27, ';'),
(0x28, '\''),
(0x2B, '#'),
(0x1c, '\n'),
(0x56, '\\'),
(0x2c, 'z'),
(0x2d, 'x'),
(0x2e, 'c'),
(0x2f, 'v'),
(0x30, 'b'),
(0x31, 'n'),
(0x32, 'm'),
(0x33, ','),
(0x34, '.'),
(0x35, '/'),
];
for (code, unicode) in data {
let ev = s.advance_state(code).unwrap().unwrap();
assert_eq!(Some(DecodedKey::Unicode(unicode)), dec.process_keyevent(ev));
}
}

#[test]
fn test_hash() {
Expand Down
72 changes: 70 additions & 2 deletions src/layouts/us104.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};

/// A standard United States 101-key (or 104-key including Windows keys) keyboard.
///
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
pub struct Us104Key;

impl KeyboardLayout for Us104Key {
Expand Down Expand Up @@ -214,7 +214,7 @@ impl KeyboardLayout for Us104Key {
DecodedKey::Unicode(']')
}
}
KeyCode::Oem7 => {
KeyCode::Oem5 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('|')
} else {
Expand Down Expand Up @@ -484,3 +484,71 @@ impl KeyboardLayout for Us104Key {
}
}
}

#[cfg(test)]
mod test {
use super::*;
use crate::{EventDecoder, ScancodeSet, ScancodeSet1};

#[test]
fn layout() {
// Codes taken from https://kbdlayout.info/kbdus/overview+scancodes?arrangement=ANSI104
let mut s = ScancodeSet1::new();
let mut dec = EventDecoder::new(Us104Key, HandleControl::Ignore);
let data = [
(0x29, '`'),
(0x02, '1'),
(0x03, '2'),
(0x04, '3'),
(0x05, '4'),
(0x06, '5'),
(0x07, '6'),
(0x08, '7'),
(0x09, '8'),
(0x0a, '9'),
(0x0b, '0'),
(0x0c, '-'),
(0x0d, '='),
(0x0f, '\t'),
(0x10, 'q'),
(0x11, 'w'),
(0x12, 'e'),
(0x13, 'r'),
(0x14, 't'),
(0x15, 'y'),
(0x16, 'u'),
(0x17, 'i'),
(0x18, 'o'),
(0x19, 'p'),
(0x1a, '['),
(0x1b, ']'),
(0x56, '\\'),
(0x1e, 'a'),
(0x1f, 's'),
(0x20, 'd'),
(0x21, 'f'),
(0x22, 'g'),
(0x23, 'h'),
(0x24, 'j'),
(0x25, 'k'),
(0x26, 'l'),
(0x27, ';'),
(0x28, '\''),
(0x1c, '\n'),
(0x2c, 'z'),
(0x2d, 'x'),
(0x2e, 'c'),
(0x2f, 'v'),
(0x30, 'b'),
(0x31, 'n'),
(0x32, 'm'),
(0x33, ','),
(0x34, '.'),
(0x35, '/'),
];
for (code, unicode) in data {
let ev = s.advance_state(code).unwrap().unwrap();
assert_eq!(Some(DecodedKey::Unicode(unicode)), dec.process_keyevent(ev));
}
}
}
Loading

0 comments on commit c28896e

Please sign in to comment.