Page 1 of 1

Android - two issues: hitching and app crashing

Posted: Wed Nov 22, 2023 12:20 pm
by TypingCat
I was successful in configuring FreePIE with my Galaxy S10 using the following script:

Code: Select all

def update():
    # Apply deadband filter to avoid drift
    # And continousRotation filter to yaw axis to avoid jumps when passing tracker center
    x = filters.deadband(filters.delta(math.degrees(filters.continuousRotation(android[0].yaw))), deadband) # Changed from android[0].pitch to android[0].yaw
    y = filters.deadband(filters.delta(math.degrees(filters.continuousRotation(android[0].roll))), deadband) # Changed from android[0].yaw to android[0].roll

    mouse.deltaX = x * multiply
    mouse.deltaY = y * multiply

if starting:
    deadband = 0.01
    multiply = 40
    android[0].update += update

This gives me a nice gyro-to-mouse input that might work in conjunction with a gamepad for gyro aiming in games. However I have two problems:

1. After the first time running the FreePIE app on my phone (where it worked fine), after rebooting my phone, I could not get the app to work again. It crashed every time I turned it on.

2. During that first time when I got it to work, I noticed that the mouse cursor hitched every second. I tried a different script that had debug variables for Pitch Yaw and Roll, and I observed in the "Watch" panel that the inputs from my phone were doing the same thing: every second, the inputs stopped for a some milliseconds and then continued.

I don't think this behavior is being caused by my phone's hardware or my network connection, because when I tested it with a different gyro mouse app, there was no hitching. Unfortunately that app won't run in the background like FreePIE can (and it's skeezy and closed source).

Re: Android - two issues: hitching and app crashing

Posted: Wed Nov 22, 2023 12:30 pm
by TypingCat
Well the hitching issue seems to be gone after uninstalling and reinstalling FreePIE. Fingers cross that the app keeps working as well.

Re: Android - two issues: hitching and app crashing

Posted: Wed Nov 22, 2023 8:34 pm
by TypingCat
OK updates.

1. The hitching issue comes and goes. When it starts happening, it seems like the only fix is to uninstall and reinstall the FreePIE APK.

2. The FreePIE APK works as long as I don't reboot my Android phone. Once I do, it's dead until I uninstall and reinstall.

3. It works in the background, but only for a couple minutes. After that it stops until I make the app active again.

4. With my script above, sometimes FreePIE gets the axes wrong. If I hold my phone a certain way and stop and start the script from the PC app, it fixes it. I have tried locking my phone's screen orientation but that has no effect.

I'm not a developer, but what if I attempted to recompile the APK with an updated devkit? Could that maybe resolve some issues?

Re: Android - two issues: hitching and app crashing

Posted: Thu Nov 23, 2023 3:06 am
by Jabberwock
Unfortunately newer versions of Android have quite agressive algorithms for battery saving that affect older applications. It might be that the system first learns about the app after it is installed and launched, and then tries to 'optimize' its energy profile. Check the settings for energy management/saving (it is usually implemented by phone manufacturers, so they are not the same in every phone) and try to exclude the app from any optimization.

Re: Android - two issues: hitching and app crashing

Posted: Thu Nov 23, 2023 10:53 am
by TypingCat
For now, all my problems seem to be solved by using the ported version of the APK that is now bundled with OpenTrack. https://github.com/opentrack/opentrack

I tried OpenTrack itself and it has its own issues. Its mouse emulator is quite nice with smoothing algorithms but it doesn't work in many games (a bug I am communicating with them on). For now FreePIE on PC with the above script works great.

Re: Android - two issues: hitching and app crashing

Posted: Fri Nov 24, 2023 10:41 pm
by TypingCat
Final update:

I fixed some of the code above.

Code: Select all

def update():
    global toggle
    global yaw
    global pitch # The APK is sensitive to the phone's orientation so make sure the phone is sideways when starting the script. 
    yaw = android[0].yaw
    pitch = android[0].pitch
    if toggle:
        # Apply deadband filter to avoid drift
        # And continousRotation filter to yaw axis to avoid jumps when passing tracker center
        x = filters.deadband(filters.delta(math.degrees(filters.continuousRotation(yaw))), deadband)
        y = filters.deadband(filters.delta(math.degrees(pitch)), deadband)
        diagnostics.watch(yaw)
        diagnostics.watch(pitch)

        mouse.deltaX = x * multiply
        mouse.deltaY = y * multiply * -1

if starting:
    deadband = 0.01
    multiply = 80
    toggle = False
    android[0].update += update

if keyboard.getPressed(Key.Z):
    toggle = not toggle
    
Part of my problem was that I had continuousRotation on both axes. Putting it on only Yaw fixed the problem when the axes were drifting. I'm not 100% sure why.

I experimented with googleYaw, googlePitch, etc., they were too jittery. I also tried smoothing using an averaging algorithm but that was unnecessary. The above works perfectly.