-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb8db54
commit fcf827c
Showing
6 changed files
with
841 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Colin Leroy <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
bindir=/usr/local/bin | ||
etcdir=/etc/raspi-rotate | ||
tmpldir=$(etcdir)/xorg.conf.d | ||
|
||
install: | ||
mkdir -p $(bindir) | ||
mkdir -p $(etcdir) | ||
mkdir -p $(tmpldir) | ||
install -m 0755 bin/raspi-rotate-screen $(bindir) | ||
install -m 0644 etc/xorg.conf.d/99-raspi-rotate.conf.tmpl $(tmpldir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,64 @@ | ||
# raspi-rotate | ||
A convenient helper to set a Raspberry's touchscreen orientation | ||
A convenient helper to set a Raspberry's touchscreen orientation. | ||
|
||
## Installation | ||
Download or clone the repository, then: | ||
|
||
```bash | ||
$ cd raspi-rotate | ||
$ sudo make install | ||
``` | ||
|
||
## Usage | ||
The executable takes one argument, the desired rotation setting: | ||
|
||
```bash | ||
$ raspi-rotate-screen | ||
usage: raspi-rotate-screen [rotation] | ||
where rotation is one of: | ||
normal: no rotation | ||
cw, clockwise: rotate 90° clockwise | ||
ccw, counter-clockwise: rotate 90° counter-clockwise | ||
ud: rotate 180° | ||
``` | ||
|
||
For example, | ||
```bash | ||
$ sudo raspi-rotate-screen ccw | ||
Rotation set to CCW | ||
``` | ||
|
||
## How it works | ||
There are different ways to rotate a touchscreen's display (and touch input | ||
matrix) on a Raspberry. | ||
|
||
One of them is a `/boot/config.txt` parameter ; either `lcd_rotate` (for | ||
GPIO-connected screens) or `display_rotate` (for HDMI-connected screens). This | ||
is inconvenient in two ways: | ||
|
||
* It requires a reboot | ||
* It breaks most framebuffer programs like plymouth (hence breaking splashscreens) | ||
* It still requires Xorg configuration for the touch matrix | ||
|
||
Another one is using a dtoverlay parameter, for some touchscreens drivers: | ||
|
||
``` | ||
dtoverlay=waveshare35a,rotate=270 | ||
``` | ||
|
||
Drawbacks of this method are: | ||
|
||
* It requires a reboot | ||
* It depends on the touchscreen dtoverlay, making it less portable | ||
|
||
The third way is to handle rotation in Xorg. This is the method raspi-rotate | ||
uses. It still has some drawbacks: | ||
|
||
* It requires restarting Xorg | ||
* During boot, the kernel messages are not rotated | ||
|
||
The advantages are: | ||
|
||
* It is still possible to use Plymouth to display splash screens (even though it | ||
requires rotated images, this is better than static) | ||
* It is portable and should work with any touchscreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
|
||
#Variables | ||
CONF_DIR="/etc/raspi-rotate" | ||
XORG_TEMPLATE="$CONF_DIR/xorg.conf.d/99-raspi-rotate.conf.tmpl" | ||
XORG_CONF_DIR="/etc/X11/xorg.conf.d" | ||
XORG_CONF_FILE="$XORG_CONF_DIR/99-raspi-rotate.conf" | ||
|
||
function usage | ||
{ | ||
echo "usage: $0 [rotation]" | ||
echo "where rotation is one of:" | ||
echo " normal: no rotation" | ||
echo " cw, clockwise: rotate 90° clockwise" | ||
echo " ccw, counter-clockwise: rotate 90° counter-clockwise" | ||
echo " ud: rotate 180°" | ||
exit | ||
} | ||
|
||
#Parse argument and set variables | ||
if [ "$#" -gt 0 ]; then | ||
case "$1" in | ||
normal) | ||
ROTATE="NORMAL" | ||
MATRIX="1 0 0 0 1 0 0 0 1" | ||
;; | ||
cw|clockwise) | ||
ROTATE="CW" | ||
MATRIX="0 1 0 -1 0 1 0 0 1" | ||
;; | ||
ccw|counter-clockwise) | ||
ROTATE="CCW" | ||
MATRIX="0 -1 1 1 0 0 0 0 1" | ||
;; | ||
ud|upside-down) | ||
ROTATE="UD" | ||
MATRIX="-1 0 1 0 -1 1 0 0 1" | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
else | ||
usage | ||
fi | ||
|
||
#Build the config file | ||
TMP_FILE=$(mktemp /tmp/rotate.XXXXXX) | ||
|
||
if [ "$ROTATE" = "NORMAL" ]; then | ||
grep -v "Option.*rotate.*ROTATION_SETTING" $XORG_TEMPLATE > $TMP_FILE | ||
else | ||
sed "s/ROTATION_SETTING/$ROTATE/" $XORG_TEMPLATE > $TMP_FILE | ||
fi | ||
|
||
sed -i "s/MATRIX_SETTING/$MATRIX/" $TMP_FILE | ||
|
||
#Install the config file | ||
mkdir -p "$XORG_CONF_DIR" | ||
chmod 644 "$TMP_FILE" | ||
mv "$TMP_FILE" "$XORG_CONF_FILE" | ||
|
||
echo "Rotation set to $ROTATE" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Section "Device" | ||
Identifier "RpiFB" | ||
Driver "fbdev" | ||
Option "rotate" "ROTATION_SETTING" | ||
EndSection | ||
|
||
Section "InputClass" | ||
Identifier "Touchscreen" | ||
Driver "libinput" | ||
MatchIsTouchscreen "on" | ||
MatchDevicePath "/dev/input/event*" | ||
Option "calibrationmatrix" "MATRIX_SETTING" | ||
EndSection | ||
|
||
Section "Monitor" | ||
Identifier "generic" | ||
EndSection | ||
|
||
Section "Screen" | ||
Identifier "screen1" | ||
Device "RpiFB" | ||
Monitor "generic" | ||
EndSection | ||
|
||
Section "ServerLayout" | ||
Identifier "slayo1" | ||
Screen "screen1" | ||
EndSection | ||
|