Full fix-motion script
parent
467b147dd0
commit
56a8661268
@ -1,9 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Start the loop in the background
|
||||
(
|
||||
while true; do
|
||||
python /home/kuba/sdl-enable.py
|
||||
python "$SCRIPT_DIR/sdl-enable.py"
|
||||
sleep 1
|
||||
done
|
||||
) &
|
||||
@ -0,0 +1,31 @@
|
||||
import sys
|
||||
import sdl2
|
||||
import sdl2.ext
|
||||
import time
|
||||
|
||||
def enable_motion(controller):
|
||||
if sdl2.SDL_GameControllerSetSensorEnabled(controller, sdl2.SDL_SENSOR_ACCEL, 1) != 0:
|
||||
print(f"Failed to enable accelerometer: {sdl2.SDL_GetError().decode()}")
|
||||
#sdl2.SDL_GameControllerClose(controller)
|
||||
#sdl2.SDL_Quit()
|
||||
|
||||
def main():
|
||||
if sdl2.SDL_Init(sdl2.SDL_INIT_GAMECONTROLLER | sdl2.SDL_INIT_EVENTS) != 0:
|
||||
print(f"SDL_Init error: {sdl2.SDL_GetError().decode()}")
|
||||
return 1
|
||||
num_joysticks = sdl2.SDL_NumJoysticks()
|
||||
print("Joystick count: ", num_joysticks)
|
||||
for i in range(num_joysticks):
|
||||
print(i)
|
||||
name = sdl2.SDL_GameControllerNameForIndex(i)
|
||||
if name:
|
||||
print(f"Controller {i}: {name.decode()}")
|
||||
else:
|
||||
print(f"Controller {i}: (unknown name)")
|
||||
if sdl2.SDL_IsGameController(i):
|
||||
controller = sdl2.SDL_GameControllerOpen(i)
|
||||
if controller:
|
||||
enable_motion(controller)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Reference in New Issue