Gimbal lock
Seems like gimbal lock is an issue when testing out on my phone. https://en.wikipedia.org/wiki/Gimbal_lock
If it wasn't for Gimbal Lock I would've released it a week ago. It's really tricky to wrap my non-math brain around. Any ideas on fixing it are more than welcome.
All we need is to map the relative beta and gamma rotation to the x and y-axis.
The code here can compute the quaternion from the alpha, beta, gamma values: https://www.w3.org/TR/2016/CR-orientation-event-20160818/#worked-example-2 Then tracking the changes from the quaternion instead of from alpha, beta, gamma should fix it?
I believe I tried this earlier but will give it another go.
You can also prevent the angles from going to exactly zero/max to prevent gimble lock. No one will notice if an angel never goes to less than 0.0001 degrees.