# Path: kotori/vendor/ilaundry/node/gpio.py
# class GpioInput(object):
# 
#     def __init__(self, port, callback):
#         self.port = port
#         self.callback = callback
# 
#         GPIO.setup(self.port, GPIO.IN)
# 
#         print("DETECT EVENTS:", self.port)
# 
#         # GPIO.RISING, GPIO.FALLING, GPIO.BOTH
#         GPIO.remove_event_detect(self.port)
#         GPIO.add_event_detect(self.port, GPIO.RISING, callback=self.check_rising, bouncetime=300)
#         #GPIO.add_event_detect(self.port, GPIO.BOTH, callback=self.check_rising)
#         #GPIO.add_event_detect(self.port, GPIO.FALLING, callback=self.check_falling)
#         #GPIO.add_event_detect(self.port, GPIO.FALLING, self.check_falling)
# 
#     def check_rising(self, port):
#         #print "check_rising:", port, self.port
#         if port == self.port:
#             reactor.callFromThread(self.callback, port)
# 
#     # doesn't work with Adafruit GPIO
#     """
#     def check_falling(self, port):
#         if port == self.port:
#             #self.callback(port)
#             print "================= FALLING"
#     """
# 
# class GpioOutput(object):
# 
#     def __init__(self, port):
#         self.port = port
#         GPIO.setup(self.port, GPIO.OUT)
# 
#     def on(self):
#         self.high()
# 
#     def off(self):
#         self.low()
# 
#     def low(self):
#         GPIO.output(self.port, GPIO.LOW)
# 
#     def high(self):
#         GPIO.output(self.port, GPIO.HIGH)


from twisted.internet import reactor
from twisted.internet.task import LoopingCall
from kotori.vendor.ilaundry.node.gpio import GpioInput, GpioOutput

    def sensor_on(self, port):
        print("DEBUG: Port {0} EVENT".format(self.portname))

        # signal sensor-on
        if self.signal:
            self.signal.set(True)

    # currently defunct
    """
    def sensor_off(self, port):
        print "SENSOR OFF:", port

        # signal sensor-off
        if self.callback:
            self.callback(False)
    """


class BinaryOutputPort(object):

    # TODO: handle different ports, not only GPIO

    #HIGH = 1
    #LOW = 2
    #BLINK = 3

    def __init__(self, portname):
        self.portname = portname
        #self.flavor = flavor or self.HIGH

# Path: kotori/vendor/ilaundry/node/gpio.py
# class GpioInput(object):
# 
#     def __init__(self, port, callback):
#         self.port = port
#         self.callback = callback
# 
#         GPIO.setup(self.port, GPIO.IN)
# 
#         print("DETECT EVENTS:", self.port)
# 
#         # GPIO.RISING, GPIO.FALLING, GPIO.BOTH
#         GPIO.remove_event_detect(self.port)
#         GPIO.add_event_detect(self.port, GPIO.RISING, callback=self.check_rising, bouncetime=300)
#         #GPIO.add_event_detect(self.port, GPIO.BOTH, callback=self.check_rising)
#         #GPIO.add_event_detect(self.port, GPIO.FALLING, callback=self.check_falling)
#         #GPIO.add_event_detect(self.port, GPIO.FALLING, self.check_falling)
# 
#     def check_rising(self, port):
#         #print "check_rising:", port, self.port
#         if port == self.port:
#             reactor.callFromThread(self.callback, port)
# 
#     # doesn't work with Adafruit GPIO
#     """
#     def check_falling(self, port):
#         if port == self.port:
#             #self.callback(port)
#             print "================= FALLING"
#     """
# 
# class GpioOutput(object):
# 
#     def __init__(self, port):
#         self.port = port
#         GPIO.setup(self.port, GPIO.OUT)
# 
#     def on(self):
#         self.high()
# 
#     def off(self):
#         self.low()
# 
#     def low(self):
#         GPIO.output(self.port, GPIO.LOW)
# 
#     def high(self):
#         GPIO.output(self.port, GPIO.HIGH)


# Path: kotori/vendor/ilaundry/node/bricks.py
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
from kotori.vendor.ilaundry.node.gpio import GpioInput, GpioOutput


    def sensor_on(self, port):
        print("DEBUG: Port {0} EVENT".format(self.portname))

        # signal sensor-on
        if self.signal:
            self.signal.set(True)

    # currently defunct
    """
    def sensor_off(self, port):
        print "SENSOR OFF:", port

        # signal sensor-off
        if self.callback:
            self.callback(False)
    """


class BinaryOutputPort(object):

    # TODO: handle different ports, not only GPIO

    #HIGH = 1
    #LOW = 2
    #BLINK = 3

    def __init__(self, portname):
        self.portname = portname
        #self.flavor = flavor or self.HIGH

        self.gpio = GpioOutput(self.portname)