package edid import ( "fmt" "os" "github.com/anoopengineer/edidparser/edid" ) // EDID represents a display's extended display identification data: // https://wikipedia.org/wiki/Extended_Display_Identification_Data. type EDID struct { *edid.Edid bytes []byte } // "ManufacturerID-ProductCode" from EDID data. func (edid *EDID) String() string { if edid == nil { return "" } return fmt.Sprintf("%s-%d", edid.ManufacturerId, edid.ProductCode) } // Raw EDID bytes. func (edid *EDID) Bytes() []byte { if edid == nil { return nil } return edid.bytes } // Whether EDID matches a target EDID. False if either are nil. func (edid *EDID) Matches(target *EDID) bool { if edid == nil || target == nil { return false } return Matches(*edid, *target) } // Parses EDID from byte data. func NewFromBytes(bytes []byte) (*EDID, error) { edid, err := edid.NewEdid(bytes) if err != nil { return nil, fmt.Errorf("failed to parse EDID data: %w", err) } return &EDID{ Edid: edid, bytes: bytes, }, nil } // Parses EDID from the byte data in the file. func NewFromFile(path string) (*EDID, error) { bytes, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to read file %s: %w", path, err) } if string(bytes) == "" { return nil, fmt.Errorf("EDID file is empty") } return NewFromBytes(bytes) } // A and B match if they have the same (non-empty) manufacturer ID and product code. func Matches(a, b EDID) bool { if a.ManufacturerId == "" || b.ManufacturerId == "" { return false } else if a.ManufacturerId != b.ManufacturerId { return false } if a.ProductCode == 0 || b.ProductCode == 0 { return false } else if a.ProductCode != b.ProductCode { return false } return true }