2011-12-28 05:31:36 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-02-14 00:27:07 -04:00
|
|
|
#ifndef AP_Compass_HMC5843_H
|
|
|
|
#define AP_Compass_HMC5843_H
|
|
|
|
|
2013-01-04 18:26:26 -04:00
|
|
|
#include <AP_HAL.h>
|
2011-04-30 23:05:17 -03:00
|
|
|
#include "../AP_Common/AP_Common.h"
|
|
|
|
#include "../AP_Math/AP_Math.h"
|
2011-02-14 00:27:07 -04:00
|
|
|
|
|
|
|
#include "Compass.h"
|
2014-11-15 21:58:23 -04:00
|
|
|
#include "AP_Compass_Backend.h"
|
2011-02-14 00:27:07 -04:00
|
|
|
|
2014-11-15 21:58:23 -04:00
|
|
|
class AP_Compass_HMC5843 : public AP_Compass_Backend
|
2011-02-14 00:27:07 -04:00
|
|
|
{
|
2012-08-17 03:19:22 -03:00
|
|
|
private:
|
|
|
|
float calibration[3];
|
|
|
|
bool _initialised;
|
2015-03-13 17:37:39 -03:00
|
|
|
bool read_raw(void);
|
2012-08-17 03:19:22 -03:00
|
|
|
uint8_t _base_config;
|
2015-03-13 17:37:39 -03:00
|
|
|
bool re_initialise(void);
|
2012-08-17 03:19:22 -03:00
|
|
|
bool read_register(uint8_t address, uint8_t *value);
|
2012-10-11 17:48:39 -03:00
|
|
|
bool write_register(uint8_t address, uint8_t value);
|
2012-08-17 03:19:22 -03:00
|
|
|
uint32_t _retry_time; // when unhealthy the millis() value to retry at
|
2013-01-04 18:26:26 -04:00
|
|
|
AP_HAL::Semaphore* _i2c_sem;
|
2011-12-28 05:31:36 -04:00
|
|
|
|
2012-08-26 00:42:00 -03:00
|
|
|
int16_t _mag_x;
|
|
|
|
int16_t _mag_y;
|
|
|
|
int16_t _mag_z;
|
|
|
|
int16_t _mag_x_accum;
|
|
|
|
int16_t _mag_y_accum;
|
|
|
|
int16_t _mag_z_accum;
|
|
|
|
uint8_t _accum_count;
|
|
|
|
uint32_t _last_accum_time;
|
|
|
|
|
2014-11-15 21:58:23 -04:00
|
|
|
uint8_t _compass_instance;
|
2015-02-23 19:17:44 -04:00
|
|
|
uint8_t _product_id;
|
2014-11-15 21:58:23 -04:00
|
|
|
|
2012-08-17 03:19:22 -03:00
|
|
|
public:
|
2014-11-15 21:58:23 -04:00
|
|
|
AP_Compass_HMC5843(Compass &compass);
|
2012-08-26 00:42:00 -03:00
|
|
|
bool init(void);
|
2015-02-23 19:17:44 -04:00
|
|
|
void read(void);
|
2012-08-26 00:42:00 -03:00
|
|
|
void accumulate(void);
|
2011-06-28 13:30:42 -03:00
|
|
|
|
2014-11-15 21:58:23 -04:00
|
|
|
// detect the sensor
|
|
|
|
static AP_Compass_Backend *detect(Compass &compass);
|
|
|
|
|
2011-02-14 00:27:07 -04:00
|
|
|
};
|
|
|
|
#endif
|