-
Notifications
You must be signed in to change notification settings - Fork 0
/
BLEdata.bas
104 lines (88 loc) · 3.19 KB
/
BLEdata.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=8
@EndOfDesignText@
#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.
Dim const UUID_SERVICE_W = "99ddcda5-a80c-4f94-be5d-c66b9fba40cf" 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.
Dim datacount As Int
Dim Const FLASH_DATA As String = "99dd0004-a80c-4f94-be5d-c66b9fba40cf"
Dim Const COMMANDES As String = "99dd0014-a80c-4f94-be5d-c66b9fba40cf"
Dim Const BATT_LEVEL As String = "99dd0016-a80c-4f94-be5d-c66b9fba40cf"
Dim Const GET_CADENCE As String = "99dd0305-a80c-4f94-be5d-c66b9fba40cf"
Dim Const REAL_TIME_VALUE As String = "99dd0108-a80c-4f94-be5d-c66b9fba40cf"
Dim Const STATES_SHADOWS As String = "99dd0109-a80c-4f94-be5d-c66b9fba40cf"
Dim Const GENERAL_STATES As String = "99dd0110-a80c-4f94-be5d-c66b9fba40cf"
Private btnReadBatt As Button
Private ldlData As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Log("DANS BLEDATA activitycreate")
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("lytMain")
End Sub
Sub Activity_Resume
Log("DANS BLEDATA activityresume")
End Sub
Public Sub DataAvailable(Services As String, Characteristics As Map)
Log("DANS BLEDATA dataavailable")
Dim bc As ByteConverter
Dim Hex1 As Int
Dim Hex2 As Int
Dim Hex3 As Int
Dim Hex4 As Int
For Each k As String In Characteristics.Keys
Dim Value() As Byte = Characteristics.Get(k)
'Dim temp_DATA() As Int = bc.IntsFromBytes(Value)
Dim temp_DATA As String = bc.HexFromBytes(Value)
' If k = BATT_LEVEL Then
'Dim Value() As Byte = Characteristics.Get(k)
' End If
If k = GET_CADENCE Then
'Dim Value() As Byte = Characteristics.Get(k)
'Dim temp_DATA As String = bc.HexFromBytes(Value)
'Dim chaine As String = BytesToString(Value,0,18,"UTF-8")
'datacount = datacount+1
Log("LOL "&temp_DATA)
'ldlData.Text = temp_DATA(1) & " - " & datacount
End If
If k = BATT_LEVEL Then
Dim Value() As Byte = Characteristics.Get(k)
temp_DATA = bc.HexFromBytes(Value)
Hex1 = Bit.ParseInt(temp_DATA.SubString2(0, 2), 16)
'VBAT1 = Hex1
Hex2 = Bit.ParseInt(temp_DATA.SubString2(2, 4), 16)
'Hex3 = Bit.ParseInt(temp_DATA.SubString2(4, 6), 16)
'VBAT2 = Hex3
'Hex4 = Bit.ParseInt(temp_DATA.SubString2(6, 8), 16)
Log(Hex1 & " %" & Hex2 & " %")
End If
'Log("received from device: " & temp_DATA)
Next
End Sub
Sub btnReadBatt_Click
Log("DANS BLEDATA readclick")
'CallSub2(Starter, "ReadData", BAS_SERVICE)
'CallSub2(Starter, "ReadData", UUID_SERVICE_W)
Starter.manager.SetNotify(UUID_SERVICE_W, GET_CADENCE,True)
Starter.manager.SetNotify(UUID_SERVICE_W, BATT_LEVEL,True)
Sleep(1000)
Starter.manager.WriteData(UUID_SERVICE_W, COMMANDES, Array As Byte(0x01))
Sleep(1000)
CallSub2(Starter, "ReadData", UUID_SERVICE_W)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Log("DANS BLEDATA pause")
End Sub