Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
gdobato committed Jun 6, 2024
1 parent d178178 commit 5e3c166
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions examples/usb_led_ctrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Led {
*self as u8
}

pub fn from_u8(value: u8) -> Option<Self> {
pub const fn from_u8(value: u8) -> Option<Self> {
match value {
0xAA => Some(Self::Red),
0xBB => Some(Self::Green),
Expand All @@ -63,7 +63,7 @@ impl Action {
*self as u8
}

pub fn from_u8(value: u8) -> Option<Self> {
pub const fn from_u8(value: u8) -> Option<Self> {
match value {
0x01 => Some(Self::On),
0x02 => Some(Self::Off),
Expand Down Expand Up @@ -147,18 +147,18 @@ mod app {
let msg = receiver.recv().await;
match msg {
Ok(data) => {
if let Some(led) = Led::from_u8(data[0]) {
if let Some(action) = Action::from_u8(data[1]) {
match (led, action) {
(Led::Red, Action::On) => led_red.on(),
(Led::Red, Action::Off) => led_red.off(),
(Led::Green, Action::On) => led_green.on(),
(Led::Green, Action::Off) => led_green.off(),
(Led::Blue, Action::On) => led_blue.on(),
(Led::Blue, Action::Off) => led_blue.off(),
}
debug!("Received: {:?} {:?}", led, action);
if let (Some(led), Some(action)) =
(Led::from_u8(data[0]), Action::from_u8(data[1]))
{
match (led, action) {
(Led::Red, Action::On) => led_red.on(),
(Led::Red, Action::Off) => led_red.off(),
(Led::Green, Action::On) => led_green.on(),
(Led::Green, Action::Off) => led_green.off(),
(Led::Blue, Action::On) => led_blue.on(),
(Led::Blue, Action::Off) => led_blue.off(),
}
debug!("Received: {:?} {:?}", led, action);
}
}
Err(_) => {
Expand Down

0 comments on commit 5e3c166

Please sign in to comment.