Sub Activity_Create(FirstTime As Boolean)
'StartActivity(Central) '*** TO ACCESS CENTRAL
Activity.LoadLayout("setup")
End Sub 'Loads Layout 1 and initializes serial and BT COM
Sub Activity_Resume
'MyDeviceName = "Put the name of your coupled device here!"
MyDeviceName = "HC-06"
ToastMessageShow("Connecting to " & MyDeviceName, True)
timBT.Initialize("timBT",5000)
timBT.Enabled = False
Try
BT.Initialize("BT")
Serial1.Initialize("Serial1")
Catch
ToastMessageShow("No BlueTooth Device visible...", True)
End Try
'Start Bluetooth
Try
If BT.IsEnabled = False Then
lblBT.Color = Colors.Black
BT.Enable
Else
'connect to SK
BTConnectToDevice
End If
Catch
End Try
End Sub ' Calls "BTConnectToDevice
Sub BTConnectToDevice
Dim PairedDevices As Map
PairedDevices = Serial1.GetPairedDevices
Try
Serial1.Connect(PairedDevices.Get(MyDeviceName))
Catch
ToastMessageShow("Device not available",True)
End Try
End Sub ' Pairs with HC-06
Sub BT_StateChanged(NewState As Int,OldState As Int)
If NewState = BT.STATE_ON Then
BTConnectToDevice
Log("BT Connect")
Else
Serial1.Disconnect
timBT.Enabled = False
Log("BT Disconnect")
End If
End Sub ' Originally found IN MAIN.
Sub Serial1_Connected (Success As Boolean)
If Success = True Then
ToastMessageShow("Bluetooth connected to " & Serial1.Address, False)
timBT.Enabled = True
Else 'disconnected
ToastMessageShow("Connection to " & Serial1.Address & _
" broken!", True)
timBT.Enabled = False
errorSelection
End If
End Sub ' Once connected to HC-06 will enable timBT timer.