-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathBMX160Sensor.h
More file actions
executable file
·60 lines (46 loc) · 1.63 KB
/
Copy pathBMX160Sensor.h
File metadata and controls
executable file
·60 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#ifndef _BMX160_SENSOR_H_
#define _BMX160_SENSOR_H_
#include "MotionSensor.h"
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C
#if !defined(RAK2560) && __has_include(<Rak_BMX160.h>)
#include "Fusion/Fusion.h"
#include <Rak_BMX160.h>
// Numeric IDs for selecting which chip axis maps to world-up (vertical case mounts).
// Set BMX160_UP_AXIS to one of these via build flags (platformio.ini).
#define BMX160_UP_AXIS_PZ 0
#define BMX160_UP_AXIS_PX 1
#define BMX160_UP_AXIS_NX 2
#define BMX160_UP_AXIS_PY 3
#define BMX160_UP_AXIS_NY 4
class BMX160Sensor : public MotionSensor
{
private:
RAK_BMX160 sensor;
bool showingScreen = false;
static constexpr const char *compassCalibrationFileName = "/prefs/compass_bmx160.dat";
float highestX = 0, lowestX = 0, highestY = 0, lowestY = 0, highestZ = 0, lowestZ = 0;
// Per-axis EMA on raw accel + mag: the stateless compass fusion turns dynamic
// acceleration into heading noise, so filtering the inputs steadies rotation.
static constexpr float accelFilterAlpha = 0.15f;
static constexpr float magFilterAlpha = 0.20f;
FusionVector accelFiltered = {{0, 0, 0}};
FusionVector magFiltered = {{0, 0, 0}};
bool filtersSeeded = false;
public:
explicit BMX160Sensor(ScanI2C::FoundDevice foundDevice);
virtual bool init() override;
virtual int32_t runOnce() override;
virtual void calibrate(uint16_t forSeconds) override;
virtual bool providesHeading() const override { return true; }
};
#else
// Stub
class BMX160Sensor : public MotionSensor
{
public:
explicit BMX160Sensor(ScanI2C::FoundDevice foundDevice);
};
#endif
#endif
#endif