#!/usr/bin/env python3 import subprocess import time mode = "up" def get_accel(axis): with open( f"/sys/bus/i2c/drivers/mxc4005/i2c-MDA6655:00/iio:device0/in_accel_{axis}_raw", "r", ) as f: x = int(f.read()) return x if __name__ == "__main__": while True: x = get_accel("x") y = get_accel("y") new_mode = mode if x < -500 and mode != "up": new_mode = "up" elif x > 500 and mode != "down": new_mode = "down" if y < -500 and mode != "normal": new_mode = "normal" elif y > 500 and mode != "flip": new_mode = "flip" if new_mode != mode: print(x, y, new_mode) mode = new_mode # todo also disable / enable touchpad if mode == "up": subprocess.run("xrandr --output DSI-1 --rotate right".split()) subprocess.run( [ "xinput", "set-prop", "pointer:Goodix Capacitive TouchScreen", "--type=float", "Coordinate Transformation Matrix", "0", "1", "0", "-1", "0", "1", "0", "0", "1", ] ) subprocess.run(["xinput", "enable", "AT Translated Set 2 keyboard"]) subprocess.run(["xinput", "enable", "XXXX0000:05 0911:5288 Touchpad"]) elif mode == "down": subprocess.run("xrandr --output DSI-1 --rotate left".split()) subprocess.run( [ "xinput", "set-prop", "pointer:Goodix Capacitive TouchScreen", "--type=float", "Coordinate Transformation Matrix", "0", "-1", "1", "1", "0", "0", "0", "0", "1", ] ) subprocess.run(["xinput", "disable", "AT Translated Set 2 keyboard"]) subprocess.run(["xinput", "disable", "XXXX0000:05 0911:5288 Touchpad"]) elif mode == "normal": subprocess.run("xrandr --output DSI-1 --rotate normal".split()) subprocess.run( [ "xinput", "set-prop", "pointer:Goodix Capacitive TouchScreen", "--type=float", "Coordinate Transformation Matrix", "1", "0", "0", "0", "1", "0", "0", "0", "1", ] ) subprocess.run(["xinput", "disable", "AT Translated Set 2 keyboard"]) subprocess.run(["xinput", "disable", "XXXX0000:05 0911:5288 Touchpad"]) elif mode == "flip": subprocess.run("xrandr --output DSI-1 --rotate inverted".split()) subprocess.run( [ "xinput", "set-prop", "pointer:Goodix Capacitive TouchScreen", "--type=float", "Coordinate Transformation Matrix", "-1", "0", "1", "0", "-1", "1", "0", "0", "1", ] ) subprocess.run(["xinput", "disable", "AT Translated Set 2 keyboard"]) subprocess.run(["xinput", "disable", "XXXX0000:05 0911:5288 Touchpad"]) else: print(x, y) time.sleep(1)