-
Notifications
You must be signed in to change notification settings - Fork 1
/
i2c-bus-by-monitor-serial
executable file
·60 lines (54 loc) · 2.38 KB
/
i2c-bus-by-monitor-serial
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
#!/bin/bash
# This script will return i2c bus device number of monitor with specified
# serial number. It is usefull, because i2c bus numbers are not consistent over reboots,
# and you may want to control specific monitor via ddccontrol/gddccontrol
# and you have several monitors of the same model.
# Note also that you can see your monitor's s/n in /var/log/Xorg.0.log
# Search there for "Serial No:" or your monitor model.
# In case you have several monitors with the same s/n (for example, you flashed the same edid) or
# you have attached several video cables to the same monitor, then several ids will be returned.
# switch-monitor-source script uses this script as a dependency.
I2C_ID=-1 # do not change this
SN_FOUND=FALSE # for detecting duplication of sn
if [[ $1 == "-s" ]]; then
TARGET_SERIAL=$2 # use passed s/n via second argument
else
:
# TARGET_SERIAL="0G2TG7360DXB" # default sn. change to your monitor's serial number
echo "You have not specified serial number to search. Use -s <serial_number>"; exit
fi
echo "Searching i2c device number which monitor s/n is $TARGET_SERIAL"
sudo get-edid 1>/dev/null 2>~/tmp.txt
POTENTIAL_BUSES=`cat ~/tmp.txt | grep "potential busses found:" | cut -f2 -d":"`
# echo POTENTIAL_BUSES=$POTENTIAL_BUSES
for X in $POTENTIAL_BUSES
do
# echo $X
sudo get-edid -b $X 2>/dev/null | grep $TARGET_SERIAL >/dev/null
# It would be better to use "get-edid -b $X | parse-edid | grep $TARGET_SERIAL"
# instead of just grepping binary output, but for the monent of
# programming this script, parse-edid do not shows monitor serial =(
# TODO parse-edid to show monitor serial number
if [[ $? != 0 ]]; then
# echo "$X is not for $TARGET_SERIAL"
continue
else
# echo "Got it! $X is for $TARGET_SERIAL"
if [[ $SN_FOUND == "FALSE" ]]; then
SN_FOUND=TRUE
I2C_ID=$X
#break # do not break, because we will also check for duplication of sn on other buses
else
SN_FOUND=DUPLICATED
I2C_ID=" $I2C_ID and $X" # do not remove starting space, it will separate found ids with spaces
fi
fi
done
if [[ $I2C_ID == "-1" ]]; then
echo "Not found";
elif [[ $SN_FOUND == "DUPLICATED" ]]; then
echo "Warning! you have several buses with the same monitor s/n."
echo "$I2C_ID" # we need quotes to save beginning space in variable. It prevents from blindly using first found I2C_ID
else
echo "$I2C_ID" # All ok, found single i2c id for specified sn
fi