Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass_LIS2MDL.h
6351 views
1
/*
2
* This file is free software: you can redistribute it and/or modify it
3
* under the terms of the GNU General Public License as published by the
4
* Free Software Foundation, either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* This file is distributed in the hope that it will be useful, but
8
* WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
* See the GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License along
13
* with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
#pragma once
16
17
#include "AP_Compass_config.h"
18
19
#if AP_COMPASS_LIS2MDL_ENABLED
20
21
#include <AP_Common/AP_Common.h>
22
#include <AP_HAL/AP_HAL.h>
23
#include <AP_HAL/Device.h>
24
#include <AP_Math/AP_Math.h>
25
26
#include "AP_Compass.h"
27
#include "AP_Compass_Backend.h"
28
29
// LIS2MDL has a fixed I2C address
30
#define HAL_COMPASS_LIS2MDL_I2C_ADDR 0x1E
31
32
class AP_Compass_LIS2MDL : public AP_Compass_Backend
33
{
34
public:
35
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
36
bool force_external,
37
enum Rotation rotation);
38
39
void read() override;
40
41
static constexpr const char *name = "LIS2MDL";
42
43
private:
44
AP_Compass_LIS2MDL(AP_HAL::OwnPtr<AP_HAL::Device> dev,
45
bool force_external,
46
enum Rotation rotation);
47
48
AP_HAL::OwnPtr<AP_HAL::Device> dev;
49
50
/**
51
* @brief Initialize the sensor
52
* @return True if successful, false otherwise.
53
*/
54
bool init();
55
56
/**
57
* @brief Device periodic callback to read data from the sensor.
58
*/
59
void timer();
60
61
bool force_external;
62
enum Rotation rotation;
63
};
64
65
#endif // AP_COMPASS_LIS2MDL_ENABLED
66
67