1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::os::unix::ffi::OsStrExt;
use std::io;
use ddc::Edid;
use {I2cDdc, I2cDeviceDdc, i2c_linux};
pub struct Enumerator {
inner: i2c_linux::Enumerator,
}
impl Enumerator {
pub fn new() -> io::Result<Self> {
Ok(Enumerator {
inner: i2c_linux::Enumerator::new()?,
})
}
}
impl Iterator for Enumerator {
type Item = I2cDeviceDdc;
fn next(&mut self) -> Option<Self::Item> {
while let Some((i2c, dev)) = self.inner.next() {
let name = match dev.attribute_value("name") {
Some(v) => v,
None => continue,
};
let skip_prefix = [
"SMBus",
"soc:i2cdsi",
"smu",
"mac-io",
"u4",
];
if skip_prefix.iter().any(|p| name.as_bytes().starts_with(p.as_bytes())) {
continue
}
let mut i2c = I2cDdc::new(i2c);
if i2c.read_edid(0, &mut [0u8]).is_err() {
continue
}
return Some(i2c)
}
None
}
}