I have a UI app which reads in serial data and updates a label (GameClock) based on a certain element in that data stream. In part the code is:
My problem is that I need to delay each label update by say 150ms, however given the nature of the data stream, ast_NewText may be called every 100ms. So it seems I can't just simply put a 150ms delay ahead of the label update:
but instead need to put the updates into a queue and execute each update 150ms after it has entered the queue.
Any suggestions how to achieve that in code?
B4X:
Sub btnOpen_Action
sp.Open(cmbPort.Value)
sp.SetParams(115200,8,1,0)
ast.Initialize(Me, "ast", sp.GetInputStream, sp.GetOutputStream)
btnOpen.Enabled = False
lblStatus.Text = "Status: Open"
End Sub
Sub ast_NewText(Text As String)
Select js.left(Text,1)
Case "T"
GameClock.Text = js.Mid(Text,2,5)
End Select
End Sub
My problem is that I need to delay each label update by say 150ms, however given the nature of the data stream, ast_NewText may be called every 100ms. So it seems I can't just simply put a 150ms delay ahead of the label update:
B4X:
GameClock.Text = js.Mid(Text,2,5)
but instead need to put the updates into a queue and execute each update 150ms after it has entered the queue.
Any suggestions how to achieve that in code?