Beispiel #1
0
    def read_raw(self):
        # reads the raw value from the selected previously planned one-shot operation or continuous
        # requires correctly bits
        readlen = 4 if self.lastmeasure.bits == 18 else 3  # if bits=18 : 4 else: 3
        with (yield self.i2cbus.iolock.acquire()):
            bytes = pigpio.u2i((yield self.i2cbus.apigpio_command(pigpio._PI_CMD_I2CRD, self.i2c, readlen)))
            if bytes <= 0: return
            data = yield self.i2cbus.arxbuf(bytes)

        status = data[readlen - 1]
        if status & 0x80:
            print("Converting in progress")
            return  # converting in progress
        if (self.lastmeasure._mode & 0x7f) != (status & 0x7f):
            print("Status unexpected")
            return  # something is bad

        value = 0
        for i in range(readlen - 1): value = (value << 8) | data[i]  # join bytes into number
        #print("readRaw end %s %x" %(value,status))
        bits = (status & 0x0c) >> 2
        sign = BIT_MASKS[bits][1] & value
        value &= BIT_MASKS[bits][0]
        if sign: value = -value
        self.lastmeasure._set_voltage(2.048 / BIT_MASKS[bits][0] * value)
        raise gen.Return(True)
Beispiel #2
0
    def read_raw(self):
        # reads the raw value from the selected previously planned one-shot operation or continuous
        # requires correctly bits
        readlen = 4 if self.lastmeasure.bits == 18 else 3  # if bits=18 : 4 else: 3
        with (yield self.i2cbus.iolock.acquire()):
            bytes = pigpio.u2i(
                (yield self.i2cbus.apigpio_command(pigpio._PI_CMD_I2CRD,
                                                   self.i2c, readlen)))
            if bytes <= 0: return
            data = yield self.i2cbus.arxbuf(bytes)

        status = data[readlen - 1]
        if status & 0x80:
            print("Converting in progress")
            return  # converting in progress
        if (self.lastmeasure._mode & 0x7f) != (status & 0x7f):
            print("Status unexpected")
            return  # something is bad

        value = 0
        for i in range(readlen - 1):
            value = (value << 8) | data[i]  # join bytes into number
        #print("readRaw end %s %x" %(value,status))
        bits = (status & 0x0c) >> 2
        sign = BIT_MASKS[bits][1] & value
        value &= BIT_MASKS[bits][0]
        if sign: value = -value
        self.lastmeasure._set_voltage(2.048 / BIT_MASKS[bits][0] * value)
        raise gen.Return(True)