Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
分享红外触控屏旋转操作与小工具源码
社区开发
845
views ·
1
replies ·
To
floor
Go
137******60
deepin
2019-03-07 00:17
Author
本帖最后由 kevin_lu 于 2019-3-11 10:40 编辑
近来在DEEPIN平台上开发一个基于红外触控直屏的应用,发现在deepin中屏幕转了但触控未改变,查了相关资料发现可以使用xinput指令进行修改。方法如下:一、手工操作
1. 安装xinput如果没有
sudo apt-get install xinput
2.查找红外线屏设备,这里系统直接识别的是"Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen"
xinput list
3.查看该屏相关参数(可选)
方法一,使用描述名称:xinput list-props "Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen"
方法二,使用ID值(例如在第2步中看到的ID=11):xinput list-props 11
4.修改属性"Coordinate Transformation Matrix"值,使触控坐标与屏幕同步,如右转
命令为:xinput set-prop 设备名|设备ID 属性名|属性ID 属性值
如:
xinput set-prop "Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen" "Coordinate Transformation Matrix" 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
或
xinput set-prop 11 131 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
注意,后面的属性值在逗号后必须要有至少1个空格。
5.在屏幕中测试方向是否正确
关于属性值(共9个)说明:
这是将物理坐标转化为逻辑坐标的矩阵,9个参数依次用字母表示如下:
a, b, c,
d, e, f,
h, i, g
设物理坐标为(x,y) 最后得到的逻辑坐标为(x', y')
计算公式为:
x' = (ax + by +c)/w'
y' = (dx + ey + f)/w'
其中w=(hx+iy+g),通常情况下屏幕坐标都用0-65535值来表示,所以h, i, g一般保持0, 0, 1不变。
以此计算得到正常、左转、右转、反转(旋转180度)4种值分别为
正常:1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0
左转:0.0, -1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0
右转:0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
反转:-1.0, 0.0, 1.0, 0.0, -1.0, 1.0, 0.0, 0.0, 1.0
二、使用sh脚本
这里仅使右转参数,也可详细编程,将有关参数定义都写入
xinput set-prop "Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen" "Coordinate Transformation Matrix" 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
存为一个脚本文件,如touch-right.sh
然后放入/usr/local/bin/ ,并设为可执行
sudo cp ./touch-right.sh /usr/local/bin/
sudo chmod +x /usr/local/bin/touch-right.sh
下面就可以直接在终端中使用命令touch-right.sh进行控制
另外,根据
snyh1010
网友的提示重新做了可以自己检测和同步的脚本auto-rotate,供参考。使用--map-to-output参数的好处是运行后当屏幕旋转时会自动同步触摸屏。
#! /bin/bash
has_xrandr=$(whereis xrandr | awk -F ':' '{print $2}')
if [ -z "$has_xrandr" ]
then
echo "未发现xrandr工具,请先用sudo apt-get install xrandr安装后重新运行本工具"
exit 1
fi
has_xinput=$(whereis xinput | awk -F ':' '{print $2}')
if [ -z "$has_xinput" ]
then
echo "未发现xinput工具,请先用sudo apt-get install xinput安装后重新运行本工具"
exit 1
fi
out_dev=$(xrandr | grep connected | awk '{print $1}')
touch_dev_id=$(xinput | grep IRTOUCH | awk -F '\t' '{print $2}' | awk -F '=' '{print $2}')
touch_dev_name=$(xinput | grep IRTOUCH | awk -F '\t' '{print substr($1, 7)}')
echo "屏幕设备为
{out_dev}"
echo "触摸设备为
{touch_dev_name} ID=${touch_dev_id}"
xinput --map-to-output $touch_dev_id "$out_dev"
echo "触摸设备[${touch_dev_name}]已经与屏幕[${out_dev}]同步"
exit 0
在此建议deepin把同步问题考虑进去,方便触控屏用户使用。
三、用python3写成小工具
touch-rotate.py.tar
四、登录桌面直接运行
以使用上面sh脚本为例
建立一个desktop实体文件touch-right.desktop
[Desktop Entry]
Type=Application
Exec=touch-right.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_IN]=Touch-Turn-Right
Name=Touch-Turn-Right
Comment[en_IN]=Touch Turn Right
Comment=Touch-Turn Right
复制到用户主目录下的.config/autostart/中
cp ./touch-right.desktop ~/.config/autostart/
重新注销登录桌面,检查触控屏是否与屏幕方向同步。
Reply
Like 0
Favorite
View the author
All Replies
许自强
deepin
2019-03-08 17:30
#1
过来点个赞
Reply
Like 0
View the author
Please
sign
in first
Featured Collection
Change
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Events
More
近来在DEEPIN平台上开发一个基于红外触控直屏的应用,发现在deepin中屏幕转了但触控未改变,查了相关资料发现可以使用xinput指令进行修改。方法如下:一、手工操作
1. 安装xinput如果没有
sudo apt-get install xinput
2.查找红外线屏设备,这里系统直接识别的是"Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen"
xinput list
3.查看该屏相关参数(可选)
方法一,使用描述名称:xinput list-props "Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen"
方法二,使用ID值(例如在第2步中看到的ID=11):xinput list-props 11
4.修改属性"Coordinate Transformation Matrix"值,使触控坐标与屏幕同步,如右转
命令为:xinput set-prop 设备名|设备ID 属性名|属性ID 属性值
如:
xinput set-prop "Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen" "Coordinate Transformation Matrix" 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
或
xinput set-prop 11 131 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
注意,后面的属性值在逗号后必须要有至少1个空格。
5.在屏幕中测试方向是否正确
关于属性值(共9个)说明:
这是将物理坐标转化为逻辑坐标的矩阵,9个参数依次用字母表示如下:
a, b, c,
d, e, f,
h, i, g
设物理坐标为(x,y) 最后得到的逻辑坐标为(x', y')
计算公式为:
x' = (ax + by +c)/w'
y' = (dx + ey + f)/w'
其中w=(hx+iy+g),通常情况下屏幕坐标都用0-65535值来表示,所以h, i, g一般保持0, 0, 1不变。
以此计算得到正常、左转、右转、反转(旋转180度)4种值分别为
正常:1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0
左转:0.0, -1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0
右转:0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
反转:-1.0, 0.0, 1.0, 0.0, -1.0, 1.0, 0.0, 0.0, 1.0
二、使用sh脚本
这里仅使右转参数,也可详细编程,将有关参数定义都写入
xinput set-prop "Beijing IRTOUCHSYSTEMS Co.,LtD IRTOUCH InfraRed USB TouchScreen" "Coordinate Transformation Matrix" 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0
存为一个脚本文件,如touch-right.sh
然后放入/usr/local/bin/ ,并设为可执行
sudo cp ./touch-right.sh /usr/local/bin/
sudo chmod +x /usr/local/bin/touch-right.sh
下面就可以直接在终端中使用命令touch-right.sh进行控制
另外,根据snyh1010网友的提示重新做了可以自己检测和同步的脚本auto-rotate,供参考。使用--map-to-output参数的好处是运行后当屏幕旋转时会自动同步触摸屏。
#! /bin/bash
has_xrandr=$(whereis xrandr | awk -F ':' '{print $2}')
if [ -z "$has_xrandr" ]
then
echo "未发现xrandr工具,请先用sudo apt-get install xrandr安装后重新运行本工具"
exit 1
fi
has_xinput=$(whereis xinput | awk -F ':' '{print $2}')
if [ -z "$has_xinput" ]
then
echo "未发现xinput工具,请先用sudo apt-get install xinput安装后重新运行本工具"
exit 1
fi
out_dev=$(xrandr | grep connected | awk '{print $1}')
touch_dev_id=$(xinput | grep IRTOUCH | awk -F '\t' '{print $2}' | awk -F '=' '{print $2}')
touch_dev_name=$(xinput | grep IRTOUCH | awk -F '\t' '{print substr($1, 7)}')
echo "屏幕设备为
echo "触摸设备为
xinput --map-to-output $touch_dev_id "$out_dev"
echo "触摸设备[${touch_dev_name}]已经与屏幕[${out_dev}]同步"
exit 0
在此建议deepin把同步问题考虑进去,方便触控屏用户使用。
三、用python3写成小工具
touch-rotate.py.tar
四、登录桌面直接运行
以使用上面sh脚本为例
建立一个desktop实体文件touch-right.desktop
[Desktop Entry]
Type=Application
Exec=touch-right.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_IN]=Touch-Turn-Right
Name=Touch-Turn-Right
Comment[en_IN]=Touch Turn Right
Comment=Touch-Turn Right
复制到用户主目录下的.config/autostart/中
cp ./touch-right.desktop ~/.config/autostart/
重新注销登录桌面,检查触控屏是否与屏幕方向同步。