Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(orb-mcu-util): print new diamond evt version #381

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ seek-camera.path = "seek-camera/wrapper"

[workspace.dependencies.orb-messages]
git = "https://github.com/worldcoin/orb-messages"
rev = "3dffed6e01fa4aaca347eca52be87bfc298508eb"
rev = "c251751145f5376087f99305fbdfba10718e3cdd"

[workspace.dependencies.nusb]
git = "https://github.com/kevinmehall/nusb"
Expand Down
85 changes: 67 additions & 18 deletions mcu-util/src/orb/revision.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,77 @@
use std::fmt::{Display, Formatter};

use orb_mcu_interface::orb_messages;
use std::fmt::{Display, Formatter};

#[derive(Clone, Debug, Default)]
pub struct OrbRevision(pub orb_messages::Hardware);

trait OrbVersionFromInt {
fn from_version_i32(value: i32) -> Self;
}
impl OrbVersionFromInt for orb_messages::hardware::OrbVersion {
fn from_version_i32(value: i32) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn from_version_i32(value: i32) -> Self {
const fn from_version_i32(value: i32) -> Self {

Copy link
Collaborator Author

@fouge fouge Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting... is this const a new thing?
what does it bring?

Copy link
Collaborator

@TheButlah TheButlah Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its like constexpr in c++ - evaluation is done at compile-time. Const functions have been around for a long time (possibly since 1.0?). But they are more useful nowadays, and especially after the inline_const feature was stabilized last year: rust-lang/rust#104087.

const mostly gets used in places where assignment to a const or a static variable is necessary.

match value {
1 => orb_messages::hardware::OrbVersion::HwVersionPearlEv1,
2 => orb_messages::hardware::OrbVersion::HwVersionPearlEv2,
3 => orb_messages::hardware::OrbVersion::HwVersionPearlEv3,
4 => orb_messages::hardware::OrbVersion::HwVersionPearlEv4,
5 => orb_messages::hardware::OrbVersion::HwVersionPearlEv5,
6 => orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1,
7 => orb_messages::hardware::OrbVersion::HwVersionDiamondPoc2,
8 => orb_messages::hardware::OrbVersion::HwVersionDiamondB3,
9 => orb_messages::hardware::OrbVersion::HwVersionDiamondEvt,
_ => orb_messages::hardware::OrbVersion::HwVersionUnknown,
}
}
}

impl Display for OrbRevision {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.0.version
== i32::from(orb_messages::hardware::OrbVersion::HwVersionUnknown)
{
write!(f, "unknown")
} else if self.0.version
< orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1 as i32
{
write!(f, "EVT{:?}", self.0.version)
} else {
write!(
f,
"Diamond_B{:?}",
self.0.version
- orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1 as i32
+ 1
)
match orb_messages::hardware::OrbVersion::from_version_i32(self.0.version) {
orb_messages::hardware::OrbVersion::HwVersionUnknown => {
// from_version_i32 returned unknown but the version might not be 0
// meaning it's known by the firmware but not by the current binary
if self.0.version
== orb_messages::hardware::OrbVersion::HwVersionUnknown as i32
{
return write!(f, "unknown");
}

tracing::error!(
"A new orb revision might not be implemented by that binary: {:?}.",
self.0.version
);

// let's write if it's a pearl or diamond orb, guessing by the version number
if self.0.version
< orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1 as i32
{
write!(f, "Pearl_unknown")
} else {
write!(f, "Diamond_unknown")
}
}
orb_messages::hardware::OrbVersion::HwVersionPearlEv1
| orb_messages::hardware::OrbVersion::HwVersionPearlEv2
| orb_messages::hardware::OrbVersion::HwVersionPearlEv3
| orb_messages::hardware::OrbVersion::HwVersionPearlEv4
| orb_messages::hardware::OrbVersion::HwVersionPearlEv5 => {
write!(f, "EVT{:?}", self.0.version)
Copy link
Member

@Qbicz Qbicz Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
write!(f, "EVT{:?}", self.0.version)
write!(f, "Pearl EV{:?}", self.0.version)

I'd prefer verbose unless any tools depend on it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would prefer too but indeed, this would break things

}
orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1
| orb_messages::hardware::OrbVersion::HwVersionDiamondPoc2
| orb_messages::hardware::OrbVersion::HwVersionDiamondB3 => {
write!(
f,
"Diamond_B{:?}",
self.0.version
- orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1
as i32
+ 1
)
}
orb_messages::hardware::OrbVersion::HwVersionDiamondEvt => {
write!(f, "Diamond_EVT")
}
}
}
}