
' ==========================================================
'                   TO TEST THIS EXAMPLE
' ==========================================================
' - Open Theremino_Cobot V1.1.22 or more recent
' - Load example "Test_A.txt" (or TestB or TestC or TestD)
' - In the app Cobot enable "Repeat"
' - In the app Cobot press "Execute"

Variable Numeric Slot_CommandsToCobot = 51
Variable Numeric Slot_ResponsesFromCobot = 52
Variable Numeric Slot_CommandsFromCobot = 53
Loop1
Stop

Label Loop1
	Loop2
Return

Label Loop2
	Print SlotText(Slot_ResponsesFromCobot)
	Wait Seconds 0.1
	If Key("CTRL")
		Return
	EndIf
Goto Loop2

Label Event_CommandsFromCobot
	' --------------------------------- Extract first word
	Select GetSeparatedString(CommandText, 0)
		' -----------------------------
		Case "Beep"
			ClearCommand
			ExecBeep
		' -----------------------------
		Case "Beep_Multiple"
			ClearCommand
			ExecBeepMultiple
		' -----------------------------
		Case "LoadSequence-Test_A"
			LoadSequenceA
		' -----------------------------
		Case "LoadSequence-Test_B"
			LoadSequenceB
				' --------------------- Commands with parameters
		Case "Pause"
			Wait Seconds GetSeparatedString(CommandText, 1)
		Case "Say"
			TTS Speak Mid(CommandText, 5)
			Wait TTSready
			' ------------------------- Unrecognized command
		CaseElse
			Wait Seconds 0.5
			Beep 200 500
			Print "Unrecognized command: " + CommandText
			Wait Seconds 0.5
	EndSelect
	ClearCommand
Return

Label ClearCommand
	SlotText(Slot_CommandsFromCobot) = ""
Return

Label ExecBeep
	Beep 440 300
	Wait Seconds 0.5
	Beep 440 300
Return

Label ExecBeepMultiple
	For v1 = 1 To 3
		Beep 880 400
		Wait Seconds 0.5
	Next
Return

Label LoadSequenceA
	Beep 1660 200
	SendCommand(Slot_CommandsToCobot)(LoadSequence Test_A.txt)
Return

Label LoadSequenceB
	Beep 2200 200
	SendCommand(Slot_CommandsToCobot)(LoadSequence Test_B.txt)
Return

' ------------------------------------------
'  SEND COMMAND (default timeout = 0.5 Sec)
' ------------------------------------------
Label SendCommand
	Variable Numeric SC1       '<-- Parameter Destinat.-Slot
	Variable String  SC2       '<-- Parameter Command-String
	Variable Numeric SC3 = 0.5 '<-- The timeout in seconds
	Variable Numeric SC4
	SlotText SC1 = SC2
	For SC4 = 0.1 To SC3 Step 0.1
		If SlotText(SC1) = ""
			Exit
		EndIf
		Wait Seconds 0.1
	Next
Return


'WATCH v1
'EXEC DestX = 12
