示例#1
0
    def __init__(self, sensors, pin_index=None, timer=None):
        "DRDY and timer data stream"
        assert sensors[0].name in KX134Driver.supported_parts
        StreamConfig.__init__(self, sensors[0])
        sensors[0].resource[CFG_AXIS_MAP] = [0, 1, 2, 3, 4, 5, 6]

        sensor = sensors[0]

        # get pin_index if it is not given and timer is not used
        if pin_index is None:
            pin_index = get_drdy_pin_index()

        if timer is None:
            timer = get_drdy_timer()

        proto = self.adapter.protocol
        message = RequestMessageDefinition(sensor,
                                           fmt=self.fmt,
                                           hdr=self.hdr,
                                           pin_index=pin_index,
                                           timer=timer)

        if pin_index is not None:
            req = proto.create_macro_req(
                trigger_type=proto.EVKIT_MACRO_TYPE_INTR,
                gpio_pin=message.gpio_pin,
                gpio_sense=self.sense_dict[sensor.resource[CFG_POLARITY]],
                gpio_pullup=self.pullup_dict[sensor.resource[CFG_PULLUP]])
        elif timer is not None:
            time_unit, time_val = proto.seconds_to_proto_time(message.timer)
            req = proto.create_macro_req(
                trigger_type=proto.EVKIT_MACRO_TYPE_POLL,
                timer_scale=time_unit,
                timer_value=time_val)
        self.adapter.send_message(req)
        _, macro_id = self.adapter.receive_message(
            proto.EVKIT_MSG_CREATE_MACRO_RESP)
        self.macro_id_list.append(macro_id)
        self.msg_ind_dict[macro_id] = message
        message.msg_req.append(req)

        # read three separate register areas
        reg_read_cfgs = [(r.KX134_1211_XOUT_L, 6, False), (self.reg, 6, False),
                         (r.KX134_1211_STATUS_REG, 1, False),
                         (r.KX134_1211_INT_REL, 1, True)]
        for addr_start, read_size, discard in reg_read_cfgs:
            if self.sensor.resource.get(CFG_SPI_PROTOCOL, 0) == 1:
                # With Kionix components, MSB must be set 1 to indicate reading
                addr_start = addr_start | 1 << 7
            req = proto.add_macro_action_req(
                macro_id,
                action=proto.EVKIT_MACRO_ACTION_READ,
                target=self.sensor.resource[CFG_TARGET],
                identifier=self.sensor.get_identifier(),
                discard=discard,
                start_register=addr_start,
                bytes_to_read=read_size)
            self.adapter.send_message(req)
            self.adapter.receive_message(proto.EVKIT_MSG_ADD_MACRO_ACTION_RESP)
            message.msg_req.append(req)
示例#2
0
    def __init__(self, sensors, pin_index=None, timer=None):
        "DRDY and timer data stream"
        assert sensors[0].name in KX134Driver.supported_parts
        StreamConfig.__init__(self, sensors[0])

        # get pin_index if it is not given and timer is not used
        if pin_index is None:
            pin_index = get_drdy_pin_index()

        if timer is None:
            timer = get_drdy_timer()

        self.define_request_message(fmt=self.fmt,
                                    hdr=self.hdr,
                                    reg=self.reg,
                                    pin_index=pin_index,
                                    timer=timer)
    def __init__(self, sensors, pin_index=None, timer=None):
        "DRDY and timer data stream"
        assert sensors[0].name in KXTJ3Driver.supported_parts
        StreamConfig.__init__(self, sensors[0])

        # get pin_index if it is not given and timer is not used
        if pin_index is None:
            pin_index = get_drdy_pin_index()

        if timer is None:
            timer = get_drdy_timer()

        'Sensor can only be connected to adapter logical int pin 1'
        assert pin_index in [None, 1]

        self.define_request_message(fmt=self.fmt,
                                    hdr=self.hdr,
                                    reg=self.reg,
                                    pin_index=pin_index,
                                    timer=timer)