示例#1
0
 def _mag_callback(self):
     '''
     Update magnetometer Vector3d object (if data available)
     '''
     try:                                    # If read fails, returns last valid data
         if self.mag_ready:                  # Starts mag if necessary
             self._read(self.buf6, 0x03, self._mag_addr)
             self.mag_triggered = False
         else:
             self._mag_stale_count += 1      # Data not ready: retain last value
             return                          # but increment stale count
         self._read(self.buf6, 0x03, self._mag_addr)  # Mag was ready
         self._read(self.buf1, 0x09, self._mag_addr)  # Read ST2
     except OSError:
         self.mag_triggered = False
         raise MPUException(self._I2Cerror)
     if self.buf1[0] & 0x0C > 0:             # An overflow or data error has occurred
         self._mag_stale_count += 1           # transitory condition? User checks stale count.
         return
     self._mag._ivector[1] = bytes_toint(self.buf6[1], self.buf6[0])  # Note axis twiddling and little endian
     self._mag._ivector[0] = bytes_toint(self.buf6[3], self.buf6[2])
     self._mag._ivector[2] = -bytes_toint(self.buf6[5], self.buf6[4])
     scale = 0.3                             # 0.3uT/LSB
     self._mag._vector[0] = self._mag._ivector[0]*self.mag_correction[0]*scale
     self._mag._vector[1] = self._mag._ivector[1]*self.mag_correction[1]*scale
     self._mag._vector[2] = self._mag._ivector[2]*self.mag_correction[2]*scale
     self._mag_stale_count = 0
示例#2
0
 def get_mag_irq(self):
     '''
     Uncorrected values because floating point uses heap
     '''
     if not self.mag_triggered:              # Can't do exception handling here
         self._write(1, 0x0A, self._mag_addr)
         self.mag_triggered = True
     self._read(self.buf1, 0x02, self._mag_addr)
     if self.buf1[0] == 1:
         self._read(self.buf6, 0x03, self._mag_addr)  # Note axis twiddling
         self._mag._ivector[1] = bytes_toint(self.buf6[1], self.buf6[0])
         self._mag._ivector[0] = bytes_toint(self.buf6[3], self.buf6[2])
         self._mag._ivector[2] = -bytes_toint(self.buf6[5], self.buf6[4])
         self.mag_triggered = False
示例#3
0
 def temperature(self):
     '''
     Returns the temperature in degree C.
     '''
     try:
         self._read(self.buf2, 0x41, self.mpu_addr)
     except OSError:
         raise MPUException(self._I2Cerror)
     return bytes_toint(self.buf2[0], self.buf2[1])/340 + 35  # I think