'╔════════════════════════════════════════════════════════════╗
'║     Name: TWinGoBasicTouch_03.txt        Date: 20 Mar 2024 ║
'║   Author: Leonardo                                         ║
'║    Scope: Test all the functionality of the TWinGo BASIC1  ║
'╠════════════════════════════════════════════════════════════╣
'║ MOTOR 1 STS3215 FeeTech                                    ║
'║ MOTOR 2 STS3215 FeeTech                                    ║
'║ MOTOR 3 STS3215 FeeTech                                    ║
'║ MOTOR 4 STS3215 FeeTech                                    ║
'╠════════════════════════════════════════════════════════════╣
'║Hardware: One URT-1 from FeeTech                            ║
'║          Master with 4 encoders knob & 10 buttons          ║
'╠════════════════════════════════════════════════════════════╣
'║ISO   Culture  Gender   Age     Name                        ║
'╟────────────────────────────────────────────────────────────╢
'║ENG   EN-US    Male     Adult   Microsoft David Desktop     ║
'║ENG   EN-US    Female   Adult   Microsoft Zira Desktop      ║
'║ITA   IT-IT    Female   Adult   Microsoft Elsa Desktop      ║
'║JPN   JA-JP    Female   Adult   Microsoft Haruka Desktop    ║
'║ZHO   ZH-CN    Female   Adult   Microsoft Huihui Desktop    ║
'╚════════════════════════════════════════════════════════════╝
Option Speed 9
Load images\TWinGo_Touch.jpg
'Beep "2500 20, 1500 100"
TTS SelectVoice "ENG"
'TTS SelectVoice "ZHO"
's1 = TTSvoices
TTS SetVolume 0'100      '100
TTS SetSpeed -1
'TTS SelectVoice 5   '3

' ╔════════════════════════════════════════════╗
' ║ SLOT TEXT for COMMANDS and RESPONSES       ║
' ╚════════════════════════════════════════════╝
'Variable Numeric Slot_CommandsToMotors      = 50
Variable Numeric Slot_CommandsToCobot       = 51
Variable Numeric Slot_ResponsesFromCobot    = 52
Variable Numeric Slot_ExternalCommands      = 53

' ╔════════════════════════════════════════════╗ ▄▀▀▀ █   █▀▀█ ▀▀█▀▀
' ║ SLOT INITIALIZATIONS                       ║ ▀▀▀▄ █   █  █   █
' ╚════════════════════════════════════════════╝ ▄▄▄▀ █▄▄ █▄▄█   █
'Variable Numeric Slot_Pedal              =  10
'Variable Numeric Slot_SetWayPoint        =  914

Variable Numeric Slot_MasterStatus        =  908

Variable Numeric Slot_SignalScope         =  983

Variable Numeric Slot_Encoder1            =  921
Variable Numeric Slot_Encoder2            =  922
Variable Numeric Slot_Encoder3            =  923
Variable Numeric Slot_Encoder4            =  924

Variable Numeric Slot_FirstFiveButton     =  926
Variable Numeric Slot_SecondFiveButton    =  927

Variable Numeric Slot_MotorsFPS           =  56

Variable Numeric Slot_M1_desBase          = 101
Variable Numeric Slot_M2_desInner         = 151
Variable Numeric Slot_M3_desMiddle        = 201
Variable Numeric Slot_M4_desOuter         = 251

Variable Numeric Slot_M1_posBase          = 102
Variable Numeric Slot_M2_posInner         = 152
Variable Numeric Slot_M3_posMiddle        = 202
Variable Numeric Slot_M4_posOuter         = 252

Variable Numeric Slot_M1_DeltaBase        = 149
Variable Numeric Slot_M2_DeltaInner       = 199
Variable Numeric Slot_M3_DeltaMiddle      = 249
Variable Numeric Slot_M4_DeltaOuter       = 299

' --------------------------------------------- MicroVideo
Variable Numeric Slot_TakeImage           = 915
Variable Numeric Slot_StartStopVideo      = 916
Variable Numeric Slot_SaveVideo           = 917

Variable Numeric Slot_M1_Min              = 85
Variable Numeric Slot_M1_Max              = 280
Variable Numeric Slot_M2_Min              = 80
Variable Numeric Slot_M2_Max              = 275
Variable Numeric Slot_M3_Min              = 40
Variable Numeric Slot_M3_Max              = 320
Variable Numeric Slot_M4_Min              = 37
Variable Numeric Slot_M4_Max              = 320

Variable Numeric Slot_UNUSED1              = 320
'variable numeric a

' ╔═══════════════════════════════════╗ █▀▀▄ █  █ ▀▀█▀▀ ▀▀█▀▀ █▀▀█ █▄ █ ▄▀▀▀
' ║ BUTTONS                           ║ █▀▀█ █  █   █     █   █  █ █ ▀█ ▀▀▀▄
' ╚═══════════════════════════════════╝ █▄▄█ █▄▄█   █     █   █▄▄█ █  █ ▄▄▄▀
Button 1 Label MotorFPS
Button MotorFPS Text "NO MOTORS"
Button MotorFPS Color Flashing7 Yellow DarkOrange

Button 2 Label "MotorTemp"

Button 3 Label CurrentMeter




' ╔════════════════════════════════════════════╗ █   █▀▀█ █▀▀█ █▀▀▄
' ║ LOAD APPS                                  ║ █   █  █ █▄▄█ █  █
' ╚════════════════════════════════════════════╝ █▄▄ █▄▄█ █  █ █▄▄█


'Load Theremino_Motors.exe
'Load Theremino_SlotViewer_Motors.exe
'Load Theremino_HAL.exe
'Load Theremino_SlotViewer_Master_Enc.exe
'Load Theremino_SlotViewer_STR.exe
'Load Theremino_Microvideo.exe
'Load Theremino_SlotViewer_TSIO.exe

WaitApplicationsStarted

'WaitAllMotors

'DeActivateMotors
'CopyPositionsToDestinations

' -------------------------------------
'  MOTORS must be active before Cobot
' -------------------------------------

Load Theremino_Cobot.exe

'Load "..\Files\Analog_Button_Functions.txt"
Load Hide

' ╔════════════════════════════════════════════╗   █▀▀▀  ▀▀█▀▀  █▀▀▀█  █▀▀▀█  ▀▀█▀▀
' ║  EXECUTION START FROM HERE                 ║   ▀▀▀█    █    █▀▀▀█  █▀█▀▀    █
' ╚════════════════════════════════════════════╝   ▄▄▄█    █    █   █  █  ▀▄    █

'ResetEncoders
'Slot(Slot_SignalScope) = 1000
'Controls OpenTextBox
'Controls ClearTextBox
'
''VoiceCommandsCommandsStatus = "active"
''VoiceCommandsCommandsStatus = ""
''InterpretateVoiceCommandsCommands
'
'VoiceOutputStatus = "active"
''VoiceOutputStatus = ""
'VoiceOutputOnOff
'TTS Speak "Theremino Automation language is running."
'
''TWinGoTest
''Needles
''Tuning
''SeaSun
''Coins

Loop

' ╔════════════════════════════════════════════╗ █   █▀▀█ █▀▀█ █▀▀█
' ║ LOOP                                       ║ █   █  █ █  █ █▄▄█
' ╚════════════════════════════════════════════╝ █▄▄ █▄▄█ █▄▄█ █
Label Loop
	'CurrentMeter
	''TorqueMeter
	''TestTemp
	''InterpretateVoiceCommandsCommands
	'
	'ShowMotorFPS
	'PositionDelta
	'Encoders
	'StatusMaster
	'FirstFiveButtons
	'Delta
Goto Loop

Label Delta
	Slot(Slot_M1_DeltaBase)  = Slot(Slot_M1_desBase) - Slot(Slot_M1_posBase)
	Slot(Slot_M2_DeltaInner) = Slot(Slot_M2_desInner) - Slot(Slot_M2_posInner)
	Slot(Slot_M3_DeltaMiddle) = Slot(Slot_M3_desMiddle) - Slot(Slot_M3_posMiddle)
	Slot(Slot_M4_DeltaOuter)   = Slot(Slot_M4_desOuter) - Slot(Slot_M4_posOuter)
Return

Label TestTemp
	Variable Numeric TT1
	Variable Numeric TT2 = 0
	'TT2 = 0
	For TT1 = 1 To 5
		TT2 = Max(TT2, Slot(TT1 * 100 + 6))                       '<<<<<<<<<<<<<<<<
	Next
	Button MotorTemp Text "MaxT " + TT2 + "°C"
Return

' ╔═════════════════════╗
' ║ MASTER STATUS QUERY ║
' ╚═════════════════════╝
Label StatusMaster
	Variable String Master
	If Slot(Slot_MasterStatus) <> 1000
		Master = "OFF"
		'Print "MASTER OFF  "
	Else
		Master = "ON"
		'Print "MASTER ON  "
	EndIf
Return

' ╔════════════════════════════════════════════╗
' ║ ENABLE/DISABLE BUTTONS                     ║
' ╚════════════════════════════════════════════╝
Label EnableAllButtons
	For v1 = 1 To 32
		Button v1 Enabled
	Next
Return

Label DisableAllButtons
	For v1 = 1 To 32
		Button v1 Disabled
	Next
Return

' ╔════════════════════════════════════════════╗
' ║  WAIT COBOT READY                          ║
' ╚════════════════════════════════════════════╝
Label WaitCobotReady
	Variable Numeric WCR1
	For WCR1 = 1 To Infinity
		Wait Seconds 0.05
		If SlotText(Slot_ResponsesFromCobot) = "Ready"
			Exit
		EndIf
	Next
Return

' ╔════════════════════════════════════════════╗
' ║  WAIT APPS STARTED                         ║
' ╚════════════════════════════════════════════╝
Label WaitApplicationsStarted
	Slot(Slot_MotorsFPS) = 0
	Wait Slot(Slot_MotorsFPS) > 10
	Wait Seconds 0.1
Return

' ╔════════════════════════════════════════════╗ █▀▀▀ ▀▀█▀▀ █▀▀█ █▀▀█
' ║ STOP EVENT (when pressing stop button)     ║ ▀▀▀█   █   █  █ █▄▄█
' ╚════════════════════════════════════════════╝ ▄▄▄█   █   █▄▄█ █
Label EventStop
	'Safe
	Load CloseApps "..\Files\WiFi_controller_buttons.txt"
	'GoToHome
	'StopCobot
	Slot(Slot_SignalScope) = 0
	'DeActivateMotors
End

' =============================================================
'  SEND COMMAND (default timeout = 0.5 Sec)
' =============================================================
Label SendCommand			'(Destination Slot)(Command String)
	Variable Numeric SC1
	Variable String  SC2
	Variable Numeric SC3 = 0.7 '<-- The timeout in seconds was 0.5
	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

'╔═════════════════╗
'║COMMANDS TO COBOT║
'╚═════════════════╝
' █▀▀▀ █▀▀█ █▄ ▄█ █▄ ▄█   ▀▀█▀▀ █▀▀█   █▀▀▀ █▀▀█ █▀█  █▀▀█ ▀▀█▀▀
' █    █  █ █ ▀ █ █ ▀ █     █   █  █   █    █  █ █▀▀█ █  █   █
' █▄▄▄ █▄▄█ █   █ █   █ ▄   █   █▄▄█   █▄▄▄ █▄▄█ █▄▄█ █▄▄█   █

Label ExecCobot
	'SendCommand(Slot_CommandsToCobot)("DisableRepeat")
	'SendCommand(Slot_CommandsToCobot)("EnableRepeat")
	SendCommand(Slot_CommandsToCobot)("SelectLine 1")
	SendCommand(Slot_CommandsToCobot)("StartExecution")
Return

Label StopCobot
	SendCommand(Slot_CommandsToCobot)("StopExecution")
Return

Label ArrowUpCobot
	SendCommand(Slot_CommandsToCobot)("ArrowUp")
Return

Label ArrowDownCobot
	SendCommand(Slot_CommandsToCobot)("ArrowDown")
Return

Label ExecuteCobotFromSelectedLine
	SendCommand(Slot_CommandsToCobot)("StartExecution")
Return

Label UpdateCobot
	If Master = "OFF"
		Return
	EndIf
	SendCommand(Slot_CommandsToCobot)("CorrectSelectedPosition")
Return


Label DeleteSelectedLine
	SendCommand(Slot_CommandsToCobot)("DeleteSelectedLine")
Return

Label AddNewPosition
	SendCommand(Slot_CommandsToCobot)("AddNewPosition")
Return

Label EnableRepeat
	SendCommand(Slot_CommandsToCobot)("EnableRepeat")
Return

Label DisableRepeat
	SendCommand(Slot_CommandsToCobot)("DisableRepeat")
Return


'BOOKMARKS 362 356 

'WATCH CR
