def __init__(self, serial, board_size, *args, **kwargs):
     OutputBase.__init__(self, *args, **kwargs)
     self.serial = Serial(**serial)
     self.board_size = board_size
     if min(self.relays.keys()) <= 0 or max(self.relays.keys()) > self.board_size:
         raise InvalidModuleConfigurationException(
                 "Module %r io_ports %r out of range %d - %d" % (
                 self, self.io_ports, 1, self.board_size))
 def __init__(self, baseurl, *args, **kwargs):
     OutputBase.__init__(self, *args, **kwargs)
     self.baseurl = baseurl
     physicalPorts = self.getPhysicalIoPortsState()
     for relay in self.relays:
         if not relay in physicalPorts:
             raise InvalidModuleConfigurationException(
                 "%r Relay %r does not exist in url %r",
                 self.__class__.__name,
                 relay, self.baseUrl)
    def __init__(self, port, board_type='arduino', baud_rate=57600, reverse=False,
                 *args, **kwargs):
        OutputBase.__init__(self, *args, **kwargs)
        self.firmata = pyfirmata.Board(port, pyfirmata.BOARDS[board_type], baud_rate)
        # for using relay boards where HIGH means ON, LOW means OFF
        self.reverse = reverse

        # analog ports will be parsed as strings from the YAML config file
        # digital ports can be either integers or strings, we don't care.
        analog_ports = [io_port_id for io_port_id in self.relays.keys()
                if type(io_port_id) == str and
                io_port_id.lower().startswith('a')]
        digital_ports = list(set(self.relays.keys()) - set(analog_ports))
        analog_ports = [int(io_port_id[1:]) for io_port_id in analog_ports]
        digital_ports = map(int, digital_ports)

        outofrange_digital_ports = [port for port in digital_ports
            if port < 0 or port >= len(self.firmata.digital)]
        if outofrange_digital_ports:
            raise InvalidModuleConfigurationException(
                "Module %s digital io_ports %s out of range %d - %d" % (
                self.__class__.__name__,
                ', '.join(map(str, outofrange_digital_ports)),
                0, len(self.firmata.digital) - 1))

        outofrange_analog_ports = ['A' + str(port)
            for port in analog_ports
            if port < 0 or port >= len(self.firmata.analog)]
        if outofrange_analog_ports:
            raise InvalidModuleConfigurationException(
                "Module %s analog io_ports %s out of range A%d - A%d" % (
                self.__class__.__name__,
                ', '.join(outofrange_analog_ports),
                0, len(self.firmata.analog) - 1))

        # set all analog ports to output
        for analog_port in analog_ports:
            port = self.firmata.analog[analog_port]
            port.mode = pyfirmata.OUTPUT
            port.write(0)

        # if we're using reversed logic, set all outputs to HIGH (relays off)
        if self.reverse:
            for analog_port in analog_ports:
                self.firmata.analog[analog_port].write(1)
            for digital_port in digital_ports:
                self.firmata.digital[digital_port].write(1)
 def __init__(self, *args, **kwargs):
     OutputBase.__init__(self, *args, **kwargs)
     self.io_ports_state = dict(
             zip(self.relays.keys(), [False]*len(self.relays)))