#!/usr/bin/python
import hal
import time
import linuxcnc

import sys

s = linuxcnc.stat()
c = linuxcnc.command()

rapidselect = hal.component("rapidselect")

rapidselect.newpin("scale-output", hal.HAL_FLOAT, hal.HAL_OUT)
rapidselect.newpin("one", hal.HAL_BIT, hal.HAL_IN)
rapidselect.newpin("two", hal.HAL_BIT, hal.HAL_IN)
rapidselect.newpin("increase", hal.HAL_BIT, hal.HAL_OUT)
rapidselect.newpin("decrease", hal.HAL_BIT, hal.HAL_OUT)
rapidselect.newpin("value", hal.HAL_FLOAT, hal.HAL_IN)
rapidselect.ready()


try:
    while 1:
        if rapidselect['one'] == 1 and rapidselect['two'] == 0 and not round(rapidselect['value'] == .25):
            rapidselect['decrease'] = 1
            time.sleep(.02) 
            rapidselect['scale-output'] = 0
            rapidselect['increase'] = 0
            rapidselect['decrease'] = 0
            rapidselect['scale-output'] = .25
            rapidselect['increase'] = 1
            time.sleep(.02)
            rapidselect['increase'] = 0
            rapidselect['decrease'] = 0
        if rapidselect['one'] == 0 and rapidselect['two'] == 0 and not round(rapidselect['value'] == .5): 
            rapidselect['decrease'] = 1
            time.sleep(.02)
            rapidselect['scale-output'] = 0
            rapidselect['increase'] = 0
            rapidselect['decrease'] = 0
            rapidselect['scale-output'] = .5
            rapidselect['increase'] = 1
            time.sleep(.02)
            rapidselect['increase'] = 0
            rapidselect['decrease'] = 0
        if rapidselect['one'] == 0 and rapidselect['two'] == 1 and not round(rapidselect['value'] == 1): 
            rapidselect['decrease'] = 1
            time.sleep(.02)
            rapidselect['scale-output'] = 0
            rapidselect['increase'] = 0
            rapidselect['decrease'] = 0
            rapidselect['scale-output'] = 1
            rapidselect['increase'] = 1
            time.sleep(.02)
            rapidselect['increase'] = 0
            rapidselect['decrease'] = 0

except KeyboardInterrupt:
    raise SystemExit
