Sub Process_Globals
Private accelerometer, magnetic As PhoneSensors
Private accValues(), magValues() As Float
Private sm As JavaObject
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
accelerometer.Initialize(accelerometer.TYPE_ACCELEROMETER)
magnetic.Initialize(magnetic.TYPE_MAGNETIC_FIELD)
sm.InitializeStatic("android.hardware.SensorManager")
End If
End Sub
Private Sub Accelerometer_SensorChanged (Values() As Float)
accValues = Values
CalcOrientation
End Sub
Private Sub Magnetic_SensorChanged (Values() As Float)
magValues = Values
CalcOrientation
End Sub
Private Sub CalcOrientation
If accValues.Length = 0 Or magValues.Length = 0 Then Return
Dim R(9), I(9) As Float
Dim success As Boolean = sm.RunMethod("getRotationMatrix", Array(R, I, accValues, magValues))
If success Then
Dim orientation(3) As Float
sm.RunMethod("getOrientation", Array(R, orientation))
Log((orientation(0) * 180 / cPI + 360) mod 360)
End If
End Sub
Sub Activity_Resume
accelerometer.StartListening("Accelerometer")
magnetic.StartListening("Magnetic")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
accelerometer.StopListening
magnetic.StopListening
End Sub