Skip to content

Instantly share code, notes, and snippets.

@zultron
Created October 6, 2016 04:04
Show Gist options
  • Save zultron/06105e8cd49f03e3a9584d74cb56b85e to your computer and use it in GitHub Desktop.
Save zultron/06105e8cd49f03e3a9584d74cb56b85e to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import hal, time
h = hal.component("tr1openclose")
h.newpin("open_close", hal.HAL_BIT, hal.HAL_IN)
h.newpin("rev_prox", hal.HAL_BIT, hal.HAL_IN)
h.newpin("fwd_prox", hal.HAL_BIT, hal.HAL_IN)
h.newpin("ev_fwd", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("ev_rev", hal.HAL_BIT, hal.HAL_OUT)
h.ready()
try:
while 1:
time.sleep(0.01)
if h["open_close"] == 0 && h["rev_prox"] == 1 && h["fwd_prox"] == 0:
# State: closed
h["ev_fwd"] = 0
h["ev_rev"] = 0
if h["open_close"] == 1 && h["fwd_prox"] == 0: # (don't care about rev_prox)
# State: opening
h["ev_fwd"] = 1
h["ev_rev"] = 0
# etc. etc.
except KeyboardInterrupt:
raise SystemExit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment