Sub Process_Globals
'Bluetooth connection related variables
Dim serial1 As Serial
Dim admin As BluetoothAdmin
Dim AStream As AsyncStreams
Type NameAndMac (Name As String, Mac As String)
Dim connectedDevice As NameAndMac
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
'Initialize bluetooth
admin.Initialize("admin")
serial1.Initialize("serial1")
connectedDevice.Mac = StateManager.GetSetting2("RemoteMac", "00:00:00:00:00:00")
serial1.Connect(connectedDevice.Mac)
ProgressDialogShow ("Connecting to Bluetooth remote device ...")
End If
End Sub
Sub serial1_Connected (Success As Boolean)
If Success = False Then
ToastMessageShow("Error connecting to remote Bluetooth device", True)
Else
If AStream.IsInitialized = False Then
AStream.InitializePrefix(serial1.InputStream, True, serial1.OutputStream, "AStreams")
End If
'Save the remote device Mac in registry
StateManager.SetSetting("RemoteMac", connectedDevice.Mac)
StateManager.SaveSettings
End If
ProgressDialogHide
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Log("Received " & Buffer.Length & " bytes")
End Sub
Sub AStream_Error
ToastMessageShow("Connection is broken. " & LastException.Message, True)
Log(LastException.Message)
End Sub
Sub AStream_Terminated
AStream_Error
End Sub