# Include your customized HAL commands here
# The commands in this file are run after the AXIS GUI (including PyVCP panel) starts

#estop/reset	disabled iocontrol in MyAxis.hal
net estop-btn toggle.3.in == pyvcp.estop-button
net estop toggle.3.out iocontrol.0.emc-enable-in

#abort
net abort-btn halui.abort == pyvcp.abort-btn

#cycle timer
loadrt time count=2
addf time.0 servo-thread
addf time.1 servo-thread
#net cycle-time time.0.start halui.program.is-running 
net cycle-seconds pyvcp.time-seconds <= time.0.seconds
net cycle-minutes pyvcp.time-minutes <= time.0.minutes
net cycle-hours pyvcp.time-hours <= time.0.hours

#run-time 
#net run-time time.1.start halui.program.is-on
net run-seconds pyvcp.run-seconds <= time.1.seconds
net run-minutes pyvcp.run-minutes <= time.1.minutes
net run-hours pyvcp.run-hours <= time.1.hours

#offsets
net x-offset halui.tool.length_offset.x == pyvcp.x-offset
net y-offset halui.tool.length_offset.y == pyvcp.y-offset
net z-offset halui.tool.length_offset.z == pyvcp.z-offset

#tool number
net tool-num pyvcp.tool-num == halui.tool.number

#home x
net home-x-btn and2.0.in0 == pyvcp.just-home-x
net home-x halui.joint.0.home == and2.0.out

#home y
net home-y-btn and2.1.in0 == pyvcp.just-home-y
net home-y halui.joint.1.home == and2.1.out

#home z
net home-z-btn and2.2.in0 == pyvcp.just-home-z
net home-z halui.joint.2.home == and2.2.out

#home each
net hom-in-man and2.0.in1 and2.1.in1 and2.2.in1 and2.3.in1 and2.7.in1 and2.8.in1  and2.9.in1 and2.10.in1 == halui.mode.is-manual

#home all
net home-btn and2.3.in0 == pyvcp.home-all
net zero-all halui.home-all == and2.3.out

# MDI commands = x0 y0 z0  <in ini>
net make-rapid-home and2.4.in0 == pyvcp.rapid-to-home
net link-rapid-home and2.4.in1 == halui.program.is-idle and2.14.in1
net remote-rapid-home halui.mdi-command-00 == and2.4.out

#MDI command move xyz	<in MyAxis.ini>
net move-x and2.7.in0 == pyvcp.move-x-zero	    #and2.7.in1 linked /w home each
net x-to-zero halui.mdi-command-01 == and2.7.out

net move-y and2.8.in0 == pyvcp.move-y-zero	    #and2.8.in1 linked /w home each
net y-to-zero halui.mdi-command-02 == and2.8.out

net move-z and2.9.in0 == pyvcp.move-z-zero	    #and2.9.in1 linked /w home each
net z-to-zero halui.mdi-command-03 == and2.9.out

net pos-start and2.10.in0 == pyvcp.x0y0z.2	    #and2.10.in1 linked /w home each
net start-pos halui.mdi-command-04 == and2.10.out

#m124 - reset m123 script counter
net reset-m123 halui.mdi-command-05 == pyvcp.reset-m123

#led
net on-Led halui.machine.is-on == toggle2nist.1.is-on pyvcp.mill-on and2.12.in1 time.1.start gladevcp.Power_led
net running-Led halui.program.is-running == pyvcp.running and2.6.in1 not.4.in time.0.start gladevcp.Run_led
net estop-led halui.estop.is-activated == pyvcp.estop-led gladevcp.Estop_led
net is-paused halui.program.is-paused == pyvcp.paused-led toggle2nist.0.is-on and2.5.in1
net x-home halui.joint.0.is-homed == pyvcp.x-homed gladevcp.X_homed_led
net y-home halui.joint.1.is-homed == pyvcp.y-homed gladevcp.Y_homed_led
net z-home halui.joint.2.is-homed == pyvcp.z-homed gladevcp.Z_homed_led

#movement x led
net x1 axis.0.joint-vel-cmd => comp.0.in1
net xled-not comp.0.equal => not.0.in
net xled-equal not.0.out => pyvcp.x-moving 

#movement y led
net y1 axis.1.joint-vel-cmd => comp.1.in1
net yled-not comp.1.equal => not.1.in
net yled-equal not.1.out => pyvcp.y-moving

#movement z led
net z1 axis.2.joint-vel-cmd => comp.2.in1
net zled-not comp.2.equal => not.2.in
net zled-equal not.2.out => pyvcp.z-moving 

#dro	doesn't adjust for offset
#net x-dro halui.axis.0.pos-relative == pyvcp.dro-x
#net y-dro halui.axis.1.pos-relative == pyvcp.dro-y
#net z-dro halui.axis.2.pos-relative == pyvcp.dro-z  

#feed display
setp mult2.0.in0 60
net inchPsec-in mult2.0.in1 <== motion.current-vel
net inchPmin-out mult2.0.out == pyvcp.feed-rate

# x jog
net plus-x pyvcp.X-plus == halui.jog.0.plus
net minus-x pyvcp.X-minus == halui.jog.0.minus

# y jog
net plus-y pyvcp.Y-plus == halui.jog.1.minus
net minus-y pyvcp.Y-minus == halui.jog.1.plus

# z jog
net plus-z pyvcp.Z-plus == halui.jog.2.plus
net minus-z pyvcp.Z-minus == halui.jog.2.minus

# xyz jog scale
net my-jogspeed halui.jog-speed <= pyvcp.jog-speed-f

# feed override
setp halui.feed-override.scale 0.02
net over-plus halui.feed-override.increase pyvcp.override_plus
net over-minus halui.feed-override.decrease pyvcp.override_minus
setp mult2.1.in0 100
net over-ride mult2.1.in1 <== halui.feed-override.value
net per_over mult2.1.out ==> pyvcp.override_percent

#power on/off
net power-btn and2.11.in0 <= pyvcp.on-off
net power-ok and2.11.in1 not.3.out
#net power-not not.3.in <= halui.estop.is-activated
net power-request toggle.4.in <= and2.11.out
net power-toggle toggle2nist.1.in <= toggle.4.out
#net power-is-on toggle2nist.1.is-on <= halui.machine.is-on
net power-on halui.machine.on <= toggle2nist.1.on
net power-off halui.machine.off <= toggle2nist.1.off 

#==========================================  needs work - gets out of sync
#program run/stop 				
#net run-btn halui.mode.auto halui.program.run == pyvcp.run-prog
#net run-btn halui.program.stop == pyvcp.stop-prog
net run-prog toggle.1.in == halui.mode.auto halui.program.run pyvcp.run-prog 
net stop-prog toggle.1.out halui.program.stop
#net stop-not not.4.in halui.program.is-running
net not-stop not.4.out pyvcp.RunStopimage

# Flood Coolant Toggle               from john - make run/stop
net coolant-btn and2.12.in0 <= pyvcp.flood
#net coolant-ok and2.12.in1 <= halui.machine.is-on
net coolant-request toggle.0.in <= and2.12.out
net coolant-toggle toggle2nist.2.in <= toggle.0.out
net coolant-is-on toggle2nist.2.is-on pyvcp.flood-led <= halui.flood.is-on
net coolant-on halui.flood.on <= toggle2nist.2.on
net coolant-off halui.flood.off <= toggle2nist.2.off

#============================================================================

#pause/resume
net pause-resume-btn and2.5.in0 and2.6.in0 <= pyvcp.prog-pause
#net pause-on toggle2nist.0.is-on and2.5.in1 <= halui.program.is-paused linked/w leds
#net run-on and2.6.in1 <= halui.program.is-running	   linked/w leds
net pause-sig or2.0.in0 <= and2.5.out
net resume-sig or2.0.in1 <= and2.6.out
net toggle-ok toggle.2.in <= or2.0.out
net togglesig toggle2nist.0.in <= toggle.2.out
net pause halui.program.pause <= toggle2nist.0.on
net resume halui.program.resume <= toggle2nist.0.off


#testing   and2.12.in0	toggle.6.in   motion.enable	wsum.0.bit.0.in
#net test-pin conv-bit-u32.0.in == pyvcp.test
#net tested-pin conv-bit-u32.0.out == pyvcp.testimage
#net tes-pin pyvcp.testimage pyvcp.test

#spindle
setp mult2.2.in0 1400
setp halui.spindle-override.scale .1
net spin-incre halui.spindle-override.increase pyvcp.Spindle-incre
net spin-decre halui.spindle-override.decrease pyvcp.Spindle-decre
##net spin-value halui.spindle-override.value pyvcp.Spindle-value

net spindle mult2.2.in1 <== halui.spindle-override.value
net spindle-value mult2.2.out ==> pyvcp.Spindle-value gladevcp.RPM

net spindle-on halui.spindle.start pyvcp.Spindle-on
net spindle-off halui.spindle.stop pyvcp.Spindle-off
net Spin-led pyvcp.spindle-led halui.spindle.is-on

#net flood-stop halui.flood.on pyvcp.flood.Flood-on
#net stop-flood halui.flood.off pyvcp.flood.Flood-off
#net mist-on halui.mist.on pyvcp.flood.Mist
#radiobutton = pyvcp.flood.Flood-on pyvcp.flood.Flood-off pyvcp.flood.Flood.mist