A wrap for this Github project.
Keep your phone in a "portrait vertical position" and move it around in a figure 8 motion. The returned values are radians. Convert them to degrees if you want to display the values in degrees.
Sample code:
The B4A manifest file:
Attached the B4A sample project and the B4A library files. Extract and copy the B4A library files to your additional library folder.
Library:
CalibratorSensor
Version: 1
Keep your phone in a "portrait vertical position" and move it around in a figure 8 motion. The returned values are radians. Convert them to degrees if you want to display the values in degrees.
Sample code:
B4X:
#Region Project Attributes
#ApplicationLabel: b4aCalibratorSensor
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private cs As CalibratorSensor
Private Label1 As Label
Private Label2 As Label
Private Label3 As Label
Private Label4 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
cs.stopOrientation
End Sub
Sub cs_percentage_completed(percentage As Int)
Label4.Text = "% Calibration completed = " & percentage
End Sub
Sub cs_apr_values(azimuth As Float, pitch As Float, roll As Float)
Label1.Text = "Azimuth = " & azimuth
Label2.Text = "Pitch = " & pitch
Label3.Text = "Roll = " & roll
End Sub
The B4A manifest file:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddManifestText(<uses-feature android:name="android.hardware.sensor.accelerometer"
android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.sensor.magnetic"
android:required="true" />)
Attached the B4A sample project and the B4A library files. Extract and copy the B4A library files to your additional library folder.
Library:
CalibratorSensor
Version: 1
- CalibratorSensor
Events:- apr_values (azimuth As Float, pitch As Float, roll As Float)
- percentage_completed (percentage As Int)
- ba As BA
- BringToFront
- DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
- Initialize (EventName As String)
- Invalidate
- Invalidate2 (arg0 As Rect)
- Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- IsInitialized As Boolean
- RemoveView
- RequestFocus As Boolean
- SendToBack
- SetBackgroundImage (arg0 As Bitmap)
- SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
- SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
- SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
- stopOrientation
- Background As Drawable
- Color As Int [write only]
- Enabled As Boolean
- Height As Int
- Left As Int
- Padding()() As Int
- Parent As Object [read only]
- Tag As Object
- Top As Int
- Visible As Boolean
- Width As Int
Attachments
Last edited: