Пример #1
0
 def load_interface(self, config_path, interface_name):
     try:
         module_type = DOORPI.config(config_path + interface_name + '/type', None)
         if not module_type: raise MissingInterfaceTypException()
         interface_object = importlib.import_module(DOORPI.CONST.INTERFACES_BASE_IMPORT_PATH + module_type).__interface__(
             name = interface_name,
             config_path = config_path + interface_name
         )
         if interface_name in self._interfaces:
             raise InterfaceNameAlreadyExistsException(interface_name)
         else:
             self._interfaces[interface_name] = interface_object.start()
     except Exception as exp:
         logger.exception('failed to load interface with error %s', exp)
Пример #2
0
    def start(self):
        super(GPIOBasedInterface, self).start()

        GPIO.setwarnings(DOORPI.config(self._conf + '/setwarnings', False))
        GPIO.setmode(DOORPI.config(self._conf + '/mode', GPIO.BOARD))

        logger.debug('use GPIO %s - %s', GPIO.VERSION, GPIO.RPI_INFO)

        self._register_channels()

        DOORPI.events.register_events(self.module_name, *self.channel_events)

        default_edge = DOORPI.config('%s/event_edge' % self._conf, GPIO.BOTH)
        default_bouncetime = DOORPI.config('%s/event_bouncetime' % self._conf,
                                           40)
        default_pull_up_down = DOORPI.config('%s/pull_up_down' % self._conf,
                                             GPIO.PUD_OFF)

        for input_id in self.inputs:
            GPIO.setup(channel=self.inputs[input_id].technical_name,
                       direction=GPIO.IN,
                       pull_up_down=DOORPI.config(
                           '%s/outputs/%s/pull_up_down' %
                           (self._conf, self.inputs[input_id].name),
                           default_pull_up_down))
            GPIO.add_event_detect(gpio=self.inputs[input_id].technical_name,
                                  edge=DOORPI.config(
                                      '%s/outputs/%s/event_edge' %
                                      (self._conf, self.inputs[input_id].name),
                                      default_edge),
                                  callback=self.event_detect,
                                  bouncetime=DOORPI.config(
                                      '%s/outputs/%s/event_bouncetime' %
                                      (self._conf, self.inputs[input_id].name),
                                      default_bouncetime))

        for output_id in self.outputs:
            GPIO.setup(channel=self.outputs[output_id].technical_name,
                       direction=GPIO.OUT,
                       initial=self.outputs[output_id].value)
            self.set_output(output_id,
                            self.outputs[output_id].value,
                            log=False)

        self._register_outputs_actions()
Пример #3
0
 def start(self):
     super(HardwareInterfaceBaseClass, self).start()
     if DOORPI.config(self._conf + '/reverse_polarity', False):
         self._high_level = DOORPI.CONST.LOW_LEVEL
         self._low_level = DOORPI.CONST.HIGH_LEVEL
Пример #4
0
    def _register_channels(self):
        inputs = DOORPI.config(self._conf + '/inputs', [], function='keys')
        logger.info('%s has %s inputs', self.fullname, len(inputs))
        for input_name in inputs:
            if input_name in self._inputs:
                raise InputNameAlreadyExistsException()
            input_id = DOORPI.generate_id(prefix='Input_')
            self._inputs[input_id] = SingleChannel(
                id=input_id,
                name=input_name,
                technical_name=DOORPI.config(
                    '%s/inputs/%s/technical_name' % (self._conf, input_name),
                    input_name),
                initial_value=DOORPI.config(
                    '%s/inputs/%s/initial_value' % (self._conf, input_name),
                    False),
                log=DOORPI.config(
                    '%s/inputs/%s/log' % (self._conf, input_name), True),
            )

        outputs = DOORPI.config(self._conf + '/outputs', [], function='keys')
        logger.info('%s has %s outputs', self.fullname, len(inputs))
        for output_name in outputs:
            if output_name in self._outputs:
                raise OutputNameAlreadyExistsException()
            output_id = DOORPI.generate_id(prefix='Output_')
            self._outputs[output_id] = SingleChannel(
                id=output_id,
                name=output_name,
                technical_name=DOORPI.config(
                    '%s/outputs/%s/technical_name' % (self._conf, output_name),
                    output_name),
                initial_value=DOORPI.config(
                    '%s/outputs/%s/initial_value' % (self._conf, output_name),
                    False),
                log=DOORPI.config(
                    '%s/outputs/%s/log' % (self._conf, output_name), True),
                high_level=DOORPI.config(
                    '%s/outputs/%s/high_level' % (self._conf, output_name),
                    True),
                low_level=DOORPI.config(
                    '%s/outputs/%s/low_level' % (self._conf, output_name),
                    False),
                high_by_event=DOORPI.config(
                    '%s/outputs/%s/high_by_event' % (self._conf, output_name),
                    None),
                low_by_event=DOORPI.config(
                    '%s/outputs/%s/low_by_event' % (self._conf, output_name),
                    None),
            )
Пример #5
0
 def start(self):
     logger.debug("start InterfaceHandler")
     for interface_name in DOORPI.config('/interfaces', default = [], function = 'keys'):
         self.load_interface('/interfaces/', interface_name)
     logger.debug('loaded %s interfaces', len(self._interfaces))