예제 #1
0
    def start(self):

        # Main operating loop
        while not self._exit_flag:

            try:

                # Polls until ready
                while not(self._is_ready()):
                    time.sleep(0.1)

                # Sample sps30
                read = self._read_data()

                # Check crc8 and deserialize
                for i in range(0, 10):

                    # crc8 check
                    assert calc_crc8(read[i * 6 : i * 6 + 2]) == bytes([read[i * 6 + 2]]), "Bad upper crc8"
                    assert calc_crc8(read[i * 6 + 3: i * 6 + 5]) == bytes([read[i * 6 + 5]]), "Bad lower crc8"

                    # Deserialize
                    float_struct = struct.pack('>BBBB', read[i * 6], read[i * 6 + 1], read[i * 6 + 3], read[i * 6 + 4])
                    self._curr_data[i] = struct.unpack('>f', float_struct)[0]

                # Sleep timer
                time.sleep(self._interval)

            except Exception as e:
                # Reset sensor in case I2C Bus fail, bad crc8, whatever
                print(e)
                self._reset()
                time.sleep(3)
예제 #2
0
    def _is_ready(self):

        # Returns device ready flag
        self._i2c.writeto(SCD30_I2C_ID, SCD30_READY_ADDR)
        read = self._i2c.readfrom(SCD30_I2C_ID, 3)

        return bytes([read[2]]) == calc_crc8(read[0:2])
    def startMeasurement(self):
        cmd = bytearray([
            0x00, 0x10, 0x03, 0x00,
            crc8.calc_crc8([0x03, 0x00], self.crc_init, self.crc_poly)
        ])

        with self.i2c_device as i2c:
            i2c.write(cmd)
예제 #4
0
    def _send_start(self):

        # Start measurement mode, returns number of bytes written
        return self._i2c.writeto(
            SCD30_I2C_ID, SCD30_START_ADDR + SCD30_START_MEASUREMENT +
            calc_crc8(SCD30_START_MEASUREMENT))