Sub Process_Globals
Public manager As BleManager2
Public manager2 As BleManager2
Public currentStateText As String = "UNKNOWN"
Public currentState As Int
Public connected As Boolean = False
Public ConnectedName As String
Private serviceId, charId As String
Private serviceId2, charId2 As String
Private ConnectedServices As List
Private ConnectedServices2 As List
Dim messagesToSend As List
End Sub
Sub Service_Create
manager.Initialize("manager")
manager2.Initialize("manager2")
serviceId = UUID("ffe0")
charId = UUID("ffe1")
' serviceId2 = UUID("ffe0")
' charId2 = UUID("ffe1")
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Public Sub Scan
manager.Scan2(Array(serviceId),True)
manager2.Scan2(Array(serviceId),True)
End Sub
Public Sub Scan2
' manager2.Scan2(Array(serviceId), False)
End Sub
Public Sub ReadData
For Each s As String In ConnectedServices
manager.ReadData(s)
Next
End Sub
Public Sub Disconnect
manager.Disconnect
manager2.Disconnect
End Sub
Sub Manager_StateChanged (State As Int)
Select State
Case manager.STATE_POWERED_OFF
currentStateText = "POWERED OFF"
Case manager.STATE_POWERED_ON
currentStateText = "POWERED ON"
Case manager.STATE_UNSUPPORTED
currentStateText = "UNSUPPORTED"
End Select
currentState = State
CallSub(Main, "StateChanged")
End Sub
Public Sub connect
manager.Connect(Main.felt)
manager2.Connect(Main.felt2)
End Sub
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
Main.doroso="Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData
ConnectedName = Name
' Try
' manager.StopScan
' manager2.StopScan
' manager.Connect(Main.felt)
' manager2.Connect(Main.felt2)
' Catch
' Scan
' End Try
End Sub
Sub Manager_DataAvailable (sid As String, Characteristics As Map)
Dim b() As Byte = Characteristics.Get(charId)
Dim msg As String = BytesToString(b, 0, b.Length, "utf8")
' Dim c() As Byte = Characteristics.Get(charId2)
' Dim msg2 As String = BytesToString(c, 0, c.Length, "utf8")
'CallSub2(Main, "DeviceMessage", msg)
End Sub
Sub Manager_Disconnected
Log("Disconnected")
connected = False
CallSub(Main, "StateChanged")
End Sub
Sub Manager_Connected (services As List)
Log("connected: " & services)
connected = True
Log(serviceId)
' Log(serviceId2)
manager.SetNotify(serviceId, charId, True)
' manager2.SetNotify(serviceId, charId, True)
CallSub(Main,"StateChanged")
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
'Public Sub SendMessage(msg() As Byte)
' If connected Then
' manager.WriteData(serviceId, charId, msg)
' manager.Scan2(Array(serviceId), False)
'End If
'CallSub(Main,"dc")
'End Sub
Public Sub SendMessage2(msg() As Byte)
If Not(connected) Then Return
manager.WriteData(serviceId, charId, msg)
manager2.WriteData(serviceId, charId, msg)
' manager.Disconnect
'manager2.Scan2(Array(serviceId), False)
'CallSub(Main,"dc")
End Sub
Private Sub UUID(id As String) As String
#if B4A
Return "0000" & id.ToLowerCase & "-0000-1000-8000-00805f9b34fb"
#else if B4I
Return id.ToUpperCase
#End If
End Sub
Sub Service_Destroy
End Sub