Arduino/LSM303Soft/LSM303Soft.cpp
// Reads the 3 magnetometer channels and stores them in vector m

Reads the 3 magnetometer channels and stores them in vector m
Reads the 3 magnetometer channels and stores them in vector m
void LSM303Soft::readMag(void)
{
  SoftWire.beginTransmission(mag_address);
  SoftWire.write((_device == device_D) ? translated_regs[-OUT_X_L_M] | (1 << 7) : translated_regs[-OUT_X_H_M]);
  last_status = SoftWire.endTransmission();
  SoftWire.requestFrom(mag_address, (byte)6);
  unsigned int millis_start = millis();
  while (SoftWire.available() < 6) {
    if (io_timeout > 0 && ((unsigned int)millis() - millis_start) > io_timeout)
    {
      did_timeout = true;
      return;
    }
  }
  byte xlm, xhm, ylm, yhm, zlm, zhm;
  if (_device == device_D)
  {
    xlm = SoftWire.read();
    xhm = SoftWire.read();
    ylm = SoftWire.read();
    yhm = SoftWire.read();
    zlm = SoftWire.read();
    zhm = SoftWire.read();
  }
  else
  {
    xhm = SoftWire.read();
    xlm = SoftWire.read();
    if (_device == device_DLH)
    {
      yhm = SoftWire.read();
      ylm = SoftWire.read();
      zhm = SoftWire.read();
      zlm = SoftWire.read();
    }
    else
    {
      zhm = SoftWire.read();
      zlm = SoftWire.read();
      yhm = SoftWire.read();
      ylm = SoftWire.read();
    }
  }
  m.x = (int16_t)(xhm << 8 | xlm);
  m.y = (int16_t)(yhm << 8 | ylm);
  m.z = (int16_t)(zhm << 8 | zlm);
}
void LSM303Soft :: readMag ( void ) { SoftWire . beginTransmission ( mag_address ) ; SoftWire . write ( ( _device == device_D ) ? translated_regs [ - OUT_X_L_M ] | ( 1 << 7 ) : translated_regs [ - OUT_X_H_M ] ) ; last_status = SoftWire . endTransmission ( ) ; SoftWire . requestFrom ( mag_address , ( byte ) 6 ) ; unsigned int millis_start = millis ( ) ; while ( SoftWire . available ( ) < 6 ) { if ( io_timeout > 0 && ( ( unsigned int ) millis ( ) - millis_start ) > io_timeout ) { did_timeout = true ; return ; } } byte xlm , xhm , ylm , yhm , zlm , zhm ; if ( _device == device_D ) { xlm = SoftWire . read ( ) ; xhm = SoftWire . read ( ) ; ylm = SoftWire . read ( ) ; yhm = SoftWire . read ( ) ; zlm = SoftWire . read ( ) ; zhm = SoftWire . read ( ) ; } else { xhm = SoftWire . read ( ) ; xlm = SoftWire . read ( ) ; if ( _device == device_DLH ) { yhm = SoftWire . read ( ) ; ylm = SoftWire . read ( ) ; zhm = SoftWire . read ( ) ; zlm = SoftWire . read ( ) ; } else { zhm = SoftWire . read ( ) ; zlm = SoftWire . read ( ) ; yhm = SoftWire . read ( ) ; ylm = SoftWire . read ( ) ; } } m . x = ( int16_t ) ( xhm << 8 | xlm ) ; m . y = ( int16_t ) ( yhm << 8 | ylm ) ; m . z = ( int16_t ) ( zhm << 8 | zlm ) ; }
Reads the 3 magnetometer channels and stores them in vector m
Reads the 3 magnetometer channels and stores them in vector m
// If LSM303D, assert MSB to enable subaddress updating
 // OUT_X_L_M comes first on D, OUT_X_H_M on others
 // D: X_L, X_H, Y_L, Y_H, Z_L, Z_H
 // DLHC, DLM, DLH: X_H, X_L...
 // DLH: ...Y_H, Y_L, Z_H, Z_L
 // DLM, DLHC: ...Z_H, Z_L, Y_H, Y_L
 // combine high and low bytes
