
' -------------------------------------------
' IF COM IS CLOSED EXTERNALLY WHILE RUNNING
' AND THEN DOING STOP AND RUN
' SOMETIMES AUTOMATION CRASHES AND CLOSES
' -------------------------------------------
' This does not happens if debugging
' -------------------------------------------



' ----------------------------------- Restored by LoadVars
Numeric DutyCycle1 = 8000
Numeric DutyCycle2 = 8000
Numeric Linearity = 0.5
Numeric Smoothing = 0.3

Numeric Slot_Duty1 = 120
Numeric Slot_Duty2 = 121

' ----------------------------------- Load App
Load Theremino_SlotViewer.exe

' ----------------------------------- Start
COM Open 32 1000000
Goto Loop
Stop


' ----------------------------------- Send Commands
Label EnablePwm
	COM WriteString "ENABLE_PWM" + CRLF
Return

' ----------------------------------- Send Options
Label SendOptions
	SendOptionsToDriverModule
Return

Label SendOptionsToDriverModule
	String Cmd = DutyCycle1 + " " + DutyCycle2
	Cmd = Cmd + " " + Linearity + " " + Smoothing
	COM WriteString "OPTIONS " + Cmd  + CRLF
Return

' =====================================================
'  LOOP
' =====================================================
Label Loop
	' ------------------------------------------- Loop time
	Wait Seconds 0.001
	' ------------------------------------------- Debugs
	DutyCycleFromSlot
Goto Loop

Label DutyCycleFromSlot
	If Slot(Slot_Duty1) <> DutyCycle1
		EnablePwm
		DutyCycle1 = Slot(Slot_Duty1)
		SendOptions
	EndIf
	If Slot(Slot_Duty2) <> DutyCycle2
		EnablePwm
		DutyCycle2 = Slot(Slot_Duty2)
		SendOptions
	EndIf
Return


'BOOKMARKS 

'EDITEDLINES 21 1 10 6 8 7 7 10 1 9 5 10 

'EXEC DestX = 12
