AP_Compass: HMC5843: use a struct for raw value

Like is done in AK8963, declare a raw_value struct.
This commit is contained in:
Lucas De Marchi 2015-08-10 19:24:56 -03:00 committed by Andrew Tridgell
parent 9ecd1daf81
commit 628e446e3e
2 changed files with 11 additions and 7 deletions

View File

@ -128,22 +128,22 @@ bool AP_Compass_HMC5843::write_register(uint8_t address, uint8_t value)
// Read Sensor data
bool AP_Compass_HMC5843::read_raw()
{
uint8_t buff[6];
struct AP_HMC5843_SerialBus::raw_value rv;
if (_bus->register_read(0x03, buff, 6) != 0) {
if (_bus->register_read(0x03, (uint8_t*)&rv, sizeof(rv)) != 0) {
_bus->set_high_speed(false);
_retry_time = hal.scheduler->millis() + 1000;
return false;
}
int16_t rx, ry, rz;
rx = (((int16_t)buff[0]) << 8) | buff[1];
rx = (((int16_t)rv.val[0]) << 8) | rv.val[1];
if (_product_id == AP_COMPASS_TYPE_HMC5883L) {
rz = (((int16_t)buff[2]) << 8) | buff[3];
ry = (((int16_t)buff[4]) << 8) | buff[5];
rz = (((int16_t)rv.val[2]) << 8) | rv.val[3];
ry = (((int16_t)rv.val[4]) << 8) | rv.val[5];
} else {
ry = (((int16_t)buff[2]) << 8) | buff[3];
rz = (((int16_t)buff[4]) << 8) | buff[5];
ry = (((int16_t)rv.val[2]) << 8) | rv.val[3];
rz = (((int16_t)rv.val[4]) << 8) | rv.val[5];
}
if (rx == -4096 || ry == -4096 || rz == -4096) {
// no valid data available

View File

@ -61,6 +61,10 @@ public:
class AP_HMC5843_SerialBus
{
public:
struct PACKED raw_value {
uint8_t val[6];
};
virtual ~AP_HMC5843_SerialBus() { };
virtual void set_high_speed(bool val) = 0;
virtual uint8_t register_read(uint8_t reg, uint8_t *buf, uint8_t size) = 0;