Skip to content

Fix ID Manufacturer Name property #2

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ impl<'a> Reader<'a> {
fn read_u32(&mut self) -> Result<u32> {
Ok((self.read_u16()? as u32) | ((self.read_u16()? as u32) << 16))
}

// Big-endian version of `read_u16`
fn read_u16_be(&mut self) -> Result<u16> {
Ok((self.read_u8()? as u16) << 8 | ((self.read_u8()? as u16)))
}
}

/// The EDID information block.
Expand Down Expand Up @@ -182,11 +187,11 @@ pub struct ManufacturerID(pub char, pub char, pub char);
impl ManufacturerID {
fn parse(r: &mut Reader) -> Result<ManufacturerID> {
// The manufacturer ID is stored as three 5-bit
// characters in a 16-bit little endian field.
let k = r.read_u16()?;
let c1 = ((k & 0b0111110000000000) >> 10) as u8;
let c2 = ((k & 0b0000001111100000) >> 05) as u8;
let c3 = ((k & 0b0000000000011111) >> 00) as u8;
// characters in a 16-bit big-endian field.
let k = r.read_u16_be()?;
let c1 = (((k & 0b0111110000000000) >> 10) + 64) as u8;
let c2 = (((k & 0b0000001111100000) >> 05) + 64) as u8;
let c3 = (((k & 0b0000000000011111) >> 00) + 64) as u8;
Ok(ManufacturerID(c1 as char, c2 as char, c3 as char))
}
}
Expand Down