コード例 #1
0
ファイル: pa1010d.py プロジェクト: crdietrich/meerkat
 def get(self, nmea_sentences=None, timeout=15):
     """Get NMEA sentences
     
     Parameters
     ----------
     nmea_sentence : list of str, NMEA sentence codes to return i.e. 'GSV'
     timeout : int, seconds to wait for data before returning
     
     Returns
     -------
     list of str, NMEA sentences
     """
     
     if nmea_sentences is None:
         nmea_sentences = self.metadata.supported_nmea_sentences
     
     check = {s: False for s in nmea_sentences}
     
     t0 = time.time()
     while sum([x == False for x in check.values()]) > 0:
         if time.time() - t0 > timeout:  # timeout in seconds
             break
         
         for single_line in self.raw_get():
             sentence_type = single_line[3:6]
             if (sentence_type in nmea_sentences) & ("*" in single_line):
                 gps_data = single_line.split("*")
                 gps_cs = gps_data[1]
                 gps_data = gps_data[0][1:]
                 driver_cs = calc_checksum(gps_data)
                 if gps_cs == driver_cs:
                     check[sentence_type] = single_line
                     
     return [v for k, v in check.items()]
コード例 #2
0
        def _connect(_round):
            self.wlan.connect(ssid=self.ssid,
                              bssid=self.bssid,
                              auth=(WLAN.WPA2, self.key))

            t0 = time.time()
            while not self.wlan.isconnected():
                machine.idle()

                if time.time() - t0 > self.connect_timeout:
                    return False

                if self.verbose:
                    print(_round, time.time())
            return True
コード例 #3
0
    def measure_single_shot_blocking(self):
        """On-demand measurement of CO2 concentration, relative humidity 
        and temperature. See Ch 3.10.1
        
        Returns
        -------
        co2 : int, CO2 concentration in ppm
        t : float, temperature in degrees Celsius
        rh : int, relative humidity in percent
        """

        t0 = time.time()
        self.measure_single_shot()
        time.sleep(5)  # 5000 ms
        self.dt = time.time() - t0
        return self.read_measurement()
コード例 #4
0
    def measure(self, verbose=False):
        """Get the temperature, pressure and humidity"""
        self._new_data = 0

        t0 = time.time()
        cx = 1
        while True:
            self.get_measurement_status()
            dt = (time.time() - t0)

            if self._measuring == 1:
                if verbose:
                    print('Still measuring, waiting 1 second...')
                time.sleep(1)

            elif self._new_data == 1:
                if verbose:
                    print('New data found!')
                break

            elif dt > 5:
                if verbose:
                    print('Timeout waiting for new data :(')
                return False
            if verbose:
                print('While loop %s' % cx)
            cx += 1

        data = self.bus.read_register_nbit(0x1F, 3)  # 0x1F
        self._adc_pres = ((data[0] << 16) + (data[1] << 8) + data[2]) >> 4

        data = self.bus.read_register_nbit(0x22, 3)  # 0x22
        self._adc_temp = ((data[0] << 16) + (data[1] << 8) + data[2]) >> 4

        data = self.bus.read_register_nbit(0x25, 3)  # 0x25
        self._adc_hum = (data[0] << 8) + data[1]

        _gas_r_msb = self.bus.read_register_8bit(0x2A)
        _gas_r_lsb = self.bus.read_register_8bit(0x2B)

        self._adc_gas = (_gas_r_msb << 2) + (_gas_r_lsb >> 6)
        self._gas_valid = (_gas_r_lsb >> 5) & 0b1
        self._heat_stab = (_gas_r_lsb >> 4) & 0b1
        self._gas_range = _gas_r_lsb & 0b1111  # 0x2B <4:0>
        return True
コード例 #5
0
ファイル: sps30.py プロジェクト: crdietrich/meerkat
    def measured_values_blocking(self, verbose=False):
        """Block and poll until new data is available

        Parameters
        ----------
        dt : int, seconds to pause between polling requests
        timeout : int, maximum seconds to poll
        # continuous : bool, if True do not stop measurement to read latest data
        verbose : bool, print debug statements
        """
        self.start_measurement()
        time.sleep(self.blocking_settle_dt)

        t0 = time.time()
        while (time.time() - t0 < self.blocking_timeout):
            if self.data_ready():
                self.stop_measurement()
                return self.measured_values()
            if verbose:
                print('waiting...')
        return False