Skip to content
Snippets Groups Projects
Commit e1c6aca7 authored by koenigl's avatar koenigl
Browse files

button subsystem: use manual panic! instead of unwrap()

unwrap only works if the error value implements Debug, however since the
buttons subsystem doesn't return TockValue<E> but TockError this isn't the case
(anymore).  In theory one should think about refactoring check_user_presence()
to return TockResult<()> and possibly implementing some way for Ctap2StatusCode
to be converted to TockError enums or similar.  Then we can just pass errors
up the stack instead of panicking early.
parent 0b6cecf6
No related branches found
No related tags found
No related merge requests found
......@@ -333,17 +333,26 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> {
Ok(x) => x,
Err(err) => panic!("Drivers were already taken when attempting to retrieve them"),
};
let buttons_driver = all_drivers.buttons.init_driver().unwrap();
let _buttons_callback = buttons_driver.subscribe(&mut |_button_num, state| {
let buttons_driver = match all_drivers.buttons.init_driver() {
Ok(x) => x,
Err(err) => panic!("Couldn't init buttons subsystem"),
};
let _buttons_callback = match buttons_driver.subscribe(&mut |_button_num, state| {
match state {
ButtonState::Pressed => button_touched.set(true),
ButtonState::Released => (),
};
}).unwrap();
}) {
Ok(x) => x,
Err(err) => panic!("Couldn't subscribe to button"),
};
let mut buttons = buttons_driver.buttons();
// At the moment, all buttons are accepted. You can customize your setup here.
for mut button in &mut buttons {
button.enable_interrupt().unwrap();
match button.enable_interrupt() {
Ok(_) => {},
Err(_) => panic!("Couldn't enable interrupts"),
}
}
let mut keepalive_response = Ok(());
......@@ -362,8 +371,14 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> {
let mut keepalive_callback = timer_context.with_callback(|_, _| {
keepalive_expired.set(true);
});
let mut keepalive = keepalive_callback.init().unwrap();
let keepalive_alarm = keepalive.set_alarm(KEEPALIVE_DELAY).unwrap();
let mut keepalive = match keepalive_callback.init() {
Ok(x) => x,
Err(_) => panic!("Couldn't init callback!"),
};
let keepalive_alarm = match keepalive.set_alarm(KEEPALIVE_DELAY) {
Ok(x) => x,
Err(_) => panic!("Couldn't set alarm"),
};
// Wait for a button touch or an alarm.
usb_ctap_hid::yieldk_for(|| button_touched.get() || keepalive_expired.get());
......@@ -398,7 +413,10 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> {
// Cleanup button callbacks.
for mut button in &mut buttons {
button.disable_interrupt().unwrap();
match button.disable_interrupt() {
Ok(_) => {},
Err(_) => panic!("Couldn't disable interrupts"),
};
}
// Returns whether the user was present.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment