undg / autorotate

Auto rotate 2in1 (touch)screens.
MIT License
12 stars 1 forks source link

panic: runtime error: index out of range [0] with length 0 #3

Closed slavekrouta closed 5 months ago

slavekrouta commented 1 year ago

I downloaded the latest zip and extracted the executable to /bin/ directory and also installed GO with sudo apt install golang Commands like autorotate left, right or normal works, but when i run autorotate --daemon or autorotate --daemon --display eDP, i get this error:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/undg/autorotate/sys.getInAccel()
    /home/runner/work/autorotate/autorotate/sys/position.go:19 +0x32c
github.com/undg/autorotate/sys.SetOrientation({0x592d49, 0x3})
    /home/runner/work/autorotate/autorotate/sys/position.go:57 +0x27
github.com/undg/autorotate/sys.Autorotate({0x592d49, 0x3}, 0x0?)
    /home/runner/work/autorotate/autorotate/sys/position.go:49 +0x65
github.com/undg/autorotate/cmd.glob..func8(0x6c2220?, {0x592eb7?, 0x1?, 0x1?})
    /home/runner/work/autorotate/autorotate/cmd/root.go:25 +0x2c
github.com/spf13/cobra.(*Command).execute(0x6c2220, {0xc000012050, 0x1, 0x1})
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x847
github.com/spf13/cobra.(*Command).ExecuteC(0x6c2220)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968
github.com/undg/autorotate/cmd.Execute()
    /home/runner/work/autorotate/autorotate/cmd/root.go:32 +0x25
main.main()
    /home/runner/work/autorotate/autorotate/main.go:6 +0x17

(i use xorg btw)

undg commented 1 year ago

I'm wondering if your laptop have accelerometer.

Could you check if you have those files in your system? They should hold values from -9 to 9, and change when you are rotating screen.

https://github.com/undg/autorotate/blob/598483e65eb3f70c500513ce73a414dc4810f112/sys/position.go#L15-L18

You can check it in command line:

cat /sys/bus/iio/devices/*/in_accel_x_raw
cat /sys/bus/iio/devices/*/in_accel_y_raw
cat /sys/bus/iio/devices/*/in_accel_z_raw

image

undg commented 5 months ago

Issue is not active, I'm closing it. Let me know if you need to re-open it.