def __init__(self, **kwargs): """ :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self.lock = threading.Lock() self.mifare = None
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._spi_lock = threading.Lock() self.load_extensions(OID) self._ada_gpio = None try: self._ada_gpio = GPIO.get_platform_gpio() except: logger.exception("[%s] - Can't get GPIO", self.__class__.__name__) self._ada_spi = None try: self._ada_spi = SPI except: logger.exception("[%s] - Can't get SPI", self.__class__.__name__) self.export_attrs('_ada_spi', self._ada_spi) self.export_attrs('_ada_gpio', self._ada_gpio) self.export_attrs('spi_acquire', self.spi_acquire) self.export_attrs('spi_release', self.spi_release) self.export_attrs('spi_locked', self.spi_locked) self.export_attrs('get_spi_device', self.get_spi_device) self.export_attrs('get_spi_device_pin', self.get_spi_device_pin)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._spi_lock = threading.Lock() self.load_extensions(OID) self._ada_gpio = None try: self._ada_gpio = GPIO.get_platform_gpio() except : logger.exception("[%s] - Can't get GPIO", self.__class__.__name__) self._ada_spi = None try: self._ada_spi = SPI except : logger.exception("[%s] - Can't get SPI", self.__class__.__name__) self.export_attrs('_ada_spi', self._ada_spi) self.export_attrs('_ada_gpio', self._ada_gpio) self.export_attrs('spi_acquire', self.spi_acquire) self.export_attrs('spi_release', self.spi_release) self.export_attrs('spi_locked', self.spi_locked) self.export_attrs('get_spi_device', self.get_spi_device) self.export_attrs('get_spi_device_pin', self.get_spi_device_pin)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ # ~ self.kernel_modprobe('i2c-dev') # ~ self.kernel_modprobe('i2c-bcm2708') JNTBus.__init__(self, **kwargs) # ~ self._i2c_lock = threading.Lock() # ~ self.load_extensions(OID) # ~ self._ada_i2c = I2C # ~ """ The shared ADAFruit I2C bus """ # ~ self.export_attrs('i2c_acquire', self.i2c_acquire) # ~ self.export_attrs('i2c_release', self.i2c_release) # ~ self.export_attrs('get_i2c_device', self.get_i2c_device) # ~ self.export_attrs('get_busnum', self.get_busnum) # ~ self.export_attrs('get_adafruit_i2c', self.get_adafruit_i2c) # ~ self.export_attrs('software_reset', self.software_reset) # ~ self.export_attrs('require_repeated_start', self.require_repeated_start) uuid = "%s_busnum" % OID self.values[uuid] = self.value_factory['config_integer']( options=self.options, uuid=uuid, node_uuid=self.uuid, help='The I2C bus number to use. Set it to None to get default bus', label='BusNum', default=None, )
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ oid = kwargs.pop('oid', 'fake') JNTBus.__init__(self, oid=oid, **kwargs)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._camera_lock = threading.Lock() self.camera = None uuid = "%s_led" % OID self.values[uuid] = self.value_factory["config_boolean"]( options=self.options, uuid=uuid, node_uuid=self.uuid, help="Led state", label="led", default=True ) uuid = "%s_actions" % OID self.values[uuid] = self.value_factory["action_list"]( options=self.options, uuid=uuid, node_uuid=self.uuid, help="The actions on the camera", label="Actions", list_items=["start_preview", "stop_preview"], set_data_cb=self.rpicamera_set_action, is_writeonly=True, cmd_class=COMMAND_CAMERA_PREVIEW, genre=0x01, ) self.export_attrs("camera_acquire", self.camera_acquire) self.export_attrs("camera_release", self.camera_release) self.export_attrs("camera", self.camera)
def __init__(self, **kwargs): """ :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._sound_lock = threading.Lock() self.load_extensions(OID) self.export_attrs('sound_acquire', self.sound_acquire) self.export_attrs('sound_release', self.sound_release) self.export_attrs('sound_locked', self.sound_locked)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._tellstick_lock = threading.Lock() self._lock_delay = 0.25 self.load_extensions(OID) self.cant_aggregate(OID) self.sensors = {}
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ self.kernel_modprobe('i2c-dev') self.kernel_modprobe('i2c-bcm2708') JNTBus.__init__(self, **kwargs) self._i2c_lock = threading.Lock() self.load_extensions(OID) self._ada_i2c = I2C """ The shared ADAFruit I2C bus """ self.export_attrs('i2c_acquire', self.i2c_acquire) self.export_attrs('i2c_release', self.i2c_release)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ self.kernel_modprobe('w1-gpio') self.kernel_modprobe('w1-therm') JNTBus.__init__(self, **kwargs) uuid="%s_sensors_dir"%OID self.values[uuid] = self.value_factory['config_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The sensor directory', label='dir.', default='/sys/bus/w1/devices/', )
def __init__(self, **kwargs): """ :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._lock = threading.Lock() self.gpio = None uuid="%s_boardmode"%OID self.values[uuid] = self.value_factory['config_list'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The board mode to use', label='Boardmode', default='BOARD', list_items=['BCM', 'BOARD'], ) self.export_attrs('gpio', self.gpio)
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['1wire'] = OnewireBus(masters=[self], **kwargs) uuid="{:s}_temperature".format(OID) self.values[uuid] = self.value_factory['sensor_temperature'](options=self.options, uuid=uuid, node_uuid=self.uuid, get_data_cb=self.get_temperature_cb, help='The average temperature of tutorial. Can be use as a good quality source for a thermostat.', label='Temp', ) poll_value = self.values[uuid].create_poll_value(default=300) self.values[poll_value.uuid] = poll_value
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['camera'] = CameraBus(masters=[self], **kwargs) self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['spibus'] = SPIBus(masters=[self], **kwargs) self.buses['i2cbus'] = I2CBus(masters=[self], **kwargs) self._lapinoo_lock = threading.Lock() self.check_timer = None uuid="%s_timer_delay"%OID self.values[uuid] = self.value_factory['config_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The delay between 2 checks', label='Timer.', default=45, )
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['camera'] = CameraBus(masters=[self], **kwargs) self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['spibus'] = SPIBus(masters=[self], **kwargs) self.buses['i2cbus'] = I2CBus(masters=[self], **kwargs) self._lapinoo_lock = threading.Lock() self.check_timer = None uuid = "%s_timer_delay" % OID self.values[uuid] = self.value_factory['config_integer']( options=self.options, uuid=uuid, node_uuid=self.uuid, help='The delay between 2 checks', label='Timer.', default=45, )
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._lock = threading.Lock() self._server = None if 'home_dir' in self.options.data and self.options.data['home_dir'] is not None: dirname = self.options.data['home_dir'] directory = os.path.join(dirname, 'public') if not os.path.exists(directory): os.makedirs(directory) uuid="host" self.values[uuid] = self.value_factory['config_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The host or IP to use for the server', label='Host', default='localhost', ) uuid="port" self.values[uuid] = self.value_factory['config_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The port', label='Port', default=8081, ) uuid="actions" self.values[uuid] = self.value_factory['action_list'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The action on the HTTP server', label='Actions', list_items=['start', 'stop', 'reload'], set_data_cb=self.set_action, is_writeonly = True, cmd_class=COMMAND_WEB_CONTROLLER, genre=0x01, )
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs)
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['1wire'] = OnewireBus(masters=[self], **kwargs) self._statemachine = None self.check_timer = None uuid="{:s}_timer_delay".format(OID) self.values[uuid] = self.value_factory['config_float'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The delay between 2 checks', label='Timer.', default=30, ) uuid="{:s}_temperature_critical".format(OID) self.values[uuid] = self.value_factory['config_float'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The critical temperature. If 2 of the 3 temperature sensors are up to this value, a security notification is sent.', label='Critical', default=50, ) uuid="{:s}_temperature".format(OID) self.values[uuid] = self.value_factory['sensor_temperature'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The average temperature of tutorial.', label='Temp', ) poll_value = self.values[uuid].create_poll_value(default=300) self.values[poll_value.uuid] = poll_value uuid="{:s}_overheat".format(OID) self.values[uuid] = self.value_factory['sensor_boolean'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='Temperature overheat.', label='Overheat', default=False, ) poll_value = self.values[uuid].create_poll_value(default=60) self.values[poll_value.uuid] = poll_value uuid="{:s}_transition".format(OID) self.values[uuid] = self.value_factory['transition_fsm'](options=self.options, uuid=uuid, node_uuid=self.uuid, list_items=[ v['trigger'] for v in self.transitions ], fsm_bus=self, ) poll_value = self.values[uuid].create_poll_value() self.values[poll_value.uuid] = poll_value uuid="{:s}_state".format(OID) self.values[uuid] = self.value_factory['sensor_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, genre=0x01, help='The state of the fsm.', get_data_cb = self.get_state, label='State', ) poll_value = self.values[uuid].create_poll_value(default=60) self.values[poll_value.uuid] = poll_value self._bus_lock = threading.Lock() self.presence_events = {} self.state = "sleeping"
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.states = [ 'booting', 'halted', 'sleeping', 'working', ] """The fsm states : - the first state must be booting - do what you want with the other ones. """ self.transitions = [ { 'trigger': 'boot', 'source': 'booting', 'dest': 'sleeping', }, { 'trigger': 'halt', 'source': '*', 'dest': 'halted', }, { 'trigger': 'sleep', 'source': '*', 'dest': 'sleeping', }, { 'trigger': 'work', 'source': '*', 'dest': 'working', }, ] """The fsm transitions - the first transition is used to get out the boot state : its a good idea to check values availability in ths trigger. - the second transition is used to stop the machine. - do what you want with the other ones. """ self._fsm = None """The finish state machine""" self._fsm_boot_timer = None """The timer that's start the finish state machine""" self._fsm_boot_lock = threading.Lock() """The timer that's start the finish state machine""" self._fsm_timer_delay = 3.1 """The timer delay between 2 retries""" self._fsm_max_retries = 5 """The max retries to boot the fsm""" self._fsm_retry = 0 """The current retry to boot the fsm""" self._fsm_slow_start = 0 """The slow delay to boot the fsm""" self.state = self.states[0] """Initial state of the fsm""" self._bus_lock = threading.Lock() """A lock for the bus""" uuid="{:s}_transition".format(self.oid) self.values[uuid] = self.value_factory['transition_fsm'](options=self.options, uuid=uuid, node_uuid=self.uuid, list_items=[ v['trigger'] for v in self.transitions ], fsm_bus=self, ) poll_value = self.values[uuid].create_poll_value() self.values[poll_value.uuid] = poll_value config_value = self.values[uuid].create_config_value(default=self.transitions[0]['trigger']) self.values[config_value.uuid] = config_value uuid="{:s}_state".format(self.oid) self.values[uuid] = self.value_factory['sensor_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, genre = 0x01, get_data_cb = self.get_state, help='The state of the fsm.', label='State', ) poll_value = self.values[uuid].create_poll_value(default=60) self.values[poll_value.uuid] = poll_value
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self.store = None self.store_last = False uuid="count_values" self.values[uuid] = self.value_factory['sensor_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The number of values in the store', label='#Values', get_data_cb=self.get_count_values, genre=0x01, ) poll_value = self.values[uuid].create_poll_value(default=300) self.values[poll_value.uuid] = poll_value uuid="count_series" self.values[uuid] = self.value_factory['sensor_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The number of series of values in the store', label='#Series', get_data_cb=self.get_count_series, genre=0x01, ) poll_value = self.values[uuid].create_poll_value(default=300) self.values[poll_value.uuid] = poll_value uuid="cache_rrd_ttl" self.values[uuid] = self.value_factory['config_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The cache_rrd_ttl', label='Rrd ttl', default=60*60, ) uuid="cache_pickle_ttl" self.values[uuid] = self.value_factory['config_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The cache_pickle_ttl', label='Pickle ttl', default=60, ) uuid="cache_dead_ttl" self.values[uuid] = self.value_factory['config_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The cache_dead_ttl', label='Cache dead ttl', default=60*60*24, ) uuid="actions" self.values[uuid] = self.value_factory['action_list'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The action on the store', label='Actions', list_items=['flush'], set_data_cb=self.set_action, is_writeonly = True, cmd_class = COMMAND_CONTROLLER, genre=0x01, )
def __init__(self, manager_id=None, **kwargs): """ :param int manager_id: the id of the manager :param kwargs: parameters """ JNTBus.__init__(self, **kwargs) if manager_id == None: self.manager_id = randint(0,9999) else: self.manager_id = manager_id for cls in [COMMAND_EVENT_CONTROLLER_CONF, COMMAND_EVENT_ACTUATOR_CONF, COMMAND_CONFIGURATION]: self.cmd_classes.append(cls) uuid = '%s_manager_id'%OID self.values[uuid] = JNTValue( uuid=uuid, help='The id of the event manager', label='%s' % uuid, index=0, cmd_class=0x0070, genre=0x03, type=0x02, set_data_cb=self.set_config_manager_id, get_data_cb=self.get_config_manager_id, is_writeonly=False, is_readonly=False, default=1, ) uuid = "%s_add_event"%OID self.values[uuid] = JNTValue( uuid=uuid, help='Add the event', label='%s' % uuid, units='', index=0, cmd_class=COMMAND_EVENT_CONTROLLER_CONF, genre=0x05, type=0x15, set_data_cb=self.add_event, is_writeonly=True, node_uuid=self.uuid, ) uuid = "%s_remove_event"%OID self.values[uuid] = JNTValue( uuid=uuid, help='Remove the event', label='%s' % uuid, units='', index=0, cmd_class=COMMAND_EVENT_CONTROLLER_CONF, genre=0x05, type=0x15, set_data_cb=self.remove_event, is_writeonly=True, node_uuid=self.uuid, ) uuid = "%s_get_num_events"%OID self.values[uuid] = JNTValue( uuid=uuid, help='Get the number of events', label='%s' % uuid, units='', index=0, cmd_class=COMMAND_EVENT_CONTROLLER_CONF, genre=0x05, type=0x15, set_data_cb=self.get_num_events, is_writeonly=True, node_uuid=self.uuid, ) uuid = "%s_get_event"%OID self.values[uuid] = JNTValue( uuid=uuid, help='Get all the values in a event', label='%s' % uuid, units='', index=0, cmd_class=COMMAND_EVENT_CONTROLLER_CONF, genre=0x05, type=0x15, set_data_cb=self.get_event, is_writeonly=True, node_uuid=self.uuid, ) uuid = "%s_add_value_to_event"%OID self.values[uuid] = JNTValue( uuid=uuid, help='Add a value to a event', label='%s' % uuid, units='', index=0, cmd_class=COMMAND_EVENT_CONTROLLER_CONF, genre=0x05, type=0x15, set_data_cb=self.add_value_to_event, is_writeonly=True, node_uuid=self.uuid, ) uuid = "%s_set_value_in_event"%OID self.values[uuid] = JNTValue( uuid=uuid, help='Set a value in a event', label='%s' % uuid, units='', index=0, cmd_class=COMMAND_EVENT_CONTROLLER_CONF, genre=0x05, type=0x15, set_data_cb=self.set_value_in_event, is_writeonly=True, node_uuid=self.uuid, ) uuid = "%s_remove_value_from_event"%OID self.values[uuid] = JNTValue( uuid=uuid, help='Remove a value from a event', label='%s' % uuid, units='', index=0, cmd_class=COMMAND_EVENT_CONTROLLER_CONF, genre=0x05, type=0x15, set_data_cb=self.remove_value_from_event, is_writeonly=True, node_uuid=self.uuid, ) self.load_extensions(OID)
def __init__(self, **kwargs): """ :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs)