' ====================================================================
'   KEYBOARD JOG TESTER
' ====================================================================

Option GlobalKeys Enabled
Option Speed 9

' ---------------------------------------- Software limits
Xmax =  100
Xmin =    0
Ymax =  100
Ymin =    0
Zmax =  100
Zmin =    0

' ---------------------------------------- Slots
Slot_X = 1
Slot_Y = 3
Slot_Z = 5

' -------------------------------------- BUTTONS


' -------------------------------------- KEYS
Key Right		Gosub ExecKeys
Key Left 		Gosub ExecKeys
Key Up 			Gosub ExecKeys
Key Down 		Gosub ExecKeys
Key Pageup		Gosub ExecKeys
Key Pagedown	Gosub ExecKeys

Stop

' ====================================================================
'  VARIABLES
' ====================================================================
Variable Numeric Slot_X
Variable Numeric Slot_Y
Variable Numeric Slot_Z

' -------------------------------------- SOFTWARE LIMITS
Variable Numeric Xmax
Variable Numeric Xmin
Variable Numeric Ymax
Variable Numeric Ymin
Variable Numeric Zmax
Variable Numeric Zmin


' ===================================================================
'  JOG with keyboard
' ===================================================================
Label ExecKeys
	Gosub SpeedModifiers
	'
	If Key("Right")
		Slot Slot_X = Limit(Slot(Slot_X) + JogSpeed, Xmin, Xmax)
	EndIf
	If Key("Left")
		Slot Slot_X = Limit(Slot(Slot_X) - JogSpeed, Xmin, Xmax)
	EndIf
	'
	If Key("Up")
		Slot Slot_Y = Limit(Slot(Slot_Y) + JogSpeed, Ymin, Ymax)
	EndIf
	If Key("Down")
		Slot Slot_Y = Limit(Slot(Slot_Y) - JogSpeed, Ymin, Ymax)
	EndIf
	'
	If Key("PageUp")
		Slot Slot_Z = Limit(Slot(Slot_Z) + JogSpeed, Zmin, Zmax)
	EndIf
	If Key("PageDown")
		Slot Slot_Z = Limit(Slot(Slot_Z) - JogSpeed, Zmin, Zmax)
	EndIf
	'
	Gosub PrintValues
Return

Label SpeedModifiers
	Variable Numeric JogSpeed
	JogSpeed = 1
	Select True
		Case Key("SHIFT")
			JogSpeed = JogSpeed * 0.1
		Case Key("CTRL")
			JogSpeed = JogSpeed * 0.01
		Case Key("ALT")
			JogSpeed = JogSpeed * 0.001
	EndSelect
Return


' ===================================================================
'  PRINT COORDINATES
' ===================================================================
Label PrintValues
	s1 =       "X=" + Format(Slot(Slot_X), "0.000")
	s1 = s1 + " Y=" + Format(Slot(Slot_Y), "0.000")
	s1 = s1 + " Z=" + Format(Slot(Slot_Z), "0.000")
	Print CRLF + s1
Return




'WATCH SlotMotor
'WATCH Abs(Slot(SlotMotor))
'WATCH v1
'WATCH Load
'EXEC Sin2 = Sin(33)
