' ====================================================================
'   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 MoveRight
Key Left 		Gosub MoveLeft
Key Up 			Gosub MoveFar
Key Down 		Gosub MoveNear
Key Pageup		Gosub MoveUp
Key Pagedown	Gosub MoveDown

Stop

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


' ===================================================================
'  JOG with keyboard
' ===================================================================
Label MoveRight
	Gosub SpeedModifiers
	Slot Slot_X = Slot(Slot_X) + JogSpeed
	Gosub SoftwareLimits
Return

Label MoveLeft
	Gosub SpeedModifiers
	Slot Slot_X = Slot(Slot_X) - JogSpeed
	Gosub SoftwareLimits
Return

Label MoveFar
	Gosub SpeedModifiers
	Slot Slot_Y = Slot(Slot_Y) + JogSpeed
	Gosub SoftwareLimits
Return

Label MoveNear
	Gosub SpeedModifiers
	Slot Slot_Y = Slot(Slot_Y) - JogSpeed
	Gosub SoftwareLimits
Return

Label MoveUp
	Gosub SpeedModifiers
	Slot Slot_Z = Slot(Slot_Z) + JogSpeed
	Gosub SoftwareLimits
Return

Label MoveDown
	Gosub SpeedModifiers
	Slot Slot_Z = Slot(Slot_Z) - JogSpeed
	Gosub SoftwareLimits
Return

Variable Numeric JogSpeed
Label SpeedModifiers
	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


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

Label SoftwareLimits
	If Slot(Slot_X) > Xmax
		Slot(Slot_X) = Xmax
	EndIf
	If Slot(Slot_X) < Xmin
		Slot(Slot_X) = Xmin
	EndIf
	
	If Slot(Slot_Y) > Ymax
		Slot(Slot_Y) = Ymax
	EndIf
	If Slot(Slot_Y) < Ymin
		Slot(Slot_Y) = Ymin
	EndIf
	
	If Slot(Slot_Z) > Zmax
		Slot(Slot_Z) = Zmax
	EndIf
	If Slot(Slot_Z) < Zmin
		Slot(Slot_Z) = Zmin
	EndIf
	Gosub PrintValues
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)
