diff --git a/hcu/src/main.rs b/hcu/src/main.rs index 276354d..f196a45 100644 --- a/hcu/src/main.rs +++ b/hcu/src/main.rs @@ -494,31 +494,35 @@ mod app { match pgn { PGN::SoftwareIdentification => { - let id = IdBuilder::from_pgn(PGN::SoftwareIdentification) - .sa(config.j1939_address) - .build(); - - let frame = FrameBuilder::new(id) - .copy_from_slice(&[ - 0x01, - crate::PKG_VERSION_MAJOR.parse::().unwrap(), - crate::PKG_VERSION_MINOR.parse::().unwrap(), - crate::PKG_VERSION_PATCH.parse::().unwrap(), - FIELD_DELIMITER, - ]) - .build(); - - ctx.shared.canbus1.lock(|canbus1| canbus1.send(frame)); + ctx.shared.canbus1.lock(|canbus1| { + let id = IdBuilder::from_pgn(PGN::SoftwareIdentification) + .sa(config.j1939_address) + .build(); + + let frame = FrameBuilder::new(id) + .copy_from_slice(&[ + 0x01, + crate::PKG_VERSION_MAJOR.parse::().unwrap(), + crate::PKG_VERSION_MINOR.parse::().unwrap(), + crate::PKG_VERSION_PATCH.parse::().unwrap(), + FIELD_DELIMITER, + ]) + .build(); + + canbus1.send(frame) + }); } PGN::ComponentIdentification => { - let id = IdBuilder::from_pgn(PGN::ComponentIdentification) - .sa(config.j1939_address) - .build(); + ctx.shared.canbus1.lock(|canbus1| { + let id = IdBuilder::from_pgn(PGN::ComponentIdentification) + .sa(config.j1939_address) + .build(); - // TODO: Get the serial number from the EEPROM - let frame = FrameBuilder::new(id).build(); + // TODO: Get the serial number from the EEPROM + let frame = FrameBuilder::new(id).build(); - ctx.shared.canbus1.lock(|canbus1| canbus1.send(frame)); + canbus1.send(frame) + }); } PGN::AddressClaimed => { ctx.shared.canbus1.lock(|canbus1| { diff --git a/vecraft/src/state.rs b/vecraft/src/state.rs index 850fce8..939f9ef 100644 --- a/vecraft/src/state.rs +++ b/vecraft/src/state.rs @@ -11,6 +11,11 @@ pub enum State { } impl State { + /// Converts the state to a byte value. + /// + /// # Returns + /// + /// The byte value corresponding to the state. pub fn as_byte(&self) -> u8 { match self { State::Nominal => 0x14, @@ -22,6 +27,11 @@ impl State { } } + /// Converts the state to an LED color. + /// + /// # Returns + /// + /// The LED color corresponding to the state. pub fn as_led(&self) -> crate::led::Color { match self { State::Nominal => crate::led::GREEN, @@ -100,14 +110,14 @@ impl System { /// Get the current state of the system. pub fn state(&self) -> State { - if self.ident { - State::Ident - } else if self.bus_error { + if self.bus_error { State::FaultyBusError } else if self.configuration_error { State::ConfigurationError } else if self.application_specific { State::ApplicationSpecific + } else if self.ident { + State::Ident } else { State::Nominal }