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

' ----------------------------------- Not affected by LoadVars
Numeric CommandsTextSlot = 100
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

Label DisablePwm
	COM WriteString "DISABLE_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

' =============================================================
'  SEND COMMAND (default timeout = 0.5 Sec)
' =============================================================
Label SendCommand
	Variable String SC1           '<-- Parameter Command-String
	SlotText CommandsTextSlot = SC1
	Variable Numeric SC2
	For SC2 = 0.1 To 0.5 Step 0.1 ' <-- 0.5 seconds timeout
		If SlotText(CommandsTextSlot) = ""
			Exit
		EndIf
		Wait Seconds 0.1
	Next
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 -1 0 

'EXEC DestX = 12
