PR

Raspberry pi4 タッチパネル縦向き設定

raspberry pi & touch screen raspberry pi
スポンサーリンク

シェルスクリプトの作成

rotate_touch_screen.sh

#!/bin/bash
#90 deg
#xinput --set-prop 'wch.cn USB2IIC_CTP_CONTROL' 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1
#270 deg
xinput --set-prop 'wch.cn USB2IIC_CTP_CONTROL' 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1

実行権限の追加

chmod +x rotate_touch_screen.sh

自動起動の設定

自動実行はsystemdを使用。OSのバージョンが変わってautostartは使えないらしい。

/etc/systemd/system/rotate_touch_screen.service

[Unit]
Description=routate_touch_screen
After=multi-user.target rescue.service rescue.target display-manager.service
[Service]
User=pi
Environment=DISPLAY=:0
ExecStart=/home/pi/rotate_touch_screen.sh
[Install]
WantedBy=graphical.target

[Unit] After display-manager.service
[Service] Environment=DISPLAY=:0
[Install] graphical.target
ディスプレイ起動後に実行するために必要らしい。

サービスの再読み込みと登録、開始

sudo systemctl daemon-reload
sudo systemctl enable rotate_touch_screen.service
sudo systemctl start rotate_touch_screen.service

手動で実行するときはGUI上のコマンドから実行しないとエラーになる。
sshからコマンド実行しても

Unable to connect to X server

のエラーが返ってくる。

後は、再起動して問題なくタッチ操作ができるか確認!
問題なければ完了!!

タイトルとURLをコピーしました