'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim UAV As UAVisualization
Dim Timer1, Timer2 As Timer
Dim BufferSize As Int: BufferSize = 128
Dim UAVinitialized As Boolean
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
Timer2.Enabled = True
If UAVinitialized = False Then
Try
UAV.initialize("UAVV",0) 'Initialize the Visualizer. 0 is for the Generalsoung
UAV.setCaptureSize(BufferSize) 'Set the Max Buffer
UAV.setEnabled(True) 'Set Enable
UAVinitialized = True
Timer1.Initialize("Timer1", Interval)
Catch
UAVinitialized = False
ToastMessageShow("Error during audio capture, restart device.", True)
StopService("")
Return
End Try
If UAV.Enabled=False Then
UAV.setEnabled(True)
End If
Timer1.Enabled=True
Else
StopService("")
ToastMessageShow("Service is already started.", True)
End If
End Sub
Sub Timer1_Tick
Timer1.Enabled = False
Dim MBytes(BufferSize-1) As Byte 'Byte in 512 Array = Max BufferSize
UAV.getWaveForm(MBytes) 'Get the Byte from getWaveForm
For I = 0 To MBytes.Length -1
level = Bit.AND(MBytes(I), 0xff) 'Convert unsignat Byte
.............