CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass_LIS3MDL.h
Views: 1798
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_LIS3MDL_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
#ifndef HAL_COMPASS_LIS3MDL_I2C_ADDR
30
# define HAL_COMPASS_LIS3MDL_I2C_ADDR 0x1c
31
#endif
32
33
#ifndef HAL_COMPASS_LIS3MDL_I2C_ADDR2
34
# define HAL_COMPASS_LIS3MDL_I2C_ADDR2 0x1e
35
#endif
36
37
class AP_Compass_LIS3MDL : public AP_Compass_Backend
38
{
39
public:
40
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
41
bool force_external,
42
enum Rotation rotation);
43
44
void read() override;
45
46
static constexpr const char *name = "LIS3MDL";
47
48
private:
49
AP_Compass_LIS3MDL(AP_HAL::OwnPtr<AP_HAL::Device> dev,
50
bool force_external,
51
enum Rotation rotation);
52
53
AP_HAL::OwnPtr<AP_HAL::Device> dev;
54
55
/**
56
* Device periodic callback to read data from the sensor.
57
*/
58
bool init();
59
void timer();
60
61
uint8_t compass_instance;
62
bool force_external;
63
enum Rotation rotation;
64
};
65
66
#endif // AP_COMPASS_LIS3MDL_ENABLED
67
68