#!/usr/bin/env python
import hal, time, linuxcnc
h = hal.component("units")
h.newpin("G21", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("G20", hal.HAL_BIT, hal.HAL_OUT)
h.ready()
s = linuxcnc.stat()
try:
    while 1:
        time.sleep(1)
        s.poll()
        if s.program_units == 1:
              h['G21'] = 0
              h['G20'] = 1
        else:
              h['G21'] = 1
              h['G20'] = 0
except KeyboardInterrupt:
    raise SystemExit
