# Enable using XBC "A" axis as an input for tool number (tool change purpose)
#Use this pins (signal) from XHC pendant (external)
#xhc-hb04.jog.counts (pendant:jog-counts)
#xhc-hb04.jog.enable-a
#xhc-hb04.button-zero-a (pendant:zero-a)
loadrt sum2 names=xhc_sum1,xhc_sum2,xhc_sum3
loadrt mux2 names=xhc_mux1,xhc_mux2
loadrt conv_s32_float names=xhc_s32tofloat
#Call order matters!
addf xhc_mux2 servo-thread
addf xhc_sum3 servo-thread
addf xhc_mux1 servo-thread
addf xhc_sum2 servo-thread
addf xhc_sum1 servo-thread
addf xhc_s32tofloat servo-thread
### Count to increments block "count(t)-count(t-1)"
# delay
net pendant:jog-counts => xhc_s32tofloat.in
net pendant:jog-counts-float xhc_s32tofloat.out => xhc_sum1.in0
setp xhc_sum1.in1 0.0
net pendant:jog-counts-float-1 <= xhc_sum1.out
# substract
setp xhc_sum2.gain1 -1.0
net pendant:jog-counts-float xhc_sum2.in0
net pendant:jog-counts-float-1 xhc_sum2.in1
net pendant:increment xhc_sum2.out
### Mask increment when A is not selected
net pendant:enable-a xhc-hb04.jog.enable-a => xhc_mux1.sel
setp xhc_mux1.in0 0.0
net pendant:increment => xhc_mux1.in1
net pendant:increment-a <= xhc_mux1.out
### Accumulate increments
net pendant:increment-a => xhc_sum3.in0
net pendant:value-a xhc_sum3.in1 => xhc_mux2.out
net pendant:acc-a xhc_sum3.out => xhc_mux2.in0
setp xhc_mux2.in1 0.0
net pendant:zero-a => xhc_mux2.sel
### Link to xhc display
net pendant:value-a => xhc-hb04.a.pos-absolute
net pendant:value-a => xhc-hb04.a.pos-relative