Skip to content

Commit c144a43

Browse files
Cleanups.
Prints the keycode after decoding, not the pix-engine event code. Also has some clippy fixes.
1 parent 724adb1 commit c144a43

1 file changed

Lines changed: 15 additions & 21 deletions

File tree

src/main.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ extern "C" fn memory_get_region(region: u8) -> common::Option<common::MemoryRegi
978978
static mut MEMORY_BLOCK: (*mut u8, usize) = (std::ptr::null_mut(), 0);
979979
match region {
980980
0 => {
981-
if unsafe { MEMORY_BLOCK.0 } == std::ptr::null_mut() {
981+
if unsafe { MEMORY_BLOCK.0.is_null() } {
982982
// Allocate 256 KiB of storage space for the OS to use
983983
let mut data = Box::new([0u8; 256 * 1024]);
984984
unsafe {
@@ -1004,16 +1004,14 @@ extern "C" fn hid_get_event() -> common::Result<common::Option<common::hid::HidE
10041004
let queue = EV_QUEUE.lock().unwrap();
10051005
match queue.as_ref().unwrap().try_recv() {
10061006
Ok(AppEvent::KeyUp(key)) => {
1007-
debug!("hid_get_event(KeyUp({:?}))", key);
1008-
common::Result::Ok(common::Option::Some(common::hid::HidEvent::KeyRelease(
1009-
convert_keycode(key),
1010-
)))
1007+
let code = common::hid::HidEvent::KeyRelease(convert_keycode(key));
1008+
debug!("hid_get_event() -> {:?}", code);
1009+
common::Result::Ok(common::Option::Some(code))
10111010
}
10121011
Ok(AppEvent::KeyDown(key)) => {
1013-
debug!("hid_get_event(KeyDown({:?}))", key);
1014-
common::Result::Ok(common::Option::Some(common::hid::HidEvent::KeyPress(
1015-
convert_keycode(key),
1016-
)))
1012+
let code = common::hid::HidEvent::KeyPress(convert_keycode(key));
1013+
debug!("hid_get_event() -> {:?}", code);
1014+
common::Result::Ok(common::Option::Some(code))
10171015
}
10181016
_ => common::Result::Ok(common::Option::None),
10191017
}
@@ -1457,22 +1455,18 @@ impl AppState for MyApp {
14571455
fn on_event(&mut self, _s: &mut PixState, event: &Event) -> PixResult<()> {
14581456
match event {
14591457
Event::KeyUp {
1460-
key,
1461-
keymod,
1462-
repeat,
1458+
key: Some(key),
1459+
keymod: _,
1460+
repeat: _,
14631461
} => {
1464-
if let Some(key) = key {
1465-
self.sender.send(AppEvent::KeyUp(key.clone())).unwrap();
1466-
}
1462+
self.sender.send(AppEvent::KeyUp(*key)).unwrap();
14671463
}
14681464
Event::KeyDown {
1469-
key,
1470-
keymod,
1471-
repeat,
1465+
key: Some(key),
1466+
keymod: _,
1467+
repeat: _,
14721468
} => {
1473-
if let Some(key) = key {
1474-
self.sender.send(AppEvent::KeyDown(key.clone())).unwrap();
1475-
}
1469+
self.sender.send(AppEvent::KeyDown(*key)).unwrap();
14761470
}
14771471
_ => {}
14781472
}

0 commit comments

Comments
 (0)