#Region Project Attributes
#ApplicationLabel: Ultrasonic Broadcast Receiver
#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.
Public uiTimer As Timer
Public broadcastTimer As Timer
Public ctr As Int
Public broadcastIntent As Intent
Public AWA As Float
Public AWD As Float
Public AWS As Float
Public dataFieldsAPI As List
Public broadcastReceiverID As String
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.
Public lblTitle As Label
Public ListView1 As ListView
' Initialize a list of all available Broadcast Intent Extras
dataFieldsAPI.Initialize2(Array As String("Battery", "Temp", "AWA", "AWD", "AWS", "TWA", "TWD", "TWS", _
"Pitch", "Roll", "Compass", "COG", "SOG"))
broadcastReceiverID = "com.calypso.api.ACTION_DATA_AVAILABLE" ' must match the Manifest entry
ctr = 0
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("MainActivity")
Activity.Title = "Calypso Ultrasonic API"
lblTitle.Text = "Calypso Ultrasonic API"
' initialize the data fields available thru the API
End Sub
Sub Activity_Resume
uiTimer.Initialize("uiTimer", 1000)
uiTimer.Enabled = True
broadcastTimer.Initialize("broadcastTimer", 800)
broadcastTimer.Enabled = True
Log("Initialized the timers.. ")
broadcastIntent.Initialize(broadcastReceiverID, "")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
uiTimer.Enabled = False
broadcastTimer.Enabled = False
If UserClosed Then
Activity.Finish
End If
End Sub
Sub uiTimer_Tick
Log("Received AWA = " & AWA)
Log("--")
ctr = ctr + 1
lblTitle.Text = ctr & ". dataset"
ListView1.AddSingleLine( ctr & ". AWS record received = " & AWS)
ListView1.SingleLineLayout.Label.TextSize = 14
End Sub
Sub broadcastTimer_Tick
'Sub broadcastIntent_OnReceive
Log("Intent Action: "&broadcastIntent.Action&" looking for: "&broadcastReceiverID)
If broadcastIntent.Action = broadcastReceiverID Then
If broadcastIntent.HasExtra("AWA") Then
Dim value() As String
value = broadcastIntent.GetExtra("AWA")
Log("AWA value: " & value(0))
If (value.Length>0 And value(0).Length>0) Then
AWA = value(0)
Else
AWA = 0.0
End If
End If
End If
End Sub